| View previous topic :: View next topic |
| Author |
Message |
richy486

Joined: 08 Mar 2006 Posts: 4
|
Posted: Wed Mar 08, 2006 4:37 pm Post subject: hex codes for colours |
|
|
I was wondering why the hex codes for colours on the psp are different from on pc. I am using SDL in 2.01 firmware.
thanks |
|
| Back to top |
|
 |
fish
Joined: 08 Feb 2006 Posts: 25
|
Posted: Wed Mar 08, 2006 7:22 pm Post subject: |
|
|
Depends what colour depth you're using, in HEX each pair of letters represents 2 bytes or 8 bits, or 0-255 in DEC. The PSP uses whatever colour depth you've set, it can be anything for textures* but printing to the screen should be in 16 or 32 bit, web colours are defined as 24 bit which I imagine is the source of your confusion.
@16 bit you can have: 0x0000 to 0xFFFF (this is harder to read because the middle two bytes contribute to both the R and G, and, G and B values respectively, and each individual value of R,G or B can only be 0-31. Unless you're also using alpha, in which case each byte corresponds to a colour directly RGBA with the last being the alpha byte)
@24 bit you can have: 0x000000 to 0xFFFFFF (I presume this is what you mean by 'PC' colours).
@32 bit you can have: 0x00000000 to 0xFFFFFFFF (the last 8 bits are for alpha) |
|
| Back to top |
|
 |
Wil
Joined: 23 Feb 2005 Posts: 15 Location: Las Vegas
|
Posted: Wed Mar 08, 2006 8:30 pm Post subject: |
|
|
I dunno. When I wanted to load a color from an INI file and use it in the graphics.cpp file from Lua the color I had to use was '16777215' for pure white.
#define RGB(r, g, b) ((b << 16) | (g << 8) | r)
#define WHITE RGB(255, 255, 255)
And then I just did a printf("%d", WHITE);
Perhaps it's just the way I did the output, but when I feed that number as an int to graphics.cpp it works. _________________ Wil |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Wed Mar 08, 2006 9:37 pm Post subject: |
|
|
| Code: | I was wondering why the hex codes for colours on the psp are different from on pc. I am using SDL in 2.01 firmware.
thanks
|
The answer is simple: The PSP uses BGR color format, while the PC uses RGB color format (however the windows API and GDI also use BGR afaik).
For PSP you have a macro:
#define BGR(r,g,b) (r | g << 8 | b << 16)
while for PC you'd have:
#define RGB(r,g,b) (r << 16 | g << 8 | b)
all respectively to a 32/24bit framebuffer.
@fish: one pair of letters is 1 byte == 8bit |
|
| Back to top |
|
 |
fish
Joined: 08 Feb 2006 Posts: 25
|
Posted: Thu Mar 09, 2006 9:39 pm Post subject: |
|
|
| Raphael wrote: |
@fish: one pair of letters is 1 byte == 8bit |
That's what I meant:p |
|
| Back to top |
|
 |
richy486

Joined: 08 Mar 2006 Posts: 4
|
Posted: Thu Mar 16, 2006 6:10 pm Post subject: |
|
|
| Quote: | | The PSP uses BGR color format, while the PC uses RGB color format |
I see, thanks.
I thought it was something like that, it was weird having the same code produce two different colours. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Thu Mar 16, 2006 7:00 pm Post subject: |
|
|
| Quote: | For PSP you have a macro:
#define BGR(r,g,b) (r | g << 8 | b << 16)
while for PC you'd have:
#define RGB(r,g,b) (r << 16 | g << 8 | b) |
You need more brackets than that
#define BGR(r,g,b) ((r) | ((g) << 8) | ((b) << 16))
#define RGB(r,g,b) (((r) << 16) | ((g) << 8) | (b))
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
|