diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index c459d009c..1f7c4bbb6 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -93,14 +93,56 @@ bool QRasterPixmapData::fromData(const uchar *buffer, uint len, const char *form if (image.isNull()) return false; - createPixmapForImage(image, flags); + fromImage(image, flags); return !isNull(); } void QRasterPixmapData::fromImage(const QImage &sourceImage, Qt::ImageConversionFlags flags) { - createPixmapForImage(sourceImage, flags); + QImage::Format format; + if (flags & Qt::NoFormatConversion) { + format = sourceImage.format(); + } else if (pixelType() == BitmapType) { + format = QImage::Format_MonoLSB; + } else { + if (sourceImage.depth() == 1) { + format = sourceImage.hasAlphaChannel() + ? QImage::Format_ARGB32_Premultiplied + : QImage::Format_RGB32; + } else { + QImage::Format opaqueFormat = QImage::systemFormat(); + QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied; + + // We don't care about the others... + if (opaqueFormat == QImage::Format_RGB16) { + alphaFormat = QImage::Format_ARGB8565_Premultiplied; + } + + if (!sourceImage.hasAlphaChannel()) { + format = opaqueFormat; + } else if ((flags & Qt::NoOpaqueDetection) == 0 + && !sourceImage.data_ptr()->checkForAlphaPixels()) + { + format = opaqueFormat; + } else { + format = alphaFormat; + } + } + } + + image = sourceImage.convertToFormat(format); + + if (image.d) { + w = image.d->width; + h = image.d->height; + d = image.d->depth; + } else { + w = h = d = 0; + } + is_null = (w <= 0 || h <= 0); + + setSerialNumber(image.cacheKey() >> 32); } void QRasterPixmapData::fromImageReader(QImageReader *imageReader, @@ -110,7 +152,7 @@ void QRasterPixmapData::fromImageReader(QImageReader *imageReader, if (image.isNull()) return; - createPixmapForImage(image, flags); + fromImage(image, flags); } // from qwindowsurface.cpp @@ -261,53 +303,6 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const return 0; } -void QRasterPixmapData::createPixmapForImage(const QImage &sourceImage, Qt::ImageConversionFlags flags) -{ - QImage::Format format; - if (flags & Qt::NoFormatConversion) { - format = sourceImage.format(); - } else if (pixelType() == BitmapType) { - format = QImage::Format_MonoLSB; - } else { - if (sourceImage.depth() == 1) { - format = sourceImage.hasAlphaChannel() - ? QImage::Format_ARGB32_Premultiplied - : QImage::Format_RGB32; - } else { - QImage::Format opaqueFormat = QImage::systemFormat(); - QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied; - - // We don't care about the others... - if (opaqueFormat == QImage::Format_RGB16) { - alphaFormat = QImage::Format_ARGB8565_Premultiplied; - } - - if (!sourceImage.hasAlphaChannel()) { - format = opaqueFormat; - } else if ((flags & Qt::NoOpaqueDetection) == 0 - && !sourceImage.data_ptr()->checkForAlphaPixels()) - { - format = opaqueFormat; - } else { - format = alphaFormat; - } - } - } - - image = sourceImage.convertToFormat(format); - - if (image.d) { - w = image.d->width; - h = image.d->height; - d = image.d->depth; - } else { - w = h = d = 0; - } - is_null = (w <= 0 || h <= 0); - - setSerialNumber(image.cacheKey() >> 32); -} - QImage* QRasterPixmapData::buffer() { return ℑ diff --git a/src/gui/image/qpixmap_raster_p.h b/src/gui/image/qpixmap_raster_p.h index fbc48410d..e6696ccb7 100644 --- a/src/gui/image/qpixmap_raster_p.h +++ b/src/gui/image/qpixmap_raster_p.h @@ -75,7 +75,6 @@ public: protected: int metric(QPaintDevice::PaintDeviceMetric metric) const; - void createPixmapForImage(const QImage &sourceImage, Qt::ImageConversionFlags flags); void setImage(const QImage &image); QImage image;