Microsoft Windows CE 3.0  

What Are Palettes?

This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Palettized surfaces need palettes to be meaningfully displayed. A palettized surface, also known as a color-indexed surface, is simply a collection of numbers where each number represents a pixel. The value of the number is an index into a color table that tells DirectDraw what color to use when displaying that pixel. DirectDrawPalette objects, casually referred to as palettes, provide you with an easy way to manage a color table. Surfaces that use a 16-bit or greater pixel format do not use palettes.

A DirectDrawPalette object represents an indexed color table that has 2, 4, 16 or 256 entries to be used with a color indexed surface. Each entry in the palette is an RGB triplet that describes the color to be used when displaying pixels within the surface. The color table can contain 16- or 24-bit RGB triplets representing the colors to be used. For 16-color palettes, the table can also contain indexes to another 256-color palette. Palettes are supported for textures, off-screen surfaces, and overlay surfaces, none of which is required to have the same palette as the primary surface.

You can create a palette by calling the IDirectDraw4::CreatePalettemethod. This method retrieves a pointer to the palette object's IDirectDrawPaletteinterface. You can use the methods of this interface to manipulate palette entries or retrieve information about the object's capabilities.

You apply a palette to a surface by calling the surface's IDirectDrawSurface5::SetPalettemethod. A single palette can be applied to multiple surfaces.

DirectDrawPalette objects reserve entry 0 and entry 255 for 8-bit palettes, unless you specify the DDPCAPS_ALLOW256 flag to request that these entries be made available to you.

You can retrieve palette entries by using the IDirectDrawPalette::GetEntriesmethod, and you can change entries by using the IDirectDrawPalette::SetEntriesmethod.

The Ddutil.cpp source file included with the SDK contains some handy application-defined functions for working with palettes. For more information, see the DDLoadPalettefunctions in that source file.

 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.