From 91f5c7314afdfd43c867266fc1bc418e0f70bac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 3 Jun 2009 14:16:39 +0200 Subject: Fixed raster bug causing fully clipped images to be partially blended. The blend functions assume the width / height of the images being blended to be greater than 0. A width of 0 caused the first iteration of a duff's device memcpy (QT_MEMCPY_USHORT) to be executed, thus blending 8 pixels instead of none. BT: yes Task-number: 255014 Reviewed-by: Trond --- src/gui/painting/qpaintengine_raster.cpp | 4 ++-- tests/auto/qpainter/tst_qpainter.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 58ffb02..1a1c204 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1053,7 +1053,7 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, int d = x + iw - cx2; iw -= d; } - if (iw < 0) + if (iw <= 0) return; // adapt the y paremeters... @@ -1070,7 +1070,7 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt, int d = y + ih - cy2; ih -= d; } - if (ih < 0) + if (ih <= 0) return; // call the blend function... diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 87f9c13..8d6c9d2 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -215,6 +215,7 @@ private slots: void imageCoordinateLimit(); void imageBlending_data(); void imageBlending(); + void imageBlending_clipped(); void paintOnNullPixmap(); void checkCompositionMode(); @@ -3792,6 +3793,31 @@ void tst_QPainter::imageBlending() } } +void tst_QPainter::imageBlending_clipped() +{ + QImage src(20, 20, QImage::Format_RGB16); + QPainter p(&src); + p.fillRect(src.rect(), Qt::red); + p.end(); + + QImage dst(40, 20, QImage::Format_RGB16); + p.begin(&dst); + p.fillRect(dst.rect(), Qt::white); + p.end(); + + QImage expected = dst; + + p.begin(&dst); + p.setClipRect(QRect(23, 0, 20, 20)); + + // should be completely clipped + p.drawImage(QRectF(3, 0, 20, 20), src); + p.end(); + + // dst should be left unchanged + QCOMPARE(dst, expected); +} + void tst_QPainter::paintOnNullPixmap() { QPixmap pix(16, 16); -- cgit v0.12