Glossary Item Box
The above functions allow some basic manipulation of images; however, the most needed function is usually the ability to dither and/or color reduce an image (especially when displaying a 24-bit image on a 256 color device). That's where the ImgReduceColors and ImgReduceColorsPal functions are useful.
Note that display color depth, image color depth, and palettes are a complicated topic. While the sections below will give several examples of how to use the ImgReduceColors and ImgReduceColorsPal functions, you should refer to your favorite Windows programming books for full explanations of these subjects.
ImgReduceColors has several options which allow you to reduce the colors in an image, dither an image, or convert an image to grayscale (or combinations of the above). This function has three parameters: the first is the handle of the image we wish to work from (remember, this function returns a handle to a new image, so we're not altering the original); the second is the number of colors you wish to have in the resulting image (this is currently limited to 256, 16, or 2); the third parameter is a set of flags which represent several differing operations to perform during the color reduction process, including dithering (Burkes, Floyd-Steinberg, or Bayer methods are available) and grayscaling the image. The following example will show several operations using this function:
.
.
.
// hImg is a 24-bit image. Note that it is not altered
// in the following operations.
hImg = ImgOpenSolo("colorful.jpg", NULL);
// first we'll dither it to black & white using the
// Burkes dither
hImg2 = ImgReduceColors(hImg, 2, IMG_BURKES);
// next, we'll reduce it from 24-bit color to
// 256-colors.
// To do this, we use the IMG_OCTREEPALETTE option, which
// calculates a palette based on the colors in the
// image. We also use the FLOYD dithering option.
// This is a time-consuming operation, but
// gives excellent results.
hImg3 = ImgReduceColors(hImg, 256, IMG_OCTREEPALETTE | IMG_FLOYD);
// The following command will reduce and
// dither the image to a pre-defined palette.
// This is much faster than the above code,
// but yields results that are not as good.
// This is also useful for displaying more than
// one color image at a time.
hImg4 = ImgReduceColors(hImg, 256, IMG_FIXEDPALETTE | IMG_FLOYD);
// You can also dither a 256-color image to a
// pre-defined palette. This makes it easy to display
// multiple color images simultaneously without
// palette problems.
// Here we reduce it to 16-bit color and dither it
// using the Floyd-Steinberg dither
hImg5 = ImgReduceColor(hImg, 16, IMG_FLOYD);
// finally, we'll produce a grayscale version of
// the image in 256 colors
hImg6 = ImgReduceColor(hImg, 256, IMG_GRAYSCALE);
.
.
Copyright 2008 Data Techniques, Inc. All Rights Reserved