Using palettes
A palette defines a mapping from pixel values to colors. Palettes have two common uses:
Specifying a set of colors that an application requires. The palette is selected into a shell window before any drawing occurs, to ensure that its colors are available for later drawing requests. A shell window has exactly one palette associated with it. This palette is called the selected palette. When drawing is done in a window, the foreground and background values in the CgGC are used as indices into the selected palette.
Specifying the mapping from pixel values to colors in an image. Images are often represented using 8 or fewer bits per pixel. In these cases, a palette defines the colors corresponding to each pixel value in the image. Images using 16, 24, or more bits per pixel typically encode colors directly in the pixel values. In a 24-bit-per-pixel image, one byte is used to encode each of the primary (red, green, or blue) intensities. In these cases the palette defines which bits in a pixel value map to each color primary.
Common Graphics defines the following palette classes:
CgPalette
Abstract superclass of CgIndexedPalette and CgDirectPalette.
CgIndexedPalette
Defines a pixel-value-to-color mapping as an array of colors, indexed by 0-based pixel values. There is no restriction on the size of the palette (sizes of 2, 16, and 256 are often encountered in standard image formats). Colors are undefined for pixel values not in the palette. A drawable can select a CgIndexedPalette but not a CgDirectPalette.
CgDirectPalette
Defines a pixel-value-to-color mapping that encodes colors directly in pixel values. The palette specifies which bits in a pixel value correspond to each of the RGB primaries. Only the specified bits are used when doing conversions; other bits in a pixel value are ignored. A CgDirectPalette cannot be selected in a drawable. It is used only to specify the pixel-value-to-color mapping of images using direct pixel values. The following sections describe ways of selecting a CgDirectPalette, in order to display images using direct pixel values.
Last modified date: 01/29/2015