diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-09-13 14:08:27 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-09-18 11:38:47 +0000 |
commit | 49b3510bb929f37f1c549f25e999c42521f9a5fa (patch) | |
tree | 6d3b3054a6858e089c0742667f2a27f54f976bd6 /src/plugins/platforms/cocoa/qcocoahelpers.mm | |
parent | e419403ebf98c6c0524d4db664caca36052c1fc9 (diff) |
macOS: Move image conversion functions to QtGui
Change-Id: I911f2648e506f27519e98be1bffe2c5ab0f388f1
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index c73587a821..a1566f4011 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -57,25 +57,6 @@ #include <Carbon/Carbon.h> -@interface NSGraphicsContext (QtAdditions) - -+ (NSGraphicsContext *)qt_graphicsContextWithCGContext:(CGContextRef)graphicsPort flipped:(BOOL)initialFlippedState; - -@end - -@implementation NSGraphicsContext (QtAdditions) - -+ (NSGraphicsContext *)qt_graphicsContextWithCGContext:(CGContextRef)graphicsPort flipped:(BOOL)initialFlippedState -{ -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_NA) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) - return [self graphicsContextWithCGContext:graphicsPort flipped:initialFlippedState]; -#endif - return [self graphicsContextWithGraphicsPort:graphicsPort flipped:initialFlippedState]; -} - -@end - QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaCocoaWindow, "qt.qpa.cocoa.window"); @@ -102,62 +83,6 @@ void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list) return result; } -CGImageRef qt_mac_toCGImage(const QImage &inImage) -{ - CGImageRef cgImage = inImage.toCGImage(); - if (cgImage) - return cgImage; - - // Convert image data to a known-good format if the fast conversion fails. - return inImage.convertToFormat(QImage::Format_ARGB32_Premultiplied).toCGImage(); -} - -CGImageRef qt_mac_toCGImageMask(const QImage &image) -{ - static const auto deleter = [](void *image, const void *, size_t) { delete static_cast<QImage *>(image); }; - QCFType<CGDataProviderRef> dataProvider = - CGDataProviderCreateWithData(new QImage(image), image.bits(), - image.byteCount(), deleter); - - return CGImageMaskCreate(image.width(), image.height(), 8, image.depth(), - image.bytesPerLine(), dataProvider, NULL, false); -} - -NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image) -{ - NSImage *newImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize]; - return newImage; -} - -NSImage *qt_mac_create_nsimage(const QPixmap &pm) -{ - if (pm.isNull()) - return 0; - QImage image = pm.toImage(); - CGImageRef cgImage = qt_mac_toCGImage(image); - NSImage *nsImage = qt_mac_cgimage_to_nsimage(cgImage); - CGImageRelease(cgImage); - return nsImage; -} - -NSImage *qt_mac_create_nsimage(const QIcon &icon) -{ - if (icon.isNull()) - return nil; - - NSImage *nsImage = [[NSImage alloc] init]; - foreach (QSize size, icon.availableSizes()) { - QPixmap pm = icon.pixmap(size); - QImage image = pm.toImage(); - CGImageRef cgImage = qt_mac_toCGImage(image); - NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; - [nsImage addRepresentation:imageRep]; - [imageRep release]; - CGImageRelease(cgImage); - } - return nsImage; -} - QColor qt_mac_toQColor(const NSColor *color) { QColor qtColor; @@ -457,28 +382,6 @@ NSRect qt_mac_flipRect(const QRect &rect) return NSMakeRect(rect.x(), flippedY, rect.width(), rect.height()); } -OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage) -{ - // Verbatim copy if HIViewDrawCGImage (as shown on Carbon-Dev) - OSStatus err = noErr; - - require_action(inContext != NULL, InvalidContext, err = paramErr); - require_action(inBounds != NULL, InvalidBounds, err = paramErr); - require_action(inImage != NULL, InvalidImage, err = paramErr); - - CGContextSaveGState( inContext ); - CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds)); - CGContextScaleCTM(inContext, 1, -1); - - CGContextDrawImage(inContext, *inBounds, inImage); - - CGContextRestoreGState(inContext); -InvalidImage: -InvalidBounds: -InvalidContext: - return err; -} - Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) { if (buttonNum == 0) @@ -499,37 +402,4 @@ QString qt_mac_removeAmpersandEscapes(QString s) return QPlatformTheme::removeMnemonics(s).trimmed(); } -QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size) -{ - const NSSize pixmapSize = NSMakeSize(size.width(), size.height()); - QPixmap pixmap(pixmapSize.width, pixmapSize.height); - pixmap.fill(Qt::transparent); - [image setSize:pixmapSize]; - const NSRect iconRect = NSMakeRect(0, 0, pixmapSize.width, pixmapSize.height); - QMacCGContext ctx(&pixmap); - if (!ctx) - return QPixmap(); - NSGraphicsContext *gc = [NSGraphicsContext qt_graphicsContextWithCGContext:ctx flipped:YES]; - if (!gc) - return QPixmap(); - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:gc]; - [image drawInRect:iconRect fromRect:iconRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; - [NSGraphicsContext restoreGraphicsState]; - return pixmap; -} - -QImage qt_mac_toQImage(CGImageRef image) -{ - const size_t w = CGImageGetWidth(image), - h = CGImageGetHeight(image); - QImage ret(w, h, QImage::Format_ARGB32_Premultiplied); - ret.fill(Qt::transparent); - CGRect rect = CGRectMake(0, 0, w, h); - QMacCGContext ctx(&ret); - qt_mac_drawCGImage(ctx, &rect, image); - return ret; -} - - QT_END_NAMESPACE |