gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > From BGR To RGB

#49211 - NighTiger - Wed Jul 27, 2005 9:21 am

Hi guys,
I did read that the gba saves the colors information in BGR format, in
2 bytes where every variable takes 5 bit and the most important bit
is not checked.

Code:

X B B B     B B G G     G G G R     R R R R
F E D C     B A 9 8     7 6 5 4     3 2 1 0



So if We want a RGB format We need to apply the following code to the
variables

(r | (g<<5) | (b<<10))

I know how the left-shift works and how the logical-OR works , but I
can't understand how the compilator works to make the correct format.

Can anybody help me to understand that?
tnx

#49212 - NoMis - Wed Jul 27, 2005 9:40 am

If you already know how shifting and bitwise OR works then I don't understand your question.
It's basically just a 16 bit integer.

NoMis
_________________
www.gamedev.at - The austrian gamedev site
hde.gamedev.at - The Handheld Dev Env plugins for Eclipse

#49214 - NighTiger - Wed Jul 27, 2005 9:45 am

I don't understand the sequence.

for example

Code:

F E D C    B A 9 8    7 6 5 4    3 2 1 0
X 0 1 0     1 0 1 1    1 1 0 1    0 1 1 0


before We shift the 5 bit of the blue

So

Code:

E D C    B A
0 1 0     1 0

4    3 2 1 0
1    0 1 1 0


right?
And with the logical OR?

#49216 - NoMis - Wed Jul 27, 2005 10:44 am

Lets take the color white (31,31,31) as an example of what happens.

Code:

these are the color values in their bit format:

r  0000 0000 0001 1111
g  0000 0000 0001 1111
b  0000 0000 0001 1111

first of all the shifts (g<<5)  and  (b<<10) are exected wich result in the following values that will be combined with the bitwise or.

r  0000 0000 0001 1111
g  0000 0011 1110 0000  -> Green shifted by 5 bits
b  0111 1100 0000 0000  -> Blue shifted by 10 bits
---------------------------------
   0111 1111 1111 1111


_________________
www.gamedev.at - The austrian gamedev site
hde.gamedev.at - The Handheld Dev Env plugins for Eclipse

#49217 - NighTiger - Wed Jul 27, 2005 10:46 am

Thank you so much