Important: The information in this document is obsolete and should not be used for new development.
Customizing Search Functions
Specialized color applications may need to modify the way in which the Color Manager determines the best-mapping color in a CLUT. A custom search function you provide can implement its own mapping rules. For instance, a color-selection application might want to map all levels of green to a single green on a monitor.To do this, you write your own color search function and use the
AddSearch
function to install it in the list of search functions that the Color Manager maintains. Then when your application or Color QuickDraw calls theColor2Index
function, the Color Manager calls on your search function to find and return the index for the best-mapping color. Your function should be defined as:
Boolean MySearchProc (RGBColor *rgb, long *position);If your search function decides to act on the color, it returns the index of the desired color in theposition
parameter, and returnstrue
for the function value. Otherwise, it should returnfalse
as the function value, and pass the input color back to the Color Manager in thergb
parameter. The Color Manager then looks to the next search function in the list, and if there are no other custom functions it uses the normal inverse table mechanism.The functions are chain elements in a linked list beginning in the
gdSearchProc
field of the currentGDevice
data structure. Each link is anSProcRec
data structure, which has the format shown below.
struct SProcRec { Handle nxtSrch; /* handle to next sProcRec */ ColorSearchProcPtrsrchProc;/* pointer to search function */ }; typedef struct SProcRec SProcRec;The Color Manager provides functions to add and delete custom functions from the linked list. You can install any number of search functions in the list. The Color Manager gives each function the chance to act or pass on the color until one returnstrue
. Since each device is a shared resource, you can use theSetClientID
function to set thegdID
field of theGDevice
data structure to identify your application as the caller to your search functions. When your application is finished mapping colors, it should remove your custom search function, by calling theDelSearch
function.For example, Listing 7-1 shows a function that adds a custom search function before drawing with a user-supplied color.
Listing 7-1 Adding and using a custom search function
void MyDrawUserColor(void) { ColorSearchProcPtrMyColorSearch; RGBColor *UserColor; Rect *sampleRect; AddSearch(MyColorSearch); RGBForeColor(UserColor); FrameRect(sampleRect); DelSearch(MyColorSearch); }TheMyColorSearch
function could entirely replace the Color Manager's search algorithm by accepting theRGBColor
data structure, doing a search, and then returning the index value andtrue
. It could also merely modify the color and then let the Color Manager perform its inverse table lookup. For example, theMyColorSearch
function could accept theRGBColor
, do an arithmetic add with a gray color to lighten all three components, and then return theRGBColor
data structure in thergb
VAR
parameter and returnfalse
as the function value. The Color Manager then uses the returned color as the input for its default search.