Colors and Palettes

Some display devices and printers display only monochrome images; others use hundreds, thousands, or even millions of colors. You should design your applications to display properly on devices with a variety of color capabilities.

The color range available to a display device is determined primarily by the pixel depth that it supports. Pixel depth is measured in bits per pixel (bpp). Each bit can have a value of 1 or 0. A pixel depth of 1 bit per pixel allows only two values, black and white. A pixel depth of 2-bpp has four possible color values or all possible combinations of 0s and 1s with two bits. In general, the number of possible colors is equal to 2 raised to the power of the pixel depth. Windows CE supports pixel depths of 1-, 2-, 4-, 8-, 16-, 24-, and 32-bpp.

Note Windows CE supports a pixel depth of 2-bpp, which is not supported in Windows-based desktop platforms.

A color palette is an array that contains the color values that can be displayed or drawn on a output device. Color palettes are used by devices that can only display a subset of their potential colors at any specified time.

Each time you create a device context, Windows CE creates a default palette for that device context. Windows CE has no standard color palette. It assigns colors to a bitmap based on the bitmap's associated color table. If an image has no color table, Windows uses the color palette in the currently selected device context.

The default palette typically has 256 entries (colors), though the exact number varies. The device determines which colors are in the default palette. Display devices, for example, often use the 16 standard VGA colors and 4 other Window-defined colors. Printer devices may use other default colors.

If you specify a pen or text color that is not in the default palette, Windows CE will approximate the color with the closest color in the palette.

You cannot change the entries in the default palette. However, you can create your own logical palette and select the palette into a device context in place of the default palette. You can use logical palettes to define and use colors that meet your specific needs. Windows CE enables you to create multiple logical palettes. You can attach each logical palette to a unique device context or you can switch between multiple logical palettes in a single device context.

Windows CE supports both palettized and non-palettized color display devices. Palettized devices have a color palette coded directly into their display card. Non-palettized devices use the pixels' bit values in the frame buffer to directly define colors in terms of their red, green, and blue values. You can use the GetDeviceCaps function to determine whether or not a device supports color palettes.