From 6a9cf6717abbe1a76557d6c3eb2910b658af24d7 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 2 Oct 2009 09:35:05 +0200 Subject: Explicitly check for alpha pixels in X11 before making an alpha XPixmap Reviewed-by: Samuel --- src/gui/image/qpixmap_x11.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index f77d200..6cde898 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -67,6 +67,7 @@ #include #include "qx11info_x11.h" #include +#include #include @@ -369,6 +370,30 @@ void QX11PixmapData::resize(int width, int height) #endif // QT_NO_XRENDER } +struct QX11AlphaDetector +{ + bool hasAlpha() const { + if (checked) + return has; + // Will implicitly also check format and return quickly for opaque types... + checked = true; + has = const_cast(image)->data_ptr()->checkForAlphaPixels(); + return has; + } + + bool hasXRenderAndAlpha() const { + if (!X11->use_xrender) + return false; + return hasAlpha(); + } + + QX11AlphaDetector(const QImage *i) : image(i), checked(false), has(false) { } + + const QImage *image; + mutable bool checked; + mutable bool has; +}; + void QX11PixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags) { @@ -402,7 +427,9 @@ void QX11PixmapData::fromImage(const QImage &img, return; } - int dd = X11->use_xrender && img.hasAlphaChannel() ? 32 : xinfo.depth(); + QX11AlphaDetector alphaCheck(&img); + int dd = alphaCheck.hasXRenderAndAlpha() ? 32 : xinfo.depth(); + if (qt_x11_preferred_pixmap_depth) dd = qt_x11_preferred_pixmap_depth; @@ -454,7 +481,7 @@ void QX11PixmapData::fromImage(const QImage &img, uchar *newbits= 0; #ifndef QT_NO_XRENDER - if (X11->use_xrender && image.hasAlphaChannel()) { + if (alphaCheck.hasXRenderAndAlpha()) { const QImage &cimage = image; d = 32; @@ -1091,7 +1118,7 @@ void QX11PixmapData::fromImage(const QImage &img, } #endif - if (image.hasAlphaChannel()) { + if (alphaCheck.hasAlpha()) { QBitmap m = QBitmap::fromImage(image.createAlphaMask(flags)); setMask(m); } -- cgit v0.12