Binary color separation trick [RESOLVED]

Blitz3D Forums/Blitz3D Beginners Area/Binary color separation trick [RESOLVED]

Mikorians(Posted 2015) [#1]
I'm darned if I can remember the old
'And' trick to obtain red, green, blue, alpha values
In that rapid way with the logical AND trick...
Red=Col AND $something bla bla...
Erm, anybody remember it?
Should be an easy one to solve.
The REAL FAST one?
I need it for another programming language also.


Matty(Posted 2015) [#2]
Yep....

Rgb = red shl 16 or green shl 8 or blue


And to get components

Red =( rgb shr 16) and 255
etc....


GfK(Posted 2015) [#3]
BlitzMax code but you get the idea:
Local col:Int = $FF0AC216

Local Alpha:Int = (col Shr 24) & $FF
Local RED:Int = (col Shr 16) & $FF
Local GREEN:Int = (col Shr 8) & $FF
Local BLUE:Int = col & $FF



Mikorians(Posted 2015) [#4]
Yep.
And for those who need the Visual Basic 6 version (Yeesh):
B=(Col And &HFF0000)/&H10000
G=(Col And &HFF00)/&H100
R=(Col And &HFF&)
If Col<0 Then A=((Col And &H7F000000)/&H1000000) Or &H80& Else A=Col/&H1000000

If I've made an error with the alpha, let me know...


Floyd(Posted 2015) [#5]
Silly trick which I occasionally use:

Print DottedIP( $01020304 )

WaitKey


I know that doesn't answer the original question of getting A,R,G,B. But it is a handy way to see the four bytes in an integer.


Guy Fawkes(Posted 2015) [#6]
O for god sake, GFK! HELP the man.

Here, @Mikorians:



I hope you like this. It took an hour & a half to make! :)

And yes, I'm aware that if you go above 255 for some reason, even though I TOLD it NOT to, the "Red" value will be set to "10" for some reason. Other than that, I think it's pretty straight forward!

Anyways, good luck with your project! I hope this helps! :)

Sincerely,

~GF