This is exactly the thing I was setting up yesterday… I have run the following code snippet, with the display profile set to some wide-gamut colorspace in the preferences:
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
if( !colorSpace ) {
std::cout<<"Cannot get CGColorSpaceCreateDeviceRGB()"<<std::endl;
} else {
std::cout<<"Display profile: "<<CFStringGetCStringPtr(CGColorSpaceCopyName(colorSpace),kCFStringEncodingASCII)<<std::endl;
CFDataRef data = CGColorSpaceCopyICCProfile(colorSpace);
if( !data ) {
std::cout<<"Display profile: cannot get CGColorSpaceCopyICCProfile()"<<std::endl;
} else {
CFIndex icc_length = CFDataGetLength(data);
const UInt8* icc_data = CFDataGetBytePtr(data);
cmsHPROFILE icc_profile = cmsOpenProfileFromMem( icc_data, icc_length );
char tstr[1024];
cmsGetProfileInfoASCII(icc_profile, cmsInfoDescription, "en", "US", tstr, 1024);
std::cout<<"Display profile: "<<tstr<<std::endl;
}
}
colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
if( !colorSpace ) {
std::cout<<"Cannot get CGColorSpaceCreateWithName(kCGColorSpaceSRGB)"<<std::endl;
} else {
std::cout<<"sRGB profile: "<<CFStringGetCStringPtr(CGColorSpaceCopyName(colorSpace),kCFStringEncodingASCII)<<std::endl;
CFDataRef data = CGColorSpaceCopyICCProfile(colorSpace);
if( !data ) {
std::cout<<"Cannot get CGColorSpaceCopyICCProfile()"<<std::endl;
} else {
CFIndex icc_length = CFDataGetLength(data);
const UInt8* icc_data = CFDataGetBytePtr(data);
cmsHPROFILE icc_profile = cmsOpenProfileFromMem( icc_data, icc_length );
char tstr[1024];
cmsGetProfileInfoASCII(icc_profile, cmsInfoDescription, "en", "US", tstr, 1024);
std::cout<<"sRGB profile: ICC name = "<<tstr<<std::endl;
}
}
The terminal output from the above code is quite interesting:
Display profile: kCGColorSpaceDeviceRGB
Display profile: cannot get CGColorSpaceCopyICCProfile()
sRGB profile: kCGColorSpaceSRGB
sRGB profile: ICC name = sRGB IEC61966-2.1
To cut it short, the profile retrieved with CGColorSpaceCreateDeviceRGB()
DOES NOT HAVE any associated ICC data, while the one retrieved with CGColorSpaceCreateWithName(kCGColorSpaceSRGB)
corresponds to a standard sRGB ICC profile.
Also, quoting the Apple documentation:
Device color spaces are primarily used by iOS applications because other options
are not available. In most cases, a Mac OS X application should use a generic
color space instead of creating a device color space.
However, some Quartz routines expect images with a device color space.
For example, if you call CGImageCreateWithMask and specify an image as the mask,
the image must be defined with the device gray color space.
Nowhere I see mentioned that CGColorSpaceCreateDeviceRGB()
should return the display profile, and from what I observe it seems to be a very bad choice for handling color management stuff…