Merge lp:~fboucault/ubuntu-ui-toolkit/shape_fix_distortion into lp:ubuntu-ui-toolkit

Proposed by Florian Boucault on 2013-04-20
Status: Merged
Approved by: Loïc Molinari on 2013-04-26
Approved revision: 440
Merged at revision: 451
Proposed branch: lp:~fboucault/ubuntu-ui-toolkit/shape_fix_distortion
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 185 lines (+119/-7)
5 files modified
modules/Ubuntu/Components/plugin/shapeitem.cpp (+9/-6)
tests/unit/tst_ubuntu_shape/no_distortion.qml (+40/-0)
tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.cpp (+63/-0)
tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.pro (+5/-0)
tests/unit/unit.pro (+2/-1)
To merge this branch: bzr merge lp:~fboucault/ubuntu-ui-toolkit/shape_fix_distortion
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2013-04-26
Loïc Molinari (community) 2013-04-20 Approve on 2013-04-24
Review via email: mp+159914@code.launchpad.net

Commit message

UbuntuShape: fix slight distortion of image when set.

This distortion was quite disturbing when the content has text in it, as it is often the case in Popups and Popovers.

To post a comment you must log in.
Florian Boucault (fboucault) wrote :

I'm not sure at all it's the correct patch.

Loïc Molinari (loic.molinari) wrote :

You're right, there's a clearly a problem there. I wonder why I was subtracting 1 to the radius and size (width or height). I think the subtraction on the size that you kept should not even be there, I tested and it works correctly.

Now there's still another problem. I'm testing with a 512x512 image with an UbuntuShape of the same size with fillMode set to PreserveAspectCrop, if you set the width (or height) to an even value, the rendering is good, if you set it to an odd value the rendering is slightly stretched.

Loïc Molinari (loic.molinari) wrote :

Can you please remove the remaining substraction on the sizes?

I haven't found the reason of that even/odd size issue, I'll investigate later. Can you add a FIXME meanwhile? Something like:

// FIXME(loicm) With a NxM image, a preserve aspect crop fill mode and a width
// component size of N (or a height component size of M), changing the the
// height (or width) breaks the 1:1 texel/pixel mapping for odd values.

review: Needs Fixing
Loïc Molinari (loic.molinari) wrote :

Good

review: Approve
439. By Florian Boucault on 2013-04-26

QSKIP unit test for now.

440. By Florian Boucault on 2013-04-26

Fixed conflict

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/shapeitem.cpp'
2--- modules/Ubuntu/Components/plugin/shapeitem.cpp 2013-04-25 15:09:49 +0000
3+++ modules/Ubuntu/Components/plugin/shapeitem.cpp 2013-04-26 13:39:36 +0000
4@@ -374,6 +374,9 @@
5 float radiusCoordinateWidth;
6 float radiusCoordinateHeight;
7
8+ // FIXME(loicm) With a NxM image, a preserve aspect crop fill mode and a width
9+ // component size of N (or a height component size of M), changing the the
10+ // height (or width) breaks the 1:1 texel/pixel mapping for odd values.
11 if (!stretched && texture) {
12 // Preserve source image aspect ratio cropping areas exceeding destination rectangle.
13 const float factors[3] = { 0.0f, 0.5f, 1.0f };
14@@ -387,8 +390,8 @@
15 bottomCoordinate = 1.0f;
16 leftCoordinate = outCoordinateSize * factors[hAlignment];
17 rightCoordinate = 1.0f - (outCoordinateSize * (1.0f - factors[hAlignment]));
18- radiusCoordinateHeight = (radius - 1.0f) / (height - 1.0f);
19- radiusCoordinateWidth = ((radius - 1.0f) / (width - 1.0f)) * inCoordinateSize;
20+ radiusCoordinateHeight = radius / height;
21+ radiusCoordinateWidth = (radius / width) * inCoordinateSize;
22 } else {
23 const float inCoordinateSize = srcRatio / dstRatio;
24 const float outCoordinateSize = 1.0f - inCoordinateSize;
25@@ -396,8 +399,8 @@
26 bottomCoordinate = 1.0f - (outCoordinateSize * (1.0f - factors[vAlignment]));
27 leftCoordinate = 0.0f;
28 rightCoordinate = 1.0f;
29- radiusCoordinateHeight = ((radius - 1.0f) / (height - 1.0f)) * inCoordinateSize;
30- radiusCoordinateWidth = (radius - 1.0f) / (width - 1.0f);
31+ radiusCoordinateHeight = (radius / height) * inCoordinateSize;
32+ radiusCoordinateWidth = radius / width;
33 }
34 } else {
35 // Don't preserve source image aspect ratio stretching it in destination rectangle.
36@@ -405,8 +408,8 @@
37 bottomCoordinate = 1.0f;
38 leftCoordinate = 0.0f;
39 rightCoordinate = 1.0f;
40- radiusCoordinateHeight = (radius - 1.0f) / (height - 1.0f);
41- radiusCoordinateWidth = (radius - 1.0f) / (width - 1.0f);
42+ radiusCoordinateHeight = radius / height;
43+ radiusCoordinateWidth = radius / width;
44 }
45
46 // Set top row of 4 vertices.
47
48=== added directory 'tests/unit/tst_ubuntu_shape'
49=== added file 'tests/unit/tst_ubuntu_shape/no_distortion.qml'
50--- tests/unit/tst_ubuntu_shape/no_distortion.qml 1970-01-01 00:00:00 +0000
51+++ tests/unit/tst_ubuntu_shape/no_distortion.qml 2013-04-26 13:39:36 +0000
52@@ -0,0 +1,40 @@
53+/*
54+ * Copyright 2013 Canonical Ltd.
55+ *
56+ * This program is free software; you can redistribute it and/or modify
57+ * it under the terms of the GNU Lesser General Public License as published by
58+ * the Free Software Foundation; version 3.
59+ *
60+ * This program is distributed in the hope that it will be useful,
61+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
62+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+ * GNU Lesser General Public License for more details.
64+ *
65+ * You should have received a copy of the GNU Lesser General Public License
66+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
67+ */
68+
69+import QtQuick 2.0
70+import Ubuntu.Components 0.1
71+
72+Item {
73+ width: 900
74+ height: 500
75+
76+ Row {
77+ spacing: 50
78+ anchors.centerIn: parent
79+
80+ Image {
81+ id: grid
82+ source: "no_distortion_source.png"
83+ }
84+
85+ Shape {
86+ id: shape
87+ width: grid.width
88+ height: grid.height
89+ image: grid
90+ }
91+ }
92+}
93
94=== added file 'tests/unit/tst_ubuntu_shape/no_distortion_expected.png'
95Binary files tests/unit/tst_ubuntu_shape/no_distortion_expected.png 1970-01-01 00:00:00 +0000 and tests/unit/tst_ubuntu_shape/no_distortion_expected.png 2013-04-26 13:39:36 +0000 differ
96=== added file 'tests/unit/tst_ubuntu_shape/no_distortion_source.png'
97Binary files tests/unit/tst_ubuntu_shape/no_distortion_source.png 1970-01-01 00:00:00 +0000 and tests/unit/tst_ubuntu_shape/no_distortion_source.png 2013-04-26 13:39:36 +0000 differ
98=== added file 'tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.cpp'
99--- tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.cpp 1970-01-01 00:00:00 +0000
100+++ tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.cpp 2013-04-26 13:39:36 +0000
101@@ -0,0 +1,63 @@
102+/*
103+ * Copyright 2013 Canonical Ltd.
104+ *
105+ * This program is free software; you can redistribute it and/or modify
106+ * it under the terms of the GNU Lesser General Public License as published by
107+ * the Free Software Foundation; version 3.
108+ *
109+ * This program is distributed in the hope that it will be useful,
110+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
112+ * GNU Lesser General Public License for more details.
113+ *
114+ * You should have received a copy of the GNU Lesser General Public License
115+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
116+ *
117+ * Author: Florian Boucault <florian.boucault@canonical.com>
118+ */
119+
120+#include <QtTest/QtTest>
121+#include <QtQuick/QQuickView>
122+#include <QtQml/QQmlEngine>
123+
124+class tst_UbuntuShape: public QObject
125+{
126+ Q_OBJECT
127+
128+private:
129+ QQuickView *m_quickView;
130+
131+private Q_SLOTS:
132+
133+ void initTestCase()
134+ {
135+ m_quickView = new QQuickView;
136+ m_quickView->setGeometry(0, 0, 900, 500);
137+ m_quickView->show();
138+
139+ // add modules folder so we have access to the plugin from QML
140+ QQmlEngine *engine = m_quickView->engine();
141+ QString modules("../../../modules");
142+ QStringList imports = engine->importPathList();
143+ imports.prepend(QDir(modules).absolutePath());
144+ engine->setImportPathList(imports);
145+ }
146+
147+ void noDistortion() {
148+ QSKIP("This test passes on local machines but not in CI as it requires working OpenGL");
149+ m_quickView->setSource(QUrl::fromLocalFile("no_distortion.qml"));
150+ QCoreApplication::processEvents();
151+
152+ QImage result = m_quickView->grabWindow();
153+ QVERIFY(!result.isNull());
154+
155+ QImage expected = QImage("no_distortion_expected.png");
156+ QVERIFY(!expected.isNull());
157+
158+ QCOMPARE(result, expected);
159+ }
160+};
161+
162+QTEST_MAIN(tst_UbuntuShape)
163+
164+#include "tst_ubuntu_shape.moc"
165
166=== added file 'tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.pro'
167--- tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.pro 1970-01-01 00:00:00 +0000
168+++ tests/unit/tst_ubuntu_shape/tst_ubuntu_shape.pro 2013-04-26 13:39:36 +0000
169@@ -0,0 +1,5 @@
170+include(../test-include.pri)
171+SOURCES += tst_ubuntu_shape.cpp
172+OTHER_FILES += no_distortion.qml \
173+ no_distortion_source.png \
174+ no_distortion_expected.png
175
176=== modified file 'tests/unit/unit.pro'
177--- tests/unit/unit.pro 2013-04-22 15:38:15 +0000
178+++ tests/unit/unit.pro 2013-04-26 13:39:36 +0000
179@@ -27,4 +27,5 @@
180 tst_theme_engine_stylecache \
181 tst_theme_engine_style \
182 tst_inversemousearea \
183- tst_performance
184+ tst_performance \
185+ tst_ubuntu_shape

Subscribers

People subscribed via source and target branches

to status/vote changes: