#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Tue, 28 Feb 2017 15:23:12 +0100
changeset 21598 4eb1335fe937
parent 21597 4af9c6c70126
child 21599 32f9f39dedce
#FEATURE by cg class: OSXOperatingSystem changed: #getFrameBufferImage:in:
OSXOperatingSystem.st
--- a/OSXOperatingSystem.st	Tue Feb 28 15:10:31 2017 +0100
+++ b/OSXOperatingSystem.st	Tue Feb 28 15:23:12 2017 +0100
@@ -611,10 +611,10 @@
     |rx ry rwidth rheight bytesPerPixel bytesPerRow address pixels depth pad img ok|
 
     aRectangleOrNil notNil ifTrue:[
-	rx := aRectangleOrNil left.
-	ry := aRectangleOrNil top.
-	rwidth := aRectangleOrNil width.
-	rheight := aRectangleOrNil height.
+        rx := aRectangleOrNil left.
+        ry := aRectangleOrNil top.
+        rwidth := aRectangleOrNil width.
+        rheight := aRectangleOrNil height.
     ].
 %{
 #ifndef NO_COCOA
@@ -623,59 +623,61 @@
 
     ok = false;
     if (rx == nil) {
-	image_ref  = CGDisplayCreateImage(displayID);
+        image_ref  = CGDisplayCreateImage(displayID);
     } else {
-	CGRect rect;
-	rect.origin.x = (CGFloat)__intVal(rx);
-	rect.origin.y = (CGFloat)__intVal(ry);
-	rect.size.width = (CGFloat)__intVal(rwidth);
-	rect.size.height = (CGFloat)__intVal(rheight);
-	image_ref  = CGDisplayCreateImageForRect(displayID, rect);
+        CGRect rect;
+        rect.origin.x = (CGFloat)__intVal(rx);
+        rect.origin.y = (CGFloat)__intVal(ry);
+        rect.size.width = (CGFloat)__intVal(rwidth);
+        rect.size.height = (CGFloat)__intVal(rheight);
+        image_ref  = CGDisplayCreateImageForRect(displayID, rect);
     }
 
     if (image_ref != NULL) {
-	CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
-	CFDataRef dataref = CGDataProviderCopyData(provider);
-	size_t c_width = CGImageGetWidth(image_ref);
-	size_t c_height = CGImageGetHeight(image_ref);
-	size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref);
-	size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8;
-	unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref);
-
-	pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * c_bytesPerPixel);
+        CGDataProviderRef provider = CGImageGetDataProvider(image_ref);
+        CFDataRef dataref = CGDataProviderCopyData(provider);
+        size_t c_width = CGImageGetWidth(image_ref);
+        size_t c_height = CGImageGetHeight(image_ref);
+        size_t c_bytesPerRow = CGImageGetBytesPerRow(image_ref);
+        size_t c_bytesPerPixel = CGImageGetBitsPerPixel(image_ref) / 8;
+        unsigned char *c_pixels = (unsigned char *)CFDataGetBytePtr(dataref);
 
-	if (c_bytesPerPixel == 4) {
-	    int row;
-	    unsigned char *srcRowPtr = c_pixels;
-	    unsigned char *dstRowPtr = __byteArrayVal(pixels);
+        if (c_bytesPerPixel == 4) {
+            int row;
+            pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * 3);
+            unsigned char *srcRowPtr = c_pixels;
+            unsigned char *dstRowPtr = __byteArrayVal(pixels);
 
-	    for (row=c_height; row>0; row--) {
-		int col;
-		unsigned int *pixSrcPtr = (int*)srcRowPtr;
-		unsigned int *pixDstPtr = (int*)dstRowPtr;
+            for (row=c_height; row>0; row--) {
+                int col;
+                unsigned int *pixSrcPtr = (int*)srcRowPtr;
+                unsigned char *pixDstPtr = dstRowPtr;
 
-		// swap abgr to argb
-		for (col=c_width; col>0;col--) {
-		    unsigned int pix = *pixSrcPtr++;
+                // swap abgr to argb
+                for (col=c_width; col>0;col--) {
+                    unsigned int pix = *pixSrcPtr++;
 
-		    pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00);
-		    *pixDstPtr++ = pix;
-		}
-		dstRowPtr += c_width * c_bytesPerPixel;
-		srcRowPtr += c_bytesPerRow;
-	    }
-	    ok = true;
-	} else {
-	    // to be determined what we get...
-	    ok = false;
-	}
-	CFRelease(dataref);
-	CGImageRelease(image_ref);
+                    pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00);
+                    pixDstPtr[0] = (pix >> 0);
+                    pixDstPtr[1] = (pix >> 8);
+                    pixDstPtr[2] = (pix >> 16);
+                    pixDstPtr += 3;
+                }
+                dstRowPtr += c_width * 3;
+                srcRowPtr += c_bytesPerRow;
+            }
+            bytesPerPixel = __MKSMALLINT(3);
+            bytesPerRow = __MKSMALLINT( c_width*3 );
+            ok = true;
+        } else {
+            // to be determined what we get...
+            ok = false;
+        }
+        CFRelease(dataref);
+        CGImageRelease(image_ref);
 
-	rwidth = __MKUINT( c_width );
-	rheight = __MKUINT( c_height );
-	bytesPerPixel = __MKUINT( c_bytesPerPixel );
-	bytesPerRow = __MKUINT( c_bytesPerRow );
+        rwidth = __MKUINT( c_width );
+        rheight = __MKUINT( c_height );
     }
 
     // the following is no longer supported by apple
@@ -696,32 +698,42 @@
 
 %}.
     (ok not or:[rwidth isNil]) ifTrue:[
-	^ self primitiveFailed
+        ^ self primitiveFailed
     ].
     depth := bytesPerPixel * 8.
 
     "/ Transcript printf:'w:%d h:%d bpp:%d depth:%d bpr: %d\n'
     "/            withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}.
 
-    ( #(16 32) includes:depth) ifFalse:[
-	"/ check what we get here...
-	^ self primitiveFailed:'unsupported depth'
+    ( #(24) includes:depth) ifFalse:[
+        "/ check what we get here...
+        ^ self primitiveFailed:'unsupported depth'
     ].
 
     img := Image extent:(rwidth @ rheight) depth:depth bits:pixels.
-
-    img bitsPerSample:#[8 8 8 8].
-    img samplesPerPixel:4.
-    img photometric:#rgb.
+    depth == 24 ifTrue:[
+        img bitsPerSample:#[8 8 8].
+        img samplesPerPixel:3.
+        img photometric:#rgb.
+    ] ifFalse:[
+        depth == 16 ifTrue:[
+            "/ to be determined...
+            img bitsPerSample:#[5 5 5].
+            img samplesPerPixel:3.
+            img photometric:#rgb.
+        ].    
+    ].    
     ^ img
 
     "
      self getFrameBufferImage:0 in:nil
      self getFrameBufferImage:0 in:(100@100 corner:301@303)
+
+     Delay waitFor:3 seconds. self getFrameBufferImage:0 in:nil
     "
 
     "Created: / 25-02-2017 / 09:49:07 / cg"
-    "Modified: / 27-02-2017 / 02:01:24 / cg"
+    "Modified (comment): / 28-02-2017 / 15:22:17 / cg"
 ! !
 
 !OSXOperatingSystem class methodsFor:'documentation'!
@@ -733,3 +745,4 @@
 version_CVS
     ^ '$Header$'
 ! !
+