Avoiding colorspace transformations when blitting, Mac OS X 10.11 SDK

一笑奈何 提交于 2019-12-07 15:55:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/33075557/avoiding-colorspace-transformations-when-blitting-mac-os-x-10-11-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!