forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

hex codes for colours

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
richy486



Joined: 08 Mar 2006
Posts: 4

PostPosted: Wed Mar 08, 2006 4:37 pm    Post subject: hex codes for colours Reply with quote

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
View user's profile Send private message
fish



Joined: 08 Feb 2006
Posts: 25

PostPosted: Wed Mar 08, 2006 7:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
Wil



Joined: 23 Feb 2005
Posts: 15
Location: Las Vegas

PostPosted: Wed Mar 08, 2006 8:30 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Mar 08, 2006 9:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
fish



Joined: 08 Feb 2006
Posts: 25

PostPosted: Thu Mar 09, 2006 9:39 pm    Post subject: Reply with quote

Raphael wrote:

@fish: one pair of letters is 1 byte == 8bit


That's what I meant:p
Back to top
View user's profile Send private message
richy486



Joined: 08 Mar 2006
Posts: 4

PostPosted: Thu Mar 16, 2006 6:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Thu Mar 16, 2006 7:00 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group