#7933 - MidiMouse - Sat Jun 28, 2003 10:14 pm
I was looking at the Loirak Development GBA Tutorial:
http://www.loirak.com/gameboy/gbatutor.html
but I don't understand the reason the purpose for shifting in this line in the first program:
#define RGB16(r,g,b) ((r)+(g<<5)+(b<<10))
I read the description, but still don't understand. Can someone clarify?
Thanks.
#7941 - Archeious - Sun Jun 29, 2003 1:19 am
Pixel on the GBA are made up of three primary colors (RED,GREEN,BLUE) stored in a 16bit word (XBBBBBGGGGGRRRRR). The << and >> are shift operators. In other words it shift the bits up or down. So a 0000000000011111b << 5 becomes 0000001111100000b. Hope that helps.
#7943 - MidiMouse - Sun Jun 29, 2003 3:29 am
Ohhh, I see...that makes sense. Thanks
Okay, say I shift green <<3. Does that mean that I can only have 8 possible colors for red?
Thanks,
Lam
#7946 - Archeious - Sun Jun 29, 2003 6:01 am
MidiMouse wrote: |
Ohhh, I see...that makes sense. Thanks
Okay, say I shift green <<3. Does that mean that I can only have 8 possible colors for red?
Thanks,
Lam |
No because #define RGB16(r,g,b) ((r)+(g<<3)+(b<<6)) Let say you pass the values RGB16(31,18,25) it would resolve like this
((11111b)+(10010b<<3)+(11001b<<6)) or
((11111)+(10010000)+(11001000000)) or
31+144+1600 = 1775 or
000011011101111 and when that is stuck into a 16 palette it would be this
(0) Extra Bit (00001)Red (10111)Green (01111)Blue
Nothing like the intended color. Does that make sense?
#7948 - tepples - Sun Jun 29, 2003 6:15 am
On the other hand, some programs that render to an 8-bit buffer do set up the palette in such a way (3:3:2 direct color) that green is shifted left by 3 bits:
Code: |
#define RGB8(r,g,b) ((r)+(g<<3)+(b<<6))
/*
76543210 8-bit direct color
||||||||
|||||+++- Red (0-7)
||+++---- Green (0-7)
++------- Blue (0-3)
*/ |
But it still doesn't make sense in a 16-bit environment.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#7979 - MidiMouse - Sun Jun 29, 2003 8:34 pm
okay, I get it! Thanks alot!
-Lam