diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2010-06-17 08:38:06 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2010-06-17 13:10:34 (GMT) |
commit | 4cdeac4d4780e163eee3a1916683766f16747f90 (patch) | |
tree | 53be9e6897380a8a877af468b111fc6e0df25eb1 /src/gui | |
parent | 0a852d51c6d74712cda8c7d08da4f5c90d99d5cd (diff) | |
download | Qt-4cdeac4d4780e163eee3a1916683766f16747f90.zip Qt-4cdeac4d4780e163eee3a1916683766f16747f90.tar.gz Qt-4cdeac4d4780e163eee3a1916683766f16747f90.tar.bz2 |
Optimized QPixmap::fromImage for raster pixmaps.
If we know that the QImage is ARGB32 or ARGB32_Premultiplied and doesn't
contain any alpha pixels we can treat it as RGB32 when doing the
conversion.
Reviewed-by: Gunnar Sletta
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qpixmap_raster.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 9dc15fc..4f32d2f 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -192,10 +192,23 @@ void QRasterPixmapData::fromImage(const QImage &sourceImage, } #endif - if (!sourceImage.hasAlphaChannel() - || ((flags & Qt::NoOpaqueDetection) == 0 - && !const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels())) { + if (!sourceImage.hasAlphaChannel()) { image = sourceImage.convertToFormat(opaqueFormat); + } else if ((flags & Qt::NoOpaqueDetection) == 0 + && !const_cast<QImage &>(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) + { + QImage rgbImage(sourceImage.bits(), sourceImage.width(), sourceImage.height(), + QImage::Format_RGB32); + image = rgbImage.convertToFormat(opaqueFormat); + image.detach(); + } else { + image = sourceImage.convertToFormat(opaqueFormat); + } } else { image = sourceImage.convertToFormat(alphaFormat); } |