Image.st
changeset 8524 d5cb3cda12b2
parent 8523 81d5dfb99b62
child 8663 b24e56c97483
--- a/Image.st	Thu Oct 18 10:38:08 2018 +0200
+++ b/Image.st	Mon Oct 22 09:48:03 2018 +0200
@@ -2515,11 +2515,7 @@
                                                     with:aRectangle top
                                                     with:aRectangle width
                                                     with:aRectangle height).
-                [
-                    img := Image fromFile:tmpFile.
-                ] ensure:[
-                    tmpFile remove.
-                ].
+                img := [Image fromFile:tmpFile] ensure:[tmpFile remove].
             ].
         ].
         ^ img
@@ -2548,6 +2544,7 @@
 
     "Modified: / 30-01-2017 / 19:49:01 / stefan"
     "Modified (comment): / 26-02-2017 / 18:24:41 / cg"
+    "Modified: / 19-10-2018 / 16:10:41 / Stefan Vogel"
 !
 
 fromScreenArea
@@ -4262,7 +4259,7 @@
     visual := aDevice visualType.
     
     (aDevice depth == 1
-    or:[aDevice hasGrayscales not]) ifTrue:[
+     or:[aDevice hasGrayscales not]) ifTrue:[
         form := self asMonochromeFormOn:aDevice.
     ] ifFalse:[
         (visual == #StaticGray) ifTrue:[
@@ -4275,53 +4272,38 @@
     ].
 
     form isNil ifTrue:[
-        "/ kludge: repair a 'should not happen' situation...
-        photometric isNil ifTrue:[ self repairPhotometric ].
-
+        photometric isNil ifTrue:[ 
+            "/ kludge: repair a 'should not happen' situation...
+            self repairPhotometric 
+        ].
         (photometric == #palette) ifTrue:[
             form := self paletteImageAsFormOn:aDevice
         ] ifFalse:[
-            (photometric == #rgb or:[photometric == #rgba or:[photometric == #argb]]) ifTrue:[
-                form := self rgbImageAsFormOn:aDevice
-            ] ifFalse:[
-                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
-                    form := self rgbImageAsFormOn:aDevice
-                ] ifFalse:[
-                    (photometric == #blackIs0 or:[photometric == #whiteIs0]) ifTrue:[
-                        form := self rgbImageAsFormOn:aDevice
-                    ] ifFalse:[
-                        "/ other encodings (cmy, for example)
-                        "/ calls a slow fallback (which usually enumerates each pixel)
-                        form := self rgbImageAsFormOn:aDevice
-                    ]
-                ]
-            ]
-        ].
-    ].
-
-    (device isNil or:[aDevice == device]) ifTrue:[
+            "#(rgb rgba argb cmy cmyk blackIs0 whiteIs0) includes:photometric and any other"
+            form := self rgbImageAsFormOn:aDevice
+        ].
+    ].
+
+    (form notNil and:[device isNil or:[aDevice == device]]) ifTrue:[
         "remember this form in the receiver ..."
-
-        form notNil ifTrue:[
-            form := form asImageForm.
-            deviceForm := form.
-            maskedPixelsAre0 := nil.
-            device isNil ifTrue:[
-                device := aDevice.
-                Lobby register:self
-            ] ifFalse:[
-                Lobby registerChange:self
-            ].
-            mask notNil ifTrue:[
-                self clearMaskedPixels.
-            ].
-
-            "
-             can save space, by not keeping the images data-bits
-             twice (here and in the device form)
-            "
-            form forgetBits
-        ]
+        form := form asImageForm.
+        deviceForm := form.
+        maskedPixelsAre0 := nil.
+        device isNil ifTrue:[
+            device := aDevice.
+            Lobby register:self
+        ] ifFalse:[
+            Lobby registerChange:self
+        ].
+        mask notNil ifTrue:[
+            self clearMaskedPixels.
+        ].
+
+        "
+         can save space, by not keeping the images data-bits
+         twice (here and in the device form)
+        "
+        form forgetBits
     ].
 
     ^ form
@@ -4334,6 +4316,7 @@
     "
 
     "Modified: / 25-08-2017 / 09:41:22 / cg"
+    "Modified (format): / 19-10-2018 / 16:23:17 / Stefan Vogel"
 !
 
 asGrayFormOn:aDevice
@@ -6481,10 +6464,7 @@
 anyImageAsFormOn:aDevice
     "return a (usually truecolor) deviceForm from an arbitrary image."
 
-    |nPlanes|
-
-    nPlanes := samplesPerPixel.
-    (nPlanes == 2) ifTrue:[
+    (samplesPerPixel == 2) ifTrue:[
         'Image [info]: alpha plane ignored' infoPrintCR.
     ].
 
@@ -6497,6 +6477,15 @@
     ^ self anyImageAsPseudoFormOn:aDevice
 
     "Created: / 25-08-2017 / 09:31:17 / cg"
+    "Modified: / 19-10-2018 / 16:01:01 / Stefan Vogel"
+!
+
+anyImageAsPseudoFormOn:aDevice
+    "return a (usually truecolor) deviceForm from an arbitrary image."
+
+    ^ self subclassResponsibility.
+
+    "Created: / 19-10-2018 / 16:02:16 / Stefan Vogel"
 !
 
 greyImageAsFormOn:aDevice
@@ -10628,7 +10617,7 @@
         
         almostSamePixel := 
             [:pixelValue |
-                |same pixelColor pixelHue pixelLight errHue errLight|
+                |same pixelColor pixelHue pixelLight|
 
                 (same := (pixelColor == detectedPixel)) ifFalse:[
                     pixelColor := self colorFromValue:pixelValue.
@@ -10715,6 +10704,7 @@
     ^ allDetectedPixelCoordinates
 
     "Created: / 17-02-2017 / 15:03:33 / cg"
+    "Modified (format): / 19-10-2018 / 16:24:27 / Stefan Vogel"
 !
 
 rectangle: aRectangle withColor:aColor
@@ -12446,7 +12436,7 @@
                 srcCol := col / mX.
                 srcCol-rX to:srcCol+rX do:[:srcX |
                     srcRow-rY to:srcRow+rY do:[:srcY |
-                        |pX pY d weight rgb "{ Class: SmallInteger }"|
+                        |pX pY weight rgb "{ Class: SmallInteger }"|
                         pX := (srcX rounded max:0) min:width-1.
                         pY := (srcY rounded max:0) min:height-1.
                         rgb := self rgbValueAtX:pX y:pY.
@@ -12550,6 +12540,7 @@
     "
 
     "Created: / 30-08-2017 / 15:01:53 / cg"
+    "Modified (format): / 19-10-2018 / 16:25:17 / Stefan Vogel"
 !
 
 lightened
@@ -13135,13 +13126,13 @@
      If anything fails, return nil."
 
     |xMax yMax r g b nR nG nB clr pix map revMap n_clr n_pix mask anyChange
-     newColors newColorArray newImage extMask extBits newPixelValue|
+     newColors newColorArray newImage newPixelValue|
 
     numBits > 7 ifTrue:[
         ^ nil
     ].
     mask := (16rFF bitShift:numBits) bitAnd:16rFF. "/ has 0 in numBits low bits
-    extMask := (1 bitShift:numBits)-1.             "/ has 1 in numBits low bits
+"/    extMask := (1 bitShift:numBits)-1.             "/ has 1 in numBits low bits
 
     anyChange := false.
 
@@ -13199,9 +13190,9 @@
                     r := clr redByte.
                     g := clr greenByte.
                     b := clr blueByte.
-                    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
-                    nG := g bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
-                    nB := b bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
+                    nR := r bitAnd:mask. "/(nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
+                    nG := g bitAnd:mask. "/(nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
+                    nB := b bitAnd:mask. "/(nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
                     n_clr := Color redByte:nR greenByte:nG blueByte:nB.
                     (newColors includes:n_clr) ifFalse:[
                         newColors add:n_clr.
@@ -13230,6 +13221,7 @@
 
     "Modified: / 30-01-2017 / 20:15:02 / stefan"
     "Modified: / 06-08-2018 / 00:59:27 / Claus Gittinger"
+    "Modified: / 19-10-2018 / 16:29:09 / Stefan Vogel"
 !
 
 withPixelFunctionApplied:pixelFunctionBlock
@@ -15030,13 +15022,14 @@
             alphaBits := self numAlphaBits.
             (pixel rightShift:(blueBits + alphaBits)) bitAnd:greenMask.   
         ].
-        ^ (pixel bitShift:blueBits negated) bitAnd:greenMask
+        ^ (pixel rightShift:blueBits) bitAnd:greenMask
     ].
 
     self subclassResponsibility
 
     "Created: / 08-06-1996 / 09:44:37 / cg"
     "Modified: / 25-08-2017 / 12:23:29 / cg"
+    "Modified: / 19-10-2018 / 16:34:02 / Stefan Vogel"
 !
 
 greenComponentOf:pixel
@@ -15363,13 +15356,14 @@
             alphaBits := self numAlphaBits.
             ^ (pixel rightShift:(greenBits+blueBits+alphaBits)) bitAnd:redMask.
         ].
-        ^ (pixel bitShift:(greenBits+blueBits) negated) bitAnd:redMask.
+        ^ (pixel rightShift:(greenBits+blueBits)) bitAnd:redMask.
     ].
 
     self subclassResponsibility
 
     "Created: / 08-06-1996 / 09:44:51 / cg"
     "Modified: / 25-08-2017 / 12:24:40 / cg"
+    "Modified: / 19-10-2018 / 16:34:26 / Stefan Vogel"
 !
 
 redComponentOf:pixel