简体   繁体   English

划线时避免颜色空间转换,Mac OS X 10.11 SDK

[英]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. 当使用从CGColorSpaceCreateDeviceRGB()返回的色彩空间时,色彩空间转换将应用于任何CGContextDrawImage()调用,与不使用该转换的blitting相比,性能降低5-6倍。

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(). 上面的方法效果很好,并且完全禁用了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. 从10.6开始,CMGetSystemProfile被标记为不推荐使用,但是由于我们没有找到避免这些色彩空间转换的任何其他可能性,因此我们将其保留在代码中以实现高性能打印。

In 10.11 SDK, the ColorSpace API CMGetSystemProfile() is removed. 在10.11 SDK中,删除了ColorSpace API CMGetSystemProfile()。 Is there a suitable replacement, or an alternative method on how to disable colorspace transformations? 是否有合适的替代品,或关于如何禁用色彩空间转换的替代方法?

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 : 我最终使用的解决方案是使用CGDisplayCopyColorSpaceCGMainDisplayID函数从主显示ID中获取颜色空间:

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(). 这在10.11 SDK中可用,并将创建一个颜色空间,该颜色空间可避免通过调用CGContextDrawImage()进行颜色空间转换。

Analyzing the call stack with Instruments shows a callstack that is identical to the previous code we've been using. 使用Instruments分析调用栈将显示与我们之前使用的代码相同的调用栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM