How do colours work with respect to bits per pixel

Posted on 2003-03-26
Medium Priority
Last Modified: 2010-04-15
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,

Question by:Dawkins
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

catbutt earned 200 total points
ID: 8211754
Generally 8 bit color uses a pallete, so the number is simply a index into a color table, which is an array of 256 24 bit values.

16 bit color is usually stored in a 5-6-5 format, giving one more bit to the green component. (64 shades vs. 32 for red and blue)

32 bit usually uses the "extra" byte for either an alpha channel (transparency) or sometimes represents color as CMYK for printing.

Expert Comment

ID: 8216710
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 :)

Author Comment

ID: 8223336
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  :)

Author Comment

ID: 8223337
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  :)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question