4

I'm trying to convert 24bit (8R, 8G, 8B) into 8bit (RRRGGGBB) colors

I understand the basic concept of scaling the color bytes down and adding them together (after shifting). i.e. given RGB(255,254,253) I would take 255/32*32 + 254/32*4 + 253/64 and this would give me in 111,111,11b (white).

This works pretty well for pictures with a lot of red and green but once blue starts to appear, things get really thrown off. The blues start to look more turquoise or purple than before.

I'm not trying to do dithering but rather to find a better mapping between RGB and 8bit.

I considered converting RGB to HSV and then to 8 bit but I'm not sure how to convert from HSV to 8bit either, the H byte does not correspond to RRRGGGBB. Even if it did, I couldn't get black and white. Is there a way to weight the H,S,V bytes (like how I did with RGB) to get what I want? Or should I just stick with finding a better mapping between RGB straight to 8bit

Vbomm
  • 53
  • 5
  • Are you going to be using a specific language, since it may already provide you the operations you need? – Andre M Mar 01 '16 at 21:20
  • It's written in assembly – Vbomm Mar 01 '16 at 22:34
  • With only 2 bits of information for the blue channel, don't expect the colors to look correct. You do just fine, there will not be any much better conversion to RRRGGGBB, if you do not dither. 8-bit palette image may look much better – galinette Mar 01 '16 at 22:38

1 Answers1

1

To convert 8bit [0 - 255] value into 3bit [0, 7], the 0 is not a problem, but remember 255 should be converted to 7, so the formula should be Red3 = Red8 * 7 / 255.

To convert 24bit color into 8bit,

8bit Color = (Red8 * 7 / 255) << 5 + (Green8 * 7 / 255) << 2 + (Blue8 * 3 / 255)
Mingjie Li
  • 145
  • 2
  • 6