hex codes for colours

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
richy486
Posts: 4
Joined: Wed Mar 08, 2006 4:30 pm

hex codes for colours

Post by richy486 »

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
fish
Posts: 25
Joined: Wed Feb 08, 2006 5:12 am

Post by fish »

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)
Wil
Posts: 15
Joined: Wed Feb 23, 2005 7:30 pm
Location: Las Vegas
Contact:

Post by Wil »

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
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Code: Select all

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
fish
Posts: 25
Joined: Wed Feb 08, 2006 5:12 am

Post by fish »

Raphael wrote: @fish: one pair of letters is 1 byte == 8bit
That's what I meant:p
User avatar
richy486
Posts: 4
Joined: Wed Mar 08, 2006 4:30 pm

Post by richy486 »

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.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

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
Post Reply