Replacing CMNewProfileSearch with non-deprecated, 64-bit code

六月ゝ 毕业季﹏ 提交于 2019-12-20 04:28:14

问题


I have existing code that uses CMNewProfileSearch to find then iterate over the color profiles on the system getting their names and full paths. Unfortunately, CMNewProfileSearch is deprecated in Mac OS X 10.5 and is also unavailable when compiling a 64-bit application.

In reading the ColorSync Manager 2.5 Reference, it seems like the new way to iterate over installed color profiles is to use the CMIterateColorSyncFolder function.

  1. Is that true?
  2. Is there a Cocoa way to do what I want instead?
  3. Anybody got any sample code?

Thanks.


回答1:


  1. Yes. As you indicated, the ColorSync Manager Reference says the following:

    The CMNewProfileSearch function does not take full advantage of the optimized profile searching available starting with ColorSync version 2.5. Use CMIterateColorSyncFolder instead.

  2. CMIterateColorSyncFolder is the official way to do this. Besides, it's also the optimized way.

  3. From Apple's ImageApp sample code:

EDIT: I've 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 don't need NewCMProfileIterateUPP and DisposeCMProfileIterateUPP so they haven't been replaced with anything, as far as I can tell. Instead, you can define the callback function with a signature that matches profileIterate, above. You can then just pass the callback function directly to CMIterateColorSyncFolder.

I've tested my changes in ImageApp on Mac OS X 10.5 it it works as expected.



来源:https://stackoverflow.com/questions/822945/replacing-cmnewprofilesearch-with-non-deprecated-64-bit-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!