colorreduction code moved to image
authorClaus Gittinger <cg@exept.de>
Wed, 02 Jul 2003 17:22:17 +0200
changeset 2534 39f2ebf77c40
parent 2533 93463469dba8
child 2535 4df3f0a09b83
colorreduction code moved to image
ImageEditView.st
--- a/ImageEditView.st	Tue Jul 01 16:37:58 2003 +0200
+++ b/ImageEditView.st	Wed Jul 02 17:22:17 2003 +0200
@@ -1323,98 +1323,16 @@
 !
 
 reduceColorResolutionBy:numBits
-    |xMax yMax r g b nR nG nB clr pix map revMap n_clr n_pix mask anyChange
-     newColors newColorArray newImage extMask extBits newPixelValue|
+    |newImage|
 
     numBits > 7 ifTrue:[
         self warn:'Max. number of bits to strip off is 7.'.
         ^ false
     ].
-    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
-    extMask := (1 bitShift:numBits).
-    extBits := extMask - 1.
-
-    anyChange := false.
-
-    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:(image bits copy).
-    newImage mask:(image mask copy).
-
-    xMax := image width - 1.
-    yMax := image height - 1.
-
-    newPixelValue := 
-        [:image :pixelValue |
-            |r g b nR nG nB|
-
-            r := image redBitsOf:pixelValue.
-            g := image greenBitsOf:pixelValue.
-            b := image blueBitsOf:pixelValue.
-            nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
-            nG := g bitAnd:mask. (nG bitAnd:extMask)~~0 ifTrue:[nG := nG bitOr:extBits].
-            nB := b bitAnd:mask. (nB bitAnd:extMask)~~0 ifTrue:[nB := nB bitOr:extBits].
-            image valueFromRedBits:nR greenBits:nG blueBits:nB.
-        ].
-
-
-    image photometric == #palette ifFalse:[
-        "/ direct manipulation of the pixels
-        0 to:yMax do:[:y |
-            0 to:xMax do:[:x |
-                pix := image pixelAtX:x y:y.
-                n_pix := newPixelValue value:image value:pix.
-                n_pix ~= pix ifTrue:[
-                    newImage pixelAtX:x y:y put:n_pix.
-                    anyChange := true.
-                ]
-            ]
-        ].
-        anyChange ifFalse:[
-            ^ false
-        ].
-    ] ifTrue:[
-        "/ manipulate the colormap
-        0 to:yMax do:[:y |
-            0 to:xMax do:[:x |
-                pix := image pixelAtX:x y:y.
-                (n_pix := map at:pix+1) isNil ifTrue:[
-                    clr := image colorAtX:x y:y.
-
-                    r := clr redByte.
-                    g := clr greenByte.
-                    b := clr blueByte.
-                    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
-                    nG := g bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
-                    nB := b bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
-                    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
-                    (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.
-            ]
-        ].
-        revMap size == image colorMap size ifTrue:[
-            revMap = (0 to:revMap size-1) ifTrue:[
-                ^ false
-            ]
-        ].
-
-        newImage colorMap:(MappedPalette withColors:newColorArray).
+    newImage := image withColorResolutionReducedBy:numBits.
+    newImage isNil ifTrue:[
+        self warn:'Could not reduce color resolution.'.
+        ^ false.
     ].
 
     self makeUndo.
@@ -2333,7 +2251,7 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.183 2003-06-21 10:00:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.184 2003-07-02 15:22:17 cg Exp $'
 ! !
 
 ImageEditView initialize!