![]() |
PATH![]() |
![]() ![]() |
Embedding a profile in an image guarantees that the image can be rendered correctly on a different system. However, profiles can be large--the largest can be more than several hundred kilobytes. The ColorSync Manager defines a profile identifier structure, CMProfileIdentifier , that can identify a profile but that takes up much less space than a large profile.
The profile identifier structure contains a profile header, an optional calibration date, a profile description string length, and a variable-length profile description string. Your application might use an embedded profile identifier, for example, to change just the rendering intent or flag values in an image without having to embed an entire copy of a profile. For more information on the profile identifier structure, including a description of how a match is determined between a profile reference and a profile identifier, see
CMProfileIdentifier
.
IMPORTANT
A document containing an embedded profile identifier can not necessarily be ported to different systems or platforms.
The ColorSync Manager provides the
NCMUseProfileComment
routine to embed profiles and profile identifiers in an open picture file. For information on embedding, see
Embedding Profiles and Profile Identifiers
. Your application can embed profile identifiers in place of entire profiles, or in addition to them. A profile identifier can refer to an embedded profile or to a profile on disk.
The ColorSync Manager provides the
CMProfileIdentifierListSearch
routine for finding a profile identifier in a list of profile identifiers and the
CMProfileIdentifierFolderSearch
routine for finding a profile identifier in the ColorSync Profiles folder.
When your application or device driver processes an image, it typically keeps a list of profile references for each profile it encounters in the image. Each time it encounters an embedded profile identifier, your application first calls the CMProfileIdentifierListSearch function to see if there is already a matching profile reference in its list. That function returns a list of profile references that match the profile identifier. Although the returned list would normally contain at most one reference, it is possible to have two or more matches. If the CMProfileIdentifierListSearch routine does not find a matching profile reference, your application calls the CMProfileIdentifierFolderSearch routine to see if a matching profile can be found in the ColorSync Profiles folder.
Listing 3-17 demonstrates how your application can use the ColorSync Manager's search routines to obtain a profile reference for an embedded profile identifier. It uses the following structure to store a list of profile identifiers, along with a count of the number of items in the list.
typedef struct {
long count;
CMProfileRef profs[1];
} ProfileCacheList, **ProfileCacheHandle;
Listing 3-17 Searching for a profile that matches a profile identifier
CMError MyFindAndOpenProfileByIdentifier(ProfileCacheHandle profCache,
CMProfileIdentifierPtr unique,
Boolean *pFoundInCache,
CMProfileRef *pProf)
{
CMError theErr = noErr;
CMProfileRef prof = nil;
long cacheCount = (**profCache).count;
unsigned long foundCount = 0;
*pFoundInCache = false;
/* If there are any profile references in the cache (the list of profile
references for profiles or profile identifiers we have already
encountered) look there for a match with the passed profile identifier. */
if (cacheCount)
{
CMProfileRef *cacheList;
cacheList = (**profCache).profs;
foundCount = 1; // return no more than one match
theErr = CMProfileIdentifierListSearch(unique, cacheList, cacheCount,
&foundCount, &prof);
if (foundCount && !theErr)
*pFoundInCache = true;
else
prof = nil;
}
/* If we didn't find a match for the passed profile identifier in the list of
previously encountered profiles, look for a match on disk, in the
ColorSync Profiles folder */
if (!prof)
{
CMProfileSearchRef search = nil;
foundCount = 0;
theErr = CMProfileIdentifierFolderSearch(unique, &foundCount, &search);
/* If we found one or more matches, obtain a profile reference for the
first matching profile; if no error, dispose of the search result. */
if (!theErr)
{
if (foundCount)
theErr = CMSearchGetIndProfile(search, 1, &prof);
CMDisposeProfileSearch(search);
}
}
/* If we still didn't find a match for the passed profile identifier,
use the system profile. */
if (!prof)
{
theErr = CMGetSystemProfile(&prof);
}
if (theErr)
prof = nil;
*pProf = prof;
return theErr;
}
Although typically there is at most one profile reference in your application's list or one profile in the ColorSync Profiles folder that matches the searched-for profile identifier, it is possible that two or more profiles may qualify. It is not an error condition if either the CMProfileIdentifierListSearch or the CMProfileIdentifierFolderSearch routine finds no matching profile.