iosobjective-cmetadatacore-graphicscgimagesource

How to create CGColorSpace from EXIF number?


I have a CGImageSourceRef with a following metadata:

// CGImageSourceCopyMetadataAtIndex
<CGImageMetadata 0x10225ed50> (
    exif:SubsecTimeDigitized = 000
    exif:ColorSpace = 1
    // and more ... 
)


// CGImageSourceCopyPropertiesAtIndex
{
    ProfileName = "sRGB IEC61966-2.1";
    "{Exif}" =     {
        ColorSpace = 1;
    };
    // and more ...
} 

"ColorSpace" here is "1". I've seen all constructors of CGColorSpaceRef, none of them creates a color space from a number.

CGColorSpaceCreateWithName(CFStringRef name) takes a name, which isn't enum, just a bunch of hardcoded strings like kCGColorSpaceDisplayP3.

How to create a CGColorSpace from this 1 magic number?


Solution

  • Well, currently I'm using CoreImage approach because it's simple and fast:

    CIImage* ciImage = [CIImage imageWithData:rawData];
    CGColorSpaceRef cs = ciImage.colorSpace;
    

    CIImage doesn't have memory overhead if created with pre-allocated bytes. It also doesn't have performance overhead if not rendered e.g. with [CIContext render].