A direct-color image is an image in which the pixel values directly encode the colors. Typically these images have 16 or more bits per pixel, with 24 bits per pixel being the most common. A CgDirectPalette is used to define the pixel-value-to-color mapping for direct-color images. Although
CgDirectPalettes cannot be selected into a
CgDrawable, a
CgIndexedPalette creation convenience method,
colorCube:, can be used to create an approximation of all possible colors. The
colorCube: method takes an array of three integers specifying the number of levels of red (R), green (G), and blue (B) to include in the palette. The resulting palette has R*G*B entries. The following example creates and displays a 256-by-256 direct-color image with a constant amount of red, with green increasing from top to bottom, and with blue increasing from left to right. The resulting image has red at the top left corner, magenta at the top right, yellow at the bottom left, and white at the bottom right. The image is not shown here because it cannot be adequately reproduced in black and white.
The putDeviceIndependentImage: method supports 1-, 4-, and 8-bit per pixel images on all platforms. Twenty-four-bit images are supported on Windows and OS/2 PM only. 16- and 32-bit images are not supported. In the 24-bit case, the image's palette must be a
CgDirectPalette with the same masks as used in the example above. Note also that the display of 24-bit images on Windows is very slow unless it is directly supported by the video driver.