working with colors

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

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

working with colors

Post by coolkehon »

i've posted this on another website and no one could help

I'm trying to work with colors and before now oslib had #defines that did it for me but i'm using SDL and i need to know how to work with colors i know the basic RGBA stuff 0 to 255 but how are they combined to be in one int (ex Uint32) and be a color and then how do i extract the values from that also i looked it up but i see a bunch of rgb stuff, etc but nothing i'm looking for

what i'm wanting is to learn how they work when casting to an in say for instance i know i need a color RGB r = 255, b = 100, g = 30, a = 240

now how can i take all of those values and bit the or whatever i need to do to make them into a Uint32 that i can use that is a color that would be also useable on other systems also for future reference

i know somewhere i've seen something like

r << (sum num) << g (sum num) << ...

that i dont fully understand or remember but it made a color i believe that oslib uses this in #define's but dont understand it

thats about all that went on in that post summed up
svxs
Posts: 15
Joined: Fri Jun 19, 2009 10:03 am

Post by svxs »

One eight-bit byte can store a value from 0 to 255.

The PSP uses integers that are 4 bytes, 32 bits.

The way you encode the colors depends on the pixel format you're using. Just realize that there are typically four channels in a color: red, green, blue, and alpha. But sometimes there're less.

To put it together, encoding a color that uses one byte per channel is as simple as using one byte per channel.

My advice is to read about bytes and integers, bit-shifting and logical operations, and the pixel format that you're wanting to encode to.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

cool thanks right direction after an hour got to this page cause one thing led to another and i found it thanks so much

http://hrboyceiii.blogspot.com/2007/02/ ... d-why.html
Post Reply