• Advertisement
Sign in to follow this  

RGB8888 to RGB565 pixel format conversion

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

I went through the gamedev forums on finding exactly what 565 format means. So 565 format represents each pixel in the following bit order: 565 format: RRRR RGGG GGGB BBBB What I wanted to know is: Suppose an artist is working in an art package like Photoshop. He is working in RGB mode where he works on 32 bit RGBA mode. So there is no loss in color as all the R, G B and A channels are 8 bits each (RGBA 8888). So each color will have the values ranging from 0 to 255. Now this image is converted to 16 bit image. So the conversion happens from 32 bit (RGB 8888) format to 16bit (RGB 565) format. How is this calculation done? How does the color loss happen? How does it select the color value (which color of RED converts from 8 bit to 5 bit)? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Why is it being converted to 16 bit in the first place? 16 bit color is pretty ugly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The simplest way is to simply drop the least-significant bits.

Ie.
NewR = R >> 3;
NewG = G >> 2;
NewB = B >> 3;


However, I suppose a more thorough method might include some form of dithering, to minimise banding.

Share this post


Link to post
Share on other sites
Don t latest vidcards s prefer 8bit aligned colors? so why would you want to use 16bit at all?

Share this post


Link to post
Share on other sites
certain mobile handsets support only RGB332 or RGB565 formats. This is the reason why we need to convert them.

Share this post


Link to post
Share on other sites
The color loss happens because in 16 bit color there is only 65536 different hues and in 24 bit color there is like 16.7 million. So there is less bits to present each color channel. If you use 8-bit RGB, the quality loss is very huge, since it has only 256 different hues

Certain colors won't be affected of course, but mostly what happens is that small differences between shades will disappear, making color gradients look ugly. There are different ways to improve the color conversion such as dithering, but I am not sure if it is an improvement on a mobile.

Naive and simple way to do the conversion is to extract the different color channels from 24 bit pixel and then drop the least significant bits (using Shifts and ANDs) and then pack the channels in 16 bit value (using shifts and ORs).

[Edited by - Demus79 on April 6, 2006 5:50:17 AM]

Share this post


Link to post
Share on other sites
As the AP said, drop the least significant bits of each color channel, ex:

R8 = 255
Convert R8 => R5 by dropping the last bits (255 >> 3)
R5 = 31

Going the other way (R5G6B5 => R8G8B8) is trickier.
A naive implementation reverses the R8 => R3 operation by shifting up:

R5 = 31
Convert R5 => R8 by shifting up (31 << 3)
R8 = 248 (Not what we wanted, the channel is darker now).

Some people use the following formula for R5 to R8

R8 = (R5 * 255) / 31;

I prefer to replicate the higher bits into the undefined lower bits:

R8 = (R5 << 3) | (R5 >> 2);



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement