Extracting Alpha Bit from a texture
Blitz3D Forums/Blitz3D Beginners Area/Extracting Alpha Bit from a texture
| ||
I'm creating texture with alpha flag set. I have drawn text directly to the texture which I assume will have a default of 0. I can iterate through the texture pixels and pick up all non-black pixels but I then need to apply full alpha to them so that they can be seen. I know there should be $FF for the left most bit in this case but how do I add it. Say I use argb=readpixel(x,y,texture) how do I add the $FF to the result, bearing in mind I'm only using 16bit colors? |
| ||
i'd image it would be 4 bits each then for RGB and A |
| ||
Thanks. I'm at work Ross so can't try this. So I would just use newargb = argb and $FF000000? |
| ||
I asked about on IRC channel. I'm not really sure what the answer was, so i can't really help you any, sorry m8 :( [EDIT] It appears that you just write to it the same way you would write to a 32 bit texture :) |
| ||
Not sure if this will help, but here's some code to return integer/'normal' color values (from Vein).Const RALPHA = 24 ;Return Alpha when using RColor Const RRED = 16 ;Return Red when using RColor Const RGREEN = 8 ;Return Green when using RColor Const RBLUE = 0 ;Return Blue when using RColor Function IntColor(R,G,B,A=255) ;Usage: WritePixelFast X,Y,IntColor(Red,Green,Blue,Alpha) or C = IntColor(Red,Green,Blue,Alpha) : WritePixel X,Y,C Return A Shl 24 Or R Shl 16 Or G Shl 8 Or B Shl 0 End Function Function RColor%(c%,d%) ;Usage: Red = RColor(ReadPixelFast(255,127),RGREEN) Return c Shr d And 255 Shl 0 End Function |
| ||
Hi, I've been working on something similar, and came up with the following : ;ARGB Functions by Rob Farley 2003 ;rob@... ;http://www.mentalillusion.co.uk ;updated by Andrew Nixon Feb 2004 to include read and write alpha Function read_r(x,y,image_name) argb=ReadPixel(x,y,TextureBuffer(image_name)) Return (ARGB Shr 16) And $ff End Function Function read_g(x,y,image_name) argb=ReadPixel(x,y,TextureBuffer(image_name)) Return (ARGB Shr 8) And $ff End Function Function read_b(x,y,image_name) argb=ReadPixel(x,y,TextureBuffer(image_name)) Return ARGB And $ff End Function Function read_a(x,y,image_name) argb=ReadPixel(x,y,TextureBuffer(image_name)) Return (ARGB Shr 24) And $ff End Function Function write_argb(x,y,a,r,g,b,image_name) argb=(b Or (g Shl 8) Or (r Shl 16) Or (a Shl 24)) WritePixel x,y,argb,TextureBuffer(image_name) End Function Hope this helps, Cheers, Unc |
| ||
Thanks folks - managed to fix this by just using the argb from readpixel "or $ff000000" which works. It's a bit of a pain that when using flag 2 to create a texture that it does not read any argb at all for the text I print on it. The argb value is always 0 for some reason. I had to temporarily write text to an image and readpixel from this to ensure I got an argb > 0 to add alpha too. Not sure if that made any sense but is there a way of doing this without using that temp image? |