#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 11 Oct 2018 13:28:28 +0200
changeset 5920 bf761a3591fd
parent 5919 25799af0939c
child 5921 452bdfc2db29
#FEATURE by cg class: ImageEditView added: #exchangeGreenBlueChannels #exchangeRedBlueChannels #exchangeRedGreenChannels
ImageEditView.st
--- a/ImageEditView.st	Sun Oct 07 21:52:10 2018 +0200
+++ b/ImageEditView.st	Thu Oct 11 13:28:28 2018 +0200
@@ -2692,6 +2692,96 @@
     "Modified: / 31-08-2017 / 12:09:23 / cg"
 !
 
+exchangeGreenBlueChannels
+    "exchange red and blue channels"
+
+    |newImage w h|
+
+    image colorMap notNil ifTrue:[
+        Dialog information:'This operation cannot be applied to palette images.'.
+        ^ self.
+    ].
+
+    newImage := image copy.
+
+    w := image width - 1.
+    h := image height - 1.
+
+    0 to:h do:[:y |
+        0 to:w do:[:x |
+            |oldColor newColor|
+
+            oldColor := (image colorAtX:x y:y).
+            newColor := Color redByte:(oldColor redByte)
+                              greenByte:(oldColor blueByte)
+                              blueByte:(oldColor greenByte)
+                              alphaByte:(oldColor alphaByte).
+            newImage colorAtX:x y:y put:newColor
+        ]
+    ].
+    self newImageWithUndo:newImage.
+!
+
+exchangeRedBlueChannels
+    "exchange red and blue channels"
+
+    |newImage w h|
+
+    image colorMap notNil ifTrue:[
+        Dialog information:'This operation cannot be applied to palette images.'.
+        ^ self.
+    ].
+
+    newImage := image copy.
+
+    w := image width - 1.
+    h := image height - 1.
+
+    0 to:h do:[:y |
+        0 to:w do:[:x |
+            |oldColor newColor|
+
+            oldColor := (image colorAtX:x y:y).
+            newColor := Color redByte:(oldColor blueByte)
+                              greenByte:(oldColor greenByte)
+                              blueByte:(oldColor redByte)
+                              alphaByte:(oldColor alphaByte).
+            newImage colorAtX:x y:y put:newColor
+        ]
+    ].
+    self newImageWithUndo:newImage.
+!
+
+exchangeRedGreenChannels
+    "exchange red and green channels"
+
+    |newImage w h|
+
+    image colorMap notNil ifTrue:[
+        Dialog information:'This operation cannot be applied to palette images.'.
+        ^ self.
+    ].
+
+    newImage := image copy.
+
+    w := image width - 1.
+    h := image height - 1.
+
+    0 to:h do:[:y |
+        0 to:w do:[:x |
+            |oldColor newColor|
+
+            oldColor := (image colorAtX:x y:y).
+            newColor := Color redByte:(oldColor greenByte)
+                              greenByte:(oldColor redByte)
+                              blueByte:(oldColor blueByte)
+                              alphaByte:(oldColor alphaByte).
+            newImage colorAtX:x y:y put:newColor
+        ]
+    ].
+    self newImageWithUndo:newImage.
+!
+
 flipHorizontal
 
     self newImageWithUndo:(image copy flipHorizontal).