61.4.12 Palette Management

Many color graphic displays are capable of displaying a wide range of colors. In most cases, however, the actual number of colors which the display can render at any given time is more limited. For example, a display that is potentially able to produce over 262,000 different colors may be able to show only 256 of those colors at a time because of hardware limitations. In such cases, the display device often maintains a palette of colors; when an application requests a color that is not currently displayed, the display device adds the requested color to the palette. However, when the number of requested colors exceeds the maximum number for the device, it must replace an existing color with the requested color. As a result, if the total number of colors requested by one or more windows exceeds the number available on the display, many of the actual colors displayed will be incorrect.

Windows color palettes act as a buffer between color-intensive applications and the system, allowing an application to use as many colors as needed without interfering with its own color display or colors displayed by other windows. When a window has input focus, Windows ensures that the window will display all the colors it requests, up to the maximum number simultaneously available on the display, and displays additional colors by matching them to available colors. In addition, Windows matches the colors requested by inactive windows as closely as possible to the available colors. This significantly reduces undesirable changes in the colors displayed in inactive windows.

The following list briefly describes the functions an application calls to use color palettes:

Function Description

AnimatePalette Replaces entries in a logical palette; Windows maps the new entries into the system palette immediately
CreatePalette Creates a logical palette
GetNearestPaletteIndex Retrieves the index of a logical palette entry most nearly matching a specified RGB value
GetPaletteEntries Retrieves entries from a logical palette
GetSystemPaletteEntries Retrieves a range of palette entries from the system palette
GetSystemPaletteUse Determines whether an application has access to the full system palette
RealizePalette Maps entries in a logical palette to the system palette
SelectPalette Selects a logical palette into a device context
SetPaletteEntries Sets new palette entries in a logical palette; Windows does not map the new entries to the system palette until the application realizes the logical palette
SetSystemPaletteUse Allows an application to use the full system palette
UpdateColors Performs a pixel-by-pixel translation of each pixel's current color to the system palette This allows an inactive window to correct its colors without redrawing its client area