From 15f3191981908b786b93e1e0dd7d6828e2bf18f9 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 7 Feb 2014 14:38:47 +0100 Subject: Fix drawing vertical gradients in RGBA8888 formats The RGBA8888 formats was incorrectly using the qt_gradient_quint32 which is argb specific. This caused vertical gradients but only vertical gradients to be drawn incorrectly. This changes the RGBA8888 formats formats to use the generic gradient method and renames qt_gradient_quint32 to qt_gradient_argb32 to indicate its limitation. Change-Id: Ia1cd48ca7f4f78b64f31d6263e81cd8ac3b0954e Reviewed-by: Gunnar Sletta --- src/gui/painting/qdrawhelper.cpp | 14 +++---- tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 46 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index d3e5b645c4..c71d75cf94 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -5507,7 +5507,7 @@ inline void qt_bitmapblit_template(QRasterBuffer *rasterBuffer, } } -static void qt_gradient_quint32(int count, const QSpan *spans, void *userData) +static void qt_gradient_argb32(int count, const QSpan *spans, void *userData) { QSpanData *data = reinterpret_cast(userData); @@ -5964,7 +5964,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = // Format_RGB32, { blend_color_argb, - qt_gradient_quint32, + qt_gradient_argb32, qt_bitmapblit_quint32, qt_alphamapblit_quint32, qt_alphargbblit_quint32, @@ -5973,7 +5973,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = // Format_ARGB32, { blend_color_generic, - qt_gradient_quint32, + qt_gradient_argb32, qt_bitmapblit_quint32, qt_alphamapblit_quint32, qt_alphargbblit_quint32, @@ -5982,7 +5982,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = // Format_ARGB32_Premultiplied { blend_color_argb, - qt_gradient_quint32, + qt_gradient_argb32, qt_bitmapblit_quint32, qt_alphamapblit_quint32, qt_alphargbblit_quint32, @@ -6048,7 +6048,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = // Format_RGBX8888 { blend_color_generic, - qt_gradient_quint32, + blend_src_generic, qt_bitmapblit_quint32, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN qt_alphamapblit_quint32, @@ -6062,7 +6062,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = // Format_RGBA8888 { blend_color_generic, - qt_gradient_quint32, + blend_src_generic, qt_bitmapblit_quint32, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN qt_alphamapblit_quint32, @@ -6076,7 +6076,7 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = // Format_RGB8888_Premultiplied { blend_color_generic, - qt_gradient_quint32, + blend_src_generic, qt_bitmapblit_quint32, #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN qt_alphamapblit_quint32, diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 27c0f6e66a..4c4e46de05 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -201,6 +201,9 @@ private slots: void linearGradientSymmetry(); void gradientInterpolation(); + void gradientPixelFormat_data(); + void gradientPixelFormat(); + void fpe_pixmapTransform(); void fpe_zeroLengthLines(); void fpe_divByZero(); @@ -3723,6 +3726,49 @@ void tst_QPainter::linearGradientSymmetry() QCOMPARE(a, b); } +void tst_QPainter::gradientPixelFormat_data() +{ + QTest::addColumn("format"); + + QTest::newRow("argb32") << QImage::Format_ARGB32; + QTest::newRow("rgb32") << QImage::Format_RGB32; + QTest::newRow("rgb888") << QImage::Format_RGB888; + QTest::newRow("rgbx8888") << QImage::Format_RGBX8888; + QTest::newRow("rgba8888") << QImage::Format_RGBA8888; + QTest::newRow("rgba8888_pm") << QImage::Format_RGBA8888_Premultiplied; +} + +void tst_QPainter::gradientPixelFormat() +{ + QFETCH(QImage::Format, format); + + QImage a(8, 64, QImage::Format_ARGB32_Premultiplied); + QImage b(8, 64, format); + + + QGradientStops stops; + stops << qMakePair(qreal(0.0), QColor(Qt::blue)); + stops << qMakePair(qreal(0.3), QColor(Qt::red)); + stops << qMakePair(qreal(0.6), QColor(Qt::green)); + stops << qMakePair(qreal(1.0), QColor(Qt::black)); + + a.fill(0); + b.fill(0); + + QLinearGradient gradient(QRectF(b.rect()).topLeft(), QRectF(b.rect()).bottomLeft()); + gradient.setStops(stops); + + QPainter pa(&a); + pa.fillRect(a.rect(), gradient); + pa.end(); + + QPainter pb(&b); + pb.fillRect(b.rect(), gradient); + pb.end(); + + QCOMPARE(a, b.convertToFormat(QImage::Format_ARGB32_Premultiplied)); +} + void tst_QPainter::gradientInterpolation() { QImage image(256, 8, QImage::Format_ARGB32_Premultiplied); -- cgit v1.2.3