Replacing CMNewProfileSearch with non-hard 64-bit code
I have existing code that uses it CMNewProfileSearch
to search, then iterate over the color profiles in the system, getting their names and full paths. Unfortunately CMNewProfileSearch
deprecated in Mac OS X 10.5 and also not available when compiling a 64-bit application.
Reading the ColorSync Manager 2.5 reference it seems like the new way to iterate through the installed color profiles is to use the feature CMIterateColorSyncFolder
.
- It's true?
- Is there a Cocoa way to do what I want?
- Anyone have some sample code?
Thanks.
source to share
-
Yes. As you pointed out, the ColorSync Manager Reference says this:
The CMNewProfileSearch function does not make full use of the optimized profile. The search is possible starting from version 2.5 of ColorSync. Use CMIterateColorSyncFolder instead.
-
CMIterateColorSyncFolder
is the official way to do it. Moreover, it is also an optimized way. -
From Apple ImageApp Sample Code :
EDIT: I modified the code sample to remove NewCMProfileIterateUPP
and DisposeCMProfileIterateUPP
.
// Callback routine with a description of a profile that is
// called during an iteration through the available profiles.
//
static OSErr profileIterate (CMProfileIterateData *info, void *refCon)
{
NSMutableArray* array = (NSMutableArray*) refCon;
Profile* prof = [Profile profileWithIterateData:info];
if (prof)
[array addObject:prof];
return noErr;
}
// return an array of all profiles
//
+ (NSArray*) arrayOfAllProfiles
{
NSMutableArray* profs=[[NSMutableArray arrayWithCapacity:0] retain];
CMIterateColorSyncFolder(profileIterate, NULL, 0L, profs);
return (NSArray*)profs;
}
It turns out that we do not need NewCMProfileIterateUPP
and DisposeCMProfileIterateUPP
that they are not replaced by anything, as far as I can tell. Instead, you can define a callback function with a signature that matches profileIterate
above. Then you can just pass the callback function to CMIterateColorSyncFolder
.
I tested my changes in ImageApp on Mac OS X 10.5, it works as expected.
source to share