Important: The information in this document is obsolete and should not be used for new development.
Managing the Device CLUT
The Color Manager functions that directly modify a device CLUT should be used with care, because in a multitasking environment, changes to a device CLUT affect colors used by the system software and other application windows.
Use the
- Note
- The Color Manager functions described next are designed to operate on a single
GDevice
data structure. The Palette Manager can perform most of these operations across multipleGDevice
data structures. Since the Palette Manager provides more general and portable functionality, applications should use Palette Manager functions whenever possible.SetEntries
function to change any of the entries in a device's CLUT.SetEntries
changes theCTSeed
field value, so the Color Manager knows to rebuild the inverse table.The
SaveEntries
andRestoreEntries
functions can make temporary changes to the color table under very specialized circumstances (for example, from a color selection dialog box within an application). Applications don't need these functions under normal circumstances. For example, if you use the Palette Manager functionsGetEntryColor
andSetEntryColor
on a palette, rather than directly changing a device's color table, the Palette Manager ensures that colors used by other applications and the system are not affected.You can use the
SaveEntries
function to copy any combination ofColorSpec
data structures into a color table.RestoreEntries
replaces the table created bySaveEntries
in the graphics device. UnlikeSetEntries
, these functions don't perform invalidations of the device's color table, so they avoid causing invalidations of cached data structures. If you use these functions, your application must take responsibility for rebuilding and restoring auxiliary structures as necessary.By convention, when using
SetEntries
orRestoreEntries
, you should store white at color table position 0, and black in the last color table position available, whether it is 1, 3, 15, or 255. The Palette Manager also enforces this convention. The most commonly found CLUT contains 256 entries, but a 4-entry CLUT can illustrate setting entry values more concisely. Here's aCSpecArray
data structure calledMyColors
containing four RGB color values:
Table 7-2 A sample CSpecArray
data structureValue Red Green Blue 0 FFFF FFFF FFFF 1 FFFF 0000 0000 2 8888 8888 8888 3 0000 0000 0000 Then you could use the
SetEntries
function to fill the four entries of the CLUT starting at 0 with white at the first entry, a bright red at the second, a gray at the third, and black at the last entry:
SetEntries(0, 4, MyColors);Color Manager functions maintain special information in device color tables. Using theProtectEntry
andReserveEntry
functions, an entry may be protected, which preventsSetEntries
from further changing the entry, or reserved, which makes the entry unavailable to be mapped by theRGBForeColor
andRGBBackColor
functions. Functions that change the device table (SetEntries
,ProtectEntry
, andReserveEntry
, but notRestoreEntries
) perform the appropriate invalidations of QuickDraw data structures. Your application must then redraw where necessary.Use the
RealColor
function to determine whether a particular color exists in a color table.RealColor
determines whether any color in the CLUT for the currentGDevice
data structure matches the given color to the resolution of the device's inverse table. For example, if the device's inverse table is set to a resolution of 4 (the default),RealColor
returnstrue
if any color in the CLUT exactly matches the top four bits of each component. You could makeRealColor
match to the top 5 bits by rebuilding the inverse table: callMakeITable
with ares
parameter value of 5.The
Color2Index
function returns the index in the current device's CLUT that is the best match to the requested color. TheIndex2Color
function performs the opposite function--it returns the color of a particular index value. These functions can be useful when making copies of the screen frame buffer. Use theGetSubTable
function to obtain a set of indexesfor
a CLUT; it calls theColor2Index
function for each input color.