diff options
author | Jakub Adam <jakub.adam@ktknet.cz> | 2016-01-16 15:40:16 +0100 |
---|---|---|
committer | Jakub Adam <jakub.adam@ktknet.cz> | 2016-02-01 18:27:12 +0000 |
commit | 80eabc56349b5efe4acf3fcb467b5b2d6491131f (patch) | |
tree | 764b3b8d6e9e3407ea6f7e5b6af1b005f9308ded | |
parent | 16a9c66bc538324ab8a31131e8a6a2a86d459cc0 (diff) |
QSGDefaultRectangleNode: Fix off-by-one color rendering
Implicit conversion from floating-point to int, which simply truncates
the number's fractional part, may have caused the rectangle fill
to be rendered in a color with some of its RGB components different
by ±1 from the specified value.
For example, the actual on-screen color of the following QML item was
#010101 on 32bit Intel (no antialiasing or alpha channel):
Rectangle {
width: 100
height: 100
color: '#020202'
}
This commit improves precision of the calculation by applying qRound()
before the conversion to integer.
Change-Id: Ia849c31ba9872e7a92608245406d178051b21917
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
-rw-r--r-- | src/quick/scenegraph/qsgdefaultrectanglenode.cpp | 8 | ||||
-rw-r--r-- | tests/auto/quick/qquickrectangle/data/color.qml | 8 | ||||
-rw-r--r-- | tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp | 17 |
3 files changed, 29 insertions, 4 deletions
diff --git a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp index 41e414f79d..551575573e 100644 --- a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp +++ b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp @@ -64,10 +64,10 @@ namespace inline Color4ub colorToColor4ub(const QColor &c) { - Color4ub color = { uchar(c.redF() * c.alphaF() * 255), - uchar(c.greenF() * c.alphaF() * 255), - uchar(c.blueF() * c.alphaF() * 255), - uchar(c.alphaF() * 255) + Color4ub color = { uchar(qRound(c.redF() * c.alphaF() * 255)), + uchar(qRound(c.greenF() * c.alphaF() * 255)), + uchar(qRound(c.blueF() * c.alphaF() * 255)), + uchar(qRound(c.alphaF() * 255)) }; return color; } diff --git a/tests/auto/quick/qquickrectangle/data/color.qml b/tests/auto/quick/qquickrectangle/data/color.qml new file mode 100644 index 0000000000..56b83d11c7 --- /dev/null +++ b/tests/auto/quick/qquickrectangle/data/color.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +Rectangle { + width: 100 + height: 100 + color: '#020202' +} + diff --git a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp index d0cb47c1e3..65c7e387a0 100644 --- a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp +++ b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp @@ -28,6 +28,7 @@ #include <qtest.h> #include <QtTest/QSignalSpy> +#include <QtGui/qscreen.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQuick/qquickview.h> @@ -42,6 +43,7 @@ public: tst_qquickrectangle(); private slots: + void color(); void gradient(); void gradient_border(); void antialiasing(); @@ -54,6 +56,21 @@ tst_qquickrectangle::tst_qquickrectangle() { } +void tst_qquickrectangle::color() +{ + if (QGuiApplication::primaryScreen()->depth() < 24) + QSKIP("This test does not work at display depths < 24"); + + QQuickView view; + view.setSource(testFileUrl("color.qml")); + view.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QImage image = view.grabWindow(); + QVERIFY(image.pixel(0,0) == QColor("#020202").rgba()); +} + void tst_qquickrectangle::gradient() { QQmlComponent component(&engine, testFileUrl("gradient.qml")); |