class: ImageEditView
authorClaus Gittinger <cg@exept.de>
Thu, 26 Mar 2015 10:35:43 +0100
changeset 4730 bcf8e15b7606
parent 4729 c0f052e4f414
child 4731 145b177a3203
class: ImageEditView code cleanup / common code eliminated added: #newImageWithUndo: #resizedImage:to: comment/format in: #makeGrayScaleImage #makeInverse #makeSlightlyBrighter #makeSlightlyDarker changed:12 methods
ImageEditView.st
--- a/ImageEditView.st	Thu Mar 19 16:11:17 2015 +0100
+++ b/ImageEditView.st	Thu Mar 26 10:35:43 2015 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1997 by eXept Software AG
 	      All Rights Reserved
@@ -1174,15 +1176,11 @@
 !
 
 magnifyAntiAliasedImageTo:newSize
-    self makeUndo.
-    self image: (image hardAntiAliasedMagnifiedBy: newSize/image extent).
-    self setModified.
+    self newImageWithUndo: (image hardAntiAliasedMagnifiedBy: newSize/image extent).
 !
 
 magnifyImageTo:newSize
-    self makeUndo.
-    self image: (image magnifiedBy: newSize/image extent).
-    self setModified.
+    self newImageWithUndo: (image magnifiedBy: newSize/image extent).
 !
 
 makeNewColorMapByMapping:functionOfColor
@@ -1248,9 +1246,7 @@
     image colorMap notNil ifTrue:[
         newImage colorMap:(MappedPalette withColors:newColorArray).
     ].
-    self makeUndo.
-    self image:newImage.
-    self setModified.
+    self newImageWithUndo:newImage.
     ^ true
 !
 
@@ -1968,22 +1964,16 @@
 !ImageEditView methodsFor:'image manipulation'!
 
 brightenImage
-    self makeUndo.
-    self image: (image copy lightened).
-    self setModified.
+    self newImageWithUndo: (image copy lightened).
 !
 
 darkenImage
-    self makeUndo.
-    self image: (image copy darkened).
-    self setModified.
+    self newImageWithUndo: (image copy darkened).
 !
 
 flipHorizontal
 
-    self makeUndo.
-    self image: image copy flipHorizontal.
-    self setModified.
+    self newImageWithUndo: image copy flipHorizontal.
 !
 
 flipVertical
@@ -2015,9 +2005,7 @@
     ].
 
     newImage copyFrom:image x:0 y:0 toX:newX y:newY width:oldWidth height:oldHeight.
-    self makeUndo.
-    self image:newImage.
-    self setModified.
+    self newImageWithUndo:newImage.
 
     "Created: / 7.9.1998 / 13:00:16 / cg"
     "Modified: / 7.9.1998 / 14:15:32 / cg"
@@ -2032,38 +2020,48 @@
 !
 
 makeGrayScaleImage
-    ^ self makeNewColorMapByMapping:[:clr | Color brightness:(clr brightness)].
+    ^ self makeNewColorMapByMapping:
+        [:clr | Color brightness:(clr brightness)].
 !
 
 makeInverse
-    ^ self makeNewColorMapByMapping:[:clr | 
-        Color red:(100-clr red) green:(100-clr green) blue:(100-clr blue)].
+    ^ self makeNewColorMapByMapping:
+        [:clr | 
+            Color red:(100-clr red) green:(100-clr green) blue:(100-clr blue)
+        ].
 !
 
 makeSlightlyBrighter
-    ^ self makeNewColorMapByMapping:[:clr | 
-                                        clr brightness > Color lightGray brightness
-                                            ifTrue:[ clr blendWith:Color white ] 
-                                            ifFalse:[ clr blendWith:Color lightGray ]
-                                    ].
+    ^ self makeNewColorMapByMapping:
+        [:clr | 
+            clr brightness > Color lightGray brightness
+                ifTrue:[ clr blendWith:Color white ] 
+                ifFalse:[ clr blendWith:Color lightGray ]
+        ].
 
     "Created: / 24-11-2010 / 11:08:18 / cg"
 !
 
 makeSlightlyDarker
-    ^ self makeNewColorMapByMapping:[:clr | 
-                                        clr brightness < Color darkGray brightness
-                                            ifTrue:[ clr blendWith:Color black ] 
-                                            ifFalse:[ clr blendWith:Color darkGray ]
-                                    ].
+    ^ self makeNewColorMapByMapping:
+        [:clr | 
+            clr brightness < Color darkGray brightness
+                ifTrue:[ clr blendWith:Color black ] 
+                ifFalse:[ clr blendWith:Color darkGray ]
+        ].
 
     "Created: / 24-11-2010 / 11:08:08 / cg"
 !
 
 negativeImage
 
+    self newImageWithUndo: (image copy bits:(image bits invert)).
+!
+
+newImageWithUndo:newImage
+
     self makeUndo.
-    self image: (image copy bits:(image bits invert)).
+    self image: newImage.
     self setModified.
 !
 
@@ -2080,13 +2078,17 @@
         ^ false.
     ].
 
-    self makeUndo.
-    self image:newImage.
-    self setModified.
+    self newImageWithUndo:newImage.
     ^ true
 !
 
 resizeImageTo:newSize
+    self newImageWithUndo: (self resizedImage:image to:newSize).
+!
+
+resizedImage:image to:newSize
+    "helper for image resize and mask resize.
+     return a resized version of image"
 
     |newImage newMaskImage|
 
@@ -2104,9 +2106,7 @@
     ].
 
     newImage copyFrom:image x:0 y:0 toX:0 y:0 width: (image width min:newSize x) height: (image height min:newSize y).
-    self makeUndo.
-    self image: newImage.
-    self setModified.
+    ^ newImage.
 !
 
 rotateImageBy:rotation
@@ -2115,9 +2115,7 @@
     Error handle:[:ex|
         self warn: 'Image rotation failed!!\' withCRs, 'Increasing the image depth could help.'
     ] do:[   
-        self makeUndo.
-        self image: (image hardRotated: rotation).
-        self setModified.
+        self newImageWithUndo: (image hardRotated: rotation).
     ]
 
     "Modified: / 29.7.1998 / 18:21:14 / cg"
@@ -2129,9 +2127,7 @@
     Error handle:[:ex|
         self warn: 'Image projection failed!!\' withCRs, 'Increasing the image depth could help.'
     ] do:[   
-        self makeUndo.
-        self image: (image threeDProjected:dx1 and:dx2).
-        self setModified.
+        self newImageWithUndo:(image threeDProjected:dx1 and:dx2)
     ]
 
     "Modified: / 29.7.1998 / 18:21:14 / cg"
@@ -2863,11 +2859,11 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.265 2015-02-27 18:56:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.266 2015-03-26 09:35:43 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.265 2015-02-27 18:56:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.266 2015-03-26 09:35:43 cg Exp $'
 ! !