Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How do DirectDraw Surfaces store 16-bit images?

This topic is 6298 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My question is this, how does a DirectDraw surface store the pixel values for a 16-bit image. It must have to store each pixel''s colour value in 2 bytes. The bitmaps I am loading into my game are 24 bit, so they must have 3 bytes to store the RGB values for each pixel. So how does DirectDraw convert the 3 bytes into 2? Please help!

Share this post

Link to post
Share on other sites
It stores them in 555 mode (5 bits for red, 5 for...) if you have a 555 graphic card and 565 if you have one of those cards. Yes, that makes 15 or 16-bits, 16-bits equals 2 bytes. In case of 555 the high bit is always ignored ie. 0RRRRRGGGGGBBBBB.

The easiet (but not always the best, but its sufficient) way to convert a 24-bit pixel to 16-bit is to just downshift each RGB-component 3 (or 2) bits and then mask them together again. Like:

RRRRRRRRGGGGGGGGBBBBBBBB (this is our origional 24-bit pixel)

then do this for every component (this is for 565)
RRRRRRRRGGGGGGGGBBBBBBBB & 111110000000000000000000
RRRRR0000000000000000000 << (24 - 16)

and then for green...
RRRRRRRRGGGGGGGGBBBBBBBB & 000000001111110000000000
00000000GGGGGG0000000000 << (24 - (16 - 5))

and then the same for blue...

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!