#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Thu, 16 Jan 2020 12:41:02 +0100
changeset 3830 bf667c58b12e
parent 3829 7a5b398e1316
child 3831 669f318049d2
#BUGFIX by cg class: ImageEditor changed: #colorMapMode:
ImageEditor.st
--- a/ImageEditor.st	Wed Dec 18 19:07:20 2019 +0100
+++ b/ImageEditor.st	Thu Jan 16 12:41:02 2020 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1997-1998 by eXept Software AG
               All Rights Reserved
@@ -5843,8 +5841,8 @@
         resourceSelector notNil ifTrue:[
             ^ resources 
                     string:(self modified 
-                            ifTrue:['ImageEditor (modified): %1 » %2']
-                            ifFalse:['ImageEditor: %1 » %2'])
+                            ifTrue:['ImageEditor (modified): %1 » %2']
+                            ifFalse:['ImageEditor: %1 » %2'])
                     with:resourceClass name
                     with:resourceSelector
         ].
@@ -5877,8 +5875,8 @@
         resourceSelector notNil ifTrue:[
             ^ resources 
                     string:(self modified 
-                            ifTrue:['Image (modified) from: %1 » %2']
-                            ifFalse:['Image from: %1 » %2'])
+                            ifTrue:['Image (modified) from: %1 » %2']
+                            ifFalse:['Image from: %1 » %2'])
                     with:resourceClass name
                     with:resourceSelector
         ].
@@ -7019,7 +7017,7 @@
     |depth numColors newColorMap newImage 
      oldImage image newColors realColorMap oldFileName
      usedColors useNearest usageCounts tmpBits tmpMap quest
-     prevMode maskThreshold maskImage| 
+     prevMode maskThreshold maskImage oldColors| 
 
     oldImage := self image.
 
@@ -7110,8 +7108,13 @@
                         ].
                         usageCounts := tmpBits usageCounts.
                         tmpMap := Array new:usageCounts size.
-                        oldImage colorMap asArray keysAndValuesDo:[:i :clr |
-                            tmpMap at:i put:clr
+                        oldColors := oldImage colorMap asArray.
+                        "/ sigh: there seem to be images around where the cmap has more entries
+                        "/ than expected (i.e. 257 colors in an 8 bit image)
+                        oldColors keysAndValuesDo:[:i :clr |
+                            i <= tmpMap size ifTrue:[
+                                tmpMap at:i put:clr
+                            ]
                         ].
                         usageCounts sort:[:a :b | a > b] with:tmpMap.