![]() |
PATH![]() |
![]() ![]() |
Starting with version 2.5, you can do fast, optimized profile searching that takes advantage of the profile cache added in ColorSync 2.5. For an overview, see The Profile Cache and Optimized Searching . The sample code in Listing 3-15 takes advantage of optimized searching if ColorSync version 2.5 is available; if not, it performs a search that is compatible with earlier versions of ColorSync. The compatible search may take some advantage of the profile cache, but cannot provide fully optimized results.
Listing 3-16 , shown in this section, provides an additional example of the searching mechanism available prior to ColorSync version 2.5.
IMPORTANT
You cannot use the ColorSync Manager search functions to search for ColorSync 1.0 profiles.
Your application can use the ColorSync Manager search functions to obtain a list of profiles in the ColorSync Profiles folder that meet specifications you supply in a search record. For example, you can use these functions to find all profiles for printers that meet certain criteria defined in the profile. Your application can walk through the resulting list of profiles and obtain the name and script code of each profile corresponding to a specific index in the list. Your application can then display a selection menu showing the names of the profiles. Listing 3-16 shows sample code that takes an approach similar to the one this example describes.
Note
You can also search the ColorSync Profiles folder for profiles that match a profile identifier. For more information, see Searching for a Profile That Matches a Profile Identifier , and
CMProfileIdentifierFolderSearch
.
The
MyProfileSearch function, shown in
Listing 3-16
, defines values for the search specification record fields, including the search mask, and assigns those values to the record's fields after initializing the search result. Then
MyProfileSearch calls the CMNewProfileSearch function to search the ColorSync Profiles folder for profiles that meet the search specification requirements. The
CMNewProfileSearch
function returns a one-based count of the profiles matching the search specification and a reference to the search result list of the matching profiles.
Next the
MyProfileSearch function calls the
CMSearchGetIndProfile
function to obtain a reference to a specific profile corresponding to a specific index into the search result list. Passing the profile reference returned by the
CMSearchGetIndProfile
function as the
foundProf
parameter,
MyProfileSearch calls the
CMGetScriptProfileDescription
function to obtain the profile name and script code.
Finally, the MyProfileSearch function cleans up, calling the CMCloseProfile function to close the profile and the CMDisposeProfileSearch function to dispose of the search result list.
Listing 3-16 Searching for specific profiles in the ColorSync Profiles folder
// NOTE: The preferred mechanism for searching in ColorSync 2.5 is shown
// in Listing 3-15 on page -cxxxiii.
/* field definitions for search */
#define kCMMType 'appl' /* ColorSync default CMM */
#define kProfileClass cmDisplayClass /* monitor */
#define kAttr0 0x00000000
#define kAttr1 0x00000002 /* Macintosh standard gamma */
/* Define mask to search for profiles that match on CMM type, profile class,
and attributes. */
#define kSearchMask (cmMatchProfileCMMType + cmMatchProfileClass + cmMatchAttributes)
void MyProfileSearch (void)
{
CMError cmErr;
CMProfileRef foundProf;
Str255 profName;
ScriptCode profScript;
CMSearchRecord searchSpec;
CMProfileSearchRef searchResult;
unsigned long searchCount;
unsigned long i;
/* Init for error handling. */
searchResult = NULL;
/* Specify search. */
searchSpec.CMMType = kCMMType;
searchSpec.profileClass = kProfileClass;
searchSpec.deviceAttributes[0 ]= kAttr0;
searchSpec.deviceAttributes[1] = kAttr1;
searchSpec.searchMask = kSearchMask;
searchSpec.filter= NULL; /* Filter proc is not used. */
cmErr = CMNewProfileSearch(&searchSpec, NULL, &searchCount, &searchResult);
if (cmErr == noErr)
{
for (i = 1; i <= searchCount; i++)
{
if (CMSearchGetIndProfile(searchResult, i, &foundProf) != noErr)
{
break;
}
cmErr = CMGetScriptProfileDescription(foundProf, profName, &profScript);
if (cmErr == noErr)
{
/* Assume profile name ScriptCode is smRoman. */
(void) printf("%s\n", p2cstr(profName));
}
(void) CMCloseProfile(foundProf);
}
}
if (searchResult != NULL)
{
CMDisposeProfileSearch(searchResult);
}
}