Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding colorspace transformations when blitting, Mac OS X 10.11 SDK

When using the colorspace returned from CGColorSpaceCreateDeviceRGB(), a colorspace transformation will be applied on any CGContextDrawImage() call, leading to 5-6x worse performance than blitting without this transform.

To avoid this colorspace transformation, we have been using the colorspace created with the system monitor profile:

CMProfileRef smp = 0;
if (CMGetSystemProfile(&smp) == noErr)
{
    colorSpace = CGColorSpaceCreateWithPlatformColorSpace(smp);
    CMCloseProfile(smp);
}
else
    colorSpace = CGColorSpaceCreateDeviceRGB();

The above works well and completely disables the colorspace transformations for CGContextDrawImage().

CMGetSystemProfile has been marked deprecated since 10.6, but since we haven't found any other possibility to avoid these colorspace transformations, we have kept it in our code for high-performance blitting.

In 10.11 SDK, the ColorSpace API CMGetSystemProfile() is removed. Is there a suitable replacement, or an alternative method on how to disable colorspace transformations?

like image 494
Martin Saleteg Avatar asked Mar 14 '26 07:03

Martin Saleteg


1 Answers

To answer my own question,

the solution that I ended up using is to get the color space from the main display ID, using the functions CGDisplayCopyColorSpace and CGMainDisplayID:

colorSpace = ::CGDisplayCopyColorSpace(::CGMainDisplayID());

if (!colorSpace)
    colorSpace = CGColorSpaceCreateDeviceRGB();

This is available with 10.11 SDK, and will create a colorspace which avoids colorspace transformations with calls to CGContextDrawImage().

Analyzing the call stack with Instruments shows a callstack that is identical to the previous code we've been using.

like image 195
Martin Saleteg Avatar answered Mar 16 '26 22:03

Martin Saleteg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!