Managing Display Palettes

If the video hardware supports colors that can be set, it maintains a color lookup table called a palette. GDI takes each RGB value and translates it into a device color index so that it can be displayed. GDI uses precalculated and cached tables to assist in the translation. These tables are accessible to drivers as the user object XLATEOBJ. Therefore, every GDI graphics function that takes source colors and moves them to a destination device uses a XLATEOBJ structure to translate the colors. For more information on palettes in general, and how GDI handles them, see Part 1.

If the video hardware supports palettes that can be set, GDI calls the DrvSetPalette function in the display driver when it has finished mapping colors into the device palette requested by the application. GDI passes the new palette to the display driver, and the driver queries the PALOBJ to set its internal hardware palette to match ("realize") the palette changes for the video hardware.

The DrvSetPalette function supplies a handle to a PDEV to the driver, and requests the driver to realize the palette for that device. The driver should set the hardware palette to match the entries in the given palette as closely as possible.

This entry point is required if the device supports a palette that can be set, and should not be provided otherwise. A display driver specifies that its device has a settable palette by setting the GCAPS_PALMANAGED bit in the flGraphicsCaps field of the DEVINFO structure returned in DrvEnablePDEV.

The service routine PALOBJ_cGetColors is available to display drivers. This function downloads RGB colors from an indexed palette, and should be called from within the implementation of DrvSetPalette.