#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Sat, 26 Aug 2017 13:46:02 +0200
changeset 8108 273966fa18c8
parent 8107 154acb64bf45
child 8109 017a2867ba53
#BUGFIX by cg class: Image changed: #valueFromRGB: rgb order fixed
Image.st
--- a/Image.st	Fri Aug 25 18:03:59 2017 +0200
+++ b/Image.st	Sat Aug 26 13:46:02 2017 +0200
@@ -14780,51 +14780,28 @@
 !
 
 valueFromRGB:rgb
-    "given a color, return the corresponding pixel value.
+    "given a color as rgb-value, with 8 bits per component, 
+     return the corresponding pixel value.
+     The red component is in the high 8 bits.
      Non-representable colors return nil."
 
     |pixel redBits greenBits blueBits alphaBits r g b a|
 
-    r := rgb bitAnd:16rFF.
+    b := rgb bitAnd:16rFF.
     g := (rgb bitShift:-8) bitAnd:16rFF.
-    b := (rgb bitShift:-16) bitAnd:16rFF.
+    r := (rgb bitShift:-16) bitAnd:16rFF.
     a := 255.
 
-"/    photometric == #whiteIs0 ifTrue:[
-"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
-"/        ^ maxPixel - (color brightness * maxPixel) rounded.
-"/    ].
-
-"/    photometric == #blackIs0 ifTrue:[
-"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
-"/        ^ (color brightness * maxPixel) rounded.
-"/    ].
-"/
-"/    photometric == #palette ifTrue:[
-"/        colorMap isNil ifTrue:[
-"/            "/ same as blackIs0
-"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
-"/            ^ (color brightness * maxPixel) rounded.
-"/        ].
-"/
-"/        pixel := colorMap indexOf:color.
-"/        pixel == 0 ifTrue:[
-"/            "
-"/             the color is not in the images colormap
-"/            "
-"/            ^ nil
-"/        ].
-"/        ^ pixel - 1
-"/    ].
-
     photometric == #rgb ifTrue:[
         samplesPerPixel >= 3 ifTrue:[
             "/ r,g,b  b at low end
             redBits := bitsPerSample at:1.
             greenBits := bitsPerSample at:2.
             blueBits := bitsPerSample at:3.
-            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
-            ^ pixel
+            ((redBits == 8) and:[(greenBits == 8) and:[(blueBits == 8) ]]) ifTrue:[
+                pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
+                ^ pixel
+            ]
         ]
     ].
 
@@ -14835,8 +14812,10 @@
             redBits := bitsPerSample at:2.
             greenBits := bitsPerSample at:3.
             blueBits := bitsPerSample at:4.
-            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
-            ^ pixel
+            ((redBits == 8) and:[(greenBits == 8) and:[(blueBits == 8) ]]) ifTrue:[
+                pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
+                ^ pixel
+            ]
         ]
     ].
     photometric == #rgba ifTrue:[
@@ -14846,16 +14825,36 @@
             greenBits := bitsPerSample at:2.
             blueBits := bitsPerSample at:3.
             alphaBits := bitsPerSample at:4.
-            pixel := (((((r bitShift:greenBits) + g) bitShift:blueBits) + b) bitShift:alphaBits) + a.
+            ((redBits == 8) and:[(greenBits == 8) and:[(blueBits == 8) ]]) ifTrue:[
+                pixel := (((((r bitShift:greenBits) + g) bitShift:blueBits) + b) bitShift:alphaBits) + a.
+            ].
             ^ pixel
         ]
     ].
+    
+    photometric == #palette ifTrue:[
+        colorMap notNil ifTrue:[
+            pixel := colorMap indexOf:(Color rgbValue:rgb).
+            pixel == 0 ifTrue:[
+                "/ the color is not in the image's colormap
+                ^ nil
+            ].    
+            ^ pixel - 1
+        ].
+    ].
+
     ImageErrorSignal raiseErrorString:'format not supported'.
     ^ nil
 
+    "
+     |img|
+     img := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
+     img valueFromRGB:16r55AAFF.
+    "
+
     "Created: / 15-01-2008 / 15:55:08 / cg"
     "Modified: / 31-01-2017 / 14:45:00 / stefan"
-    "Modified: / 22-08-2017 / 16:56:42 / cg"
+    "Modified (comment): / 26-08-2017 / 13:07:56 / cg"
 !
 
 valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits