added crob operations.
authorClaus Gittinger <cg@exept.de>
Tue, 08 Sep 1998 13:16:47 +0200
changeset 986 4361ba4dbbdc
parent 985 ec4907d7cdfd
child 987 1147acb8ac80
added crob operations. some fixes to allow converting 24bit images to 8-bit (req'd for screen grab on trueColor displays)
ImageEditor.st
--- a/ImageEditor.st	Tue Sep 08 12:28:52 1998 +0200
+++ b/ImageEditor.st	Tue Sep 08 13:16:47 1998 +0200
@@ -189,32 +189,50 @@
 #colorMap1
 'Convert to depth-1 image.'
 
+#colorMap1M
+'Convert to depth-1 image plus mask.'
+
 #colorMap2
 'Convert to depth-2 image.'
 
+#colorMap2M
+'Convert to depth-2 image plus mask.'
+
 #colorMap4
 'Convert to depth-4 image.'
 
+#colorMap4M
+'Convert to depth-4 image plus mask.'
+
 #colorMap8
 'Convert to depth-8 image.'
 
-#colorMap1M
-'Convert to depth-1 image plus mask.'
-
-#colorMap2M
-'Convert to depth-2 image plus mask.'
-
-#colorMap4M
-'Convert to depth-4 image plus mask.'
-
 #colorMap8M
 'Convert to depth-8 image plus mask.'
 
+#colorMapTable
+'Shows a list of used colors of the image.'
+
 #compressColormap
 'Remove unneeded entries from the colorMap.'
 
-#colorMapTable
-'Shows a list of used colors of the image.'
+#crobAll
+'Find and remove all borders.'
+
+#crobBottom
+'Find and remove bottom border.'
+
+#crobLeft
+'Find and remove left border.'
+
+#crobManual
+'Specify border(s) to remove.'
+
+#crobRight
+'Find and remove right border.'
+
+#crobTop
+'Find and remove top border.'
 
 #drawModeBox
 'Switches to box-drawing mode.'
@@ -282,9 +300,6 @@
 #fileSaveMethodAs
 'Save the image as resource method in a class.'
 
-#historyMenuItem
-'Edit this image.'
-
 #magnificationNumber
 'Shows the current magnification.'
 
@@ -305,7 +320,7 @@
 
 )
 
-    "Modified: / 29.7.1998 / 22:27:36 / cg"
+    "Modified: / 7.9.1998 / 18:20:26 / cg"
 ! !
 
 !ImageEditor class methodsFor:'image specs'!
@@ -438,6 +453,124 @@
       )
 !
 
+grobDialogSpec
+    "This resource specification was automatically generated
+     by the UIPainter of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the UIPainter may not be able to read the specification."
+
+    "
+     UIPainter new openOnClass:ImageEditor andSelector:#grobDialogSpec
+     ImageEditor new openInterface:#grobDialogSpec
+    "
+
+    <resource: #canvas>
+
+    ^
+     
+       #(#FullSpec
+          #window: 
+           #(#WindowSpec
+              #name: 'Crob Borders'
+              #layout: #(#LayoutFrame 22 0 233 0 266 0 415 0)
+              #label: 'Crob Borders'
+              #min: #(#Point 10 10)
+              #max: #(#Point 800 478)
+              #bounds: #(#Rectangle 22 233 267 416)
+              #usePreferredExtent: false
+          )
+          #component: 
+           #(#SpecCollection
+              #collection: 
+               #(
+                 #(#LabelSpec
+                    #name: 'Label1'
+                    #layout: #(#LayoutFrame 14 0 21 0 90 0 43 0)
+                    #label: 'Left:'
+                    #translateLabel: true
+                    #adjust: #right
+                )
+                 #(#InputFieldSpec
+                    #name: 'EntryField1'
+                    #layout: #(#LayoutFrame 95 0 21 0 132 0 43 0)
+                    #model: #left
+                    #type: #number
+                )
+                 #(#LabelSpec
+                    #name: 'Label2'
+                    #layout: #(#LayoutFrame 14 0 51 0 90 0 73 0)
+                    #label: 'Right:'
+                    #translateLabel: true
+                    #adjust: #right
+                )
+                 #(#InputFieldSpec
+                    #name: 'EntryField2'
+                    #layout: #(#LayoutFrame 95 0 51 0 132 0 73 0)
+                    #model: #right
+                    #type: #number
+                )
+                 #(#LabelSpec
+                    #name: 'Label3'
+                    #layout: #(#LayoutFrame 14 0 81 0 90 0 103 0)
+                    #label: 'Top:'
+                    #translateLabel: true
+                    #adjust: #right
+                )
+                 #(#InputFieldSpec
+                    #name: 'EntryField3'
+                    #layout: #(#LayoutFrame 95 0 81 0 132 0 103 0)
+                    #model: #top
+                    #type: #number
+                )
+                 #(#LabelSpec
+                    #name: 'Label4'
+                    #layout: #(#LayoutFrame 14 0 111 0 90 0 133 0)
+                    #label: 'Bottom:'
+                    #translateLabel: true
+                    #adjust: #right
+                )
+                 #(#InputFieldSpec
+                    #name: 'EntryField4'
+                    #layout: #(#LayoutFrame 95 0 111 0 132 0 133 0)
+                    #model: #bottom
+                    #type: #number
+                )
+                 #(#HorizontalPanelViewSpec
+                    #name: 'HorizontalPanel1'
+                    #layout: #(#LayoutFrame 0 0.0 -30 1 0 1.0 0 1)
+                    #component: 
+                     #(#SpecCollection
+                        #collection: 
+                         #(
+                           #(#ActionButtonSpec
+                              #name: 'Button1'
+                              #label: 'Cancel'
+                              #translateLabel: true
+                              #model: #cancel
+                              #extent: #(#Point 118 22)
+                          )
+                           #(#ActionButtonSpec
+                              #name: 'Button2'
+                              #label: 'OK'
+                              #translateLabel: true
+                              #model: #accept
+                              #extent: #(#Point 118 22)
+                          )
+                        )
+                    )
+                    #horizontalLayout: #fitSpace
+                    #verticalLayout: #center
+                    #horizontalSpace: 3
+                    #verticalSpace: 3
+                )
+              )
+          )
+      )
+
+    "Modified: / 7.9.1998 / 18:29:34 / cg"
+!
+
 windowSpec
     "This resource specification was automatically generated
      by the UIPainter of ST/X."
@@ -838,6 +971,62 @@
                           #value: #doRotateImage
                           #activeHelpKey: #editRotate
                       )
+                       #(#MenuItem
+                          #label: '-'
+                      )
+                       #(#MenuItem
+                          #label: 'Crob'
+                          #translateLabel: true
+                          #submenu: 
+                           #(#Menu
+                              
+                               #(
+                                 #(#MenuItem
+                                    #label: 'All'
+                                    #translateLabel: true
+                                    #value: #doCrobAll
+                                    #activeHelpKey: #crobAll
+                                )
+                                 #(#MenuItem
+                                    #label: '-'
+                                )
+                                 #(#MenuItem
+                                    #label: 'Left'
+                                    #translateLabel: true
+                                    #value: #doCrobLeft
+                                    #activeHelpKey: #crobLeft
+                                )
+                                 #(#MenuItem
+                                    #label: 'Right'
+                                    #translateLabel: true
+                                    #value: #doCrobRight
+                                    #activeHelpKey: #crobRight
+                                )
+                                 #(#MenuItem
+                                    #label: 'Top'
+                                    #translateLabel: true
+                                    #value: #doCrobTop
+                                    #activeHelpKey: #crobTop
+                                )
+                                 #(#MenuItem
+                                    #label: 'Bottom'
+                                    #translateLabel: true
+                                    #value: #doCrobBottom
+                                    #activeHelpKey: #crobBottom
+                                )
+                                 #(#MenuItem
+                                    #label: '-'
+                                )
+                                 #(#MenuItem
+                                    #label: 'Manual...'
+                                    #translateLabel: true
+                                    #value: #doCrobManual
+                                    #activeHelpKey: #crobManual
+                                )
+                              ) nil
+                              nil
+                          )
+                      )
                     ) nil
                     nil
                 )
@@ -980,6 +1169,8 @@
           ) nil
           nil
       )
+
+    "Modified: / 7.9.1998 / 18:21:27 / cg"
 !
 
 menuMouseButtonColors
@@ -1708,15 +1899,15 @@
                 ].
             ] ifFalse:[
                 "/ see if all used color fit the new colormap
-                usedColors := oldImage usedColors asArray.
-                usedColors size <= (1 bitShift:depth) ifTrue:[
+                usedColors := oldImage usedColorsMax:(1 bitShift:depth).
+                (usedColors notNil and:[usedColors size <= (1 bitShift:depth)]) ifTrue:[
                     "/ yea - just install them
-                    usedColors keysAndValuesDo:[:idx :clr |
+                    usedColors asArray keysAndValuesDo:[:idx :clr |
                         newColorMap at:idx put:clr
                     ]
                 ] ifFalse:[
                     "/ copy over those that are most often used.
-                    oldImage depth ~~ 8 ifTrue:[
+                    oldImage depth < 8 ifTrue:[
                         tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
                         oldImage bits
                             expandPixels:(oldImage depth)
@@ -1725,7 +1916,12 @@
                             into:tmpBits
                             mapping:nil.
                     ] ifFalse:[
-                        tmpBits := oldImage bits
+                        oldImage depth == 8 ifTrue:[
+                            tmpBits := oldImage bits
+                        ] ifFalse:[
+                            self warn:'Too many colors in image.'.
+                            ^ self
+                        ]
                     ].
                     usageCounts := tmpBits usageCounts.
                     tmpMap := Array new:usageCounts size.
@@ -1845,7 +2041,7 @@
         ]
     ]
 
-    "Modified: / 17.8.1998 / 10:22:15 / cg"
+    "Modified: / 7.9.1998 / 17:57:55 / cg"
 !
 
 compressColorMap
@@ -1960,6 +2156,83 @@
     imageEditView changeGridMagnification
 !
 
+doCrobAll
+    "find all borders and cut them off"
+
+    imageEditView crobLeft:true right:true top:true bottom:true.   
+    self updateInfoLabel
+
+    "Modified: / 7.9.1998 / 14:26:23 / cg"
+    "Created: / 7.9.1998 / 16:33:43 / cg"
+!
+
+doCrobBottom
+    "find a bottom border and cut it off"
+
+    imageEditView crobLeft:false right:false top:false bottom:true.   
+    self updateInfoLabel
+
+    "Created: / 7.9.1998 / 13:00:20 / cg"
+    "Modified: / 7.9.1998 / 14:26:23 / cg"
+!
+
+doCrobLeft
+    "find a left border and cut it off"
+
+    imageEditView crobLeft:true right:false top:false bottom:false.   
+    self updateInfoLabel
+
+    "Created: / 7.9.1998 / 13:00:14 / cg"
+    "Modified: / 7.9.1998 / 14:26:34 / cg"
+!
+
+doCrobManual
+    "let user specify borders and cut them off"
+
+    |bindings left top right bottom|
+
+    bindings := IdentityDictionary new.
+    bindings at:#left put:(left := 0 asValue).
+    bindings at:#right put:(right := 0 asValue).
+    bindings at:#top put:(top := 0 asValue).
+    bindings at:#bottom put:(bottom := 0 asValue).
+    (self openDialogInterface:#grobDialogSpec withBindings:bindings)
+    ifTrue:[
+        left := left value.
+        right := right value.
+        top := top value.
+        bottom := bottom value.
+        imageEditView
+            makeSubImageX:left y:top 
+            width:(imageEditView image width - left - right)
+            height:(imageEditView image height - top - bottom).
+        self updateInfoLabel
+    ].
+
+    "Created: / 7.9.1998 / 18:16:07 / cg"
+    "Modified: / 7.9.1998 / 18:20:42 / cg"
+!
+
+doCrobRight
+    "find a right border and cut it off"
+
+    imageEditView crobLeft:false right:true top:false bottom:false.   
+    self updateInfoLabel
+
+    "Created: / 7.9.1998 / 13:00:14 / cg"
+    "Modified: / 7.9.1998 / 14:26:44 / cg"
+!
+
+doCrobTop
+    "find a top border and cut it off"
+
+    imageEditView crobLeft:false right:false top:true bottom:false.   
+    self updateInfoLabel
+
+    "Created: / 7.9.1998 / 13:00:19 / cg"
+    "Modified: / 7.9.1998 / 14:26:52 / cg"
+!
+
 doFlipHorizontal
     "flips horizontally current image"