ImageEditor.st
changeset 3460 5d1d7e85222c
parent 3459 f264db47ed05
child 3461 bd826e508822
--- a/ImageEditor.st	Thu Aug 24 17:02:18 2017 +0200
+++ b/ImageEditor.st	Thu Aug 24 17:55:36 2017 +0200
@@ -3082,7 +3082,7 @@
                   translateLabel: true
                 )
                (MenuItem
-                  label: 'Make Monochrome'
+                  label: 'Make Monochrome...'
                   itemValue: makeMonochromeImage
                   translateLabel: true
                 )
@@ -3107,8 +3107,13 @@
                   translateLabel: true
                 )
                (MenuItem
-                  label: 'Threshold to Depth...'
-                  itemValue: thresholdToDepth
+                  label: 'Make GrayScale with Depth (Dither)...'
+                  itemValue: ditherGrayToDepth
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: 'Make GrayScale with Depth (Threshold)...'
+                  itemValue: thresholdGrayToDepth
                   translateLabel: true
                 )
                (MenuItem
@@ -3198,7 +3203,7 @@
         nil
       )
 
-    "Modified: / 24-08-2017 / 15:25:00 / cg"
+    "Modified: / 24-08-2017 / 17:49:04 / cg"
 !
 
 menuEdit
@@ -5109,6 +5114,7 @@
             self tileModeHolder value ifTrue:[
                 imagePreView tileMode:true tileOffset:(image extent).
             ].
+            self updateInfoLabel.
             ^ self.
         ].
         something == #subImageIn ifTrue:[
@@ -5149,7 +5155,7 @@
 
     super update:something with:aParameter from:changedObject
 
-    "Modified: / 20-03-2017 / 16:05:55 / cg"
+    "Modified: / 24-08-2017 / 17:12:59 / cg"
 !
 
 updateAfterImageChange
@@ -5733,6 +5739,23 @@
 
 !ImageEditor methodsFor:'private'!
 
+askForDepthThenDo:aBlock
+    |oldDepth suggestion depth|
+
+    oldDepth := self image depth.
+    suggestion := oldDepth > 8 ifTrue:[8] ifFalse:[(oldDepth // 2 - 1) nextPowerOf2].
+
+    depth := Dialog request:'New depth ?' initialAnswer:suggestion asString.
+    depth isEmptyOrNil ifTrue:[^ self].
+
+    depth := Number readFrom:depth onError:nil.
+    depth isNil ifTrue:[^ self].
+
+    aBlock value:depth
+
+    "Created: / 24-08-2017 / 17:05:39 / cg"
+!
+
 checkModified
     imageEditView modified value ifTrue:[
         (Dialog
@@ -6770,86 +6793,6 @@
     imageEditView setClipboardObject:(self selectedColorOrNil)
 !
 
-ditherToDepth
-    |oldDepth suggestion depth|
-
-    oldDepth := self image depth.
-    suggestion := oldDepth > 8 ifTrue:[8] ifFalse:[(oldDepth // 2 - 1) nextPowerOf2].
-
-    depth := Dialog request:'New depth ?' initialAnswer:suggestion asString.
-    depth isEmptyOrNil ifTrue:[^ self].
-
-    depth := Number readFrom:depth onError:nil.
-    depth isNil ifTrue:[^ self].
-
-    self ditherToDepth:depth
-
-    "Created: / 07-07-2006 / 13:22:10 / cg"
-    "Modified: / 06-04-2017 / 13:34:05 / cg"
-!
-
-ditherToDepth:depth
-    |ditherColors newImage useStandardColors nGrey greyColorsAlready moreColors d|
-
-    useStandardColors := true.
-"/    useStandardColors := Dialog confirmWithCancel:'Dither in standard colors or use a new (optimized) colormap ?'.
-"/    useStandardColors isNil ifTrue:[^ self].
-
-    useStandardColors ifTrue:[
-        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:4 green:4 blue:2. 
-        ] ifFalse:[ depth = 6 ifTrue:[
-            ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
-        ] ifFalse:[ depth <= 8 ifTrue:[
-            ditherColors := Color colorCubeWithRed:6 green:6 blue:5. 
-        ] ifFalse:[ 
-            self error:'unsupported depth'.
-        ]]]]]]].
-
-        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.
-        ].
-    ] ifFalse:[
-        self halt:'unhandled dither color setup'.
-    ].
-
-    self withExecuteCursorDo:[
-        "/ newImage := self image asDitheredImageUsing:ditherColors depth:depth.
-        newImage := self image asDitheredImageUsing:ditherColors depth:8.
-
-        imageEditView makeUndo.
-        imageEditView image:newImage.
-        imageEditView setModified.
-        self updateImage.
-        self updateImagePreView.
-
-        self fetchImageData.
-    ].
-
-    "Created: / 07-07-2006 / 13:20:56 / cg"
-    "Modified: / 05-09-2006 / 16:13:25 / cg"
-!
-
 doubleClickOnColor:aColorIndex
     self editSelectedColor.
 
@@ -7509,6 +7452,90 @@
     "Created: / 20-02-2017 / 18:06:03 / cg"
 !
 
+ditherGrayToDepth
+    self askForDepthThenDo:[:depth |
+        self ditherGrayToDepth:depth
+    ].
+
+    "Created: / 24-08-2017 / 17:49:42 / cg"
+!
+
+ditherGrayToDepth:depth
+    self withExecuteCursorDo:[
+        |newImage|
+        
+        newImage := self image asGrayImageDepth:depth dither:true.
+        imageEditView newImageWithUndo:newImage.
+    ].
+
+    "Created: / 24-08-2017 / 17:51:07 / cg"
+!
+
+ditherToDepth
+    self askForDepthThenDo:[:depth |
+        self ditherToDepth:depth
+    ].
+
+    "Created: / 07-07-2006 / 13:22:10 / cg"
+    "Modified: / 24-08-2017 / 17:06:00 / cg"
+!
+
+ditherToDepth:depth 
+    |ditherColors useStandardColors nGrey greyColorsAlready moreColors d|
+
+    useStandardColors := true.
+"/    useStandardColors := Dialog confirmWithCancel:'Dither in standard colors or use a new (optimized) colormap ?'.
+"/    useStandardColors isNil ifTrue:[^ self].
+
+    useStandardColors ifTrue:[
+        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:4 green:4 blue:2. 
+        ] ifFalse:[ depth = 6 ifTrue:[
+            ditherColors := Color colorCubeWithRed:4 green:4 blue:3.
+        ] ifFalse:[ depth <= 8 ifTrue:[
+            ditherColors := Color colorCubeWithRed:6 green:6 blue:5. 
+        ] ifFalse:[ 
+            self error:'unsupported depth'.
+        ]]]]]]].
+
+        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.
+        ].
+    ] ifFalse:[
+        self halt:'unhandled dither color setup'.
+    ].
+
+    self withExecuteCursorDo:[
+        |newImage|
+        
+        newImage := self image asDitheredImageUsing:ditherColors depth:depth.
+        imageEditView newImageWithUndo:newImage.
+    ].
+
+    "Created: / 07-07-2006 / 13:20:56 / cg"
+    "Modified (format): / 24-08-2017 / 17:53:46 / cg"
+!
+
 do3DProjection
     |box dx1 dx2 image|
 
@@ -7963,8 +7990,10 @@
 
         thresholdValue := 0.5 asValue.
 
-        box enterField converter:(PrintConverter new initForNumber).
-        box enterField model:thresholdValue.
+        box enterField 
+            converter:(PrintConverter new initForNumber);
+            model:thresholdValue.
+            
         box verticalPanel extent:1.0 @ 300.
         
         box verticalPanel add:(slider := HorizontalSlider new start:0 stop:1 step:0.05).
@@ -8000,7 +8029,26 @@
     imageEditView newImageWithUndo:(image asThresholdMonochromeImage:thresholdBrighness)
 
     "Created: / 24-08-2017 / 15:26:44 / cg"
-    "Modified (comment): / 24-08-2017 / 16:53:49 / cg"
+    "Modified: / 24-08-2017 / 17:54:21 / cg"
+!
+
+thresholdGrayToDepth
+    self askForDepthThenDo:[:depth |
+        self thresholdGrayToDepth:depth
+    ].
+
+    "Created: / 24-08-2017 / 17:49:23 / cg"
+!
+
+thresholdGrayToDepth:depth
+    self withExecuteCursorDo:[
+        |newImage|
+
+        newImage := self image asThresholdGrayImageDepth:depth.
+        imageEditView newImageWithUndo:newImage.
+    ].
+
+    "Created: / 24-08-2017 / 17:49:30 / cg"
 ! !
 
 !ImageEditor methodsFor:'user actions-image sequences'!