Image.st
changeset 8113 163bbebc807f
parent 8111 c20fb44519e3
child 8115 6b4a08f7e951
--- a/Image.st	Sun Aug 27 20:00:28 2017 +0200
+++ b/Image.st	Sun Aug 27 21:36:00 2017 +0200
@@ -4111,6 +4111,57 @@
 
 !Image methodsFor:'converting'!
 
+anyImageAsTrueColorFormOn:aDevice
+    "general fallback to return a true-color device-form for the receiver."
+
+    |form bestFormat usedDeviceDepth usedDeviceBitsPerPixel
+     pixelValue "{ Class: SmallInteger }"
+     h          "{ Class: SmallInteger }"
+     w          "{ Class: SmallInteger }"
+     pixelArray newPixelArray i rgbValue|
+
+    bestFormat := self bestSupportedImageFormatFor:aDevice.
+    usedDeviceDepth := bestFormat at:#depth.
+    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
+
+    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
+    i width:width height:height.
+    i createPixelStore.
+
+    "/ now, walk over the image and replace each pixel
+    h := height - 1.
+    w := width - 1.
+    pixelArray := self pixelArraySpecies new:width.
+    newPixelArray := i pixelArraySpecies new:width.
+
+    0 to:h do:[:y |
+        self rowAt:y into:pixelArray.
+        0 to:w do:[:x |
+            pixelValue := pixelArray at:(x+1).
+            rgbValue := self rgbFromValue:pixelValue.
+            newPixelArray at:(x+1) put:rgbValue.
+        ].
+        i rowAt:y putAll:newPixelArray.
+    ].
+
+    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
+    form isNil ifTrue:[^ nil].
+    form initGC.
+
+    form
+        copyBitsFrom:i bits
+        bitsPerPixel:usedDeviceBitsPerPixel
+        depth:usedDeviceDepth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        toX:0 y:0.
+
+    ^ form
+
+    "Created: / 27-08-2017 / 21:06:14 / cg"
+!
+
 asFormOn:aDevice
     "get a device form, with best possible approximation.
      remember it in case someone asks again."
@@ -13678,11 +13729,10 @@
     |redBits greenBits blueBits alphaBits alphaMask|
 
     samplesPerPixel >= 4 ifTrue:[
-        alphaMask := (1 bitShift:alphaBits)-1.
-        
         photometric == #rgba ifTrue:[
             "/ alpha in low bits
             alphaBits := bitsPerSample at:4.
+            alphaMask := (1 bitShift:alphaBits)-1.
 
             ^ pixel bitAnd:alphaMask
         ].
@@ -13692,6 +13742,7 @@
             greenBits := bitsPerSample at:2.
             blueBits := bitsPerSample at:3.
             alphaBits := bitsPerSample at:4.
+            alphaMask := (1 bitShift:alphaBits)-1.
 
             ^ (pixel rightShift:(redBits + greenBits + blueBits))
                     bitAnd:alphaMask
@@ -13702,7 +13753,7 @@
     self subclassResponsibility
 
     "Created: / 08-06-1996 / 09:44:51 / cg"
-    "Modified: / 25-08-2017 / 12:24:21 / cg"
+    "Modified: / 27-08-2017 / 21:29:46 / cg"
 !
 
 alphaMaskForPixelValue