class: ImageEditView
authorClaus Gittinger <cg@exept.de>
Sun, 22 Feb 2015 13:29:21 +0100
changeset 4715 c851a10dd606
parent 4714 69df9f744066
child 4716 32f891f13734
class: ImageEditView class definition added: #editModeSmooth #smoothAt: comment/format in: #editMode: changed: #buttonMotion:x:y: #initialize #pointAt:width:
ImageEditView.st
--- a/ImageEditView.st	Sun Feb 22 11:25:33 2015 +0100
+++ b/ImageEditView.st	Sun Feb 22 13:29:21 2015 +0100
@@ -25,7 +25,7 @@
 		EditModePoint EditModeBox EditModeFilledBox EditModeFill
 		EditModeCopy EditModePasteUnder EditModePaste
 		EditModePasteWithMask EditModeSpecialOperation EditModeSpray
-		EditModeCircle'
+		EditModeCircle EditModeSmooth'
 	poolDictionaries:''
 	category:'Views-Misc'
 !
@@ -76,6 +76,7 @@
     EditModeCopy := #copy.
     EditModeSpecialOperation := #specialOperation.
     EditModeSpray := #spray.
+    EditModeSmooth := #smooth.
 
     "
      self initialize
@@ -116,6 +117,10 @@
     ^ EditModePoint
 !
 
+editModeSmooth
+    ^ EditModeSmooth
+!
+
 editModeSpecialOperation
     ^ EditModeSpecialOperation
 !
@@ -709,6 +714,7 @@
         EditModeSpecialOperation 
         EditModeSpray 
         EditModeCircle 
+        EditModeSmooth 
     "
 
     editMode := anEditModeSymbol
@@ -745,6 +751,10 @@
                 self pointAt:p.
                 ^ self
             ].
+            (editMode == EditModeSmooth) ifTrue:[
+                self smoothAt:p.
+                ^ self
+            ].
             sprayProcess notNil ifTrue:[
                 sprayPosition := p.
                ^ self
@@ -1690,7 +1700,7 @@
 !
 
 pointAt:aPoint width:pw
-    "draw a single pixel with the currently selected color"
+    "draw a single pixel (or dot of width pw) with the currently selected color"
 
     |draw imagePoint clr pix|
 
@@ -1709,11 +1719,10 @@
             ].             
             self invalidate:((point * magnification extent: magnification) expandedBy:1).
         ].
+
     draw value:imagePoint.
 
-    pw == 1 ifTrue:[
-        draw value:imagePoint.
-    ] ifFalse:[
+    pw > 1 ifTrue:[
         "/ draw with a wide pen
         (pw//2) negated to:(pw-(pw//2)-1) do:[:xOffs |
             (pw//2) negated to:(pw-(pw//2)-1) do:[:yOffs |
@@ -1828,6 +1837,56 @@
     "Modified: / 7.9.1998 / 14:15:32 / cg"
 !
 
+smoothAt:aPoint
+    "smoth (average) a single pixel with pixels around"
+
+    |draw imagePoint x y w h|
+
+    imagePoint := aPoint // magnification.
+    w := image width.
+    h := image height.
+    ((x := imagePoint x) between:0 and:w-1) ifFalse:[^ self].
+    ((y := imagePoint y) between:0 and:h-1) ifFalse:[^ self].
+
+    draw := 
+        [:point |
+            |sumRed sumGreen sumBlue newClr|
+
+            sumRed := sumGreen := sumBlue := 0.
+            -1 to:1 do:[:dx |
+                -1 to:1 do:[:dy |
+                    |clr|
+
+                    ((x + dx) between:0 and:w-1) ifTrue:[
+                        ((y + dy) between:0 and:h-1) ifTrue:[   
+                            clr := image colorAtX:(x + dx) y:(y + dy).
+                            sumRed := sumRed + clr redByte.
+                            sumGreen := sumGreen + clr greenByte.
+                            sumBlue := sumBlue + clr blueByte.
+                        ]
+                    ].
+                ]
+            ].
+            newClr := Color 
+                        redByte:(sumRed / 9) rounded
+                        greenByte:(sumGreen / 9) rounded 
+                        blueByte:(sumBlue / 9) rounded. 
+            image colorMap isNil ifTrue:[
+Transcript 
+    show:(image colorAt:point);
+    show:' -> ';
+    showCR:newClr.
+                image atImageAndMask:point put:newClr.
+            ] ifFalse:[
+                image atImageAndMask:point put:(image colorMap colorNearestTo:newClr).
+            ].             
+            self invalidate:((point * magnification extent: magnification) expandedBy:1).
+        ].
+
+    draw value:imagePoint.
+    self setModified.
+!
+
 specialOperationAt: aPoint
     "special operation on a rectangular area"
 
@@ -2798,11 +2857,11 @@
 !ImageEditView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.263 2015-02-22 10:25:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.264 2015-02-22 12:29:21 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.263 2015-02-22 10:25:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.264 2015-02-22 12:29:21 cg Exp $'
 ! !