From 18940f4953bfdc08b7ee8cfe9067ead6282b06a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 19 Jun 2009 12:45:47 +0200 Subject: Fixed rounding bug in raster paint engine rect / image drawing. Change 855aa89e0ba99f8a0f75d7b31930bab2cefb93f8 incorrectly changed toNormalizedFillRect to use int truncation instead of qRound. This fixes the autotest failure in tst_QPainter::drawRect2 as well. Reviewed-by: Trond --- src/gui/painting/qpaintengine_raster.cpp | 8 ++++---- tests/auto/qpainter/tst_qpainter.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 78515ac..37f7b6d 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1771,10 +1771,10 @@ void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen) static inline QRect toNormalizedFillRect(const QRectF &rect) { - int x1 = int(rect.x() + aliasedCoordinateDelta); - int y1 = int(rect.y() + aliasedCoordinateDelta); - int x2 = int(rect.right() + aliasedCoordinateDelta); - int y2 = int(rect.bottom() + aliasedCoordinateDelta); + int x1 = qRound(rect.x() + aliasedCoordinateDelta); + int y1 = qRound(rect.y() + aliasedCoordinateDelta); + int x2 = qRound(rect.right() + aliasedCoordinateDelta); + int y2 = qRound(rect.bottom() + aliasedCoordinateDelta); if (x2 < x1) qSwap(x1, x2); diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 7e42da8..5e5bd39 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -202,6 +202,7 @@ private slots: void drawImage_task217400_data(); void drawImage_task217400(); + void drawImage_1x1(); void drawRect_task215378(); void drawRect_task247505(); @@ -4237,5 +4238,25 @@ void tst_QPainter::emptyClip() p.fillPath(path, Qt::green); } +void tst_QPainter::drawImage_1x1() +{ + QImage source(1, 1, QImage::Format_ARGB32_Premultiplied); + source.fill(0xffffffff); + + QImage img(32, 32, QImage::Format_ARGB32_Premultiplied); + img.fill(0xff000000); + QPainter p(&img); + p.drawImage(QRectF(0.9, 0.9, 32, 32), source); + p.end(); + + QImage expected = img; + expected.fill(0xff000000); + p.begin(&expected); + p.fillRect(1, 1, 31, 31, Qt::white); + p.end(); + + QCOMPARE(img, expected); +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" -- cgit v0.12