0

I am trying to get either the url path to the custom ICC profile or the generic profile name for each monitor in Mac OS from the Qt environment. I have tried the following for the main display, but it returns a null string. In my case, the correct answer is "/Users/roryhill/Library/ColorSync/Profiles/MacBook LCD_06-02-2021.icc" from system preferences.

    auto displayId = CGMainDisplayID();
    auto colorSpace = CGDisplayCopyColorSpace(displayId);
    auto name = CGColorSpaceCopyName(colorSpace);
Rory
  • 113
  • 8
  • Your question doesn’t have anything to do with qt as far as I can tell... since you are just using CoreFoundation – Grady Player Jun 05 '21 at 00:01

1 Answers1

0

I found a solution at https://github.com/ndevenish/Hugin. I have made minor adjustments to run in my Qt environment.

In the header:

static QString getDisplayProfileURL();
typedef struct {
    CFUUIDRef dispuuid;
    CFURLRef url;
} ColorSyncIteratorData;
static bool colorSyncIterateCallback(CFDictionaryRef dict, void *data);

and source

bool Mac::colorSyncIterateCallback(CFDictionaryRef dict, void *data)
{
    ColorSyncIteratorData *iterData = (ColorSyncIteratorData *)data;
    CFStringRef str;
    CFUUIDRef uuid;
    CFBooleanRef iscur;

    if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceClass, (const void**)&str))
    {
        qWarning("kColorSyncDeviceClass failed");
        return true;
    }
    if (!CFEqual(str, kColorSyncDisplayDeviceClass))
    {
        return true;
    }
    if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceID, (const void**)&uuid))
    {
        qWarning("kColorSyncDeviceID failed");
        return true;
    }
    if (!CFEqual(uuid, iterData->dispuuid))
    {
        return true;
    }
    if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceProfileIsCurrent, (const void**)&iscur))
    {
        qWarning("kColorSyncDeviceProfileIsCurrent failed");
        return true;
    }
    if (!CFBooleanGetValue(iscur))
    {
        return true;
    }
    if (!CFDictionaryGetValueIfPresent(dict, kColorSyncDeviceProfileURL, (const void**)&(iterData->url)))
    {
        qWarning("Could not get current profile URL");
        return true;
    }

    CFRetain(iterData->url);
    return false;
}

QString Mac::getDisplayProfileURL()
{
    ColorSyncIteratorData data;
    data.dispuuid = CGDisplayCreateUUIDFromDisplayID(CGMainDisplayID());
    data.url = NULL;
    ColorSyncIterateDeviceProfiles(colorSyncIterateCallback, (void *)&data);
    CFRelease(data.dispuuid);
    CFStringRef urlstr = CFURLCopyFileSystemPath(data.url, kCFURLPOSIXPathStyle);
    CFRelease(data.url);
    return QString::fromCFString(urlstr);
}
Rory
  • 113
  • 8