Reading from the alpha channel using ReadPixelFast
Blitz3D Forums/Blitz3D Programming/Reading from the alpha channel using ReadPixelFast
| ||
I must be doing something wrong here - I'm reading pixels from the alphachannel of a texture (loaded with flags 1+2) that has a black and white alpha channel, and I'm getting values 96 and 136 only, rather than 0 and 255. The code I'm using is this: rgb = ReadPixelFast(x1,y1) array(x1,y1,0) = (rgb Shr 16 And %11111111) ;RED array(x1,y1,1) = (rgb Shr 8 And %11111111) :GREEN array(x1,y1,2) = (rgb And %11111111) ;BLUE array(x1,y1,3) = (rgb Shr 24 And %11111111) ;ALPHA CHANNEL This last array slot should be the alpha channel. What am I doing wrong here? |
| ||
I always use these functions for readpixel/writepixel operations:Function GetA(rgb%) Local a=(rgb And $ff000000)/$1000000: Return a End Function Function GetR(rgb%) Local r=(rgb And $ff0000)/$10000: Return r End Function Function GetG(rgb%) Local g=(rgb And $ff00)/$100: Return g End Function Function GetB(rgb%) Local b=rgb And $ff: Return b End Function Function CombineRGB(r%,g%,b%) Return r*$10000+g*$100+b End Function Function CombineARGB(a%,r%,g%,b%) Return a*$1000000+r*$10000+g*$100+b End Function And this worked for me: a=GetA(ReadPixelFast(x,y,buffer)) And $ff Edit: I just made a small demo, you need a 32bit bmp file with an alpha channel, use this: http://www.christianhart.de/bb/haze.bmp The code will extract and show the alpha channel and the rgb part of the texture. very simple. |
| ||
Is it not something to do with you masking out 8 bits for each channel, as only having a 24 bit number to work with, in colour information terms? |
| ||
Try this:Function ReadAlpha(argb%) Return argb - 16777216 End Function Unless I'm mistaken, then yeah, it's that simple. XD |
| ||
He's wanting to seperate out the indivudal colours contained with the ARGB value. |
| ||
Yeah, I got that, but I thought the RGB values were coming out okay, and that only the Alpha was messed up. |
| ||
Thanks people - this code seems to work:alpha = getA(rgb) And $ff Function GetA(rgb%) Local a=(rgb And $ff000000)/$1000000: Return a End Function |
| ||
I've tested your first code, it works ok:Graphics3D 640,480,32,2 tex=CreateTexture(256,256,3) SetBuffer TextureBuffer(tex) LockBuffer TextureBuffer(tex) WritePixelFast 10,10,$FFffffff argb=ReadPixelFast(10,10) a=(argb Shr 24 And %11111111) UnlockBuffer TextureBuffer(tex) SetBuffer BackBuffer() Print Hex$(argb) Print Hex$(a) WaitKey() Maybe there's something wrong with the source of your argb. |