#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Thu, 06 Apr 2017 13:36:13 +0200
changeset 3433 539da315be01
parent 3432 448be738b44b
child 3434 729adaa48dab
#BUGFIX by cg class: ImageEditor added: #colorMapModeFromImage: changed: #colorMapMode: #ditherToDepth #findColorMapMode class: ImageEditor class changed: #helpPairs
ImageEditor.st
--- a/ImageEditor.st	Fri Mar 31 18:06:50 2017 +0200
+++ b/ImageEditor.st	Thu Apr 06 13:36:13 2017 +0200
@@ -525,7 +525,7 @@
 'Save the image as resource method in a class'
 
 #floodFillMaxError
-'Specify the max. allowed deviation from the clicked pixel in a flood-fill operation.\Pixels where the hue/light values differ less than that fraction\will be included in the fill.\The range must be between 0 and 1. With 0, only areas with exactly the same pixel will be filled.\With 1, every other pixel is included.\\When filling gradiented areas, start with small values, such as 0.05, and increase slowly.\This is especially useful when masking background areas.'
+'Specify the max. allowed deviation from the clicked pixel in a flood-fill operation.\Pixels where the hue/light values differ less than that fraction\will be included in the fill.\The range must be between 0 and 1. With 0, only areas with exactly the same pixel will be filled.\With 1, every other pixel is included.\\When filling gradiented areas, start with small values, such as 0.05, and increase slowly (undo and try with higher value).\This is especially useful when masking background areas from screenshots.'
 
 #magnificationNumber
 'Shows the current magnification'
@@ -601,7 +601,7 @@
 
 )
 
-    "Modified: / 26-02-2017 / 16:55:58 / cg"
+    "Modified: / 06-04-2017 / 13:26:57 / cg"
 !
 
 helpSpec
@@ -4947,20 +4947,33 @@
     "Created: / 19-02-2017 / 15:01:05 / cg"
 !
 
+colorMapModeFromImage:anImage
+    "retrieves the colorMapMode for an image"
+
+    |image colorMapModeKey|
+
+    image := self image.
+    image isNil ifTrue:[^ nil ].
+
+    image mask notNil ifTrue: [             
+        colorMapModeKey := 'masked'.
+    ] ifFalse:[
+        colorMapModeKey := 'depth'.
+    ].
+    colorMapModeKey := (colorMapModeKey , image depth printString) asSymbol.
+    ^ colorMapModeKey
+
+    "Created: / 06-04-2017 / 13:19:19 / cg"
+!
+
 findColorMapMode
     "finds the colorMapMode for a new image"
 
     |image newListOfColors colorMapModeKey drawColor1 drawColor2 someOrAllUsedColors|
 
     image := self image.
-    image isNil ifTrue:[^ self ].
-
-    image mask notNil ifTrue: [             
-        colorMapModeKey := 'masked'.
-    ] ifFalse:[
-        colorMapModeKey := 'depth'.
-    ].
-    colorMapModeKey := colorMapModeKey , image depth printString.
+    (colorMapModeKey := self colorMapModeFromImage:image) isNil ifTrue:[^ self].
+
     self colorMapMode setValue:colorMapModeKey.
 
     image photometric == #palette ifTrue:[
@@ -5017,7 +5030,7 @@
         self listOfColors contents:newListOfColors.
     ].
 
-    "Modified: / 06-12-2016 / 12:51:36 / cg"
+    "Modified: / 06-04-2017 / 13:20:10 / cg"
 !
 
 selectedColorsChanged
@@ -6402,11 +6415,14 @@
      usedColors useNearest usageCounts tmpBits tmpMap quest
      prevMode maskThreshold maskImage| 
 
+    oldImage := self image.
+
+    "/ rubbish; the mode is already changed
+    "/ prevMode := colorMapMode value.
+    prevMode := self colorMapModeFromImage:oldImage. 
+    prevMode == aMode ifTrue:[^ self].
+    
     self withExecuteCursorDo:[
-        oldImage := self image.
-
-        prevMode := colorMapMode value.
-
         newColorMap := self class listOfColorMaps at:aMode.
         (aMode == #depth32 or:[aMode == #masked32]) ifTrue:[
             depth := 32. 
@@ -6432,6 +6448,8 @@
                 quest := 'Keep colormap (or use standard)'
             ]
         ].
+        
+        "/ currently always true!!
         ((prevMode = aMode)
           or:[depth > oldImage depth
           or:[true "self confirm:(resources string:quest)"]]
@@ -6629,7 +6647,7 @@
         ]
     ]
 
-    "Modified (format): / 16-02-2017 / 10:24:41 / cg"
+    "Modified: / 06-04-2017 / 13:23:26 / cg"
 !
 
 colorize
@@ -6748,16 +6766,21 @@
 !
 
 ditherToDepth
-    |depth|
-
-    depth := Dialog request:'New depth ?'.
+    |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