[SOLVED] RGB to u32 Color

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

Moderators: cheriff, TyRaNiD

Post Reply
_BenJi
Posts: 7
Joined: Wed Jan 16, 2008 6:38 am

[SOLVED] RGB to u32 Color

Post by _BenJi »

Hi,

Yeah, I'm noob, but I don't know how to convert an RGB colour to an u32 colour.

I get the framebuffer with 'sceDisplayGetFrameBuf', and I want to change the colour of some pixels.

With SDL there is the function 'SDL_MapRGBA' but I don't want to use SDL. And there isn't the 'uint32_pack' for the PSP (or I didn't find it)

Can someone help me ? :(

Solution :

Code: Select all

color = &#40;b<<16&#41; + &#40;g<<8&#41; + r;
CpuWhiz
Posts: 42
Joined: Mon Jun 04, 2007 1:30 am

Post by CpuWhiz »

They are in pspgu.h:

Code: Select all

/* Color Macros, maps 8 bit unsigned channels into one 32-bit value */
#define GU_ABGR&#40;a,b,g,r&#41;	&#40;&#40;&#40;a&#41; << 24&#41;|&#40;&#40;b&#41; << 16&#41;|&#40;&#40;g&#41; << 8&#41;|&#40;r&#41;&#41;
#define GU_ARGB&#40;a,r,g,b&#41;	GU_ABGR&#40;&#40;a&#41;,&#40;b&#41;,&#40;g&#41;,&#40;r&#41;&#41;
#define GU_RGBA&#40;r,g,b,a&#41;	GU_ARGB&#40;&#40;a&#41;,&#40;r&#41;,&#40;g&#41;,&#40;b&#41;&#41;

/* Color Macro, maps floating point channels &#40;0..1&#41; into one 32-bit value */
#define GU_COLOR&#40;r,g,b,a&#41;	GU_RGBA&#40;&#40;u32&#41;&#40;&#40;r&#41; * 255.0f&#41;,&#40;u32&#41;&#40;&#40;g&#41; * 255.0f&#41;,&#40;u32&#41;&#40;&#40;b&#41; * 255.0f&#41;,&#40;u32&#41;&#40;&#40;a&#41; * 255.0f&#41;&#41;
So:

Code: Select all

color = GU_RGBA&#40;r, g, b, 255&#41;;
Post Reply