alpha image blending...
[1/10] from: maximo::meteorstudios::com at: 22-Jul-2003 16:23
hi,
a while ago a friend of mine told me that the latest versions of view support 8bit alpha
channels properly in order to blend images with their own transparency...
Is this still true, and if so, can anyone show me a simple example:
something as siple as:
imageA: load %imgfileA
imageB: load %imgfileB
imageC: imageA/rgb over imageB/rgb using imageA/alpha
view layout [box imageC imageC/size]
Thanks in advance !
-max
-----------
meteor Studios, T.D.
-----------
Strong enough for a man, but made for a woman
[2/10] from: roland:hadinger:arcor at: 23-Jul-2003 3:10
Warning: actually I've STILL got no good grasp of how certain things
are done with REBOL view, but I couldn't resist answering :/
A simple test which just displays two overlapping 32 bit RGBA images
taken from the PNG web site (image download ~ 500 k):
view f: layout [
origin 0x0
backcolor white
at 0x0 image
http://www.libpng.org/pub/png/img_png/MagnoliaAlpha-0.5.png
at 0x0 image
http://www.libpng.org/pub/png/img_png/OwlAlpha-0.5.png
]
If this displays what it says on your system (a window with a bright
background, magnolias and an owl in the foreground), then there is
alpha channel support.
imageC: to-image f
converts f to an image. In doing this, you get an image without alpha
channel data , however (or at least I think so, correct me if I'm wrong
here).
So depending on what you want to do besides merging images, you might
have to manipulate the alpha channel data with 'pick and 'poke
(-> http://www.compkarori.com/vanilla/display/Image+and+Alpha+Channel)
For example, to clear the alpha channel of an image:
clear-alpha: func [i [image!] /local n] [
repeat n i/size/x * i/size/y [poke i n 1.1.1.0 * pick i n]
i
]
[3/10] from: antonr:iinet:au at: 23-Jul-2003 14:12
Just a reminder of the alpha-channel bug.
Rebol/view shows the alpha channel of an image
only when the top-left pixel has a non-zero
alpha value.
Compare these two:
img1: make image! [2x2 #{ff0000ffff0000ffff0000ff} #{eeeeeeee}]
img2: make image! [2x2 #{ff0000ffff0000ffff0000ff} #{00eeeeee}]
view layout [image 100x100 img1 image 100x100 img2]
Both undoubtedly have alpha channel data on them,
but img2 has a zero alpha value on its top-left pixel.
Perhaps this has something to do with it.
Anton.
[4/10] from: g:santilli:tiscalinet:it at: 23-Jul-2003 9:48
Hi Maxim,
On Tuesday, July 22, 2003, 10:23:32 PM, you wrote:
MOA> something as siple as:
MOA> imageA: load %imgfileA
MOA> imageB: load %imgfileB
MOA> imageC: imageA/rgb over imageB/rgb using imageA/alpha
As long as imageA has an alpha channel, you just need to place the
face that contains it over the face with imageB. You can also
apply affects on the alpha channel (e.g. alphamul).
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[5/10] from: cyphre:seznam:cz at: 23-Jul-2003 11:11
Hi Max,
what about this(needs some newer View betas to work properly):
--------------start of code------------------------
site: http://www.rebol.cz/~cyphre/
x: 0
d: 5
view layout [
origin 0x0
image load-thru/binary site/city.jpg 320x240
at 0x0
image load-thru/binary site/bay.jpg 320x240 with [
rate: 30
effect: compose [fit alphamul (x)]
feel: make feel [
engage: func [f a e][
x: x + d
if x > 250 [d: -5]
if x < 5 [d: 5]
f/effect: compose [fit alphamul (x)]
show f
]
]
]
]
------------------end of code---------------------
regards,
Cyphre
----- Original Message -----
From: "Maxim Olivier-Adlhoch" <[maximo--meteorstudios--com]>
To: "Rebol-List (E-mail)" <[rebol-list--rebol--com]>
Sent: Tuesday, July 22, 2003 10:23 PM
Subject: [REBOL] alpha image blending...
hi,
a while ago a friend of mine told me that the latest versions of view
support 8bit alpha channels properly in order to blend images with their own
transparency...
Is this still true, and if so, can anyone show me a simple example:
something as siple as:
imageA: load %imgfileA
imageB: load %imgfileB
imageC: imageA/rgb over imageB/rgb using imageA/alpha
view layout [box imageC imageC/size]
Thanks in advance !
-max
-----------
meteor Studios, T.D.
-----------
Strong enough for a man, but made for a woman
[6/10] from: maximo:meteorstudios at: 23-Jul-2003 10:33
I was waiting for a reply from you...
thanks for the alphamul example.
can we alphamul with another image?
-max
-----------
meteor Studios, T.D.
-----------
Strong enough for a man, but made for a woman
[7/10] from: cyphre:seznam:cz at: 23-Jul-2003 18:20
Hi Max again,
Have a look at http://www.escribe.com/internet/rebol/m26856.html
Using this function you can draw into alphachannel using any DRAW command(so
also using a pictures) but it is not so fast as native implementation could
be (I requested possibility to draw/load images into alphachannel but this
is probably still on RTs huge todo list)
I have quickly hacked-up another way how to make alphachannel from image
fastly but this need preprocessed(in some gfx program or slowly using Rebol)
8-bit greyscale bitmap:
-------------------------start of the code(watch out line
breaks!)----------------------------------
REBOL [
title: "use 256grayscale image for alphachannel"
author: [cyphre--seznam--cz]
]
site: http://www.rebol.cz/~cyphre/
;you can write your own to-8-bit-gryscale-bitmap converter in Rebol but it
will be slow IMO
;so I exported the raw bitmap data form Photoshop for example
bay-alpha: read-thru site/bay-greyscale.raw ;this is normal raw 8-bit
grayscale bitmap
img: to-image make face [
size: 192x144 ;size of the original bay image
color: blue
edge: none
effect: [gradient -1x-1 255.0.0 0.0.255]
]
img-tmp: to-block mold img
append/only img-tmp/3 bay-alpha
img2: do bind img-tmp 'system
view layout [backcolor green image img image img2]
------------------------end of
code-------------------------------------------
regards,
Cyphre
----- Original Message -----
From: "Maxim Olivier-Adlhoch" <[maximo--meteorstudios--com]>
To: <[rebol-list--rebol--com]>
Sent: Wednesday, July 23, 2003 4:33 PM
Subject: [REBOL] Re: alpha image blending...
I was waiting for a reply from you...
thanks for the alphamul example.
can we alphamul with another image?
-max
-----------
meteor Studios, T.D.
-----------
Strong enough for a man, but made for a woman
[8/10] from: maximo:meteorstudios at: 23-Jul-2003 14:38
thanks to everyone
from simple to advanced, it all helped!
I didn't think it was now that easy :-)
-max
-----------
meteor Studios, T.D.
-----------
Strong enough for a man, but made for a woman
[9/10] from: antonr:iinet:au at: 24-Jul-2003 19:44
Hi Cyphre,
I show here how to convert an image into the
grayscale binary string that can be inserted into
a molded image as in your just-posted example.
I thought, "slowly using rebol" ?
I hope my routine is not too slow.
Anyway it was a fun couple of hours.
I have long lines which will be wrapped, so I compressed
the script:
decompress #{
789C85556B6FDB3614FD2CFE8A5B1783EDC2F2AB2930385B816E6DB10D43316C
5DBF182E4049D732178A14482A8916E4BFEF90929374C336400228F23ECF3D87
725C584D7B917D5441F38E261391BD5771F55523AF3897BA3DC9FCE86C93D74E
F6BE949A974E646F6580CDF622FFA9D3F976BD7E29B24FECBCB266479BE57AB9
16D907E6CAEF68FF49F1CD41646FBA70B20E19DE98600DFD6AB5F648F6B33475
276B049BBE33B556FE24B25F3AD75A8FADBB7B91FDEED3695C7EB46F2D5622CB
A96557B2BA66F2B661EA3C1F3B4DC7CE940125785286C289DD707C1357224380
1F940FD6F5BBD87096CAA4FD931EE8EEBD723ED0F5D0C902617CAB1C5754F454
F6EDC9F1FD58FF041DE1F96003FB545256295F5A78C25A1A7896A803E9D894FD
0EC759E795A9A9E97450AD66727C54861B36C1D38D0A279A06A71A2A257AF1C4
CE59B720AE97708DDEAF5F533C5F49AD571A8E9E26B228ABCF2B3ED69368F0E2
05FD563AD5067A177D77F4A3B9965A55D44A04C7B20388F08E381C84504DBDA3
13EB7659AB235D4604A9E8940E39A0530D2017220D7B4717384E3B14376213B3
0D7D4BC6BA46EAF960957BF5274CD39A5EC0BC5EC51D212E29C135F5D430E65F
913D1290014E2146727531D41647162C3D702C7A968EC1B2C7BDB18A5984CB76
811237A93C4963585325839C8B689CA7E682CD07FBC8633ACA92E3D4D3D60EC5
1BA6CBFFEE3F7BD253EA4F647C3C7219401FA4A91466479BDB0DAD1391B6AF5E
2DC7F78080DFE45468595EA10EBA39A900EFC0B7F09DC41247A4A41F9AC0048F
D6E070A8154BDA0FD92FD6111F554356D3465595E6431CDF25555CA24CC0039E
8FC0440462BA11374968322FFAC039D492B7EA16283D825928235DFF8C666838
153147D45938C940CA2F28C44A62EC6392440C03AD44B49D2C030472A0782B10
63943D5DA43C9472C438DF7122729C768CF1985516D0C8821C0854E32D165028
DD30786FD20CA4E9CF4EE07FBD20EBE84C910502AB4095656FA6015805D4B104
18A566E9C85FA916652B4D50E4F0312A861AABAB4888A1673A9384B6946F04AC
936152E1EC5F4CE734797E77FF79352191C01A477506D10CF022D4EC912FAB5B
48E1C9673F17AD7468D243FD55170979F6A3BDDAC54978E862E86120370A8988
27329BC0353BB8FE6131B2FD7352AB0DDEED614E5FA77E0F8918DFA77BEA0BC1
0D71A3DE86A8496AA9D1783888FD416E72E4FF82BED0998054FF262C2DFB780C
5515207A693566D5486771BBAF682B32EB548D4AD7A3EAE2ADF0149E39888CAD
DCB75CA6A885B6D04BAA6B4C061D0DF338735CC8B66553ADACD13D9D9D572FC7
BE2E495683F13FAF86986ABB0379E2CCAA075F9AFA1E9774035F8E2C3B2BAAB4
15472DD58CFE81B9D4A3C862AB03340F604670B912970F194ADBC4FFD7AA626E
699F88929C9FD17E76BE1AE7347BAC7FB5C5E720C243BC3CC249E1AF60DD9547
0D56886BFC42A9C47D031DA79BECFFA01F6A1D513C7F9EB9FC641E5BCCE02FC8
96A3A303080000
}
Anton.
[10/10] from: cyphre:seznam:cz at: 24-Jul-2003 12:39
Hi Anton,
I intentionally pointed out the "performance issue" and the missing
native(and thus really fast) feature:-) Don't take it bad but your
to-8-bit-grayscale is really slow ;-) It takes 0:00:01.515 on AthlonXP 1700+
to convert image of 400x300 size which is not usable on slower machines or
even for realtime usage....I know you can reply that "it depends on what you
want to do" and I respect this...but we are in the year 2003, most of
current desktop monitor resolutions are at least 1200x1024 and more!
Please, don't take my words ofensive at all. It is great you showed that it
can be done in Rebol too. I just can't wait for the Carl's promised plug-in
architecture :-)
keep up reboling,
Cyphre