Converting two bit color to eight bit color
I've color values coming in six bits, with two bits each for red, green and blue. So black would be represented as binary 000000
, red 110000
, blue 000011
, yellow 111100
and so on.
I have to convert this color into to 24 bit rgb value to pass it to the graphics layer (DirectFB). Since three (binary 11) is to become 255 (0xFF), I used the following formula with 85 (=255/3) as the conversion factor.
r = (color_6bit >> 4) * FACTOR;
g = ((color_6bit >> 2) & 0x3) * FACTOR;
b = (color_6bit & 0x3) * FACTOR;
color_32bit = (r << 16)| (g << 8) | b;
This correctly converts the colors (white [0x3F -> 0xFFFFFF], red [0x30 -> 0xFF0000] and so on).
Now, these colors are text and background colors of captions to be displayed on TV and we have test streams that have reference color palette embedded in the video. When I draw the eight bit colors obtained using this formula on to the screen, it is not exactly matching with the reference color present in the video - it is fairly close, but there is a difference.
Am I doing the conversion correctly or is there any standard algorithm for converting two bit rgb color values to eight bit rgb values? Could DirectFB be using some different representation (like RGB565) internally?
For what it is worth, when the factor 85 is replaced with 48 (value found by trial and error), the colors are matching almost perfectly.
The only standard I know of is EGA - there's a reference on wikipedia.
For what it's worth, 6 bits is a very small space - only 64 values. The quickest way of doing the conversion in terms of both cpu time and memory is almost certainly just looking up the value in an array of size 64. Especially if you have test data, this is really easy - just put the correct 64 values from the test data in the array. That way you don't need to worry if it is a standard - the standard is exactly whatever works for this system.
链接地址: http://www.djcxy.com/p/87800.html上一篇: 如何将24位RGB转换为8位RGB
下一篇: 将两位颜色转换为八位颜色