609 or part of the framebuffer (if non-nil) as an image object" |
609 or part of the framebuffer (if non-nil) as an image object" |
610 |
610 |
611 |rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok| |
611 |rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok| |
612 |
612 |
613 aRectangleOrNil notNil ifTrue:[ |
613 aRectangleOrNil notNil ifTrue:[ |
614 rx := aRectangleOrNil left. |
614 rx := aRectangleOrNil left. |
615 ry := aRectangleOrNil top. |
615 ry := aRectangleOrNil top. |
616 rwidth := aRectangleOrNil width. |
616 rwidth := aRectangleOrNil width. |
617 rheight := aRectangleOrNil height. |
617 rheight := aRectangleOrNil height. |
618 ]. |
618 ]. |
619 %{ |
619 %{ |
620 #ifndef NO_COCOA |
620 #ifndef NO_COCOA |
621 CGImageRef image_ref; |
621 CGImageRef image_ref; |
622 CGDirectDisplayID displayID = CGMainDisplayID(); |
622 CGDirectDisplayID displayID = CGMainDisplayID(); |
623 |
623 |
624 ok = false; |
624 ok = false; |
625 if (rx == nil) { |
625 if (rx == nil) { |
626 image_ref = CGDisplayCreateImage(displayID); |
626 image_ref = CGDisplayCreateImage(displayID); |
627 } else { |
627 } else { |
628 CGRect rect; |
628 CGRect rect; |
629 rect.origin.x = (CGFloat)__intVal(rx); |
629 rect.origin.x = (CGFloat)__intVal(rx); |
630 rect.origin.y = (CGFloat)__intVal(ry); |
630 rect.origin.y = (CGFloat)__intVal(ry); |
631 rect.size.width = (CGFloat)__intVal(rwidth); |
631 rect.size.width = (CGFloat)__intVal(rwidth); |
632 rect.size.height = (CGFloat)__intVal(rheight); |
632 rect.size.height = (CGFloat)__intVal(rheight); |
633 image_ref = CGDisplayCreateImageForRect(displayID, rect); |
633 image_ref = CGDisplayCreateImageForRect(displayID, rect); |
634 } |
634 } |
635 |
635 |
636 if (image_ref != NULL) { |
636 if (image_ref != NULL) { |
637 CGDataProviderRef provider = CGImageGetDataProvider(image_ref); |
637 CGDataProviderRef provider = CGImageGetDataProvider(image_ref); |
638 CFDataRef dataref = CGDataProviderCopyData(provider); |
638 CFDataRef dataref = CGDataProviderCopyData(provider); |
639 size_t c_width = CGImageGetWidth(image_ref); |
639 size_t c_width = CGImageGetWidth(image_ref); |
640 size_t c_height = CGImageGetHeight(image_ref); |
640 size_t c_height = CGImageGetHeight(image_ref); |
641 size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref); |
641 size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref); |
642 size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8; |
642 size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8; |
643 unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref); |
643 unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref); |
644 |
644 |
645 pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * c_bytesPerPixel); |
645 if (c_bytesPerPixel == 4) { |
646 |
646 int row; |
647 if (c_bytesPerPixel == 4) { |
647 pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * 3); |
648 int row; |
648 unsigned char *srcRowPtr = c_pixels; |
649 unsigned char *srcRowPtr = c_pixels; |
649 unsigned char *dstRowPtr = __byteArrayVal(pixels); |
650 unsigned char *dstRowPtr = __byteArrayVal(pixels); |
650 |
651 |
651 for (row=c_height; row>0; row--) { |
652 for (row=c_height; row>0; row--) { |
652 int col; |
653 int col; |
653 unsigned int *pixSrcPtr = (int*)srcRowPtr; |
654 unsigned int *pixSrcPtr = (int*)srcRowPtr; |
654 unsigned char *pixDstPtr = dstRowPtr; |
655 unsigned int *pixDstPtr = (int*)dstRowPtr; |
655 |
656 |
656 // swap abgr to argb |
657 // swap abgr to argb |
657 for (col=c_width; col>0;col--) { |
658 for (col=c_width; col>0;col--) { |
658 unsigned int pix = *pixSrcPtr++; |
659 unsigned int pix = *pixSrcPtr++; |
659 |
660 |
660 pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00); |
661 pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00); |
661 pixDstPtr[0] = (pix >> 0); |
662 *pixDstPtr++ = pix; |
662 pixDstPtr[1] = (pix >> 8); |
663 } |
663 pixDstPtr[2] = (pix >> 16); |
664 dstRowPtr += c_width * c_bytesPerPixel; |
664 pixDstPtr += 3; |
665 srcRowPtr += c_bytesPerRow; |
665 } |
666 } |
666 dstRowPtr += c_width * 3; |
667 ok = true; |
667 srcRowPtr += c_bytesPerRow; |
668 } else { |
668 } |
669 // to be determined what we get... |
669 bytesPerPixel = __MKSMALLINT(3); |
670 ok = false; |
670 bytesPerRow = __MKSMALLINT( c_width*3 ); |
671 } |
671 ok = true; |
672 CFRelease(dataref); |
672 } else { |
673 CGImageRelease(image_ref); |
673 // to be determined what we get... |
674 |
674 ok = false; |
675 rwidth = __MKUINT( c_width ); |
675 } |
676 rheight = __MKUINT( c_height ); |
676 CFRelease(dataref); |
677 bytesPerPixel = __MKUINT( c_bytesPerPixel ); |
677 CGImageRelease(image_ref); |
678 bytesPerRow = __MKUINT( c_bytesPerRow ); |
678 |
|
679 rwidth = __MKUINT( c_width ); |
|
680 rheight = __MKUINT( c_height ); |
679 } |
681 } |
680 |
682 |
681 // the following is no longer supported by apple |
683 // the following is no longer supported by apple |
682 // CGDisplayBaseAddress is deprecated |
684 // CGDisplayBaseAddress is deprecated |
683 // |
685 // |
694 |
696 |
695 #endif // NO_COCOA |
697 #endif // NO_COCOA |
696 |
698 |
697 %}. |
699 %}. |
698 (ok not or:[rwidth isNil]) ifTrue:[ |
700 (ok not or:[rwidth isNil]) ifTrue:[ |
699 ^ self primitiveFailed |
701 ^ self primitiveFailed |
700 ]. |
702 ]. |
701 depth := bytesPerPixel * 8. |
703 depth := bytesPerPixel * 8. |
702 |
704 |
703 "/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n' |
705 "/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n' |
704 "/ withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}. |
706 "/ withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}. |
705 |
707 |
706 ( #(16 32) includes:depth) ifFalse:[ |
708 ( #(24) includes:depth) ifFalse:[ |
707 "/ check what we get here... |
709 "/ check what we get here... |
708 ^ self primitiveFailed:'unsupported depth' |
710 ^ self primitiveFailed:'unsupported depth' |
709 ]. |
711 ]. |
710 |
712 |
711 img := Image extent:(rwidth @ rheight) depth:depth bits:pixels. |
713 img := Image extent:(rwidth @ rheight) depth:depth bits:pixels. |
712 |
714 depth == 24 ifTrue:[ |
713 img bitsPerSample:#[8 8 8 8]. |
715 img bitsPerSample:#[8 8 8]. |
714 img samplesPerPixel:4. |
716 img samplesPerPixel:3. |
715 img photometric:#rgb. |
717 img photometric:#rgb. |
|
718 ] ifFalse:[ |
|
719 depth == 16 ifTrue:[ |
|
720 "/ to be determined... |
|
721 img bitsPerSample:#[5 5 5]. |
|
722 img samplesPerPixel:3. |
|
723 img photometric:#rgb. |
|
724 ]. |
|
725 ]. |
716 ^ img |
726 ^ img |
717 |
727 |
718 " |
728 " |
719 self getFrameBufferImage:0 in:nil |
729 self getFrameBufferImage:0 in:nil |
720 self getFrameBufferImage:0 in:(100@100 corner:301@303) |
730 self getFrameBufferImage:0 in:(100@100 corner:301@303) |
|
731 |
|
732 Delay waitFor:3 seconds. self getFrameBufferImage:0 in:nil |
721 " |
733 " |
722 |
734 |
723 "Created: / 25-02-2017 / 09:49:07 / cg" |
735 "Created: / 25-02-2017 / 09:49:07 / cg" |
724 "Modified: / 27-02-2017 / 02:01:24 / cg" |
736 "Modified (comment): / 28-02-2017 / 15:22:17 / cg" |
725 ! ! |
737 ! ! |
726 |
738 |
727 !OSXOperatingSystem class methodsFor:'documentation'! |
739 !OSXOperatingSystem class methodsFor:'documentation'! |
728 |
740 |
729 version |
741 version |