From d89d1eb47e69c2c2dc1121ef92fd08ef983e3e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 5 May 2009 15:31:10 +0200 Subject: Fixed bug where 0-opacity would cause images to be drawn fully opaque. The bug appears in the raster paint engine and only in release mode as the cause of the bug is in the MMX and SSE blend functions which are disabled in debug. To prevent it simply we return early if we detect that we have an opacity of 0. Reviewed-by: Trond --- src/gui/painting/qpaintengine_raster.cpp | 2 +- tests/auto/qpainter/tst_qpainter.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index ba1e27c..e249b3e 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1022,7 +1022,7 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, int alpha, const QRect &sr) { - if (!clip.isValid()) + if (alpha == 0 || !clip.isValid()) return; Q_ASSERT(img.depth() >= 8); diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index c81bf67..87f9c13 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -225,6 +225,8 @@ private slots: void extendedBlendModes(); + void zeroOpacity(); + private: void fillData(); QColor baseColor( int k, int intensity=255 ); @@ -4150,5 +4152,21 @@ void tst_QPainter::extendedBlendModes() QVERIFY(testCompositionMode(191, 191, 96, QPainter::CompositionMode_Exclusion)); } +void tst_QPainter::zeroOpacity() +{ + QImage source(1, 1, QImage::Format_ARGB32_Premultiplied); + source.fill(0xffffffff); + + QImage target(1, 1, QImage::Format_RGB32); + target.fill(0xff000000); + + QPainter p(&target); + p.setOpacity(0.0); + p.drawImage(0, 0, source); + p.end(); + + QCOMPARE(target.pixel(0, 0), 0xff000000); +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" -- cgit v0.12