3

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.

Amarghosh
  • 58,710
  • 11
  • 92
  • 121
  • Do you mean *when the factor 85 is replaced with 84* perhaps ? – Paul R May 12 '11 at 09:03
  • @Paul No, i meant forty eight indeed. – Amarghosh May 12 '11 at 10:09
  • @Amarghosh: OK - that seems like a very big difference relative to 85 - how can the matching be "fairly close" with FACTOR = 85 and "almost perfect" with FACTOR = 48, I wonder ? – Paul R May 12 '11 at 10:11
  • @Paul - I'm guessing that he means visually. Obviously for two 0 bits, it doesn't matter what mapping you use, so the darker the colors the closer the match whatever value is used. Almost any monotonic sensible mapping will be "fairly close" – Nick Fortescue May 12 '11 at 10:27
  • @Nick: ah, OK - that might make sense - it sounds like the first thing the OP needs to do is develop a better way of testing/validating the result. – Paul R May 12 '11 at 10:28
  • @Nick I was referring to visual matching, sorry if I didn't make it clear. This reference video is the only thing that we have to validate the colors. Using 48 as the factor make dim-white (101010) to grey (0x606060) instead of 0xAAAAAA and this difference is significant. In short, 48 satisfies the reference video but fails on normal ones whereas 85 works everywhere else, but fails on reference video. – Amarghosh May 12 '11 at 12:25
  • If that's the case, it's impossible to have any algorithm that will produce different results depending on whether it is reference video or normal, unless I misunderstand you. – Nick Fortescue May 12 '11 at 13:00

1 Answers1

5

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.

Nick Fortescue
  • 43,045
  • 26
  • 106
  • 134
  • The color bits are indeed coming in as `RrGgBb`; I tried the EGA format of rgbRGB just in case, and it gave me totally different colors as opposed to the near matches that I am currently getting. – Amarghosh May 12 '11 at 12:21
  • OK, but my comment about the array still holds. Does it make sense to you? – Nick Fortescue May 12 '11 at 12:24
  • yeah, I got it. I was hoping there's a standard algorithm (may be that takes each of the three components into account to compute the 8 bit value of an individual component); look-up table approach will definitely help in performance side - thanks for the suggestion. – Amarghosh May 12 '11 at 14:50