Merge lp:~fboucault/qt-halide/expose_qimage into lp:qt-halide

Proposed by Florian Boucault
Status: Merged
Approved by: Ugo Riboni
Approved revision: 311
Merged at revision: 312
Proposed branch: lp:~fboucault/qt-halide/expose_qimage
Merge into: lp:qt-halide
Diff against target: 222 lines (+89/-4)
8 files modified
src/QtHalide/halide_image.cpp (+19/-0)
src/QtHalide/halide_image.h (+3/-0)
src/QtHalide/halide_transform.cpp (+6/-3)
src/QtHalide/halide_transform.h (+1/-1)
tests/unit/QtHalideTestHelper/test_helper.cpp (+10/-0)
tests/unit/QtHalideTestHelper/test_helper.h (+4/-0)
tests/unit/tst_image.qml (+16/-0)
tests/unit/tst_transform.qml (+30/-0)
To merge this branch: bzr merge lp:~fboucault/qt-halide/expose_qimage
Reviewer Review Type Date Requested Status
Ugo Riboni (community) Approve
Review via email: mp+261539@code.launchpad.net

Commit message

New property QImage HalideImage::image exposing backing QImage.
New parameter to HalideTransform::scheduleUpdate(bool requiresQImage) ensuring HalideTransform::output will be backed by a QImage.

To post a comment you must log in.
Revision history for this message
Ugo Riboni (uriboni) wrote :

LGTM unless you want to add some unit tests that cover the case when there is no backing QImage

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/QtHalide/halide_image.cpp'
2--- src/QtHalide/halide_image.cpp 2015-04-09 21:30:38 +0000
3+++ src/QtHalide/halide_image.cpp 2015-06-09 16:35:21 +0000
4@@ -142,6 +142,20 @@
5 }
6 }
7
8+/*!
9+ \qmlproperty QImage HalideImage::image
10+
11+ Returns the QImage backing the HalideImage if any.
12+*/
13+QImage HalideImage::image() const
14+{
15+ if (m_data) {
16+ return m_data->image;
17+ } else {
18+ return QImage();
19+ }
20+}
21+
22 void HalideImage::setData(QSharedPointer<HalideImageData> data)
23 {
24 Q_ASSERT_X(!data.isNull(), "HalideImage::setData", "cannot set null data");
25@@ -161,6 +175,10 @@
26 if (data->size != oldData->size) {
27 Q_EMIT sizeChanged();
28 }
29+
30+ if (data->image != oldData->image) {
31+ Q_EMIT imageChanged();
32+ }
33 }
34 Q_EMIT dataChanged();
35 }
36@@ -230,6 +248,7 @@
37
38 if (m_reload.isFinished()) {
39 if (m_source.isEmpty()) {
40+ m_data.reset(new HalideImageData);
41 setStatus(HalideImage::Null);
42 } else {
43 setStatus(HalideImage::Loading);
44
45=== modified file 'src/QtHalide/halide_image.h'
46--- src/QtHalide/halide_image.h 2015-04-08 15:48:49 +0000
47+++ src/QtHalide/halide_image.h 2015-06-09 16:35:21 +0000
48@@ -50,6 +50,7 @@
49 Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged)
50 Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
51 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
52+ Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
53
54 public:
55 explicit HalideImage(QObject *parent = 0);
56@@ -64,6 +65,7 @@
57 QSize sourceSize() const;
58 QSize size() const;
59 Status status() const;
60+ QImage image() const;
61
62 void setSource(QUrl source);
63 void setSourceSize(QSize sourceSize);
64@@ -75,6 +77,7 @@
65 void sourceSizeChanged();
66 void sizeChanged();
67 void statusChanged(HalideImage::Status);
68+ void imageChanged();
69 void dataChanged();
70
71 private Q_SLOTS:
72
73=== modified file 'src/QtHalide/halide_transform.cpp'
74--- src/QtHalide/halide_transform.cpp 2015-04-09 21:30:38 +0000
75+++ src/QtHalide/halide_transform.cpp 2015-06-09 16:35:21 +0000
76@@ -297,13 +297,16 @@
77
78
79 /*!
80- \qmlmethod HalideTransform::scheduleUpdate()
81+ \qmlmethod HalideTransform::scheduleUpdate(bool requiresQImage)
82
83 Requests the transform to recompute its output.
84+
85+ If \a requiresQImage is true then \l output will be backed by a QImage
86+ accessible through its \l HalideImage::image property.
87 */
88-void HalideTransform::scheduleUpdate()
89+void HalideTransform::scheduleUpdate(bool requiresQImage)
90 {
91- doUpdate(false);
92+ doUpdate(requiresQImage);
93 }
94
95 void HalideTransform::doUpdate(bool outputImageRequired)
96
97=== modified file 'src/QtHalide/halide_transform.h'
98--- src/QtHalide/halide_transform.h 2015-04-08 15:48:49 +0000
99+++ src/QtHalide/halide_transform.h 2015-06-09 16:35:21 +0000
100@@ -50,7 +50,7 @@
101 virtual void componentComplete();
102
103 Q_INVOKABLE bool saveToFile(QString fileName);
104- Q_SLOT void scheduleUpdate();
105+ Q_SLOT void scheduleUpdate(bool requiresQImage = false);
106
107 bool live() const;
108 void setLive(bool live);
109
110=== modified file 'tests/unit/QtHalideTestHelper/test_helper.cpp'
111--- tests/unit/QtHalideTestHelper/test_helper.cpp 2015-04-08 15:48:49 +0000
112+++ tests/unit/QtHalideTestHelper/test_helper.cpp 2015-06-09 16:35:21 +0000
113@@ -34,3 +34,13 @@
114 {
115 return QFile::remove(path);
116 }
117+
118+QColor TestHelper::pixelColor(QImage image, int x, int y)
119+{
120+ return QColor(image.pixel(x, y));
121+}
122+
123+QSize TestHelper::imageSize(QImage image)
124+{
125+ return image.size();
126+}
127
128=== modified file 'tests/unit/QtHalideTestHelper/test_helper.h'
129--- tests/unit/QtHalideTestHelper/test_helper.h 2015-04-08 15:48:49 +0000
130+++ tests/unit/QtHalideTestHelper/test_helper.h 2015-06-09 16:35:21 +0000
131@@ -18,6 +18,8 @@
132 #define TEST_HELPER_H
133
134 #include <QtCore/QObject>
135+#include <QtGui/QColor>
136+#include <QtGui/QImage>
137
138 class TestHelper : public QObject
139 {
140@@ -30,6 +32,8 @@
141 QString saveLocation() const;
142
143 Q_INVOKABLE bool deleteFile(QString path);
144+ Q_INVOKABLE QColor pixelColor(QImage image, int x, int y);
145+ Q_INVOKABLE QSize imageSize(QImage image);
146
147 Q_SIGNALS:
148 void saveLocationChanged();
149
150=== modified file 'tests/unit/tst_image.qml'
151--- tests/unit/tst_image.qml 2015-04-08 15:48:49 +0000
152+++ tests/unit/tst_image.qml 2015-06-09 16:35:21 +0000
153@@ -88,6 +88,22 @@
154 compare(input.size.height, 10, "height not matching");
155 }
156
157+ function test_qimage() {
158+ input.setSourceAndCheckStatus("", Image.Null);
159+ var imageSize = helper.imageSize(input.image);
160+ compare(imageSize.width, 0, "input.image has incorrect width");
161+ compare(imageSize.height, 0, "input.image has incorrect height");
162+
163+ input.setSourceAndCheckStatus("in.png", Image.Ready);
164+ imageSize = helper.imageSize(input.image);
165+ compare(imageSize.width, 10, "input.image has incorrect width");
166+ compare(imageSize.height, 10, "input.image has incorrect height");
167+
168+ var firstPixelColor = helper.pixelColor(input.image, 0, 0);
169+ var expectedColor = Qt.rgba(128/255, 128/255, 128/255, 255/255);
170+ verify(Qt.colorEqual(firstPixelColor, expectedColor), "input.image has incorrect content");
171+ }
172+
173 function test_setNullData() {
174 skip("CRASHES + QtHalideTestHelper does not have setImageData and checkImageData for now")
175 helper.setImageData(input, null);
176
177=== modified file 'tests/unit/tst_transform.qml'
178--- tests/unit/tst_transform.qml 2015-04-08 15:48:49 +0000
179+++ tests/unit/tst_transform.qml 2015-06-09 16:35:21 +0000
180@@ -61,6 +61,10 @@
181 test: test
182 }
183
184+ TestHelper {
185+ id: helper
186+ }
187+
188 ComparePixelsTestCase {
189 id: test
190 name: "TransformTest"
191@@ -155,6 +159,32 @@
192 transform.functions = "hello";
193 compare(transform.functions.count, 0, "function list is not empty after invalid set");
194 }
195+
196+ function test_schedule_update() {
197+ transform.live = false;
198+ transform.input = input;
199+ transform.functions = [red];
200+ compareAllPixelsWithColor(128, 128, 128, 255, "unexpected output present before going live");
201+
202+ transform.scheduleUpdate();
203+ spy.waitForUpdate();
204+ compareAllPixelsWithColor(255, 128, 128, 255, "filters were not applied when update requested");
205+ }
206+
207+ function test_schedule_update_request_qimage() {
208+ transform.live = false;
209+ transform.input = input;
210+ transform.functions = [red];
211+ transform.scheduleUpdate(true);
212+ spy.waitForUpdate();
213+
214+ var imageSize = helper.imageSize(transform.output.image);
215+ compare(imageSize.width, 10, "transform.output.image has incorrect width");
216+ compare(imageSize.height, 10, "transform.output.image has incorrect height");
217+ var firstPixelColor = helper.pixelColor(transform.output.image, 0, 0);
218+ var expectedColor = Qt.rgba(255/255, 128/255, 128/255, 255/255);
219+ verify(Qt.colorEqual(firstPixelColor, expectedColor), "transform.output.image has incorrect content");
220+ }
221 }
222 }
223

Subscribers

People subscribed via source and target branches

to all changes: