Archived

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

16bit back to 24 bit

This topic is 5654 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

Is this possible? For a test I changed Red 40, Green 50 and Blue 60 color values from 24bit to a 16 bit format, then I changed them back, the best Ive managed is Red 40, Green 48 and Blue 58. To convert to 16 bit I use DWORD Pixel = 0; Pixel += ((Red>>3)<<11); Pixel += ((Green>>2)<<5); Pixel += (Blue>>3); As this involves division Im lossing accuracy due to rounding, this apears when I change back. I was wondering if anyone knew of anyway that I can get the exact color values back to 24bit form 16bit? Ballistic Programs

Share this post


Link to post
Share on other sites
No, you can''t get the exact values back (except for those colors that divide evenly, of which 1 in 256 do). 16bit=2 bytes, 24bit=3 bytes. No matter what you do some of the information is discarded when you convert down to 16bit. If you do find a way then you''ve found a way to compress any file into just 2 bytes.

Share this post


Link to post
Share on other sites
You can''t get the exact value back, but you shouldn''t just shift up and leave the lower bits set to 0. If you do that you''ll never get something like 100% white.

The common way to do this is to shift the 5 bit color component of the 16-bpp value to the left 3 places, then set the lower 3 bits equal to the upper 3 bits.

Give this a try:

BYTE r = ((wColor >> 11) << 3) | (wColor >> 13);
BYTE g = ((wColor >> 3) & 0x00fc) | ((wColor & 0x0600) >> 9);
BYTE b = ((wColor << 3) & 0x00f8) | ((wColor & 0x001c) >> 2);

Share this post


Link to post
Share on other sites