Chroma, Chroma, Chroma Chameleon: Altering DIB's

Dear Dr. GUI:

What is the method of choice for changing the contrast and/or brightness of a DIB? I hope you're not gonna tell me I have to iterate through each pixel and add/subtract from the colour value "manually"! I could probably do that, but I don't know how to do gamma correction and all that stuff. So I'm hoping you'll say something like "Oh...use the BrightBlt function."

Steve Yolleck
Toronto, Ontario, Canada

Dr. GUI replies:

I am a master of music trivia. This song was sung by a young man who looked remarkably like an older woman wearing heavy makeup. The makeup was very bad looking but extremely colorful. Which brings me to my point (I think).

There are two approaches to your problem. Assuming that you are targeting an 8-bit-per-pixel (bpp) 256-color display (there is a strong argument that this should be your target display), you can either animate the palette or alter the existing palette entries.

I once wrote a fax application that used palletized color on a 256-color display. The images were all black and white, so I constructed 128 gray scales in the palette. To alter the contrast and brightness I animated the palette, changing the slope for contrast or changing the overall level for brightness.

In my opinion, the best approach is to alter the colors of the bitmap and then redraw it. Palette animation is too dependent on the presence of a palette. In the case of 8-bpp bitmaps, change the palette entries to reflect the desired brightness/contrast and then redraw the DIB (device-independent bitmap). On any other display you need to alter the image by walking through the DIB and altering each pixel (yeech!).