summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qimage.cpp14
-rw-r--r--src/gui/image/qimage_darwin.mm29
2 files changed, 15 insertions, 28 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 0105f1decd..da963adae6 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -149,7 +149,10 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format)
d->bytes_per_line = params.bytesPerLine;
d->nbytes = params.totalSize;
- d->data = (uchar *)malloc(d->nbytes);
+ if (depth == 64)
+ d->data = (uchar *)new (std::nothrow) quint64[d->nbytes / sizeof(quint64)];
+ else // nbytes is known to already be a multipla of 4:
+ d->data = (uchar *)new (std::nothrow) quint32[d->nbytes / sizeof(quint32)];
if (!d->data)
return nullptr;
@@ -165,8 +168,13 @@ QImageData::~QImageData()
if (is_cached)
QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
delete paintEngine;
- if (data && own_data)
- free(data);
+ if (data && own_data) {
+ // Casting to avoid being theoretically UB:
+ if (depth == 64)
+ delete[] (quint64 *)data;
+ else
+ delete[] (quint32 *)data;
+ }
data = 0;
}
diff --git a/src/gui/image/qimage_darwin.mm b/src/gui/image/qimage_darwin.mm
index a5c391ad21..7ca1a0869a 100644
--- a/src/gui/image/qimage_darwin.mm
+++ b/src/gui/image/qimage_darwin.mm
@@ -40,6 +40,7 @@
#include "qimage.h"
#include <private/qcore_mac_p.h>
+#include <private/qcoregraphics_p.h>
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@@ -98,32 +99,10 @@ CGImageRef QImage::toCGImage() const
if (isNull())
return nil;
- // Determine the target native format
- uint cgflags = kCGImageAlphaNone;
- switch (format()) {
- case QImage::Format_ARGB32:
- cgflags = kCGImageAlphaFirst | kCGBitmapByteOrder32Host;
- break;
- case QImage::Format_RGB32:
- cgflags = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
- break;
- case QImage::Format_RGBA8888_Premultiplied:
- cgflags = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big;
- break;
- case QImage::Format_RGBA8888:
- cgflags = kCGImageAlphaLast | kCGBitmapByteOrder32Big;
- break;
- case QImage::Format_RGBX8888:
- cgflags = kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big;
- break;
- case QImage::Format_ARGB32_Premultiplied:
- cgflags = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
- break;
- default: break;
- }
+ CGBitmapInfo bitmapInfo = qt_mac_bitmapInfoForImage(*this);
// Format not supported: return nil CGImageRef
- if (cgflags == kCGImageAlphaNone)
+ if (bitmapInfo == kCGImageAlphaNone)
return nil;
// Create a data provider that owns a copy of the QImage and references the image data.
@@ -140,7 +119,7 @@ CGImageRef QImage::toCGImage() const
const bool shouldInterpolate = false;
return CGImageCreate(width(), height(), bitsPerComponent, bitsPerPixel,
- this->bytesPerLine(), colorSpace, cgflags, dataProvider,
+ this->bytesPerLine(), colorSpace, bitmapInfo, dataProvider,
decode, shouldInterpolate, kCGRenderingIntentDefault);
}