summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/painting')
-rw-r--r--tests/auto/gui/painting/qbrush/tst_qbrush.cpp4
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp114
-rw-r--r--tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp2
-rw-r--r--tests/auto/gui/painting/qpainter/qpainter.pro2
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp278
-rw-r--r--tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp34
-rw-r--r--tests/auto/gui/painting/qregion/tst_qregion.cpp2
-rw-r--r--tests/auto/gui/painting/qtransform/tst_qtransform.cpp37
8 files changed, 366 insertions, 107 deletions
diff --git a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
index 4f58178f2c..30982f1e24 100644
--- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
+++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
@@ -461,8 +461,8 @@ void tst_QBrush::textureBrushComparison()
imageBrush1.setTextureImage(image1);
imageBrush2.setTextureImage(image2);
- QVERIFY(imageBrush1 == imageBrush2);
- QVERIFY(pixmapBrush == imageBrush1);
+ QCOMPARE(imageBrush1, imageBrush2);
+ QCOMPARE(pixmapBrush, imageBrush1);
}
QTEST_MAIN(tst_QBrush)
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 4fafbf9827..b81a4e2c4c 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -39,6 +39,7 @@
#include <qcolor.h>
#include <qdebug.h>
#include <private/qdrawingprimitive_sse2_p.h>
+#include <qrgba64.h>
class tst_QColor : public QObject
{
@@ -105,6 +106,10 @@ private slots:
void premultiply();
void unpremultiply_sse4();
+ void qrgba64();
+ void qrgba64MemoryLayout();
+ void qrgba64Premultiply();
+ void qrgba64Equivalence();
#ifdef Q_DEAD_CODE_FROM_QT4_X11
void setallowX11ColorNames();
@@ -249,7 +254,7 @@ void tst_QColor::isValid()
{
QFETCH(QColor, color);
QFETCH(bool, isValid);
- QVERIFY(color.isValid() == isValid);
+ QCOMPARE(color.isValid(), isValid);
}
Q_DECLARE_METATYPE(QColor::NameFormat);
@@ -1321,19 +1326,19 @@ void tst_QColor::convertTo()
QColor color(Qt::black);
QColor rgb = color.convertTo(QColor::Rgb);
- QVERIFY(rgb.spec() == QColor::Rgb);
+ QCOMPARE(rgb.spec(), QColor::Rgb);
QColor hsv = color.convertTo(QColor::Hsv);
- QVERIFY(hsv.spec() == QColor::Hsv);
+ QCOMPARE(hsv.spec(), QColor::Hsv);
QColor cmyk = color.convertTo(QColor::Cmyk);
- QVERIFY(cmyk.spec() == QColor::Cmyk);
+ QCOMPARE(cmyk.spec(), QColor::Cmyk);
QColor hsl = color.convertTo(QColor::Hsl);
- QVERIFY(hsl.spec() == QColor::Hsl);
+ QCOMPARE(hsl.spec(), QColor::Hsl);
QColor invalid = color.convertTo(QColor::Invalid);
- QVERIFY(invalid.spec() == QColor::Invalid);
+ QCOMPARE(invalid.spec(), QColor::Invalid);
}
void tst_QColor::light()
@@ -1464,5 +1469,102 @@ void tst_QColor::unpremultiply_sse4()
QSKIP("SSE4 not supported on this CPU.");
}
+void tst_QColor::qrgba64()
+{
+ QRgba64 rgb64 = QRgba64::fromRgba(0x22, 0x33, 0x44, 0xff);
+ QCOMPARE(rgb64.red(), quint16(0x2222));
+ QCOMPARE(rgb64.green(), quint16(0x3333));
+ QCOMPARE(rgb64.blue(), quint16(0x4444));
+ QCOMPARE(rgb64.alpha(), quint16(0xffff));
+
+ QColor c(rgb64);
+ QCOMPARE(c.red(), 0x22);
+ QCOMPARE(c.green(), 0x33);
+ QCOMPARE(c.blue(), 0x44);
+
+ QCOMPARE(c.rgba64(), rgb64);
+
+ QColor c2 = QColor::fromRgb(0x22, 0x33, 0x44, 0xff);
+ QCOMPARE(c, c2);
+ QCOMPARE(c2.rgba64(), rgb64);
+
+ rgb64.setAlpha(0x8000);
+ rgb64.setGreen(0x8844);
+ rgb64 = rgb64.premultiplied();
+ QCOMPARE(rgb64.red(), quint16(0x1111));
+ QCOMPARE(rgb64.blue(), quint16(0x2222));
+ QCOMPARE(rgb64.green(), quint16(0x4422));
+}
+
+void tst_QColor::qrgba64MemoryLayout()
+{
+ QRgba64 rgb64 = QRgba64::fromRgba64(0x0123, 0x4567, 0x89ab, 0xcdef);
+ QCOMPARE(rgb64.red(), quint16(0x0123));
+ QCOMPARE(rgb64.green(), quint16(0x4567));
+ QCOMPARE(rgb64.blue(), quint16(0x89ab));
+ QCOMPARE(rgb64.alpha(), quint16(0xcdef));
+
+ // Check in-memory order, so it can be used by things like SSE
+ Q_STATIC_ASSERT(sizeof(QRgba64) == sizeof(quint64));
+ quint16 memory[4];
+ memcpy(memory, &rgb64, sizeof(QRgba64));
+ QCOMPARE(memory[0], quint16(0x0123));
+ QCOMPARE(memory[1], quint16(0x4567));
+ QCOMPARE(memory[2], quint16(0x89ab));
+ QCOMPARE(memory[3], quint16(0xcdef));
+}
+
+void tst_QColor::qrgba64Premultiply()
+{
+ // Tests that qPremultiply(qUnpremultiply(rgba64)) returns rgba64.
+ for (uint a = 0; a < 0x10000; a+=7) {
+ const uint step = std::max(a/1024, 1u);
+ for (uint c = 0; c <= a; c+=step) {
+ QRgba64 p = qRgba64(c, a-c, a-c/2, a);
+ QRgba64 pp = qPremultiply(qUnpremultiply(p));
+ QCOMPARE(pp, p);
+ }
+ }
+}
+
+void tst_QColor::qrgba64Equivalence()
+{
+ // Any ARGB32 converted back and forth.
+ for (uint a = 0; a < 256; a++) {
+ for (uint c = 0; c < 256; c++) {
+ QRgb p1 = qRgba(c, 255-c, 255-c, a);
+ QRgba64 p64 = QRgba64::fromArgb32(p1);
+ QCOMPARE(p64.toArgb32(), p1);
+ }
+ }
+ // Any unpremultiplied ARGB32 value premultipled in RGB64 (except alpha 0).
+ for (uint a = 1; a < 256; a++) {
+ for (uint c = 0; c < 256; c++) {
+ QRgb p1 = qRgba(c, 255-c, 255-c, a);
+ QRgb pp1 = qPremultiply(p1);
+ QRgba64 pp64 = qPremultiply(QRgba64::fromArgb32(p1));
+ QRgb pp2 = pp64.toArgb32();
+ // 64bit premultiplied is more accurate than 32bit, so allow slight difference.
+ QCOMPARE(qAlpha(pp2), qAlpha(pp1));
+ QVERIFY(qAbs(qRed(pp2)-qRed(pp1)) <= 1);
+ QVERIFY(qAbs(qGreen(pp2)-qGreen(pp1)) <= 1);
+ QVERIFY(qAbs(qBlue(pp2)-qBlue(pp1)) <= 1);
+ // But verify the added accuracy means we can return to accurate unpremultiplied ARGB32.
+ QRgba64 pu64 = qUnpremultiply(pp64);
+ QRgb p2 = pu64.toArgb32();
+ QCOMPARE(p2, p1);
+ }
+ }
+ // Any premultiplied ARGB32 value unpremultipled in RGB64.
+ for (uint a = 0; a < 256; a++) {
+ for (uint c = 0; c <= a; c++) {
+ QRgb pp = qRgba(c, a-c, a-c, a);
+ QRgb pu = qUnpremultiply(pp);
+ QRgba64 pu64 = qUnpremultiply(QRgba64::fromArgb32(pp));
+ QCOMPARE(pu64.toArgb32(), pu);
+ }
+ }
+}
+
QTEST_MAIN(tst_QColor)
#include "tst_qcolor.moc"
diff --git a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
index 964487f566..0f2f51d9b6 100644
--- a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
+++ b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
@@ -76,7 +76,7 @@ void tst_QPageLayout::basics()
QCOMPARE(simple.paintRectPixels(72), QRect(0, 0, 595, 842));
const QPageLayout a4portrait = simple;
- QVERIFY(a4portrait == simple);
+ QCOMPARE(a4portrait, simple);
// Change orientation
simple.setOrientation(QPageLayout::Landscape);
diff --git a/tests/auto/gui/painting/qpainter/qpainter.pro b/tests/auto/gui/painting/qpainter/qpainter.pro
index 7e9d438e1b..e90b516ef2 100644
--- a/tests/auto/gui/painting/qpainter/qpainter.pro
+++ b/tests/auto/gui/painting/qpainter/qpainter.pro
@@ -2,7 +2,7 @@ CONFIG += testcase
CONFIG += parallel_test
TARGET = tst_qpainter
-QT += testlib
+QT += testlib gui-private core-private
qtHaveModule(widgets): QT += widgets widgets-private
SOURCES += tst_qpainter.cpp
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 6582755aec..e8d90edd2d 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -53,6 +53,7 @@
#endif
#include <qpixmap.h>
+#include <private/qdrawhelper_p.h>
#include <qpainter.h>
#ifndef QT_NO_WIDGETS
@@ -125,8 +126,12 @@ private slots:
void fillRect3();
void fillRect4_data() { fillRect2_data(); }
void fillRect4();
+ void fillRectNonPremul_data();
void fillRectNonPremul();
+ void fillRectRGB30_data();
+ void fillRectRGB30();
+
void drawEllipse_data();
void drawEllipse();
void drawClippedEllipse_data();
@@ -198,6 +203,11 @@ private slots:
void gradientPixelFormat_data();
void gradientPixelFormat();
+ void linearGradientRgb30_data();
+ void linearGradientRgb30();
+ void radialGradientRgb30_data();
+ void radialGradientRgb30();
+
void fpe_pixmapTransform();
void fpe_zeroLengthLines();
void fpe_divByZero();
@@ -789,7 +799,7 @@ void tst_QPainter::drawPixmapFragments()
QImage origImage = origPixmap.toImage().convertToFormat(QImage::Format_ARGB32);
QImage resImage = resPixmap.toImage().convertToFormat(QImage::Format_ARGB32);
- QVERIFY(resImage.size() == resPixmap.size());
+ QCOMPARE(resImage.size(), resPixmap.size());
QVERIFY(resImage.pixel(5, 5) == origImage.pixel(15, 15));
QVERIFY(resImage.pixel(5, 15) == origImage.pixel(15, 5));
QVERIFY(resImage.pixel(15, 5) == origImage.pixel(5, 15));
@@ -797,16 +807,16 @@ void tst_QPainter::drawPixmapFragments()
QPainter::PixmapFragment fragment = QPainter::PixmapFragment::create(QPointF(20, 20), QRectF(30, 30, 2, 2));
- QVERIFY(fragment.x == 20);
- QVERIFY(fragment.y == 20);
- QVERIFY(fragment.sourceLeft == 30);
- QVERIFY(fragment.sourceTop == 30);
- QVERIFY(fragment.width == 2);
- QVERIFY(fragment.height == 2);
- QVERIFY(fragment.scaleX == 1);
- QVERIFY(fragment.scaleY == 1);
- QVERIFY(fragment.rotation == 0);
- QVERIFY(fragment.opacity == 1);
+ QCOMPARE(fragment.x, qreal(20));
+ QCOMPARE(fragment.y, qreal(20));
+ QCOMPARE(fragment.sourceLeft, qreal(30));
+ QCOMPARE(fragment.sourceTop, qreal(30));
+ QCOMPARE(fragment.width, qreal(2));
+ QCOMPARE(fragment.height, qreal(2));
+ QCOMPARE(fragment.scaleX, qreal(1));
+ QCOMPARE(fragment.scaleY, qreal(1));
+ QCOMPARE(fragment.rotation, qreal(0));
+ QCOMPARE(fragment.opacity, qreal(1));
}
void tst_QPainter::drawPixmapNegativeScale()
@@ -1245,22 +1255,87 @@ void tst_QPainter::fillRect4()
QCOMPARE(image, expected);
}
+void tst_QPainter::fillRectNonPremul_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<uint>("color");
+
+ QTest::newRow("argb32 7f1f3f7f") << QImage::Format_ARGB32 << qRgba(31, 63, 127, 127);
+ QTest::newRow("rgba8888 7f1f3f7f") << QImage::Format_RGBA8888 << qRgba(31, 63, 127, 127);
+
+ QTest::newRow("argb32 3f1f3f7f") << QImage::Format_ARGB32 << qRgba(31, 63, 127, 63);
+ QTest::newRow("rgba8888 3f1f3f7f") << QImage::Format_RGBA8888 << qRgba(31, 63, 127, 63);
+
+ QTest::newRow("argb32 070375f4") << QImage::Format_ARGB32 << qRgba(3, 117, 244, 7);
+ QTest::newRow("rgba8888 070375f4") << QImage::Format_RGBA8888 << qRgba(3, 117, 244, 7);
+
+ QTest::newRow("argb32 0301fe0c") << QImage::Format_ARGB32 << qRgba(1, 254, 12, 3);
+ QTest::newRow("rgba8888 0301fe0c") << QImage::Format_RGBA8888 << qRgba(1, 254, 12, 3);
+
+ QTest::newRow("argb32 01804010") << QImage::Format_ARGB32 << qRgba(128, 64, 32, 1);
+ QTest::newRow("rgba8888 01804010") << QImage::Format_RGBA8888 << qRgba(128, 64, 32, 1);
+}
+
void tst_QPainter::fillRectNonPremul()
{
- QImage img1(1, 1, QImage::Format_ARGB32);
- QImage img2(1, 1, QImage::Format_RGBA8888);
+ QFETCH(QImage::Format, format);
+ QFETCH(uint, color);
+
+ QImage image(1, 1, format);
+ QRectF rect(0, 0, 1, 1);
+
+ // Fill with CompositionMode_SourceOver tests blend_color
+ image.fill(Qt::transparent);
+ QPainter painter(&image);
+ painter.fillRect(rect, QColor::fromRgba(color));
+ painter.end();
+
+ // Fill with CompositionMode_Source tests rectfill.
+ painter.begin(&image);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(rect, QColor::fromRgba(color));
+ painter.end();
+
+ QRgb p = image.pixel(0, 0);
+ QCOMPARE(qAlpha(p), qAlpha(color));
+ QVERIFY(qAbs(qRed(p)-qRed(color)) <= 1);
+ QVERIFY(qAbs(qGreen(p)-qGreen(color)) <= 1);
+ QVERIFY(qAbs(qBlue(p)-qBlue(color)) <= 1);
+}
+
+void tst_QPainter::fillRectRGB30_data()
+{
+ QTest::addColumn<uint>("color");
- QPainter p1(&img1);
- QPainter p2(&img2);
+ QTest::newRow("17|43|259") << (0xc0000000 | (17 << 20) | (43 << 10) | 259);
+ QTest::newRow("2|33|444") << (0xc0000000 | (2 << 20) | (33 << 10) | 444);
+ QTest::newRow("1000|1000|1000") << (0xc0000000 | (1000 << 20) | (1000 << 10) | 1000);
+}
+void tst_QPainter::fillRectRGB30()
+{
+ QFETCH(uint, color);
QRectF rect(0, 0, 1, 1);
- p1.fillRect(rect, qRgba(31, 63, 127, 127));
- p2.fillRect(rect, qRgba(31, 63, 127, 127));
- p1.end();
- p2.end();
+ // Fill with CompositionMode_SourceOver tests blend_color
+ QImage image1(1, 1, QImage::Format_A2BGR30_Premultiplied);
+ image1.fill(Qt::transparent);
+ QPainter painter(&image1);
+ painter.fillRect(rect, QColor::fromRgba64(qConvertA2rgb30ToRgb64<PixelOrderBGR>(color)));
+ painter.end();
+
+ uint pixel1 = ((const uint*)(image1.bits()))[0];
+ QCOMPARE(pixel1, color);
+
+ // Fill with CompositionMode_Source tests rectfill.
+ QImage image2(1, 1, QImage::Format_RGB30);
+ painter.begin(&image2);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(rect, QColor::fromRgba64(qConvertA2rgb30ToRgb64<PixelOrderRGB>(color)));
+ painter.end();
- QCOMPARE(img1.pixel(0, 0), img2.pixel(0,0));
+ uint pixel2 = ((const uint*)(image2.bits()))[0];
+ QCOMPARE(pixel2, color);
}
void tst_QPainter::drawPath_data()
@@ -1406,7 +1481,7 @@ void tst_QPainter::drawPath3()
p.drawPath(path);
p.end();
- QVERIFY(imgA == imgB);
+ QCOMPARE(imgA, imgB);
imgA.invertPixels();
imgB.fill(0xffffff);
@@ -1420,7 +1495,7 @@ void tst_QPainter::drawPath3()
p.drawPath(path);
p.end();
- QVERIFY(imgA == imgB);
+ QCOMPARE(imgA, imgB);
path.setFillRule(Qt::WindingFill);
imgB.fill(0xffffff);
@@ -2381,36 +2456,50 @@ void tst_QPainter::setOpacity_data()
QTest::newRow("RGBx8888 on RGBx8888") << QImage::Format_RGBX8888
<< QImage::Format_RGBX8888;
- QTest::newRow("RGBA8888P on ARGB32P") << QImage::Format_RGBA8888_Premultiplied
+ QTest::newRow("RGBA8888P on ARGB32P") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_RGBA8888_Premultiplied;
+
+ QTest::newRow("RGBx8888 on ARGB32P") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_RGBX8888;
+
+ QTest::newRow("ARGB32P on RGBA8888P") << QImage::Format_RGBA8888_Premultiplied
<< QImage::Format_ARGB32_Premultiplied;
- QTest::newRow("RGBx8888 on ARGB32P") << QImage::Format_RGBX8888
- << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("RGB32 on RGBx8888") << QImage::Format_RGBX8888
+ << QImage::Format_RGB32;
- QTest::newRow("ARGB32P on RGBA8888P") << QImage::Format_ARGB32_Premultiplied
- << QImage::Format_RGBA8888_Premultiplied;
+ QTest::newRow("RGB30 on RGB32") << QImage::Format_RGB32
+ << QImage::Format_BGR30;
- QTest::newRow("RGB32 on RGBx8888") << QImage::Format_RGB32
- << QImage::Format_RGBX8888;
+ QTest::newRow("BGR30 on ARGB32P") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_BGR30;
+
+ QTest::newRow("A2RGB30P on ARGB32P") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_A2BGR30_Premultiplied;
QTest::newRow("A2RGB30P on A2RGB30P") << QImage::Format_A2RGB30_Premultiplied
<< QImage::Format_A2RGB30_Premultiplied;
- QTest::newRow("ARGB32P on A2RGB30P") << QImage::Format_ARGB32_Premultiplied
- << QImage::Format_A2RGB30_Premultiplied;
+ QTest::newRow("ARGB32P on A2RGB30P") << QImage::Format_A2RGB30_Premultiplied
+ << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("RGB32 on A2BGR30P") << QImage::Format_A2BGR30_Premultiplied
+ << QImage::Format_RGB32;
- QTest::newRow("RGB32 on A2BGR30P") << QImage::Format_ARGB32_Premultiplied
- << QImage::Format_A2BGR30_Premultiplied;
+ QTest::newRow("RGB30 on A2BGR30P") << QImage::Format_A2BGR30_Premultiplied
+ << QImage::Format_RGB30;
- QTest::newRow("A2RGB30P on A2BGR30P") << QImage::Format_A2RGB30_Premultiplied
- << QImage::Format_A2BGR30_Premultiplied;
+ QTest::newRow("A2RGB30P on A2BGR30P") << QImage::Format_A2BGR30_Premultiplied
+ << QImage::Format_A2RGB30_Premultiplied;
- QTest::newRow("ARGB32P on BGR30") << QImage::Format_ARGB32_Premultiplied
- << QImage::Format_BGR30;
+ QTest::newRow("ARGB32P on BGR30") << QImage::Format_BGR30
+ << QImage::Format_ARGB32_Premultiplied;
- QTest::newRow("ARGB32P on RGB30") << QImage::Format_A2RGB30_Premultiplied
- << QImage::Format_RGB30;
+ QTest::newRow("ARGB32P on RGB30") << QImage::Format_RGB30
+ << QImage::Format_ARGB32_Premultiplied;
+
+ QTest::newRow("A2RGB30P on RGB30") << QImage::Format_RGB30
+ << QImage::Format_A2RGB30_Premultiplied;
}
@@ -2492,7 +2581,7 @@ void tst_QPainter::drawhelper_blend_untransformed()
QImage expected(size - 2, size, destFormat);
p.begin(&expected);
p.fillRect(0, 0, expected.width(), expected.height(),
- QColor(dest.pixel(1, 0)));
+ dest.pixelColor(1, 0));
p.end();
const QImage subDest(dest.bits() + dest.depth() / 8,
@@ -2500,9 +2589,7 @@ void tst_QPainter::drawhelper_blend_untransformed()
dest.bytesPerLine(), dest.format());
if (dest.format() == QImage::Format_ARGB8565_Premultiplied ||
- dest.format() == QImage::Format_ARGB8555_Premultiplied ||
- dest.format() == QImage::Format_A2BGR30_Premultiplied ||
- dest.format() == QImage::Format_A2RGB30_Premultiplied ) {
+ dest.format() == QImage::Format_ARGB8555_Premultiplied) {
// Test skipped due to rounding errors...
continue;
}
@@ -2551,7 +2638,7 @@ void tst_QPainter::drawhelper_blend_tiled_untransformed()
QImage expected(size - 2, size, destFormat);
p.begin(&expected);
p.fillRect(0, 0, expected.width(), expected.height(),
- QColor(dest.pixel(1, 0)));
+ dest.pixelColor(1, 0));
p.end();
const QImage subDest(dest.bits() + dest.depth() / 8,
@@ -2619,28 +2706,6 @@ void tst_QPainter::porterDuff_warning()
QVERIFY(qInstallMessageHandler(old) == porterDuff_warningChecker);
}
-class quint24
-{
-public:
- inline quint24(quint32 v)
- {
- data[0] = qBlue(v);
- data[1] = qGreen(v);
- data[2] = qRed(v);
- }
-
- inline operator quint32 ()
- {
- return qRgb(data[2], data[1], data[0]);
- }
-
- inline bool operator==(const quint24 &v) const {
- return (data[0] == v.data[0] && data[1] == v.data[1] && data[2] == v.data[2]);
- }
-
- uchar data[3];
-};
-
void tst_QPainter::drawhelper_blend_color()
{
QImage dest(32, 32, QImage::Format_ARGB8555_Premultiplied);
@@ -3889,6 +3954,65 @@ void tst_QPainter::gradientInterpolation()
}
}
+void tst_QPainter::linearGradientRgb30_data()
+{
+ QTest::addColumn<QColor>("stop0");
+ QTest::addColumn<QColor>("stop1");
+
+ QTest::newRow("white->black") << QColor(Qt::white) << QColor(Qt::black);
+ QTest::newRow("blue->black") << QColor(Qt::blue) << QColor(Qt::black);
+ QTest::newRow("white->red") << QColor(Qt::white) << QColor(Qt::red);
+}
+
+void tst_QPainter::linearGradientRgb30()
+{
+ QFETCH(QColor, stop0);
+ QFETCH(QColor, stop1);
+
+ QLinearGradient gradient(0, 0, 1000, 1);
+ gradient.setColorAt(0.0, stop0);
+ gradient.setColorAt(1.0, stop1);
+
+ QImage image(1000, 1, QImage::Format_RGB30);
+ QPainter painter(&image);
+ painter.fillRect(image.rect(), gradient);
+ painter.end();
+
+ for (int i = 1; i < 1000; ++i) {
+ QColor p1 = image.pixelColor(i - 1, 0);
+ QColor p2 = image.pixelColor(i, 0);
+ QVERIFY(p1 != p2);
+ QVERIFY(qGray(p1.rgb()) >= qGray(p2.rgb()));
+ }
+}
+
+void tst_QPainter::radialGradientRgb30_data()
+{
+ linearGradientRgb30_data();
+}
+
+void tst_QPainter::radialGradientRgb30()
+{
+ QFETCH(QColor, stop0);
+ QFETCH(QColor, stop1);
+
+ QRadialGradient gradient(0, 0, 1000);
+ gradient.setColorAt(0.0, stop0);
+ gradient.setColorAt(1.0, stop1);
+
+ QImage image(1000, 1, QImage::Format_A2BGR30_Premultiplied);
+ QPainter painter(&image);
+ painter.fillRect(image.rect(), gradient);
+ painter.end();
+
+ for (int i = 1; i < 1000; ++i) {
+ QColor p1 = image.pixelColor(i - 1, 0);
+ QColor p2 = image.pixelColor(i, 0);
+ QVERIFY(p1 != p2);
+ QVERIFY(qGray(p1.rgb()) >= qGray(p2.rgb()));
+ }
+}
+
void tst_QPainter::drawPolygon()
{
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
@@ -4064,10 +4188,10 @@ void tst_QPainter::extendedBlendModes()
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Plus, 0.3));
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Plus, 0.3));
- QVERIFY(testCompositionMode(127, 128, 165, QPainter::CompositionMode_Plus, 0.3));
- QVERIFY(testCompositionMode(127, 0, 37, QPainter::CompositionMode_Plus, 0.3));
+ QVERIFY(testCompositionMode(126, 128, 165, QPainter::CompositionMode_Plus, 0.3));
+ QVERIFY(testCompositionMode(127, 0, 38, QPainter::CompositionMode_Plus, 0.3));
QVERIFY(testCompositionMode( 0, 127, 127, QPainter::CompositionMode_Plus, 0.3));
- QVERIFY(testCompositionMode(255, 0, 75, QPainter::CompositionMode_Plus, 0.3));
+ QVERIFY(testCompositionMode(255, 0, 76, QPainter::CompositionMode_Plus, 0.3));
QVERIFY(testCompositionMode( 0, 255, 255, QPainter::CompositionMode_Plus, 0.3));
QVERIFY(testCompositionMode(128, 128, 166, QPainter::CompositionMode_Plus, 0.3));
QVERIFY(testCompositionMode(186, 200, 255, QPainter::CompositionMode_Plus, 0.3));
@@ -4752,6 +4876,22 @@ void tst_QPainter::blendARGBonRGB_data()
<< QPainter::CompositionMode_SourceIn << qRgba(255, 0, 0, 127) << 125;
QTest::newRow("ARGB_PM source-in RGB666") << QImage::Format_RGB666 << QImage::Format_ARGB32_Premultiplied
<< QPainter::CompositionMode_SourceIn << qRgba(127, 0, 0, 127) << 125;
+ QTest::newRow("ARGB over RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
+ << QPainter::CompositionMode_SourceOver << qRgba(255, 0, 0, 85) << 85;
+ QTest::newRow("ARGB_PM over RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
+ << QPainter::CompositionMode_SourceOver << qRgba(85, 0, 0, 85) << 85;
+ QTest::newRow("ARGB source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
+ << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 85) << 85;
+ QTest::newRow("ARGB source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
+ << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 120) << 85;
+ QTest::newRow("ARGB_PM source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
+ << QPainter::CompositionMode_Source << qRgba(85, 0, 0, 85) << 85;
+ QTest::newRow("ARGB_PM source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
+ << QPainter::CompositionMode_Source << qRgba(180, 0, 0, 180) << 170;
+ QTest::newRow("ARGB source-in RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
+ << QPainter::CompositionMode_SourceIn << qRgba(255, 0, 0, 85) << 85;
+ QTest::newRow("ARGB_PM source-in RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
+ << QPainter::CompositionMode_SourceIn << qRgba(85, 0, 0, 85) << 85;
}
void tst_QPainter::blendARGBonRGB()
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
index 0a073f5c84..ae30719ee7 100644
--- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
@@ -602,16 +602,16 @@ void tst_QPainterPath::testOperatorEquals()
{
QPainterPath empty1;
QPainterPath empty2;
- QVERIFY(empty1 == empty2);
+ QCOMPARE(empty1, empty2);
QPainterPath rect1;
rect1.addRect(100, 100, 100, 100);
- QVERIFY(rect1 == rect1);
+ QCOMPARE(rect1, rect1);
QVERIFY(rect1 != empty1);
QPainterPath rect2;
rect2.addRect(100, 100, 100, 100);
- QVERIFY(rect1 == rect2);
+ QCOMPARE(rect1, rect2);
rect2.setFillRule(Qt::WindingFill);
QVERIFY(rect1 != rect2);
@@ -622,7 +622,7 @@ void tst_QPainterPath::testOperatorEquals()
QPainterPath ellipse2;
ellipse2.addEllipse(50, 50, 100, 100);
- QVERIFY(ellipse1 == ellipse2);
+ QCOMPARE(ellipse1, ellipse2);
}
void tst_QPainterPath::testOperatorEquals_fuzzy()
@@ -638,12 +638,12 @@ void tst_QPainterPath::testOperatorEquals_fuzzy()
QPainterPath pb;
pb.addRect(b);
- QVERIFY(pa == pb);
+ QCOMPARE(pa, pb);
QTransform transform;
transform.translate(-100, -100);
- QVERIFY(transform.map(pa) == transform.map(pb));
+ QCOMPARE(transform.map(pa), transform.map(pb));
}
// higher tolerance for error when path's bounding rect is big
@@ -656,12 +656,12 @@ void tst_QPainterPath::testOperatorEquals_fuzzy()
QPainterPath pb;
pb.addRect(b);
- QVERIFY(pa == pb);
+ QCOMPARE(pa, pb);
QTransform transform;
transform.translate(-1, -1);
- QVERIFY(transform.map(pa) == transform.map(pb));
+ QCOMPARE(transform.map(pa), transform.map(pb));
}
// operator== should return true for a path that has
@@ -676,7 +676,7 @@ void tst_QPainterPath::testOperatorEquals_fuzzy()
QPainterPath b = transform.inverted().map(transform.map(a));
- QVERIFY(a == b);
+ QCOMPARE(a, b);
}
{
@@ -720,7 +720,7 @@ void tst_QPainterPath::testOperatorDatastream()
stream >> other;
}
- QVERIFY(other == path);
+ QCOMPARE(other, path);
}
void tst_QPainterPath::closing()
@@ -1066,19 +1066,19 @@ void tst_QPainterPath::setElementPositionAt()
{
QPainterPath path(QPointF(42., 42.));
QCOMPARE(path.elementCount(), 1);
- QVERIFY(path.elementAt(0).type == QPainterPath::MoveToElement);
+ QCOMPARE(path.elementAt(0).type, QPainterPath::MoveToElement);
QCOMPARE(path.elementAt(0).x, qreal(42.));
QCOMPARE(path.elementAt(0).y, qreal(42.));
QPainterPath copy = path;
copy.setElementPositionAt(0, qreal(0), qreal(0));
QCOMPARE(copy.elementCount(), 1);
- QVERIFY(copy.elementAt(0).type == QPainterPath::MoveToElement);
+ QCOMPARE(copy.elementAt(0).type, QPainterPath::MoveToElement);
QCOMPARE(copy.elementAt(0).x, qreal(0));
QCOMPARE(copy.elementAt(0).y, qreal(0));
QCOMPARE(path.elementCount(), 1);
- QVERIFY(path.elementAt(0).type == QPainterPath::MoveToElement);
+ QCOMPARE(path.elementAt(0).type, QPainterPath::MoveToElement);
QCOMPARE(path.elementAt(0).x, qreal(42.));
QCOMPARE(path.elementAt(0).y, qreal(42.));
}
@@ -1253,10 +1253,10 @@ void tst_QPainterPath::connectPathMoveTo()
path1.connectPath(path2);
- QVERIFY(path1.elementAt(0).type == QPainterPath::MoveToElement);
- QVERIFY(path2.elementAt(0).type == QPainterPath::MoveToElement);
- QVERIFY(path3.elementAt(0).type == QPainterPath::MoveToElement);
- QVERIFY(path4.elementAt(0).type == QPainterPath::MoveToElement);
+ QCOMPARE(path1.elementAt(0).type, QPainterPath::MoveToElement);
+ QCOMPARE(path2.elementAt(0).type, QPainterPath::MoveToElement);
+ QCOMPARE(path3.elementAt(0).type, QPainterPath::MoveToElement);
+ QCOMPARE(path4.elementAt(0).type, QPainterPath::MoveToElement);
}
void tst_QPainterPath::translate()
diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp
index c0e3c6d187..33f81cc10e 100644
--- a/tests/auto/gui/painting/qregion/tst_qregion.cpp
+++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp
@@ -173,7 +173,7 @@ void tst_QRegion::setRects()
QRect rect;
region.setRects(&rect, 0);
QVERIFY(region.isEmpty());
- QVERIFY(region == QRegion());
+ QCOMPARE(region, QRegion());
QVERIFY(!region.boundingRect().isValid());
QVERIFY(region.rects().isEmpty());
}
diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
index 13b15d09dd..60b89aa6ab 100644
--- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
+++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
@@ -57,6 +57,7 @@ private slots:
void mapRect();
void assignments();
void mapToPolygon();
+ void qhash();
void translate();
void scale();
void matrix();
@@ -361,6 +362,22 @@ void tst_QTransform::mapToPolygon()
QVERIFY(equal);
}
+void tst_QTransform::qhash()
+{
+ QMatrix m1;
+ m1.shear(3.0, 2.0);
+ m1.rotate(44);
+
+ QMatrix m2 = m1;
+
+ QTransform t1(m1);
+ QTransform t2(m2);
+
+ // not really much to test here, so just the bare minimum:
+ QCOMPARE(qHash(m1), qHash(m2));
+ QCOMPARE(qHash(t1), qHash(t2));
+}
+
void tst_QTransform::translate()
{
@@ -411,14 +428,14 @@ void tst_QTransform::matrix()
mat1.m21(), mat1.m22(), 0,
mat1.dx(), mat1.dy(), 1);
- QVERIFY(tran1 == dummy);
- QVERIFY(tran1.inverted() == dummy.inverted());
- QVERIFY(tran1.inverted() == QTransform(mat1.inverted()));
- QVERIFY(tran2.inverted() == QTransform(mat2.inverted()));
+ QCOMPARE(tran1, dummy);
+ QCOMPARE(tran1.inverted(), dummy.inverted());
+ QCOMPARE(tran1.inverted(), QTransform(mat1.inverted()));
+ QCOMPARE(tran2.inverted(), QTransform(mat2.inverted()));
QMatrix mat3 = mat1 * mat2;
QTransform tran3 = tran1 * tran2;
- QVERIFY(QTransform(mat3) == tran3);
+ QCOMPARE(QTransform(mat3), tran3);
/* QMatrix::operator==() doesn't use qFuzzyCompare(), which
* on win32-g++ results in a failure. So we work around it by
@@ -430,15 +447,15 @@ void tst_QTransform::matrix()
QRect rect(43, 70, 200, 200);
QPoint pt(43, 66);
- QVERIFY(tranInv.map(pt) == matInv.map(pt));
- QVERIFY(tranInv.map(pt) == matInv.map(pt));
+ QCOMPARE(tranInv.map(pt), matInv.map(pt));
+ QCOMPARE(tranInv.map(pt), matInv.map(pt));
QPainterPath path;
path.moveTo(55, 60);
path.lineTo(110, 110);
path.quadTo(220, 50, 10, 20);
path.closeSubpath();
- QVERIFY(tranInv.map(path) == matInv.map(path));
+ QCOMPARE(tranInv.map(path), matInv.map(path));
}
void tst_QTransform::testOffset()
@@ -724,8 +741,8 @@ void tst_QTransform::inverted()
const QTransform inverted = matrix.inverted();
- QVERIFY(matrix.isIdentity() == inverted.isIdentity());
- QVERIFY(matrix.type() == inverted.type());
+ QCOMPARE(matrix.isIdentity(), inverted.isIdentity());
+ QCOMPARE(matrix.type(), inverted.type());
QVERIFY((matrix * inverted).isIdentity());
QVERIFY((inverted * matrix).isIdentity());