ImageEditor.st
changeset 3475 7eafbd0cad40
parent 3472 f6c63e715a5b
child 3476 2854769b212a
--- a/ImageEditor.st	Thu Aug 31 20:17:40 2017 +0200
+++ b/ImageEditor.st	Thu Aug 31 21:39:41 2017 +0200
@@ -2491,7 +2491,7 @@
                                            activeHelpKey: colorMapTable
                                            style: (FontDescription helvetica medium roman 10)
                                            model: selectedColors
-                                           menu: colorMapMenu
+                                           menu: colorMapMenuHolder
                                            hasHorizontalScrollBar: true
                                            hasVerticalScrollBar: true
                                            miniScrollerHorizontal: true
@@ -2659,6 +2659,8 @@
         
        )
      )
+
+    "Modified: / 31-08-2017 / 18:47:02 / cg"
 ! !
 
 !ImageEditor class methodsFor:'menu specs'!
@@ -2681,13 +2683,13 @@
      #(Menu
         (
          (MenuItem
-            enabled: hasColormapHolder
+            enabled: canAddColorToColormapHolder
             label: 'Add Color'
             itemValue: addColorToColormap
             translateLabel: true
           )
          (MenuItem
-            enabled: hasColormapHolder
+            enabled: canAddColorToColormapHolder
             label: 'Pick and Add Color...'
             itemValue: pickAndAddColorToColormap
             translateLabel: true
@@ -2696,7 +2698,7 @@
             label: '-'
           )
          (MenuItem
-            enabled: hasColormapAndSingleColorSelected
+            enabled: hasColormapAndSingleColorSelectedHolder
             label: 'Cut Color'
             itemValue: cutColorFromColormap
             translateLabel: true
@@ -2710,12 +2712,13 @@
             shortcutKey: Copy
           )
          (MenuItem
-            enabled: hasColormapAndSingleColorSelected
+            enabled: hasColormapAndSingleWritableColorSelectedHolder
             label: 'Pick and Paste Color...'
             itemValue: pickAndPasteColor
             translateLabel: true
           )
          (MenuItem
+            enabled: canChangeColorInColormapHolder
             label: 'Paste Color'
             itemValue: pasteColorIntoColormap
             translateLabel: true
@@ -2725,31 +2728,31 @@
             label: '-'
           )
          (MenuItem
-            enabled: hasColormapAndSingleColorSelected
+            enabled: hasColormapAndSingleWritableColorSelectedHolder
             label: 'Edit Color...'
             itemValue: editSelectedColor
             translateLabel: true
           )
          (MenuItem
-            enabled: hasColormapAndColorSelected
+            enabled: hasColormapAndSingleWritableColorSelectedHolder
             label: 'Brighter'
             itemValue: makeSelectedColorBrighter
             translateLabel: true
           )
          (MenuItem
-            enabled: hasColormapAndColorSelected
+            enabled: hasColormapAndSingleWritableColorSelectedHolder
             label: 'Darker'
             itemValue: makeSelectedColorDarker
             translateLabel: true
           )
          (MenuItem
-            enabled: hasColormapAndColorSelected
+            enabled: hasColormapAndSingleWritableColorSelectedHolder
             label: 'Make Gray'
             itemValue: makeSelectedColorGray
             translateLabel: true
           )
          (MenuItem
-            enabled: hasColormapAndColorSelected
+            enabled: hasColormapAndSingleWritableColorSelectedHolder
             label: 'Color Shift'
             itemValue: makeSelectedColorShifted
             translateLabel: true
@@ -2764,7 +2767,7 @@
             translateLabel: true
           )
          (MenuItem
-            enabled: hasColormapHolder
+            enabled: imageHasColormapHolder
             label: 'Inspect Colormap'
             itemValue: inspectColormap
             translateLabel: true
@@ -2773,6 +2776,8 @@
         nil
         nil
       )
+
+    "Modified: / 31-08-2017 / 18:46:33 / cg"
 !
 
 menu
@@ -4336,6 +4341,41 @@
     "Modified: / 29.7.1998 / 18:49:03 / cg"
 !
 
+canAddColorToColormap
+    |img|
+    
+    img := self image.
+    img isNil ifTrue:[^ false].
+    img photometric == #blackIs0 ifTrue:[^ false].
+    img photometric == #whiteIs0 ifTrue:[^ false].
+    ^ true
+
+    "Created: / 31-08-2017 / 18:32:27 / cg"
+!
+
+canAddColorToColormapHolder
+    ^ [self canAddColorToColormap]
+
+    "Created: / 31-08-2017 / 18:32:40 / cg"
+!
+
+canChangeColorInColormap
+    |img|
+    
+    img := self image.
+    img isNil ifTrue:[^ false].
+    img photometric == #palette ifFalse:[^ false].
+    ^ true
+
+    "Created: / 31-08-2017 / 18:34:12 / cg"
+!
+
+canChangeColorInColormapHolder
+    ^ [self canChangeColorInColormap]
+
+    "Created: / 31-08-2017 / 18:34:18 / cg"
+!
+
 canResizeImage
     ^ self imageIsLoadedAndNotReadonlyHolder
 !
@@ -4535,6 +4575,8 @@
 !
 
 hasColormap
+    "true if a colormap is shown (might be a drwing map, not the real map)"
+    
     |img|
     
     ^ (img := self image) notNil 
@@ -4542,6 +4584,7 @@
 
     "Created: / 30-09-1998 / 23:53:55 / cg"
     "Modified: / 23-02-2017 / 09:57:45 / cg"
+    "Modified (comment): / 31-08-2017 / 18:36:08 / cg"
 !
 
 hasColormapAndColorSelected
@@ -4551,15 +4594,30 @@
 !
 
 hasColormapAndSingleColorSelected
-    ^ [ self hasColormapHolder value and:[self hasSingleColorSelectedHolder value]]
-
-    "Modified: / 04-07-2010 / 10:13:13 / cg"
+    ^ self hasColormapHolder value and:[self hasSingleColorSelectedHolder value]
+
+    "Modified: / 31-08-2017 / 18:44:49 / cg"
+!
+
+hasColormapAndSingleColorSelectedHolder
+    ^ [ self hasColormapAndSingleColorSelected value ]
+
+    "Created: / 31-08-2017 / 18:44:36 / cg"
+!
+
+hasColormapAndSingleWritableColorSelectedHolder
+    ^ [ self hasColormapAndSingleColorSelected and:[self canChangeColorInColormap ]]
+
+    "Created: / 31-08-2017 / 18:42:46 / cg"
 !
 
 hasColormapHolder
+    "true if a colormap is shown (might be a drwing map, not the real map)"
+
     ^ [self hasColormap]
 
     "Created: / 04-07-2010 / 10:13:05 / cg"
+    "Modified (comment): / 31-08-2017 / 18:36:47 / cg"
 !
 
 hasSingleColorSelectedHolder
@@ -4568,6 +4626,23 @@
     "Created: / 04-07-2010 / 10:12:22 / cg"
 !
 
+imageHasColormap
+    "true if a colormap is shown (might be a drwing map, not the real map)"
+    
+    |img|
+    
+    ^ (img := self image) notNil 
+        and:[img colorMap notNil ]
+
+    "Created: / 31-08-2017 / 18:36:25 / cg"
+!
+
+imageHasColormapHolder
+    ^ [self imageHasColormap]
+
+    "Created: / 31-08-2017 / 18:36:42 / cg"
+!
+
 imageHasImageSequence
     |img|
 
@@ -5011,24 +5086,33 @@
 !
 
 updateColorsFromImage:image
-    |colors|
-
-    image depth > 16 ifTrue:[
-        self listOfColors contents:#().
-        ^ self.
-    ].
-
-    colors := image colorMap.
-    colors isNil ifTrue:[
-        Error handle:[:ex |
-            colors := OrderedCollection new.
-        ] do:[
-            colors := image usedColors asSet.
+    |colors depth|
+
+    depth := image depth.
+    
+    depth > 16 ifTrue:[
+        colors := #()  "/ too many - will only show the one's which are explicitly added.
+    ] ifFalse:[
+        ((image photometric == #blackIs0)
+        or:[ image photometric == #whiteIs0 ]) ifTrue:[
+            depth <= 8 ifTrue:[
+                colors := 1 to:(1 << depth) collect:[:i | image colorFromValue:i-1]
+            ].
         ].
-    ].
+        colors isNil ifTrue:[
+            colors := image colorMap.
+            colors isNil ifTrue:[
+                Error handle:[:ex |
+                    colors := OrderedCollection new.
+                ] do:[
+                    colors := image usedColors asSet.
+                ].
+            ].
+        ].
+    ].    
     self listOfColors contents:(colors asOrderedCollection).
 
-    "Modified: / 18-01-2012 / 13:57:43 / cg"
+    "Modified: / 31-08-2017 / 18:54:53 / cg"
 !
 
 updateForNoImage
@@ -5468,6 +5552,12 @@
     "Created: / 16-02-2017 / 01:44:47 / cg"
 !
 
+colorMapMenuHolder
+    ^ [ self class colorMapMenu ]
+
+    "Created: / 31-08-2017 / 18:47:17 / cg"
+!
+
 imageIsLoadedAndAllowedToChangeImageDimension
     "returns whether an image is loaded as value holder"