ImageEditView.st
changeset 2566 d0894c5f6d4d
parent 2556 fc4dd338dee5
child 2582 5f9a25414195
--- a/ImageEditView.st	Thu Sep 04 20:39:10 2003 +0200
+++ b/ImageEditView.st	Mon Sep 08 14:11:36 2003 +0200
@@ -887,52 +887,68 @@
 !
 
 makeNewColorMapByMapping:functionOfColor
-    |xMax yMax clr pix map revMap n_clr n_pix anyChange
-     newColors newColorArray newImage|
-
-    image colorMap isNil ifTrue:[
-        self error:'image has no colormap'.
-        ^ false
-    ].
+    |xMax yMax map revMap anyChange
+     newColors newColorArray newImage pixelAction|
 
     anyChange := false.
 
     xMax := image width - 1.
     yMax := image height - 1.
 
-    newColors := Set new.
-    newColorArray := OrderedCollection new.
-    map := Array new:256.
-    revMap := OrderedCollection new.
-
     newImage := image class width:image width height:image height depth:image depth.
     newImage photometric:image photometric.
     "/ newImage colorMap:(image colorMap copy).
     newImage bits:(ByteArray new:(image bits size)).
     newImage mask:(image mask copy).
 
-    0 to:yMax do:[:y |
-        0 to:xMax do:[:x |
-            pix := image pixelAtX:x y:y.
-            (n_pix := map at:pix+1) isNil ifTrue:[
+    image colorMap notNil ifTrue:[
+        newColors := Set new.
+        newColorArray := OrderedCollection new.
+        map := Array new:256.
+        revMap := OrderedCollection new.
+
+        pixelAction := 
+            [:x :y |
+                |pix n_pix clr n_clr|
+
+                pix := image pixelAtX:x y:y.
+                (n_pix := map at:pix+1) isNil ifTrue:[
+                    clr := image colorAtX:x y:y.
+                    n_clr := functionOfColor value:clr.
+                    (newColors includes:n_clr) ifFalse:[
+                        newColors add:n_clr.
+                        newColorArray add:n_clr.
+                        revMap add:pix.
+                        map at:pix+1 put:(n_pix := revMap size - 1).
+                    ] ifTrue:[
+                        "/ mhmh - multiple pixels mapped to the same color
+                        n_pix := (newColorArray indexOf:n_clr) - 1.
+                        map at:pix+1 put:n_pix.
+                    ]
+                ].
+                newImage pixelAtX:x y:y put:n_pix.
+            ].
+    ] ifFalse:[
+        pixelAction := 
+            [:x :y |
+
+                |clr n_clr|
+
                 clr := image colorAtX:x y:y.
                 n_clr := functionOfColor value:clr.
-                (newColors includes:n_clr) ifFalse:[
-                    newColors add:n_clr.
-                    newColorArray add:n_clr.
-                    revMap add:pix.
-                    map at:pix+1 put:(n_pix := revMap size - 1).
-                ] ifTrue:[
-                    "/ mhmh - multiple pixels mapped to the same color
-                    n_pix := (newColorArray indexOf:n_clr) - 1.
-                    map at:pix+1 put:n_pix.
-                ]
+                newImage colorAtX:x y:y put:n_clr.
             ].
-            newImage pixelAtX:x y:y put:n_pix.
+    ].
+
+    0 to:yMax do:[:y |
+        0 to:xMax do:[:x |
+            pixelAction value:x value:y
         ]
     ].
 
-    newImage colorMap:(MappedPalette withColors:newColorArray).
+    image colorMap notNil ifTrue:[
+        newImage colorMap:(MappedPalette withColors:newColorArray).
+    ].
     self makeUndo.
     self image:newImage.
     ^ true
@@ -2238,7 +2254,7 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.187 2003-08-20 12:07:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.188 2003-09-08 12:11:36 cg Exp $'
 ! !
 
 ImageEditView initialize!