Direct palettes
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.
| palette |
palette := CgDirectPalette
redMask: 16rFF
greenMask: 16rFF00
blueMask: 16rFF0000
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:
palette at: 16r000000
==> aCgRGBColor(16r0000, 16r0000, 16r0000)
palette at: 16rFFFFFF
==> aCgRGBColor(16rFFFF, 16rFFFF, 16rFFFF)
palette at: 16r1F3F7F
==> aCgRGBColor(16r7F7F, 16r3F3F, 16r1F1F)
 
Note:
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.
Last modified date: 01/29/2015