Palette Lab  Report
Experiment with Windows Palettes

The purpose of this program is to provide a laboratory to experiment with various kinds of Windows palettes for 24-bit color images when displayed in a 256-color video mode.

Materials and Equipment

Software Requirements
Windows 95/98/NT/2000
Delphi 3/4/5 (to recompile)
Parrots.BMP (or other 24-bit color BMP file)

Hardware Requirements
Best when run on 800 x 600 pixel (or higher) monitor with 256-color display. You will see no difference in image quality if used on high color or true color displays.


  1. Configure your display adapter to 256-color mode, if necessary.
  2. Double click on the PaletteLab.EXE icon to start the program.
  3. Select the Load Image button and select a 24-bits/pixel BMP file to view. (The Parrots.BMP file is included for test purposes). The image will be displayed with a halftone palette.
  4. Select the Load Palette button and select a FractInt .PAL file, for example, the Volcano.PAL file. The image to the upper right will appear with the selected palette applied to the image. The lower right image shows the result of using only the "standard" 20 Windows colors to render the image.
  5. Select the Halftone Palette button to render both images with a halftone palette.
  6. Select the Optimized button to render see the lower right image rendered with an optimized palette. Compare this image with the halftone palette used to display the image at the upper right.
  7. Select the Gradient button.  Experiment with various types of gradient palettes by selecting the R, G, B checkboxes. For example, uncheck the G and B checkboxes. With only a red gradient the "reds" in the parrot on the right appear quite good in the image at the lower right.
  8. Experiment with how WM_QueryNewPalette and WM_PaletteChanged Windows messages are processed by running multiple versions of the program, with different images selected, and alternate between which application has focus. Watch how palettes are realized in foreground and background. Uncheck the button and see what happens when these messages are not processed.  [The GetTickCount values allow one to study the order the messages are processed.]

Processing the WM_QueryNewPalette and WM_PaletteChange messages is necessary if different windows receive focus. The foreground image always looks best. Sometimes the background images can suffer image quality, but this is to ensure the foreground image is displayed correctly.

Palette Entry Flags

0 - This is the most common setting for a "normal" color request to follow the standard rules of realization  The palette manager checks to see if this color is already somewhere in the system palette.  If so, and that color isn't PC_RESERVED, then this color is mapped to that entry.  If not, then it's put in an unused entry.  If there are no unused entries, then it is mapped to the closed entry currently in the system palette.
1 PC_Reserved For palette animation with AnimatePalette API call.  The palette manager tries to find an unused entry in the system palette.  If it finds one, this color is mapped there, and the entry is marked as unusable for color matching.  In other words, the entry is "reserved" exclusively for this color.  If no entry is found, this color is mapped to black (index 0), and is not available for animation.
2 PC_Explicit The palette manager treats the color value as an index instead of a color.  This color is mapped directly to whatever color is in the system palette at that index, which is useful for taking a look at the current color mappings into the system palette.  This mapping is not affected by the foreground versus background status of the palette.
4 PC_NoCollapse The palette manager tries to find an unused entry.  If one is found, this color is mapped there (other subsequent colors are allowed to map there also).  If no unused entry is found, the color is mapped to the nearest color in the system palette (just as if this entry had a 0 peFlag field).


Palettes in Windows are much more difficult to understand than differential equations -- theory and reality just don't seem to be consistent.  I avoid working with palettes whenever possbile.

References and Links
efg's Palette Links on the Color Page
efg's Palette Information on the Delphi Graphics Color Algorithms Page

Microsoft's Knowledge Base:

Halftone Palette, Gradient Palette, Optimized Palette, FractInt Color Maps

Delphi 3/4/5 Source and EXE (223 KB): PaletteLab.ZIP   Parrot.BMP image:  Parrot.ZIP

Updated 26 Feb 2005

since 1 Nov 1998