From 8d9b0179a56f4ee5afc3ac6300d6bd97089eff96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 24 Mar 2009 10:01:22 +0100 Subject: Rendering error (one pixel offset) when drawing ARGB32_PM on RGB16. Missing increments in the blend function's tail code. Task-number: 247492 Reviewed-by: Paul --- src/gui/painting/qblendfunctions.cpp | 2 + tests/auto/qpainter/tst_qpainter.cpp | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/gui/painting/qblendfunctions.cpp b/src/gui/painting/qblendfunctions.cpp index d2f4ab7..6589439 100644 --- a/src/gui/painting/qblendfunctions.cpp +++ b/src/gui/painting/qblendfunctions.cpp @@ -535,6 +535,8 @@ static void qt_blend_argb32_on_rgb16(uchar *destPixels, int dbpl, s += BYTE_MUL_RGB16(*dst, 255 - alpha); *dst = s; } + ++dst; + ++src; } dst += dstExtraStride; src += srcExtraStride; diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 5a15683..2e1335c 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -204,6 +204,9 @@ private slots: void drawImage_task217400(); void drawRect_task215378(); + void drawImage_data(); + void drawImage(); + void clippedImage(); void stateResetBetweenQPainters(); @@ -3586,6 +3589,77 @@ void tst_QPainter::drawRect_task215378() QVERIFY(img.pixel(0, 0) != img.pixel(1, 1)); } +void tst_QPainter::drawImage_data() +{ + QTest::addColumn("x"); + QTest::addColumn("y"); + QTest::addColumn("w"); + QTest::addColumn("h"); + QTest::addColumn("srcFormat"); + QTest::addColumn("dstFormat"); + + for (int srcFormat = QImage::Format_Mono; srcFormat < QImage::NImageFormats; ++srcFormat) { + for (int dstFormat = QImage::Format_Mono; dstFormat < QImage::NImageFormats; ++dstFormat) { + if (dstFormat == QImage::Format_Indexed8) + continue; + for (int odd_x = 0; odd_x <= 1; ++odd_x) { + for (int odd_width = 0; odd_width <= 1; ++odd_width) { + QString description = + QString("srcFormat %1, dstFormat %2, odd x: %3, odd width: %4") + .arg(srcFormat).arg(dstFormat).arg(odd_x).arg(odd_width); + + QTest::newRow(description) << (10 + odd_x) << 10 << (20 + odd_width) << 20 + << QImage::Format(srcFormat) + << QImage::Format(dstFormat); + } + } + } + } +} + +bool verifyImage(const QImage &img, int x, int y, int w, int h, uint background) +{ + int imgWidth = img.width(); + int imgHeight = img.height(); + for (int i = 0; i < imgHeight; ++i) { + for (int j = 0; j < imgWidth; ++j) { + uint pixel = img.pixel(j, i); + bool outside = j < x || j >= (x + w) || i < y || i >= (y + h); + if (outside != (pixel == background)) { + //printf("%d %d, expected %x, got %x, outside: %d\n", x, y, background, pixel, outside); + return false; + } + } + } + + return true; +} + +void tst_QPainter::drawImage() +{ + QFETCH(int, x); + QFETCH(int, y); + QFETCH(int, w); + QFETCH(int, h); + QFETCH(QImage::Format, srcFormat); + QFETCH(QImage::Format, dstFormat); + + QImage dst(40, 40, QImage::Format_RGB32); + dst.fill(0xffffffff); + + dst = dst.convertToFormat(dstFormat); + uint background = dst.pixel(0, 0); + + QImage src(w, h, QImage::Format_RGB32); + src.fill(0xff000000); + src = src.convertToFormat(srcFormat); + + QPainter p(&dst); + p.drawImage(x, y, src); + p.end(); + + QVERIFY(verifyImage(dst, x, y, w, h, background)); +} void tst_QPainter::imageCoordinateLimit() { -- cgit v0.12