#FEATURE by cg draft
authorClaus Gittinger <cg@exept.de>
Thu, 24 Aug 2017 16:43:47 +0200
changeset 3458 159bab42fdbb
parent 3457 3f3ea99e8af5
child 3459 f264db47ed05
#FEATURE by cg class: ImageEditor added: #makeMonochromeImage comment/format in: #doRotateImage class: ImageEditor class changed: #menuColors
ImageEditor.st
--- a/ImageEditor.st	Wed Aug 16 13:58:23 2017 +0200
+++ b/ImageEditor.st	Thu Aug 24 16:43:47 2017 +0200
@@ -3044,11 +3044,6 @@
                   translateLabel: true
                 )
                (MenuItem
-                  label: 'Dither to Depth...'
-                  itemValue: ditherToDepth
-                  translateLabel: true
-                )
-               (MenuItem
                   label: '-'
                 )
                (MenuItem
@@ -3087,6 +3082,19 @@
                   translateLabel: true
                 )
                (MenuItem
+                  label: 'Make Monochrome'
+                  itemValue: makeMonochromeImage
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: 'Make Inverse'
+                  itemValue: makeInverse
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
                   enabled: allowedToChangeImageDimensionAndDepth
                   label: 'Make dithered 8Bit Palette'
                   itemValue: makeDitheredPaletteImage
@@ -3094,8 +3102,13 @@
                   isVisible: false
                 )
                (MenuItem
-                  label: 'Make Inverse'
-                  itemValue: makeInverse
+                  label: 'Dither to Depth...'
+                  itemValue: ditherToDepth
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: 'Threshold to Depth...'
+                  itemValue: thresholdToDepth
                   translateLabel: true
                 )
                (MenuItem
@@ -3185,7 +3198,7 @@
         nil
       )
 
-    "Modified: / 16-02-2017 / 10:27:13 / cg"
+    "Modified: / 24-08-2017 / 15:25:00 / cg"
 !
 
 menuEdit
@@ -7835,7 +7848,7 @@
                         request:(resources string:'Rotate by (degrees, clockwise):')
                         list:#( '-90' '90' '180' '45' '-45'  '135' '-135' ) 
                         initialAnswer:90.
-    rotationString isEmptyOrNil ifTrue:[^ self].    "/ cancelled
+    rotationString isEmptyOrNil ifTrue:[^ self].    "/ canceled
     rotation := Number readFrom:rotationString onError:[nil].
     rotation isNil ifTrue:[^ self].   
 
@@ -7852,6 +7865,7 @@
     self updateInfoLabel.
 
     "Modified: / 18-03-2012 / 14:41:14 / cg"
+    "Modified (comment): / 24-08-2017 / 15:02:57 / cg"
 !
 
 doShiftManual
@@ -7935,6 +7949,58 @@
 
     imageEditView undo.
     self updateImagePreView
+!
+
+makeMonochromeImage
+    "let user choose a threshold, then convert to monochrome"
+    
+    |image userInput thresholdBrighness|
+
+    image := imageEditView image.
+    
+    Dialog modifyingBoxWith:[:box |
+        |preview slider update thresholdValue|
+
+        thresholdValue := 0.5 asValue.
+
+        box enterField converter:(PrintConverter new initForNumber).
+        box enterField model:thresholdValue.
+        box verticalPanel extent:1.0 @ 300.
+        
+        box verticalPanel add:(slider := HorizontalSlider new start:0 stop:1 step:0.05).
+        slider model:thresholdValue.
+        slider width:1.0; leftInset:4; rightInset:4.
+
+        box verticalPanel add:(preview := ImageView new).
+        preview extent:1.0 @300.
+        preview level:-1.
+        box verticalPanel horizontalLayout:#fitSpace.
+        
+        update := 
+            [
+                |s t|
+
+                t := thresholdValue value clampBetween:0 and:1.   
+                preview image:((image asThresholdMonochromeImage:t)
+                            magnifiedPreservingRatioTo:preview extent).
+            ].
+        update value.
+        box enterField acceptOnLostFocus:true.
+        box enterField acceptOnLeave:true.
+        thresholdValue onChangeEvaluate:update.
+        "/ box height:400.
+    ] do:[
+        userInput := Dialog request:'Treshold (0=black; 1=white) ?' initialAnswer:0.5.
+    ].
+    userInput isEmptyOrNil ifTrue:[^ self].
+    thresholdBrighness := Number readFrom:userInput onError:nil.
+    thresholdBrighness isNil ifTrue:[^ self].
+
+    thresholdBrighness := thresholdBrighness clampBetween:0 and:1.
+    imageEditView newImageWithUndo:(image asThresholdMonochromeImage:thresholdBrighness)
+
+    "Created: / 24-08-2017 / 15:26:44 / cg"
+    "Modified (comment): / 24-08-2017 / 16:43:32 / cg"
 ! !
 
 !ImageEditor methodsFor:'user actions-image sequences'!