Color Key Format

A color key is described in a DDCOLORKEY structure. If the color key is a single color, both members of this structure should be assigned the same value. Otherwise the color key is a range of colors.

Color keys are specified using the pixel format of a surface. If a surface is in a palettized format, the color key is given as an index or a range of indices. If the surface's pixel format is specified by a FOURCC code that describes a YUV format, the YUV color key is specified by the three low-order bytes in both the dwColorSpaceLowValue and dwColorSpaceHighValue members of the DDCOLORKEY structure. The lowest order byte contains the V data, the second lowest order byte contains the U data, and the highest order byte contains the Y data.

Some examples of valid color keys follow:

8-bit palettized mode

// Palette entry 26 is the color key. 
dwColorSpaceLowValue = 26; 
dwColorSpaceHighValue = 26; 
 

24-bit true-color mode

// Color 255,128,128 is the color key. 
dwColorSpaceLowValue = RGBQUAD(255,128,128); 
dwColorSpaceHighValue = RGBQUAD(255,128,128); 
 

FourCC YUV mode

// Any YUV color where Y is between 100 and 110 
// and U or V is between 50 and 55 is transparent. 
dwColorSpaceLowValue = YUVQUAD(100,50,50); 
dwColorSpaceHighValue = YUVQUAD(110,55,55); 
 

Support for a range of colors rather than a single color is hardware-dependent. Check the dwCKeyCaps member of the DDCAPS structure for the hardware. The HEL does not support color ranges.

Some hardware supports color ranges only for YUV pixel data, which is usually video. The transparent background in video footage (the "blue screen" against which the subject was photographed) might not be a single pure color, so a range of colors in the color key is desirable.