Image.st
branchjv
changeset 7600 8b42a8f0f649
parent 7576 799e0846f5b0
parent 7596 9e63984bd73f
child 7715 925b859e1758
--- a/Image.st	Mon Oct 03 12:49:54 2016 +0100
+++ b/Image.st	Sun Oct 09 22:55:22 2016 +0100
@@ -10210,16 +10210,14 @@
      and especially, the color allocations)."
 
     |yS "{Class: SmallInteger }"
-     yE "{Class: SmallInteger }"
-     yR|
+     yE "{Class: SmallInteger }"|
 
     yS := yStart.
     yE := yEnd.
 
     yS to:yE do:[:yRun |
-        yR := yRun.
         self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
-            aBlock value:xRun value:yR value:color
+            aBlock value:xRun value:yRun value:color
         ]
     ]
 
@@ -13634,9 +13632,9 @@
         numRedBits := bitsPerSample at:1.
         numGreenBits := bitsPerSample at:2.
         numBlueBits := bitsPerSample at:3.
-        (r == 0) ifFalse:[ r := (100 / ((1 bitShift:numRedBits)-1) * r)].
-        (g == 0) ifFalse:[ g := (100 / ((1 bitShift:numGreenBits)-1) * g)].
-        (b == 0) ifFalse:[ b := (100 / ((1 bitShift:numBlueBits)-1) * b)].
+        (r ~~ 0) ifTrue:[ r := 100 / ((1 bitShift:numRedBits) - 1) * r].
+        (g ~~ 0) ifTrue:[ g := 100 / ((1 bitShift:numGreenBits) - 1) * g].
+        (b ~~ 0) ifTrue:[ b := 100 / ((1 bitShift:numBlueBits) - 1) * b].
         ^ Color redPercent:r greenPercent:g bluePercent:b
     ].
 
@@ -13862,6 +13860,10 @@
 
 !
 
+nColorsUsed
+    ^ self realUsedValues size
+!
+
 pixelArraySpecies
     "return the kind of pixel-value container in rowAt:/rowAt:put: methods"
 
@@ -14139,18 +14141,19 @@
                 ^ nil
             ]
         ].
-        "/ code below is slightly faster ...
-        "/ colors := usedValues collect:[:pixel | self colorFromValue:pixel].
-        colors := usedValues collect:[:pixel | |r g b|
-                                        r := self redBitsOf:pixel.
-                                        g := self greenBitsOf:pixel.
-                                        b := self blueBitsOf:pixel.
-                                        "/ must scale to byte value...
-                                        r := r bitShift:(8 - (bitsPerSample at:1)).
-                                        g := g bitShift:(8 - (bitsPerSample at:2)).
-                                        b := b bitShift:(8 - (bitsPerSample at:3)).
-                                        Color redByte:r greenByte:g blueByte:b
-                                     ].
+"/        colors := usedValues collect:[:pixel | self colorFromValue:pixel].
+        "/ this code is slightly faster (but wrong for 16-bit images)...
+        colors := usedValues collect:[:pixel | 
+                    |r g b|
+                    r := self redBitsOf:pixel.
+                    g := self greenBitsOf:pixel.
+                    b := self blueBitsOf:pixel.
+                    "/ must scale to byte value...
+                    r := r bitShift:(8 - (bitsPerSample at:1)).
+                    g := g bitShift:(8 - (bitsPerSample at:2)).
+                    b := b bitShift:(8 - (bitsPerSample at:3)).
+                    Color redByte:r greenByte:g blueByte:b
+                 ].
         ^ colors.
     ].