*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Wed, 17 Dec 2008 14:18:33 +0100
changeset 2447 017ac2e500f7
parent 2446 862717a7ca0f
child 2448 eec01c02868e
*** empty log message ***
ImageEditor.st
--- a/ImageEditor.st	Tue Dec 16 19:44:42 2008 +0100
+++ b/ImageEditor.st	Wed Dec 17 14:18:33 2008 +0100
@@ -3189,10 +3189,9 @@
     colorMapModeKey := colorMapModeKey , image depth printString.
     self colorMapMode setValue:colorMapModeKey.
 
-    newListOfColors := OrderedCollection withAll:(self listOfColors).
 
     image depth > 12 ifTrue:[
-        newListOfColors removeAll.
+        newListOfColors := OrderedCollection new.
         image colorMap isEmptyOrNil ifTrue:[
             someOrAllUsedColors := image usedColorsMax:10000.
             someOrAllUsedColors notNil ifTrue:[
@@ -3205,6 +3204,7 @@
             newListOfColors addAll:(image colorMap).
         ].
     ] ifFalse:[
+        newListOfColors := OrderedCollection withAll:(self listOfColors).
         newListOfColors isEmpty ifTrue:[   
             self colorMapMode: colorMapMode value.
             image := self image.
@@ -3227,8 +3227,9 @@
 "/            setValue: 0;
 "/            value: (listOfColors indexOf: imageEditView selectedColor).
     ].
-    self listOfColors contents:newListOfColors.
-
+    self listOfColors asOrderedCollection ~= newListOfColors ifTrue:[
+        self listOfColors contents:newListOfColors.
+    ].
     "Modified: / 07-07-2006 / 12:27:43 / cg"
 !
 
@@ -3395,23 +3396,25 @@
         self listOfColors removeAll.
     ] ifFalse:[
         colorMap := image colorMap.
-        colorMap size <= 4096 ifTrue:[
-            image mask notNil ifTrue:[
-                colorMap := (Array with:(Color noColor)),colorMap.
-            ].
-            self listOfColors contents:colorMap.
-        ] ifFalse:[
-            self listOfColors removeAll.
-            colorMap isFixedPalette ifTrue:[
-                image colorMap:nil.
-                image photometric:#rgb.
-                image samplesPerPixel:3.
-                
-                image bitsPerSample:(Array 
-                                        with:(colorMap bitsRed)
-                                        with:(colorMap bitsGreen)
-                                        with:(colorMap bitsBlue)).
-            ].
+        colorMap notNil ifTrue:[
+            (colorMap size <= 4096) ifTrue:[
+                image mask notNil ifTrue:[
+                    colorMap := (Array with:(Color noColor)),colorMap.
+                ].
+                self listOfColors contents:colorMap.
+            ] ifFalse:[
+                self listOfColors removeAll.
+                colorMap isFixedPalette ifTrue:[
+                    image colorMap:nil.
+                    image photometric:#rgb.
+                    image samplesPerPixel:3.
+                    
+                    image bitsPerSample:(Array 
+                                            with:(colorMap bitsRed)
+                                            with:(colorMap bitsGreen)
+                                            with:(colorMap bitsBlue)).
+                ].
+            ]
         ].
     ].
     self findColorMapMode.
@@ -3869,6 +3872,7 @@
     |clr pixel|
 
     selectedColorIndex := anIndex.
+    anIndex isNil ifTrue:[^ self].
     clr := self listOfColors at:anIndex ifAbsent:nil.
     clr isNil ifTrue:[^ self].
 
@@ -3882,7 +3886,6 @@
     ].
     imageEditView selectedColorIndex:pixel.
     imageEditView selectedColor:clr.
-
 ! !
 
 !ImageEditor methodsFor:'startup & release'!
@@ -4957,12 +4960,20 @@
             ]
         ] ifFalse:[
             (img := self image) notNil ifTrue:[
-                (cMap := img colorMap) notNil ifTrue:[
+                (cMap := self listOfColors) notNil ifTrue:[
                     idx := cMap indexOf:aColor ifAbsent:nil.
-                    img mask notNil ifTrue:[
-                        idx := idx + 1.
+                ].
+                idx isNil ifTrue:[
+                    "/ should not happen...
+                    (cMap := img colorMap) notNil ifTrue:[
+                        idx := cMap indexOf:aColor ifAbsent:nil.
+                        idx notNil ifTrue:[
+                            img mask notNil ifTrue:[
+                                idx := idx + 1.
+                            ].
+                        ]
                     ].
-                ]
+                ].
             ].
         ].
     ].
@@ -4987,7 +4998,7 @@
 !
 
 selectedColorOrNil
-    |cmapIndex img cMap|
+    |cmapIndex img cMap colorList|
 
     cmapIndex := self selectedColorIndexOrNil.
     cmapIndex isNil ifTrue:[^ nil].
@@ -4995,7 +5006,11 @@
     img := self image.
     cMap := img colorMap.
     cMap isNil ifTrue:[
-        self warn:(resources stringWithCRs:'Image has no colormap.\Please change the colorMap mode first.').
+        "/ self warn:(resources stringWithCRs:'Image has no colormap.\Please change the colorMap mode first.').
+        colorList := self listOfColors.
+        colorList notNil ifTrue:[
+            ^ colorList at:cmapIndex ifAbsent:nil
+        ].
         ^ nil
     ].
     ^ cMap at:cmapIndex.