Image Masks - Completely lost

Bob Warren robertum at brturbo.com
Wed Dec 28 07:08:31 EST 2005


Yesterday, I wrote:

I am trying to apply a mask to an image without any success whatsoever
in getting it to work correctly. Would someone be kind enough to give me
an example of how it might be done? My experiments with "imagedata" and
"alphadata" have so far failed.

Let's outline a simple spec:

1. I have a normal full coloured image on the left of my window, loaded
from an RGB PNG file. The image box is called "fullcolour".

2. I have another image in the middle of my window which is exactly the
same size as the one on the left. The image it contains consists of a
big, black circle on a white background. The image was also loaded from
an RGB PNG file. The image box is called "themask".

3. There is an empty image box on the right called "result".

4. If I click on button "showblack", the black ball mask in the middle
image is applied to the image on the left to show the ball portion only
of the coloured picture in the "result" image on the right. It has a
surround of the original grey colour.

5. Alternatively, if I click on button "showwhite", the ball-surround
portion of the mask is applied to the "fullcolour" image on the left,
producing the original coloured image with a grey round hole in the
middle in "result".

Any hints regarding file types that can be used (e.g. PNG, JPG, BMP,
etc.), the richness of bits (e.g. 2-bit, 8-bit, 16-bit, 32-bit, etc.)
and so on, for the original coloured picture and the mask picture, would
be greatly appreciated.

Also, can anyone recommend useful webpages elucidating this kind of
thing? The RR HELP hasn't helped me very much so far, I'm afraid.
Thanks.



----------------------------------------------
Yesterday, Scott Rossi wrote:

 >To apply a mask to an image, you can set the alphaData of one image to 
 >the alphaData of another.

I now understand this as a general objective rather than something that 
can be done directly. I have tried statements like:-

put the alphaData of image "themask" into the alphaData of image 
"fullcolour"

set the alphaData of image "fullcolour" to the alphaData of image "themask"

- and got no joy from RR other than a great fat rasberry!

But what Scott also says is:-

 >To change image/alphaData via script, you must work with binary values 
 >-- see below

- where "below" refers to Ken Ray's article at
http://www.sonsothunder.com/devres/revolution/tips/imag003.htm .

--------------------------------------------

 From this I deduce generally that I need to:

1) convert the alphaData of image "themask" to single byte form using 
binaryDecode

2) convert the imageData of image "fullcolour" to 4-byte blocks of 
format  redByte, greenByte, blueByte, and maskOrAlphaByte using 
binaryDecode

3) substitute each instance of the binary decoded maskOrAlphaByte in 2) 
with the binary decoded bytes of 1)

4) reassemble the alphaData of image "fullcolour" using binaryEncode

--------------------------------------------
Is that more or less it, or do I still have my knickers in a twist?






More information about the use-livecode mailing list