Skip to main content
GameDev.net gamedev.net
🔒 Locked

Understanding Colours as a newbie!

Started by Paul Crane Aug 3, 2002 at 10:31 AM 3 replies 1k views
Original Post
Paul Crane
Paul Crane
Hi. I''m not sure I''m in the right forum for this question, but I am using DelphiX with Delphi 6. Please excuse me ignorance here... I am new to programming in Windows and do not understanding how Windows/Delphi handles colour. I remember the old DOS days with 256 colours. One byte stores the colour number, with each colour in the palette having RGB values 0..255. From what I understand. 24 bit colour uses 3 bytes each represent each of the RGB values. 3 bytes equals 24 bits. Therefore 255x255x255 gets us to the 16.7 million possible colours. Is that how it works?? :-) Okay. So what about 16bit colour? I am going to write a game in 16bit colour. How is this stored exactly. I haven''t been able to find anywhere where it explains how colour is handled in Windows. At least, not in a simple manner. Can anyone point me somewhere where I can start? How is a 24bit colour BMP displayed in a 16bit mode for example? Thanks for any help in advance! Paul.
Arctic Weasel
Arctic Weasel
You''ve basically got it right.
The pixel data for 256 colors or less is an index into a palette.
The pixel data for higher color depths, including 16 bit, is the color itself, not an index.
16 bit works like this:
rrrrr gggggg bbbbb
Notice that there''s an extra green bit in there. 16 bit divided by three (r,g,b) = 5 with a remainder of 1. So there is an extra bit to be used. Humans have a higher sensitivity to green, so that''s why there is 6 green bits. For a game, this extra bit can be a non-issue, or get in your way. If so, you may want to consider 15 bit, which looks like this:
0 rrrrr ggggg bbbbb

You might want to check out efg''s computer lab for more background info.

I guess it depends on what you mean when you say display a 24 bit image in 16 bit. If you succeed, there will be fewer colors, and it won''t look good unless you have a good algorithm for color reduction.
Paul Crane
Paul Crane
Thanks for the reply.

Interesting about the extra green bit being using.

Thanks also for the link. Some of the stuff looks a bit complicated but looks like a good place to start.


Thanks again...



Paul
Mike85
Mike85
Windows GDI uses 32 bit colors (4 bytes). First byte is for red, second for green, third for blue and last is usually unused. In 16 and 8 bit mode last byte can be used to define when color should be dithered and Windows XP icons use it to define alpha transparency.

example:
Form1.Color := $000000FF;//red
Form1.Color := $0000FF00;//green
Form1.Color := $00FF0000;//blue
Form1.Color := $00FFFFFF;//white

16 bit mode uses 2 bytes for each color. First byte contains information about red and first part of green, last byte contains second part of green and blue. Some videocards / drivers use 6 bits for green and some 5 bits. You don''t have to care about this because when you blit 24 bit image onto 16 bit surface, videocard will convert image into compitable format. If you draw 16 bit image which uses 6 bits for green, onto surface that uses 5 bits for green, then image will look incorrect.
Arctic Weasel
Arctic Weasel
Paul, there is a lot of stuff on Efg's. You should check out what they've got on the ScanLine property.

Mike85, you're right the extra green bit usually isn't a problem. I just thought it was worth mentioning that there is a 15 bit alternative, if you were actually doing special effects on the pixel data.


[edited by - Arctic Weasel on August 9, 2002 2:17:13 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.