Color depth


While working with the RFB protocol, I came upon a situation where I receive 16-bit pixels, with red, green, and blue, each at 5-bit color depth i.e. each color value ranges from 0 to 31. I need to change each pixel to 24-bit color depth for displaying as a bitmap, or 8-bit for each of red, green, and blue. What works is left shifting each of the 5-bit colors by 3 bits so that each color is 8-bit.

2 thoughts on “Color depth

  1. Simply shifting 3 bits right is not enough: you will loose some dynamic range.
    Consider the case where the 15 bit colour is 111111111111111, i.e. white, if you just shift the bits, you will have the following RGB color: 111110001111100011111000, i.e. each channel will be 248 / 255 of white, more than 2% off.
    A better solution is to duplicate the top three bits, i.e. o = i <> 2, this will give you a better range.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s