menu order
authorClaus Gittinger <cg@exept.de>
Wed, 21 Oct 2009 13:13:46 +0200
changeset 2652 1583e5525196
parent 2651 270672891645
child 2653 f0e64b82fa93
menu order
ImageEditor.st
--- a/ImageEditor.st	Wed Oct 21 11:00:17 2009 +0200
+++ b/ImageEditor.st	Wed Oct 21 13:13:46 2009 +0200
@@ -1956,13 +1956,13 @@
                   activeHelpKey: compressColormap
                   enabled: hasColormap
                   label: 'Compress Colormap'
-                  itemValue: compressColorMap
+                  itemValue: menu_compressColorMap
                   translateLabel: true
                 )
                (MenuItem
                   enabled: hasColormap
                   label: 'Sort Colormap'
-                  itemValue: sortColorMap
+                  itemValue: menu_sortColorMap
                   translateLabel: true
                 )
                (MenuItem
@@ -1985,12 +1985,6 @@
                 )
                (MenuItem
                   enabled: imageIsLoaded
-                  label: 'Invert'
-                  itemValue: doNegativeImage
-                  translateLabel: true
-                )
-               (MenuItem
-                  enabled: imageIsLoaded
                   label: 'Brighten'
                   itemValue: doBrightenImage
                   translateLabel: true
@@ -2001,6 +1995,12 @@
                   itemValue: doDarkenImage
                   translateLabel: true
                 )
+               (MenuItem
+                  enabled: imageIsLoaded
+                  label: 'Invert'
+                  itemValue: doNegativeImage
+                  translateLabel: true
+                )
                )
               nil
               nil
@@ -2069,20 +2069,26 @@
                   activeHelpKey: copyMask
                   enabled: hasMask
                   label: 'Copy Mask'
-                  itemValue: copyMask
+                  itemValue: menu_copyMask
                   translateLabel: true
                 )
                (MenuItem
                   activeHelpKey: pasteMask
                   enabled: hasMask
                   label: 'Paste Mask'
-                  itemValue: pasteMask
+                  itemValue: menu_pasteMask
                   translateLabel: true
                 )
                (MenuItem
                   enabled: hasMask
                   label: 'Clear Masked Pixels'
-                  itemValue: clearMaskedPixels
+                  itemValue: menu_clearMaskedPixels
+                  translateLabel: true
+                )
+               (MenuItem
+                  enabled: hasMask
+                  label: 'Clear ColormapEntry for Masked Pixels'
+                  itemValue: menu_clearColormapEntry0AndMaskedPixels
                   translateLabel: true
                 )
                )
@@ -4282,28 +4288,43 @@
     ].
 !
 
+clearColormapEntry0AndMaskedPixels
+    "ensure that there is a colorMap entry with 0/0/0 at position
+     0 and then clear all masked pixels (to pixelValue 0).
+     This is required for windows icons to be really transparent"
+
+    |index colorMap| 
+
+    self compressColorMap.
+    colorMap := self image colorMap.
+    (colorMap includes:(Color black)) ifFalse:[
+        self addColorToColormap:(Color black).
+        colorMap := self image colorMap.
+    ].
+    index := colorMap indexOf:(Color black).
+    index == 1 ifFalse:[
+        self sortColorMap.
+        colorMap := self image colorMap.
+    ].
+    self clearMaskedPixels
+!
+
 clearMaskedPixels
     "clear all masked pixels (to pixelValue 0)"
 
-    |newImage oldImage| 
-
-    oldImage := self image.
-
-    imageEditView makeUndo.
-
-    self withExecuteCursorDo:[
-        newImage := oldImage clearMaskedPixels.
-        0 to:newImage height - 1 do:[:y |
-            0 to:newImage width - 1 do:[:x |
-                (newImage maskAtX:x y:y) == 0 ifTrue:[
-                    newImage pixelAtX:x y:y put:0
-                ]
+    |newImage| 
+
+    newImage := self image clearMaskedPixels.
+    0 to:newImage height - 1 do:[:y |
+        0 to:newImage width - 1 do:[:x |
+            (newImage maskAtX:x y:y) == 0 ifTrue:[
+                newImage pixelAtX:x y:y put:0
             ]
-        ].
-
-        (imageEditView image:newImage) notNil ifTrue:[
-            self fetchImageData.
         ]
+    ].
+
+    (imageEditView image:newImage) notNil ifTrue:[
+        self fetchImageData.
     ]
 !
 
@@ -4636,82 +4657,60 @@
     oldImage := self image.
     depth := oldImage depth.
 
-    oldImage photometric ~~ #palette ifTrue:[
-        self information:'Compress colorMap: Only palette images have colormaps.'.
-        ^ self
-    ].
-
     usedColors := oldImage realUsedColors.
-    usedColors size == (1 bitShift:depth) ifTrue:[
-        self information:'Compress colorMap: All colors are used - no compression.'.
-        ^ self
-    ].
-    usedColors size == oldImage colorMap size ifTrue:[
-        self information:'Compress colorMap: Colormap already compressed - no compression.'.
-        ^ self
+
+    "/ translation table
+    oldToNew := ByteArray new:(1 bitShift:depth).
+    newColorMap := usedColors asArray.
+    newColorMap sort:self sortBlockForColors.
+
+    oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
+        |newPixel|
+
+        (usedColors includes:clr) ifTrue:[
+            newPixel := newColorMap indexOf:clr.
+            oldToNew at:oldIdx put:newPixel-1.
+        ]
     ].
 
-    imageEditView makeUndo.
-
-"/    self information:('Compress colorMap: %1 colors used.' bindWith:usedColors size).
-
-    self withExecuteCursorDo:[
-"/        newColorMap := Array new:usedColors size.
-
-        "/ translation table
-        oldToNew := ByteArray new:(1 bitShift:depth).
-        newColorMap := usedColors asArray.
-        newColorMap sort:self sortBlockForColors.
-
-        oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
-            |newPixel|
-
-            (usedColors includes:clr) ifTrue:[
-                newPixel := newColorMap indexOf:clr.
-                oldToNew at:oldIdx put:newPixel-1.
-            ]
-        ].
-
-        oldBits := oldImage bits.
-        newBits := ByteArray new:(oldBits size).
-        depth ~~ 8 ifTrue:[
-            "/ expand/compress can only handle 8bits
-            tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
-            oldBits
-                expandPixels:depth
-                width:oldImage width
-                height:oldImage height 
-                into:tmpBits
-                mapping:oldToNew.
-            tmpBits
-                compressPixels:depth 
-                width:oldImage width 
-                height:oldImage height 
-                into:newBits 
-                mapping:nil
-        ] ifFalse:[
-            oldBits
-                expandPixels:depth
-                width:oldImage width
-                height:oldImage height 
-                into:newBits
-                mapping:oldToNew.
-        ].
-
-        newImage := oldImage species new
-                        width:oldImage width
-                        height:oldImage height
-                        depth:depth
-                        fromArray:newBits.
-
-        newImage colorMap:newColorMap.  
-        newImage fileName:oldImage fileName.
-        newImage mask:(oldImage mask copy).
-
-        (imageEditView image:newImage) notNil ifTrue:
-        [
-            self fetchImageData.
-        ]
+    oldBits := oldImage bits.
+    newBits := ByteArray new:(oldBits size).
+    depth ~~ 8 ifTrue:[
+        "/ expand/compress can only handle 8bits
+        tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
+        oldBits
+            expandPixels:depth
+            width:oldImage width
+            height:oldImage height 
+            into:tmpBits
+            mapping:oldToNew.
+        tmpBits
+            compressPixels:depth 
+            width:oldImage width 
+            height:oldImage height 
+            into:newBits 
+            mapping:nil
+    ] ifFalse:[
+        oldBits
+            expandPixels:depth
+            width:oldImage width
+            height:oldImage height 
+            into:newBits
+            mapping:oldToNew.
+    ].
+
+    newImage := oldImage species new
+                    width:oldImage width
+                    height:oldImage height
+                    depth:depth
+                    fromArray:newBits.
+
+    newImage colorMap:newColorMap.  
+    newImage fileName:oldImage fileName.
+    newImage mask:(oldImage mask copy).
+
+    (imageEditView image:newImage) notNil ifTrue:[
+        self fetchImageData.
     ]
 
     "Created: / 28.7.1998 / 20:03:11 / cg"
@@ -4722,13 +4721,6 @@
     imageEditView setClipboardObject:(self selectedColorOrNil)
 !
 
-copyMask
-    |mask|
-
-    mask := self image mask.
-    MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
-!
-
 ditherToDepth
     |depth|
 
@@ -4918,23 +4910,63 @@
     self processSelectedColorWith:[:clr | Color brightness:(clr brightness)]
 !
 
-pasteColorIntoColormap
-    |copyBufferColor|
-
-    copyBufferColor := imageEditView getClipboardObject.
-    copyBufferColor isColor ifFalse:[
-        UserPreferences current beepInEditor ifTrue:[                
-            self window beep.
-        ].
+menu_clearColormapEntry0AndMaskedPixels
+    "ensure that there is a colorMap entry with 0/0/0 at position
+     0 and then clear all masked pixels (to pixelValue 0)"
+
+    imageEditView makeUndo.
+    self withExecuteCursorDo:[
+        self clearColormapEntry0AndMaskedPixels
+    ]
+!
+
+menu_clearMaskedPixels
+    "clear all masked pixels (to pixelValue 0)"
+
+    imageEditView makeUndo.
+
+    self withExecuteCursorDo:[
+        self clearMaskedPixels
+    ]
+!
+
+menu_compressColorMap
+    "calculates a new color map for the image, using only used colors"
+
+    |depth oldImage usedColors| 
+
+    oldImage := self image.
+    depth := oldImage depth.
+
+    oldImage photometric ~~ #palette ifTrue:[
+        self information:'Compress colorMap: Only palette images have colormaps.'.
         ^ self
     ].
-
-    self processSelectedColorWith:[:clr |
-        copyBufferColor
+    usedColors := oldImage realUsedColors.
+    usedColors size == (1 bitShift:depth) ifTrue:[
+        self information:'Compress colorMap: All colors are used - no compression.'.
+        ^ self
+    ].
+    usedColors size == oldImage colorMap size ifTrue:[
+        self information:'Compress colorMap: Colormap already compressed - no compression.'.
+        ^ self
+    ].
+
+    imageEditView makeUndo.
+
+    self withExecuteCursorDo:[
+        self compressColorMap
     ]
 !
 
-pasteMask
+menu_copyMask
+    |mask|
+
+    mask := self image mask.
+    MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
+!
+
+menu_pasteMask
     |img mask|
 
     imageEditView makeUndo.
@@ -4954,6 +4986,46 @@
     ]
 !
 
+menu_sortColorMap
+    "calculates a new color map for the image, sorting colors"
+
+    self menu_sortColorMapWith:self sortBlockForColors
+!
+
+menu_sortColorMapWith:sortBlock
+    "calculates a new color map for the image, sorting colors"
+
+    self image photometric ~~ #palette ifTrue:[
+        self information:'Compress colorMap: Only palette images have colormaps.'.
+        ^ self
+    ].
+
+    imageEditView makeUndo.
+
+    self withExecuteCursorDo:[
+        self sortColorMapWith:sortBlock
+    ]
+
+    "Modified: / 15.9.1998 / 17:53:32 / cg"
+    "Created: / 30.9.1998 / 23:51:23 / cg"
+!
+
+pasteColorIntoColormap
+    |copyBufferColor|
+
+    copyBufferColor := imageEditView getClipboardObject.
+    copyBufferColor isColor ifFalse:[
+        UserPreferences current beepInEditor ifTrue:[                
+            self window beep.
+        ].
+        ^ self
+    ].
+
+    self processSelectedColorWith:[:clr |
+        copyBufferColor
+    ]
+!
+
 pickAndAddColorToColormap
     self addColorToColormap:(Color fromUser)
 !
@@ -5184,8 +5256,7 @@
 sortColorMap
     "calculates a new color map for the image, sorting colors"
 
-    self 
-        sortColorMapWith:self sortBlockForColors
+    self sortColorMapWith:self sortBlockForColors
 !
 
 sortColorMapWith:sortBlock
@@ -5196,71 +5267,61 @@
     oldImage := self image.
     depth := oldImage depth.
 
-    oldImage photometric ~~ #palette ifTrue:[
-        self information:'Compress colorMap: Only palette images have colormaps.'.
-        ^ self
+    usedColors := oldImage realColorMap.
+
+
+    "/ translation table
+    oldToNew := ByteArray new:(1 bitShift:depth).
+    newColorMap := usedColors asArray.
+    newColorMap sort:sortBlock.
+
+    oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
+        |newPixel|
+
+        (usedColors includes:clr) ifTrue:[
+            newPixel := newColorMap indexOf:clr.
+            oldToNew at:oldIdx put:newPixel-1.
+        ]
     ].
 
-    usedColors := oldImage realColorMap.
-
-    imageEditView makeUndo.
-
-    self withExecuteCursorDo:[
-"/        newColorMap := Array new:usedColors size.
-
-        "/ translation table
-        oldToNew := ByteArray new:(1 bitShift:depth).
-        newColorMap := usedColors asArray.
-        newColorMap sort:sortBlock.
-
-        oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
-            |newPixel|
-
-            (usedColors includes:clr) ifTrue:[
-                newPixel := newColorMap indexOf:clr.
-                oldToNew at:oldIdx put:newPixel-1.
-            ]
-        ].
-
-        oldBits := oldImage bits.
-        newBits := ByteArray new:(oldBits size).
-        depth ~~ 8 ifTrue:[
-            "/ expand/compress can only handle 8bits
-            tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
-            oldBits
-                expandPixels:depth
-                width:oldImage width
-                height:oldImage height 
-                into:tmpBits
-                mapping:oldToNew.
-            tmpBits
-                compressPixels:depth 
-                width:oldImage width 
-                height:oldImage height 
-                into:newBits 
-                mapping:nil
-        ] ifFalse:[
-            oldBits
-                expandPixels:depth
-                width:oldImage width
-                height:oldImage height 
-                into:newBits
-                mapping:oldToNew.
-        ].
-
-        newImage := oldImage species new
-                        width:oldImage width
-                        height:oldImage height
-                        depth:depth
-                        fromArray:newBits.
-
-        newImage colorMap:newColorMap.  
-        newImage fileName:oldImage fileName.
-        newImage mask:(oldImage mask copy).
-
-        (imageEditView image:newImage) notNil ifTrue:[
-            self fetchImageData.
-        ]
+    oldBits := oldImage bits.
+    newBits := ByteArray new:(oldBits size).
+    depth ~~ 8 ifTrue:[
+        "/ expand/compress can only handle 8bits
+        tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
+        oldBits
+            expandPixels:depth
+            width:oldImage width
+            height:oldImage height 
+            into:tmpBits
+            mapping:oldToNew.
+        tmpBits
+            compressPixels:depth 
+            width:oldImage width 
+            height:oldImage height 
+            into:newBits 
+            mapping:nil
+    ] ifFalse:[
+        oldBits
+            expandPixels:depth
+            width:oldImage width
+            height:oldImage height 
+            into:newBits
+            mapping:oldToNew.
+    ].
+
+    newImage := oldImage species new
+                    width:oldImage width
+                    height:oldImage height
+                    depth:depth
+                    fromArray:newBits.
+
+    newImage colorMap:newColorMap.  
+    newImage fileName:oldImage fileName.
+    newImage mask:(oldImage mask copy).
+
+    (imageEditView image:newImage) notNil ifTrue:[
+        self fetchImageData.
     ]
 
     "Modified: / 15.9.1998 / 17:53:32 / cg"