argb help

BlitzMax Forums/BlitzMax Programming/argb help

Nope!


No wait, I mean...


Yes!
R = (RGB Shr 16) And 255 
G = (RGB Shr 8 ) And 255
B = (RGB       ) And 255



The way the first one works is it moves the green byte over to the left by 8 bits, and the red byte over to the left by 16 bits, and adds all three together. This produces an integer which has four bytes in it, ARGB.

The way the second one works is it rotates the red byte over to the right by 16 bits, which puts it in the first byte position, and then 255 is used to mask it to get rid of any bits that might be in the first byte of the integer which contains the alpha byte. 255, when stored in a longint is 00000000 00000000 00000000 11111111 in binary.

If R is in the second byte... and the alpha byte is 255..,
11111111 00001111 00000000 00000000

And we rotate the int 16 bits to the right...
00000000 00000000 11111111 00001111

Then if we AND the integer with 255, leaving only those bits on which are in 255 AND the integer...

00000000 00000000 11111111 00001111
AND
00000000 00000000 00000000 11111111
=
00000000 00000000 00000000 00001111

Then as you can see, the final number is the byte that represents the R value.