I have color values coming in six bits, two bits for red, green and blue. Thus, black will be represented as binary 000000, red 110000, blue 000011, yellow, 111100and so on.
I need to convert this color to a 24 bit rgb value to pass it to the graphics layer (DirectFB). Since three (binary 11) should become 255 (0xFF), I used the following formula with 85 (= 255/3) as the conversion coefficient.
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 colors (white [0x3F → 0xFFFFFF], red [0x30 → 0xFF0000], etc.).
Now these colors are the text and background colors of the subtitles that will be displayed on the TV screen, and we have test streams in which there is a reference color palette built into the video. When I paint the 8-bit colors obtained using this formula on the screen, this does not quite correspond to the help color present in the video - this is pretty close, but there is a difference.
Am I doing the conversion correctly or is there a standard algorithm for converting two rgb color bit values to eight rgb bits? Can DirectFB use some other representation (e.g. RGB565)?
What is it worth when the coefficient 85 is replaced by 48 (the value found by trial and error), the colors match almost perfectly.
source
share