Avoid backing store color space conversions.
authorMorten Johan Sorvig <morten.sorvig@digia.com>
Tue, 4 Dec 2012 14:19:27 +0000 (15:19 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 7 Dec 2012 11:04:48 +0000 (12:04 +0100)
We want the Qt backing store to be in the device color
space by default. This will avoid colour space conversions
when blitting it to screen, at the cost of a potential
loss in color accuracy.

As it turns out, CGColorSpaceCreateDeviceRGB no longer
crates a device color space but rather a generic color
space. (Since 10.4). Create the color space with a system
profile instead.

Accurate color representation needs to be supported
at some point, but this fast path should be the
default.

Change-Id: I7ebb77b36f81f66119d8c2ef464723401ec1d1e8
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
src/plugins/platforms/cocoa/qcocoahelpers.mm

index 008d9da..0d0d2eb 100644 (file)
@@ -789,7 +789,21 @@ CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy)
                                     NULL,
                                     false);
     } else {
-        CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB();
+        // Try get a device color space. Using the device color space means
+        // that the CGImage can be drawn to screen without per-pixel color
+        // space conversion, at the cost of less color accuracy.
+        CGColorSpaceRef cgColourSpaceRef = 0;
+        CMProfileRef sysProfile;
+        if (CMGetSystemProfile(&sysProfile) == noErr)
+        {
+            cgColourSpaceRef = CGColorSpaceCreateWithPlatformColorSpace(sysProfile);
+            CMCloseProfile(sysProfile);
+        }
+
+        // Fall back to Generic RGB if a profile was not found.
+        if (!cgColourSpaceRef)
+            cgColourSpaceRef = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+
         cgImage = CGImageCreate(width,
                                 height,
                                 colorBufferSize,