|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Converting 24bit image to 16bit
In a message dated 10/5/00 5:58:25 PM Central Daylight Time,
anime6@earthlink.net writes:
<< Someone help me please. I need to write code to load a 24 bit, bitmap
into a 16 bit buffer. How do I do this. Usually it doesn't work. >>
OK. If I'm remembering right, I think 24-bit images are stored with one byte
for Red, Green, and Blue, and 16-bit is just the three attributes split over
two bytes. So, if you load a 24-bit image in this order:
RRRRRRRR GGGGGGGG BBBBBBBB
Each color attribute is 8-bit, meaning that it is in the range 0 to 255.
16-bit (correct me if I'm wrong) is stored in this fashion:
RRRRR GGGGGG BBBBB
The red and blue color attributes are in the range 0 to 31, and the green
attribute is in the range 0 to 63, so what you need to do is convert the 0 to
255 range to 0 to 31 or 63. This can be done easily by bit shifting. Here's
pseudo-code:
5BitRed=8BitRed>>3; // 8BitRed/8
6BitGreen=8BitGreen>>2; // 8BitGreen/4
5BitBlue=8BitBlue>>3; // 8BitBlue/8
Color=5BitBlue+(6BitGreen<<5)+(5BitRed<<11)
This is the conversion, though depending on the library/video card/driver you
are using, the red and blue may be reversed in positioning.
-Ender Wiggin
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
|
|