#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 08 Aug 2016 14:06:35 +0200
changeset 7492 34cfdad00603
parent 7488 72af47b8a56a
child 7493 59db55fd753a
#FEATURE by cg class: Depth32Image added: #computeAlphaValuesFromMask: converting masks to an alpha value
Depth32Image.st
--- a/Depth32Image.st	Tue Aug 02 10:23:14 2016 +0200
+++ b/Depth32Image.st	Mon Aug 08 14:06:35 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1995 by Claus Gittinger
 	      All Rights Reserved
@@ -218,6 +220,26 @@
 
 !Depth32Image methodsFor:'converting rgb images'!
 
+computeAlphaValuesFromMask:aMaskImage
+    "convert a mask into alpha values;
+     masked pixels get an alpha value of 0,
+     unmasked of 255"
+
+    |alphaMask|
+
+    alphaMask := self alphaMaskForPixelValue.
+    self valuesFromX:0 y:0
+                 toX:width-1 y:height-1
+                  do:[:x :y :pixelValue |
+        (aMaskImage pixelAtX:x y:y) ~~ 0 ifTrue:[
+            self pixelAtX:x y:y put:(pixelValue bitOr:alphaMask).
+        ] ifFalse:[
+            self pixelAtX:x y:y put:(pixelValue bitClear:alphaMask).
+        ].
+    ].
+    photometric := #rgba
+!
+
 rgbImageAsTrueColorFormOn:aDevice
     "return a truecolor form from the rgba or argb-picture."