#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Tue, 29 Aug 2017 21:09:29 +0200
changeset 3470 da26c2e9a037
parent 3469 52837773925b
child 3471 95c973cafdc1
#FEATURE by cg class: ImageEditor changed: #ditherToDepth:
ImageEditor.st
--- a/ImageEditor.st	Tue Aug 29 20:00:56 2017 +0200
+++ b/ImageEditor.st	Tue Aug 29 21:09:29 2017 +0200
@@ -7537,55 +7537,73 @@
 !
 
 ditherToDepth:depth 
-    |ditherColors computeNewColormap nGrey greyColorsAlready moreColors d|
-
-    computeNewColormap := Dialog 
-                            confirmWithCancel:'Compute a new (optimized) colormap?\\(or else use a standard colormap)\\Warning: this may take some time...' withCRs
-                            default:false.
-    computeNewColormap isNil ifTrue:[^ self].
-
-    computeNewColormap ifFalse:[
-        depth = 1 ifTrue:[
-            ditherColors := Array with:(Color black) with:(Color white).
-        ] ifFalse:[ depth = 2 ifTrue:[
-            ditherColors := Array 
-                                with:(Color black) 
-                                with:(Color darkGray)
-                                with:(Color lightGray)
-                                with:(Color white).
-        ] ifFalse:[ depth = 3 ifTrue:[
-            ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
-        ] ifFalse:[ depth = 4 ifTrue:[
-            ditherColors := Color vgaColors. 
-        ] ifFalse:[ depth = 5 ifTrue:[
-            ditherColors := Color colorCubeWithRed:3 green:4 blue:2.
-        ] ifFalse:[ depth = 6 ifTrue:[
-            ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
-        ] ifFalse:[ depth = 7 ifTrue:[
-            ditherColors := Color colorCubeWithRed:5 green:5 blue:4. 
-        ] ifFalse:[ depth == 8 ifTrue:[
-            ditherColors := Color standardDitherColorsForDepth8. 
-        ] ifFalse:[ 
-            self error:'unsupported depth'.
-        ]]]]]]]].
-
-        "/ add as many gray colors as possible.
-        nGrey := (2 raisedTo:depth) - ditherColors size.  
-        nGrey > 0 ifTrue:[
-            nGrey := nGrey min:128.
-            greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
-            d := 1 / nGrey.
-            moreColors := (1 to:nGrey-1) 
-                            collect:[:i | Color brightness:(d * i)] 
-                            thenReject:[:clr | greyColorsAlready includes:clr ].
-
-            ditherColors := ditherColors , moreColors.
-        ].
-    ] ifTrue:[
+    |answer labels values ditherColors nGrey greyColorsAlready moreColors d|
+
+    (depth >= 8) ifTrue:[
+        labels := #('Cancel' 'Use Browser Palette' 'Use Standard' 'Compute' ).
+        values := #(nil UseBrowserPalette UseStandard Compute).
+    ] ifFalse:[
+        labels := #('Cancel' 'Use Standard' 'Compute' ).
+        values := #(nil UseStandard Compute). 
+    ].
+
+    answer := OptionBox
+              request:'Compute a new (optimized) colormap\(Warning: this may take some time)\\or else use a standard colormap?' withCRs
+              label:(resources string:'Dither how')
+              image:(YesNoBox iconBitmap)
+              buttonLabels:(resources array:labels)
+              values:values
+              default:#UseStandard
+              onCancel:nil.
+    answer isNil ifTrue:[^ self].
+    
+    (answer == #Compute) ifTrue:[
         ditherColors :=
             Color
                 best:(1 bitShift:depth) 
                 ditherColorsForImage:self image
+    ] ifFalse:[
+        (answer == #UseBrowserPalette) ifTrue:[
+            ditherColors := Color colorCubeWithRed:6 green:6 blue:6. 
+        ] ifFalse:[
+            depth = 1 ifTrue:[
+                ditherColors := Array with:(Color black) with:(Color white).
+            ] ifFalse:[ depth = 2 ifTrue:[
+                ditherColors := Array 
+                                    with:(Color black) 
+                                    with:(Color darkGray)
+                                    with:(Color lightGray)
+                                    with:(Color white).
+            ] ifFalse:[ depth = 3 ifTrue:[
+                ditherColors := Color colorCubeWithRed:2 green:2 blue:2. 
+            ] ifFalse:[ depth = 4 ifTrue:[
+                ditherColors := Color vgaColors. 
+            ] ifFalse:[ depth = 5 ifTrue:[
+                ditherColors := Color colorCubeWithRed:3 green:4 blue:2.
+            ] ifFalse:[ depth = 6 ifTrue:[
+                ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
+            ] ifFalse:[ depth = 7 ifTrue:[
+                ditherColors := Color colorCubeWithRed:5 green:5 blue:4. 
+            ] ifFalse:[ depth == 8 ifTrue:[
+                ditherColors := Color standardDitherColorsForDepth8. 
+            ] ifFalse:[ 
+                self error:'unsupported depth'.
+            ]]]]]]]].
+
+        
+            "/ add as many gray colors as possible.
+            nGrey := (2 raisedTo:depth) - ditherColors size.  
+            nGrey > 0 ifTrue:[
+                nGrey := nGrey min:128.
+                greyColorsAlready := ditherColors select:[:clr | clr isGreyColor].
+                d := 1 / nGrey.
+                moreColors := (1 to:nGrey-1) 
+                                collect:[:i | Color brightness:(d * i)] 
+                                thenReject:[:clr | greyColorsAlready includes:clr ].
+
+                ditherColors := ditherColors , moreColors.
+            ].
+        ].
     ].
 
     self withExecuteCursorDo:[
@@ -7596,7 +7614,7 @@
     ].
 
     "Created: / 07-07-2006 / 13:20:56 / cg"
-    "Modified: / 29-08-2017 / 17:37:51 / cg"
+    "Modified: / 29-08-2017 / 21:08:34 / cg"
 !
 
 do3DProjection