[REBOL] Masking, Keying and Image Composition ideas.
From: james:mustard at: 24-May-2003 20:10
Hi All,
Have added a reference demo for REBOL/View of image masking / keying /
compositing to:
http://www.mustard.co.nz/rebol/compositing.r
This includes 4 functions that will work in View or Core to do
a variety of masking / overlay / type effects.
For those who have some time for detective work / enlightening me - I am
using REBOL/View 1.2.8.4.2 3-Aug-2002 (for linux) and am getting a weird
bug/error/feature?? where save/png sometimes does not always save the
alpha channel information - so far I have only noticed this occurring on
images where black (0.0.0) or white (255.255.255) are being masked.
(This wont be apparent in the demo link above as i cheated and specified
transparency to be 0.0.0.255 in the boxen style line.)
;----- masking functions ----------------------------------
create-mask: func [mask c /local img [image!] v [integer!]][
img: copy mask
for v 1 (img/size/x * img/size/y) 1 [if not (pick mask v) = c [poke img
v 0.0.0.255]]
return img
]
create-not-mask: func [mask c /local img [image!] v [integer!]][
img: copy mask
for v 1 (img/size/x * img/size/y) 1 [if (pick mask v) = c [poke img v
0.0.0.255]]
return img
]
;--------load in test image--------------------------------
msk: load http://www.mustard.co.nz/rebol/vsml-insignia-mask.png
;
;-------Scenario 1: Mask by Color -------------------------
; Images 1 - 3 save with alpha channel,Image 4 does not.
;
save/png %image1.png create-mask msk 255.0.0
save/png %image2.png create-mask msk 0.255.0
save/png %image3.png create-mask msk 0.0.255
save/png %image4.png create-mask msk 255.255.255
;
;-------Scenario 2: Mask by Color -------------------------
;Images 5 - 7 do not save alpha channel, Image 8 does..
;
save/png image5.png create-not-mask msk 255.0.0
save/png image6.png create-not-mask msk 0.255.0
save/png image7.png create-not-mask msk 0.0.255
save/png image8.png create-not-mask msk 255.255.255
;--------------------------------------------------------
PS: Yes I am aware there are other ways rather than using FOR statements
(like repeat) but repeat was having issues with moving past the end of
image markers..?? (repeat n mask []) so what is there now works :P
James.