Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Alpha channel of image! type

From: cyphre:seznam:cz at: 14-Nov-2002 19:04

Hello Claude, Here is a snippet of my quick console session:
>> img: load %image13.png
== make image! [800x600 #{ E88878E88878E88878E88878E88878E88878E88878D88878E88878E88878 E88878D88878E88878E88878E88878E88878E88878E...
>> img/1
== 120.136.232.0 ;so here you can see four channels of first image pixel ;you can acces it also like
>> img/1/1 ;red channel
== 120
>> img/1/2 ;blue channel
== 136
>> img/1/3 ; green channel
== 232
>> img/1/4 ;alpha channel
== 0 ;that's one possible method ;but be be carful on the order of image channel bytes in the binary form
>> xx: to-image layout [origin 0 box blue]
== make image! [100x100 #{ FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000 FF0000FF0000FF0000FF0000FF0000FF0000FF0000F...
>> xx: to-image layout [origin 0 box green]
== make image! [100x100 #{ 00FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF00 00FF0000FF0000FF0000FF0000FF0000FF0000FF000...
>> xx: to-image layout [origin 0 box red]
== make image! [100x100 #{ 0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF 0000FF0000FF0000FF0000FF0000FF0000FF0000FF0...
>>
;as you can see in the lines above the bytes are in different order: BBGGRRAA ;and here you are some exaples of image channel splitting with speed comparison:
>> red: make block! 1000000 green: make block! 1000000 blue: make block!
1000000 alpha: make block! 1000000 s: now/time/precise foreach [b g r a] img [insert tail red r insert tail green g insert tail blue b insert tail alpha a] now/time/precise - s == 0:00:04.606
>> red: copy [] green: copy [] blue: copy [] alpha: copy [] s:
now/time/precise foreach [b g r a] im g [insert tail red r insert tail green g insert tail blue b insert tail alpha a] now/time/precise - s == 0:00:09.434
>> red: make block! 1000000 green: make block! 1000000 blue: make block!
1000000 alpha: make block! 1000000 s: now/time/precise foreach [b g r a] img [append red r append green g append blue b append alpha a] now/time/precise - s == 0:00:10.825
>> red: copy [] green: copy [] blue: copy [] alpha: copy [] s:
now/time/precise foreach [b g r a] im g [append red r append green g append blue b append alpha a] now/time/precise - s == 0:00:15.643 ;as you can see the fastest method from those examples is to preallocate the series for each channel and then ise "insert tail" instead of "append" ;but this is quick experiment, there are lot of other possible methods... regards Cyphre