Direct palettes, represented by the class CgDirectPalette, specify a pixel-value-to-color mapping for pixel values that directly encode colors. They are used primarily in bitmapped images with 16 or more bits per pixel. A direct palette specifies which bits of a pixel value correspond to each of the color primaries. This correspondence is defined by three non-overlapping bit masks.For example, an image with 24 bits per pixel directly encodes each pixel's color in the corresponding pixel value with 8 bits for each of the primary color (red, green, and blue). The following code creates a CgDirectPalette where the low-order byte of a 24-bit pixel value gives the intensity of red, the next highest byte gives the intensity of green, and the high byte gives the intensity of blue.The at:, nearestPixelValue:, and nearestColor: methods described for indexed palettes are also applicable to CgDirectPalettes. The following example illustrates the use of at: on the palette created above:The pixel values in this case use 8 bits (0-255) each for red, green, and blue, whereas CgRGBColors use 16 bits (0-65535). The red component of the pixel value in the last example is 16r7F. To convert this to 16 bits it is multiplied by 65535 and divided by 255 giving 16r7F7F.
|