OSXOperatingSystem.st
changeset 23954 e28c9c96d726
parent 23314 1f3913819f30
child 24028 cda4ff7bb993
--- a/OSXOperatingSystem.st	Fri Mar 22 13:53:23 2019 +0100
+++ b/OSXOperatingSystem.st	Fri Mar 22 14:44:14 2019 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2013 by Claus Gittinger
 	      All Rights Reserved
@@ -723,10 +721,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
@@ -735,61 +733,82 @@
 
     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);
+        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;
-	    pixels = __BYTEARRAY_UNINITIALIZED_NEW_INT(c_width * c_height * 3);
-	    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 char *pixDstPtr = dstRowPtr;
+            for (row=c_height; row>0; row--) {
+                int col = c_width;
+                unsigned int *pixSrcPtr = (int*)srcRowPtr;
+                unsigned char *pixDstPtr = dstRowPtr;
 
-		// swap abgr to argb
-		for (col=c_width; col>0;col--) {
-		    unsigned int pix = *pixSrcPtr++;
+                // convert abgr to rgb
+#if (__POINTER_SIZE__ == 8) && defined(__LSBFIRST__)
+                for (; col > 2; col -= 2) {
+                    // pick 2 pixels
+                    unsigned INT pix12 = ((unsigned INT*)pixSrcPtr)[0];
+                    pixSrcPtr += 2;
+                    // a2 b2 g2 r2 a1 b1 g1 r1 => r1..g1..b1..r2..g2..b2
+                    pixDstPtr[0] = pix12 & 0xFF;
+                    pixDstPtr[1] = (pix12 >> 8) & 0xFF;
+                    pixDstPtr[2] = (pix12 >> 16) & 0xFF;
+                    pixDstPtr[3] = (pix12 >> 32) & 0xFF;
+                    pixDstPtr[4] = (pix12 >> 40) & 0xFF;
+                    pixDstPtr[5] = (pix12 >> 48) & 0xFF;
+                    pixDstPtr += 6;
+                }
+#endif
 
-		    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);
+                for (; col>0;col--) {
+                    unsigned int pix = *pixSrcPtr++;
+#if 0
+                    pix = ((pix >> 16) & 0x0000FF)|((pix << 16) & 0xFF0000)|(pix & 0x00FF00);
+                    pixDstPtr[0] = (pix >> 0);
+                    pixDstPtr[1] = (pix >> 8);
+                    pixDstPtr[2] = (pix >> 16);
+#else
+                    pixDstPtr[0] = pix & 0xFF;
+                    pixDstPtr[1] = (pix >> 8) & 0xFF;
+                    pixDstPtr[2] = (pix >> 16) & 0xFF;
+#endif
+                    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 );
+        rwidth = __MKUINT( c_width );
+        rheight = __MKUINT( c_height );
     }
 
     // the following is no longer supported by apple
@@ -810,7 +829,7 @@
 
 %}.
     (ok not or:[rwidth isNil]) ifTrue:[
-	^ self primitiveFailed
+        ^ self primitiveFailed
     ].
     depth := bytesPerPixel * 8.
 
@@ -818,22 +837,22 @@
     "/            withAll:{ rwidth . rheight . bytesPerPixel . depth . bytesPerRow}.
 
     ( #(24) includes:depth) ifFalse:[
-	"/ check what we get here...
-	^ self primitiveFailed:'unsupported depth'
+        "/ check what we get here...
+        ^ self primitiveFailed:'unsupported depth'
     ].
 
     img := Image extent:(rwidth @ rheight) depth:depth bits:pixels.
     depth == 24 ifTrue:[
-	img bitsPerSample:#[8 8 8].
-	img samplesPerPixel:3.
-	img photometric:#rgb.
+        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.
-	].
+        depth == 16 ifTrue:[
+            "/ to be determined...
+            img bitsPerSample:#[5 5 5].
+            img samplesPerPixel:3.
+            img photometric:#rgb.
+        ].
     ].
     ^ img
 
@@ -846,6 +865,7 @@
 
     "Created: / 25-02-2017 / 09:49:07 / cg"
     "Modified (comment): / 28-02-2017 / 15:22:17 / cg"
+    "Modified: / 22-03-2019 / 14:44:03 / Claus Gittinger"
 !
 
 getScreenBounds:displayNr