summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoahelpers.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.mm41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm
index 9783899742..31a56b9d66 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.mm
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm
@@ -138,6 +138,8 @@ NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image)
NSImage *qt_mac_create_nsimage(const QPixmap &pm)
{
+ if (pm.isNull())
+ return 0;
QImage image = pm.toImage();
CGImageRef cgImage = qt_mac_image_to_cgimage(image);
NSImage *nsImage = qt_mac_cgimage_to_nsimage(cgImage);
@@ -784,14 +786,49 @@ 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);
+
+ // Create a CGBitmapInfo contiaining the image format.
+ // Support the 8-bit per component (A)RGB formats.
+ CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Little;
+ switch (qImage.format()) {
+ case QImage::Format_ARGB32_Premultiplied :
+ bitmapInfo |= kCGImageAlphaPremultipliedFirst;
+ break;
+ case QImage::Format_ARGB32 :
+ bitmapInfo |= kCGImageAlphaFirst;
+ break;
+ case QImage::Format_RGB32 :
+ bitmapInfo |= kCGImageAlphaNoneSkipFirst;
+ break;
+ case QImage::Format_RGB888 :
+ bitmapInfo |= kCGImageAlphaNone;
+ break;
+ default:
+ qWarning() << "qt_mac_toCGImage: Unsupported image format" << qImage.format();
+ break;
+ }
+
cgImage = CGImageCreate(width,
height,
colorBufferSize,
bitDepth,
bytesPrLine,
cgColourSpaceRef,
- kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
+ bitmapInfo,
cgDataProviderRef,
NULL,
false,