Mega Code Archive

 
Categories / Delphi / API
 

Color reduction techniques for graphics

Question: How do I accurately (and automatically) display HiColor and True Color (16 and 24 bit) images on a 256 color display? Answer: Generally, you cannot. This requires sophisticated color reduction techniques, and not all will work well on all images. Most all color reduction methods work by weighing the average of similar colored pixels in a given are of the image, and combining them. Consider a image of a person standing in a park with green grass, flowers, trees and a blue sky. You would need to remap potentially millions of colors to fit into the Windows palette (236 colors). While this can usually be done in a professional paint program with some trial and error, a single function would have much trouble remapping the colors to faithfully reproduce all images. This is the reason why paint programs that can accurately reduce colors give so many choices in the method used to reduce the color. In the above example, you could combine many shades of blue and green, and dedicate more colors to faithfully reproduce the persons flesh tones. This method would probably produce an acceptable image, since the shades of the sky, grass, and trees are far less important than the shades necessary to reproduce flesh tones. On the other hand, if the purpose of the image was to show a spectacular panorama of a canyon, you might want to put less emphasis on the exact color of a house that might be in the picture, and instead concentrate on the colors of the canyon. As you can see, where one color reduction function may work well on one image, it would most likely have trouble with others. Some paint programs use a "Color Wash" palette, that sometimes can display with fair accuracy a colorful 24 bit photograph. This is done by creating a palette that contains a wash of colors that are generally useful for displaying most images. Again, pixels are compared by area, and remapped to a color that is reasonably close to the original if possible.