From c44d7eedfdfa80598c877bd2a708a8f126c25fc4 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Fri, 13 Jul 2012 12:42:18 +0200 Subject: [PATCH] Fix crash in QPixmap::fromImage() when memory is low. Task-number: QTBUG-26451 Change-Id: I7149edb1b03d7bcd4e90f369a1ac99b25ab262b9 Reviewed-by: Gunnar Sletta --- src/gui/image/qpixmap_raster.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 260deb4482..d34596e76f 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -318,15 +318,6 @@ void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageC } else if ((flags & Qt::NoOpaqueDetection) == 0 && !const_cast(sourceImage).data_ptr()->checkForAlphaPixels()) { - // image has alpha format but is really opaque, so try to do a - // more efficient conversion - if (sourceImage.format() == QImage::Format_ARGB32 - || sourceImage.format() == QImage::Format_ARGB32_Premultiplied) - { - if (!inPlace) - sourceImage.detach(); - sourceImage.d->format = QImage::Format_RGB32; - } format = opaqueFormat; } else { format = alphaFormat; @@ -334,7 +325,17 @@ void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageC } } - if (inPlace && sourceImage.d->convertInPlace(format, flags)) { + // image has alpha format but is really opaque, so try to do a + // more efficient conversion + if (format == QImage::Format_RGB32 && (sourceImage.format() == QImage::Format_ARGB32 + || sourceImage.format() == QImage::Format_ARGB32_Premultiplied)) + { + image = sourceImage; + if (!inPlace) + image.detach(); + if (image.d) + image.d->format = QImage::Format_RGB32; + } else if (inPlace && sourceImage.d->convertInPlace(format, flags)) { image = sourceImage; } else { image = sourceImage.convertToFormat(format);