Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# How do colours work with respect to bits per pixel

Posted on 2003-03-26
Medium Priority
327 Views
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
0
Question by:Dawkins
• 2

LVL 1

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.
0

LVL 1

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 :)
0

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  :)
0

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  :)
0

## Featured Post

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
###### Suggested Courses
Course of the Month15 days, 4 hours left to enroll