I'm currently trying to wrap my head around the current state of the CGColorSpace Color Management APIs on iOS. Prior to the iOS 8.1 SDK (as far as I can tell) many of the functions & constants in CGColorSpace.h
were labeled as __IPHONE_NA
. However, according the the iOS 8.1 API Diffs for Core Graphics many of the functions & constants that were previously __IPHONE_NA
were updated to __IPHONE_2_0
. So how are we supposed to interpret that?
I don't think Apple retroactively added support for those functions to old iOS releases, rather they just changed those functions' visibility from private to public. The problems come when trying to use some of those functions on different iOS versions & devices. For example:
CGColorSpaceRef sRgb = CGColorSpaceCreateWithName( kCGColorSpaceSRGB ); // kCGColorSpaceSRGB is labeled __IPHONE_8_0
CFDataRef profData = CGColorSpaceCopyICCProfile( ... );
- On an iPad Mini (original) running iOS 8.2:
sRgb
&profData
will be NULL. - On an iPad 3 running iOS 8.3:
sRgb
&profData
will be NULL. - On an iPhone 6 Plus running iOS 9.2.1:
sRgb
will contain a non-NULLCGColorSpaceRef
,profData
will contain a non-NULLCFDataRef
buffer. - On an iPad Mini (original) running iOS 9.2.1:
sRgb
will contain a non-NULLCGColorSpaceRef
,profData
will contain a non-NULLCFDataRef
buffer.
So at least for iOS 8 it appears that these functions aren't completely implemented. For iOS 9 things appear to start working.
Are there any documentation or resources that describe how these APIs changed in iOS 8 and iOS 9? What color space should be used when CGColorSpaceCreateWithName( kCGColorSpaceSRGB )
returns NULL? It seems like CGColorSpaceCreateDeviceRGB()
may be the only option in that case.
After some testing I’ve found that it is possible to get the embedded color profile from a CGImageRef
and use that profile to apply a color transform to another color space, as long as you do the color transform yourself. The Core Graphics APIs still don’t support transforming images between color spaces, but if you have your own Color Management functions it is now possible to do it yourself on iOS - something that wasn’t possible before.
I’d just like to know what is and isn’t expected to work. I’ve tried looking through release notes and looking for tech notes that describe what changed from iOS 7 to 8 and 8 to 9, but I haven’t been able to find anything that describes the CGColorSpace API changes. Does anyone know if there are any such documents?
You can have a look at a open source library called little-CMS. It gives good results that you can integrate in your app.
https://github.com/mm2/Little-CMS