Link to home
Start Free TrialLog in
Avatar of Dawkins
Dawkins

asked on

How do colours work with respect to bits per pixel

Hi guys,

I'm a complete newbie on this topic.  How are various colour depths ecoded exactly?  For example, I believe 8 bit/pixel is 3 bits for red and green and 2 for blue?  What about 16bit, and 32bit?  Are they just scaled up versions of 8 bit (ie with less bits allocated for the blue part)?   What about the RGB value, is that 24 bit?  Is there a way to convert between the various colour depths?  

I know this isn't exactly a C question, but I need to know it for a C project and I strongly suspect 99% of C programmers reading this will know the answer ;)

Thanks for any help,

Dawkins
ASKER CERTIFIED SOLUTION
Avatar of catbutt
catbutt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cybeonix
cybeonix

There are generally 2 forms of pixel data.
Chunky pixel and Planar graphics.

Chunky pixel (as used on Windows Operating systems) stores each pixel in either 8, 16 or 32bits.  In 8 bit mode, the number stored in those 8 bits refers to a pallete entery.  If palette entry 1 is blue, then 000000001 will display blue when drawn.  Changing the pallete color forces all colors of that pixel value to change as well.  Maximum of 2^8 colors (256 colors)
16bit works as described by catbutt, the 16bits are divided up giving a slight advantage to the green range of colors.
32bit is usually represented in ARGB format (depending on the format you choose, theres many others)
A = Alpha
R = Red
G = Green
B = Blue

The alpha "channel" is rarely used, but modern graphics cards will use this as a sort of blend factor, allowing transparencies etc. and overlayed images.


You'll rarely come across planar format, but it works a bit different.  Each "plane" of pixels are stacked on top of each other.  To visualize an 8bit display, take 8 sheets of paper and write 1s and 0s all across them, then stack them on top of each other.  Reading each corrosponding bit on each sheet with the same position on the next sheet gives you your 8bit number. (top sheet to bottom sheet)

Planar graphics have the advantage of taking up less memory as opposed to chunky graphics.  If you have a 24bit display, you only need 24 planes of data.  The smallest data that will accomodate a 24bit display in chunky format is a 32bit number.  So you don't save any memory between the them when using chunky pixel graphics.

Hope that helps   I'm not big on graphics manipulation so if I'm talking out of my butt here, feel free to correct me :)
Avatar of Dawkins

ASKER

Thanks a lot guys.  I guess I should accept catbutts comment as an answer since he was first, but thanks a lot for expanding a bit more cybeonix  :)
Avatar of Dawkins

ASKER

Thanks a lot guys.  I guess I should accept catbutts comment as an answer since he was first, but thanks a lot for expanding a bit more cybeonix  :)