author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 16:40:13 +0300 | |
changeset 22 | 79de32ba3296 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qpixmap.h> |
|
45 |
#include <qbitmap.h> |
|
46 |
#include <qimage.h> |
|
47 |
#include <qmatrix.h> |
|
48 |
#include <qdesktopwidget.h> |
|
49 |
#include <qpaintengine.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
#include <qsplashscreen.h> |
0 | 51 |
|
52 |
#include <private/qpixmapdata_p.h> |
|
53 |
||
54 |
#include <QSet> |
|
55 |
||
56 |
#ifdef Q_WS_WIN |
|
57 |
#include <windows.h> |
|
58 |
#endif |
|
59 |
||
60 |
#ifdef Q_WS_QWS |
|
61 |
#include <qscreen_qws.h> |
|
62 |
#endif |
|
63 |
||
64 |
#ifdef Q_OS_SYMBIAN |
|
65 |
#include <e32std.h> |
|
66 |
#include <fbs.h> |
|
67 |
#include <gdi.h> |
|
68 |
#include <bitdev.h> |
|
69 |
#endif |
|
70 |
||
71 |
#ifdef Q_WS_X11 |
|
72 |
#include <QX11Info> |
|
73 |
#endif |
|
74 |
||
75 |
//TESTED_CLASS= |
|
76 |
//TESTED_FILES= |
|
77 |
#if defined(Q_OS_SYMBIAN) |
|
78 |
# define SRCDIR "" |
|
79 |
#endif |
|
80 |
Q_DECLARE_METATYPE(QImage::Format) |
|
81 |
||
82 |
class tst_QPixmap : public QObject |
|
83 |
{ |
|
84 |
Q_OBJECT |
|
85 |
||
86 |
public: |
|
87 |
tst_QPixmap(); |
|
88 |
virtual ~tst_QPixmap(); |
|
89 |
||
90 |
||
91 |
public slots: |
|
92 |
void init(); |
|
93 |
void cleanup(); |
|
94 |
||
95 |
private slots: |
|
96 |
void setAlphaChannel_data(); |
|
97 |
void setAlphaChannel(); |
|
98 |
||
99 |
void fromImage_data(); |
|
100 |
void fromImage(); |
|
101 |
||
102 |
void fromUninitializedImage_data(); |
|
103 |
void fromUninitializedImage(); |
|
104 |
||
105 |
void convertFromImage_data(); |
|
106 |
void convertFromImage(); |
|
107 |
||
108 |
void testMetrics(); |
|
109 |
||
110 |
void scroll_data(); |
|
111 |
void scroll(); |
|
112 |
||
113 |
void fill_data(); |
|
114 |
void fill(); |
|
115 |
void fill_transparent(); |
|
116 |
||
117 |
void createMaskFromColor(); |
|
118 |
||
119 |
void mask(); |
|
120 |
void bitmapMask(); |
|
121 |
void setGetMask_data(); |
|
122 |
void setGetMask(); |
|
123 |
void cacheKey(); |
|
124 |
void drawBitmap(); |
|
125 |
void grabWidget(); |
|
126 |
void grabWindow(); |
|
127 |
void isNull(); |
|
128 |
void task_246446(); |
|
129 |
||
130 |
#ifdef Q_WS_QWS |
|
131 |
void convertFromImageNoDetach(); |
|
132 |
#endif |
|
133 |
||
134 |
void convertFromImageDetach(); |
|
135 |
||
136 |
#if defined(Q_WS_WIN) |
|
137 |
void toWinHBITMAP_data(); |
|
138 |
void toWinHBITMAP(); |
|
139 |
void fromWinHBITMAP_data(); |
|
140 |
void fromWinHBITMAP(); |
|
141 |
||
142 |
void toWinHICON_data(); |
|
143 |
void toWinHICON(); |
|
144 |
void fromWinHICON_data(); |
|
145 |
void fromWinHICON(); |
|
146 |
#endif |
|
147 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
148 |
#if defined(Q_OS_SYMBIAN) |
0 | 149 |
void fromSymbianCFbsBitmap_data(); |
150 |
void fromSymbianCFbsBitmap(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
151 |
void toSymbianCFbsBitmap_data(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
152 |
void toSymbianCFbsBitmap(); |
0 | 153 |
#endif |
154 |
||
155 |
void onlyNullPixmapsOutsideGuiThread(); |
|
156 |
void refUnref(); |
|
157 |
||
158 |
void copy(); |
|
159 |
void depthOfNullObjects(); |
|
160 |
||
161 |
#ifdef QT3_SUPPORT |
|
162 |
void resize(); |
|
163 |
void resizePreserveMask(); |
|
164 |
#endif |
|
165 |
||
166 |
void transformed(); |
|
167 |
void transformed2(); |
|
168 |
||
169 |
void fromImage_crash(); |
|
170 |
||
171 |
void fromData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
void loadFromDataNullValues(); |
0 | 173 |
|
174 |
void preserveDepth(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
void splash_crash(); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
176 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
177 |
void loadAsBitmapOrPixmap(); |
0 | 178 |
}; |
179 |
||
180 |
static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) |
|
181 |
{ |
|
182 |
QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32); |
|
183 |
QImage actualImage = actual.toImage().convertToFormat(QImage::Format_RGB32); |
|
184 |
||
185 |
if (expectedImage.size() != actualImage.size()) |
|
186 |
return false; |
|
187 |
||
188 |
int size = actual.width() * actual.height(); |
|
189 |
||
190 |
int threshold = 2; |
|
191 |
#ifdef Q_WS_X11 |
|
192 |
if (QX11Info::appDepth() == 16) |
|
193 |
threshold = 10; |
|
194 |
#endif |
|
195 |
||
196 |
QRgb *a = (QRgb *)actualImage.bits(); |
|
197 |
QRgb *e = (QRgb *)expectedImage.bits(); |
|
198 |
for (int i = 0; i < size; ++i) { |
|
199 |
QColor ca(a[i]); |
|
200 |
QColor ce(e[i]); |
|
201 |
||
202 |
bool result = true; |
|
203 |
||
204 |
if (qAbs(ca.red() - ce.red()) > threshold) |
|
205 |
result = false; |
|
206 |
if (qAbs(ca.green() - ce.green()) > threshold) |
|
207 |
result = false; |
|
208 |
if (qAbs(ca.blue() - ce.blue()) > threshold) |
|
209 |
result = false; |
|
210 |
||
211 |
if (!result) |
|
212 |
return false; |
|
213 |
} |
|
214 |
||
215 |
return true; |
|
216 |
} |
|
217 |
||
218 |
Q_DECLARE_METATYPE(QImage) |
|
219 |
Q_DECLARE_METATYPE(QPixmap) |
|
220 |
Q_DECLARE_METATYPE(QMatrix) |
|
221 |
Q_DECLARE_METATYPE(QBitmap) |
|
222 |
||
223 |
tst_QPixmap::tst_QPixmap() |
|
224 |
{ |
|
225 |
} |
|
226 |
||
227 |
tst_QPixmap::~tst_QPixmap() |
|
228 |
{ |
|
229 |
} |
|
230 |
||
231 |
void tst_QPixmap::init() |
|
232 |
{ |
|
233 |
} |
|
234 |
||
235 |
void tst_QPixmap::cleanup() |
|
236 |
{ |
|
237 |
} |
|
238 |
||
239 |
void tst_QPixmap::setAlphaChannel_data() |
|
240 |
{ |
|
241 |
QTest::addColumn<int>("red"); |
|
242 |
QTest::addColumn<int>("green"); |
|
243 |
QTest::addColumn<int>("blue"); |
|
244 |
QTest::addColumn<int>("alpha"); |
|
245 |
||
246 |
QTest::newRow("red 0") << 255 << 0 << 0 << 0; |
|
247 |
QTest::newRow("red 24") << 255 << 0 << 0 << 24; |
|
248 |
QTest::newRow("red 124") << 255 << 0 << 0 << 124; |
|
249 |
QTest::newRow("red 255") << 255 << 0 << 0 << 255; |
|
250 |
||
251 |
QTest::newRow("green 0") << 0 << 255 << 0 << 0; |
|
252 |
QTest::newRow("green 24") << 0 << 255 << 0 << 24; |
|
253 |
QTest::newRow("green 124") << 0 << 255 << 0 << 124; |
|
254 |
QTest::newRow("green 255") << 0 << 255 << 0 << 255; |
|
255 |
||
256 |
QTest::newRow("blue 0") << 0 << 0 << 255 << 0; |
|
257 |
QTest::newRow("blue 24") << 0 << 0 << 255 << 24; |
|
258 |
QTest::newRow("blue 124") << 0 << 0 << 255 << 124; |
|
259 |
QTest::newRow("blue 255") << 0 << 0 << 255 << 255; |
|
260 |
} |
|
261 |
||
262 |
void tst_QPixmap::setAlphaChannel() |
|
263 |
{ |
|
264 |
QFETCH(int, red); |
|
265 |
QFETCH(int, green); |
|
266 |
QFETCH(int, blue); |
|
267 |
QFETCH(int, alpha); |
|
268 |
||
269 |
int width = 100; |
|
270 |
int height = 100; |
|
271 |
||
272 |
QPixmap pixmap(width, height); |
|
273 |
pixmap.fill(QColor(red, green, blue)); |
|
274 |
||
275 |
QPixmap alphaChannel(width, height); |
|
276 |
alphaChannel.fill(QColor(alpha, alpha, alpha)); |
|
277 |
pixmap.setAlphaChannel(alphaChannel); |
|
278 |
||
279 |
#ifdef Q_WS_X11 |
|
280 |
if (pixmap.pixmapData()->classId() == QPixmapData::X11Class && !pixmap.x11PictureHandle()) |
|
281 |
QSKIP("Requires XRender support", SkipAll); |
|
282 |
#endif |
|
283 |
||
284 |
QImage result; |
|
285 |
bool ok = true; |
|
286 |
||
287 |
QPixmap outAlpha = pixmap.alphaChannel(); |
|
288 |
QCOMPARE(outAlpha.size(), pixmap.size()); |
|
289 |
||
290 |
result = outAlpha.toImage().convertToFormat(QImage::Format_ARGB32);; |
|
291 |
for (int y = 0; y < height; ++y) { |
|
292 |
for (int x = 0; x < width; ++x) { |
|
293 |
ok &= qGray(result.pixel(x, y)) == alpha; |
|
294 |
} |
|
295 |
} |
|
296 |
QVERIFY(ok); |
|
297 |
||
298 |
result = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
|
299 |
QRgb expected = alpha == 0 ? 0 : qRgba(red, green, blue, alpha); |
|
300 |
for (int y = 0; y < height; ++y) { |
|
301 |
for (int x = 0; x < width; ++x) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
if (result.colorCount() > 0) { |
0 | 303 |
ok &= result.pixelIndex(x, y) == expected; |
304 |
} else { |
|
305 |
ok &= result.pixel(x, y) == expected; |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
QVERIFY(ok); |
|
310 |
} |
|
311 |
||
312 |
void tst_QPixmap::fromImage_data() |
|
313 |
{ |
|
314 |
bool is16bit = false; |
|
315 |
#ifdef Q_WS_X11 |
|
316 |
if (QX11Info::appDepth() == 16) |
|
317 |
is16bit = true; |
|
318 |
#endif |
|
319 |
||
320 |
QTest::addColumn<QImage::Format>("format"); |
|
321 |
||
322 |
QTest::newRow("Format_Mono") << QImage::Format_Mono; |
|
323 |
QTest::newRow("Format_MonoLSB") << QImage::Format_MonoLSB; |
|
324 |
// QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8; |
|
325 |
if (!is16bit) |
|
326 |
QTest::newRow("Format_RGB32") << QImage::Format_RGB32; |
|
327 |
QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32; |
|
328 |
QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; |
|
329 |
if (!is16bit) |
|
330 |
QTest::newRow("Format_RGB16") << QImage::Format_RGB16; |
|
331 |
} |
|
332 |
||
333 |
void tst_QPixmap::fromImage() |
|
334 |
{ |
|
335 |
QFETCH(QImage::Format, format); |
|
336 |
||
337 |
QImage image(37, 16, format); |
|
338 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
if (image.colorCount() == 2) { |
0 | 340 |
image.setColor(0, QColor(Qt::color0).rgba()); |
341 |
image.setColor(1, QColor(Qt::color1).rgba()); |
|
342 |
} |
|
343 |
image.fill(0x7f7f7f7f); |
|
344 |
||
345 |
const QPixmap pixmap = QPixmap::fromImage(image); |
|
346 |
#ifdef Q_WS_X11 |
|
347 |
if (pixmap.pixmapData()->classId() == QPixmapData::X11Class && !pixmap.x11PictureHandle()) |
|
348 |
QSKIP("Requires XRender support", SkipAll); |
|
349 |
#endif |
|
350 |
const QImage result = pixmap.toImage(); |
|
351 |
image = image.convertToFormat(result.format()); |
|
352 |
QCOMPARE(result, image); |
|
353 |
} |
|
354 |
||
355 |
||
356 |
void tst_QPixmap::fromUninitializedImage_data() |
|
357 |
{ |
|
358 |
QTest::addColumn<QImage::Format>("format"); |
|
359 |
||
360 |
QTest::newRow("Format_Mono") << QImage::Format_Mono; |
|
361 |
QTest::newRow("Format_MonoLSB") << QImage::Format_MonoLSB; |
|
362 |
QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8; |
|
363 |
QTest::newRow("Format_RGB32") << QImage::Format_RGB32; |
|
364 |
QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32; |
|
365 |
QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; |
|
366 |
QTest::newRow("Format_RGB16") << QImage::Format_RGB16; |
|
367 |
} |
|
368 |
||
369 |
void tst_QPixmap::fromUninitializedImage() |
|
370 |
{ |
|
371 |
QFETCH(QImage::Format, format); |
|
372 |
||
373 |
QImage image(100, 100, format); |
|
374 |
QPixmap pix = QPixmap::fromImage(image); |
|
375 |
||
376 |
// it simply shouldn't crash... |
|
377 |
QVERIFY(true); |
|
378 |
||
379 |
} |
|
380 |
||
381 |
void tst_QPixmap::convertFromImage_data() |
|
382 |
{ |
|
383 |
QTest::addColumn<QImage>("img1"); |
|
384 |
QTest::addColumn<QImage>("img2"); |
|
385 |
#ifdef Q_OS_SYMBIAN |
|
386 |
const QString prefix = QLatin1String(SRCDIR) + "convertFromImage"; |
|
387 |
#else |
|
388 |
const QString prefix = QLatin1String(SRCDIR) + "/convertFromImage"; |
|
389 |
#endif |
|
390 |
{ |
|
391 |
QImage img1; |
|
392 |
QImage img2; |
|
393 |
QVERIFY(img1.load(prefix + "/task31722_0/img1.png")); |
|
394 |
QVERIFY(img2.load(prefix + "/task31722_0/img2.png")); |
|
395 |
QVERIFY(img1.load(prefix + "/task31722_0/img1.png")); |
|
396 |
QVERIFY(img2.load(prefix + "/task31722_0/img2.png")); |
|
397 |
QTest::newRow("Task 31722 0") << img1 << img2; |
|
398 |
} |
|
399 |
{ |
|
400 |
QImage img1; |
|
401 |
QImage img2; |
|
402 |
QVERIFY(img1.load(prefix + "/task31722_1/img1.png")); |
|
403 |
QVERIFY(img2.load(prefix + "/task31722_1/img2.png")); |
|
404 |
QTest::newRow("Task 31722 1") << img1 << img2; |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
void tst_QPixmap::convertFromImage() |
|
409 |
{ |
|
410 |
QFETCH(QImage, img1); |
|
411 |
QFETCH(QImage, img2); |
|
412 |
||
413 |
QPixmap pix = QPixmap::fromImage(img1); |
|
414 |
pix = QPixmap::fromImage(img2); |
|
415 |
||
416 |
QPixmap res = QPixmap::fromImage(img2); |
|
417 |
QVERIFY( pixmapsAreEqual(&pix, &res) ); |
|
418 |
} |
|
419 |
||
420 |
void tst_QPixmap::scroll_data() |
|
421 |
{ |
|
422 |
QTest::addColumn<QImage>("input"); |
|
423 |
QTest::addColumn<int>("dx"); |
|
424 |
QTest::addColumn<int>("dy"); |
|
425 |
QTest::addColumn<QRect>("rect"); |
|
426 |
QTest::addColumn<QRegion>("exposed"); |
|
427 |
QTest::addColumn<bool>("newPix"); |
|
428 |
||
429 |
QImage input(":/images/designer.png"); |
|
430 |
||
431 |
// Noop tests |
|
432 |
QTest::newRow("null") << QImage() << 0 << 0 << QRect() << QRegion() << false; |
|
433 |
QTest::newRow("dx_0_dy_0_null") << input << 0 << 0 << QRect() << QRegion() << false; |
|
434 |
QTest::newRow("dx_1_dy_0_null") << input << 1 << 0 << QRect() << QRegion() << false; |
|
435 |
QTest::newRow("dx_0_dy_1_null") << input << 0 << 1 << QRect() << QRegion() << false; |
|
436 |
QTest::newRow("dx_0_dy_0_x_y_w_h") << input << 0 << 0 << input.rect() << QRegion() << false; |
|
437 |
||
438 |
QRegion r; |
|
439 |
// Scroll whole pixmap |
|
440 |
r = QRegion(); r += QRect(0, 0, 128, 10); |
|
441 |
QTest::newRow("dx_0_dy_10_x_y_w_h") << input << 0 << 10 << input.rect() << r << true; |
|
442 |
r = QRegion(); r += QRect(0, 0, 10, 128); |
|
443 |
QTest::newRow("dx_10_dy_0_x_y_w_h") << input << 10 << 0 << input.rect() << r << true; |
|
444 |
r = QRegion(); r += QRect(0, 0, 128, 10); r += QRect(0, 10, 10, 118); |
|
445 |
QTest::newRow("dx_10_dy_10_x_y_w_h") << input << 10 << 10 << input.rect() << r << true; |
|
446 |
r = QRegion(); r += QRect(118, 0, 10, 128); |
|
447 |
QTest::newRow("dx_-10_dy_0_x_y_w_h") << input << -10 << 0 << input.rect() << r << true; |
|
448 |
r = QRegion(); r += QRect(0, 118, 128, 10); |
|
449 |
QTest::newRow("dx_0_dy_-10_x_y_w_h") << input << 0 << -10 << input.rect() << r << true; |
|
450 |
r = QRegion(); r += QRect(118, 0, 10, 118); r += QRect(0, 118, 128, 10); |
|
451 |
QTest::newRow("dx_-10_dy_-10_x_y_w_h") << input << -10 << -10 << input.rect() << r << true; |
|
452 |
||
453 |
// Scroll part of pixmap |
|
454 |
QTest::newRow("dx_0_dy_0_50_50_100_100") << input << 0 << 0 << QRect(50, 50, 100, 100) << QRegion() << false; |
|
455 |
r = QRegion(); r += QRect(50, 50, 10, 78); |
|
456 |
QTest::newRow("dx_10_dy_0_50_50_100_100") << input << 10 << 0 << QRect(50, 50, 100, 100) << r << true; |
|
457 |
r = QRegion(); r += QRect(50, 50, 78, 10); |
|
458 |
QTest::newRow("dx_0_dy_10_50_50_100_100") << input << 0 << 10 << QRect(50, 50, 100, 100) << r << true; |
|
459 |
r = QRegion(); r += QRect(50, 50, 78, 10); r += QRect(50, 60, 10, 68); |
|
460 |
QTest::newRow("dx_10_dy_10_50_50_100_100") << input << 10 << 10 << QRect(50, 50, 100, 100) << r << true; |
|
461 |
r = QRegion(); r += QRect(118, 50, 10, 78); |
|
462 |
QTest::newRow("dx_-10_dy_0_50_50_100_100") << input << -10 << 0 << QRect(50, 50, 100, 100) << r << true; |
|
463 |
r = QRegion(); r += QRect(50, 118, 78, 10); |
|
464 |
QTest::newRow("dx_0_dy_-10_50_50_100_100") << input << 0 << -10 << QRect(50, 50, 100, 100) << r << true; |
|
465 |
r = QRegion(); r += QRect(118, 50, 10, 68); r += QRect(50, 118, 78, 10); |
|
466 |
QTest::newRow("dx_-10_dy_-10_50_50_100_100") << input << -10 << -10 << QRect(50, 50, 100, 100) << r << true; |
|
467 |
||
468 |
// Scroll away the whole pixmap |
|
469 |
r = input.rect(); |
|
470 |
QTest::newRow("dx_128_dy_0_x_y_w_h") << input << 128 << 0 << input.rect() << r << false; |
|
471 |
QTest::newRow("dx_0_dy_128_x_y_w_h") << input << 0 << 128 << input.rect() << r << false; |
|
472 |
QTest::newRow("dx_128_dy_128_x_y_w_h") << input << 128 << 128 << input.rect() << r << false; |
|
473 |
QTest::newRow("dx_-128_dy_0_x_y_w_h") << input << -128 << 0 << input.rect() << r << false; |
|
474 |
QTest::newRow("dx_0_dy_-128_x_y_w_h") << input << 0 << -128 << input.rect() << r << false; |
|
475 |
QTest::newRow("dx_-128_dy_-128_x_y_w_h") << input << -128 << -128 << input.rect() << r << false; |
|
476 |
||
477 |
// Scroll away part of the pixmap |
|
478 |
r = QRegion(); r += QRect(64, 64, 64, 64); |
|
479 |
QTest::newRow("dx_128_dy_128_64_64_128_128") << input << 128 << 128 << QRect(64, 64, 128, 128) << r << false; |
|
480 |
} |
|
481 |
||
482 |
void tst_QPixmap::scroll() |
|
483 |
{ |
|
484 |
QFETCH(QImage, input); |
|
485 |
QFETCH(int, dx); |
|
486 |
QFETCH(int, dy); |
|
487 |
QFETCH(QRect, rect); |
|
488 |
QFETCH(QRegion, exposed); |
|
489 |
QFETCH(bool, newPix); |
|
490 |
||
491 |
QPixmap pixmap = QPixmap::fromImage(input); |
|
492 |
QRegion exp; |
|
493 |
qint64 oldKey = pixmap.cacheKey(); |
|
494 |
pixmap.scroll(dx, dy, rect, &exp); |
|
495 |
if (!newPix) |
|
496 |
QCOMPARE(pixmap.cacheKey(), oldKey); |
|
497 |
else |
|
498 |
QVERIFY(pixmap.cacheKey() != oldKey); |
|
499 |
||
500 |
#if 0 |
|
501 |
// Remember to add to resources. |
|
502 |
QString fileName = QString("images/%1.png").arg(QTest::currentDataTag()); |
|
503 |
pixmap.toImage().save(fileName); |
|
504 |
#else |
|
505 |
QString fileName = QString(":/images/%1.png").arg(QTest::currentDataTag()); |
|
506 |
#endif |
|
507 |
QPixmap output(fileName); |
|
508 |
QVERIFY(input.isNull() == output.isNull()); |
|
509 |
QVERIFY(lenientCompare(pixmap, output)); |
|
510 |
QCOMPARE(exp, exposed); |
|
511 |
} |
|
512 |
||
513 |
void tst_QPixmap::fill_data() |
|
514 |
{ |
|
515 |
QTest::addColumn<uint>("pixel"); |
|
516 |
QTest::addColumn<bool>("syscolor"); |
|
517 |
QTest::addColumn<bool>("bitmap"); |
|
518 |
for (int color = Qt::black; color < Qt::darkYellow; ++color) |
|
519 |
QTest::newRow(QString("syscolor_%1").arg(color).toLatin1()) |
|
520 |
<< uint(color) << true << false; |
|
521 |
||
522 |
#ifdef Q_WS_QWS |
|
523 |
if (QScreen::instance()->depth() >= 24) { |
|
524 |
#elif defined (Q_WS_X11) |
|
525 |
QPixmap pm(1, 1); |
|
526 |
if (pm.x11PictureHandle()) { |
|
527 |
#elif defined (Q_OS_WINCE) |
|
528 |
QPixmap pixmap(1,1); |
|
529 |
if (QPixmap::grabWidget(QApplication::desktop()).depth() >= 24) { |
|
530 |
#else |
|
531 |
QPixmap pixmap(1, 1); { |
|
532 |
#endif |
|
533 |
QTest::newRow("alpha_7f_red") << 0x7fff0000u << false << false; |
|
534 |
QTest::newRow("alpha_3f_blue") << 0x3f0000ffu << false << false; |
|
535 |
QTest::newRow("alpha_b7_green") << 0xbf00ff00u << false << false; |
|
536 |
QTest::newRow("alpha_7f_white") << 0x7fffffffu << false << false; |
|
537 |
QTest::newRow("alpha_3f_white") << 0x3fffffffu << false << false; |
|
538 |
QTest::newRow("alpha_b7_white") << 0xb7ffffffu << false << false; |
|
539 |
QTest::newRow("alpha_7f_black") << 0x7f000000u << false << false; |
|
540 |
QTest::newRow("alpha_3f_black") << 0x3f000000u << false << false; |
|
541 |
QTest::newRow("alpha_b7_black") << 0xbf000000u << false << false; |
|
542 |
} |
|
543 |
||
544 |
QTest::newRow("bitmap_color0") << uint(Qt::color0) << true << true; |
|
545 |
QTest::newRow("bitmap_color1") << uint(Qt::color1) << true << true; |
|
546 |
} |
|
547 |
||
548 |
void tst_QPixmap::fill() |
|
549 |
{ |
|
550 |
QFETCH(uint, pixel); |
|
551 |
QFETCH(bool, syscolor); |
|
552 |
QFETCH(bool, bitmap); |
|
553 |
||
554 |
QColor color; |
|
555 |
||
556 |
if (syscolor) |
|
557 |
color = QColor(Qt::GlobalColor(pixel)); |
|
558 |
else |
|
559 |
color = QColor(qRed(pixel), qGreen(pixel), qBlue(pixel), qAlpha(pixel)); |
|
560 |
||
561 |
QColor compareColor = color; |
|
562 |
if (bitmap && syscolor) { |
|
563 |
// special case color0 and color1 for bitmaps. |
|
564 |
if (pixel == Qt::color0) |
|
565 |
compareColor.setRgb(255, 255, 255); |
|
566 |
else |
|
567 |
compareColor.setRgb(0, 0, 0); |
|
568 |
} |
|
569 |
||
570 |
QPixmap pm; |
|
571 |
||
572 |
if (bitmap) |
|
573 |
pm = QBitmap(400, 400); |
|
574 |
else |
|
575 |
pm = QPixmap(400, 400); |
|
576 |
||
577 |
#if defined(Q_WS_X11) |
|
578 |
if (!bitmap && pm.pixmapData()->classId() == QPixmapData::X11Class && !pm.x11PictureHandle()) |
|
579 |
QSKIP("Requires XRender support", SkipSingle); |
|
580 |
#endif |
|
581 |
||
582 |
pm.fill(color); |
|
583 |
if (syscolor && !bitmap && pm.depth() < 24) { |
|
584 |
QSKIP("Test does not work on displays without true color", SkipSingle); |
|
585 |
} |
|
586 |
||
587 |
QImage image = pm.toImage(); |
|
588 |
if (bitmap && syscolor) { |
|
589 |
int pixelindex = (pixel == Qt::color0) ? 0 : 1; |
|
590 |
QCOMPARE(image.pixelIndex(0,0), pixelindex); |
|
591 |
} |
|
592 |
QImage::Format format = compareColor.alpha() != 255 |
|
593 |
? QImage::Format_ARGB32 |
|
594 |
: QImage::Format_RGB32; |
|
595 |
image = image.convertToFormat(format); |
|
596 |
||
597 |
||
598 |
QImage shouldBe(400, 400, format); |
|
599 |
shouldBe.fill(compareColor.rgba()); |
|
600 |
||
601 |
QCOMPARE(image, shouldBe); |
|
602 |
} |
|
603 |
||
604 |
void tst_QPixmap::fill_transparent() |
|
605 |
{ |
|
606 |
QPixmap pixmap(10, 10); |
|
607 |
#ifdef Q_WS_X11 |
|
608 |
if (pixmap.pixmapData()->classId() == QPixmapData::X11Class && !pixmap.x11PictureHandle()) |
|
609 |
QSKIP("Requires XRender support", SkipAll); |
|
610 |
#endif |
|
611 |
pixmap.fill(Qt::transparent); |
|
612 |
QVERIFY(pixmap.hasAlphaChannel()); |
|
613 |
} |
|
614 |
||
615 |
void tst_QPixmap::mask() |
|
616 |
{ |
|
617 |
QPixmap pm(100, 100); |
|
618 |
QBitmap bm(100, 100); |
|
619 |
||
620 |
pm.fill(); |
|
621 |
bm.fill(); |
|
622 |
||
623 |
QVERIFY(!pm.isNull()); |
|
624 |
QVERIFY(!bm.isNull()); |
|
625 |
// hw: todo: this will fail if the default pixmap format is |
|
626 |
// argb32_premultiplied. The mask will be all 1's |
|
627 |
QVERIFY(pm.mask().isNull()); |
|
628 |
||
629 |
QImage img = bm.toImage(); |
|
630 |
QVERIFY(img.format() == QImage::Format_MonoLSB |
|
631 |
|| img.format() == QImage::Format_Mono); |
|
632 |
||
633 |
pm.setMask(bm); |
|
634 |
QVERIFY(!pm.mask().isNull()); |
|
635 |
||
636 |
bm = QBitmap(); |
|
637 |
// Invalid format here, since isNull() == true |
|
638 |
QVERIFY(bm.toImage().isNull()); |
|
639 |
QCOMPARE(bm.toImage().format(), QImage::Format_Invalid); |
|
640 |
pm.setMask(bm); |
|
641 |
QVERIFY(pm.mask().isNull()); |
|
642 |
||
643 |
bm = QBitmap(100, 100); |
|
644 |
bm.fill(); |
|
645 |
pm.setMask(bm); |
|
646 |
QVERIFY(!pm.mask().isNull()); |
|
647 |
} |
|
648 |
||
649 |
void tst_QPixmap::bitmapMask() |
|
650 |
{ |
|
651 |
QImage image(3, 3, QImage::Format_Mono); |
|
652 |
image.setColor(0, Qt::color0); |
|
653 |
image.setColor(1, Qt::color1); |
|
654 |
image.fill(Qt::color0); |
|
655 |
image.setPixel(1, 1, Qt::color1); |
|
656 |
image.setPixel(0, 0, Qt::color1); |
|
657 |
||
658 |
QImage image_mask(3, 3, QImage::Format_Mono); |
|
659 |
image_mask.setColor(0, Qt::color0); |
|
660 |
image_mask.setColor(1, Qt::color1); |
|
661 |
image_mask.fill(Qt::color0); |
|
662 |
image_mask.setPixel(1, 1, Qt::color1); |
|
663 |
image_mask.setPixel(2, 0, Qt::color1); |
|
664 |
||
665 |
QBitmap pm = QBitmap::fromImage(image); |
|
666 |
QBitmap pm_mask = QBitmap::fromImage(image_mask); |
|
667 |
pm.setMask(pm_mask); |
|
668 |
||
669 |
image = pm.toImage(); |
|
670 |
image.setColor(0, Qt::color0); |
|
671 |
image.setColor(1, Qt::color1); |
|
672 |
image_mask = pm_mask.toImage(); |
|
673 |
image_mask.setColor(0, Qt::color0); |
|
674 |
image_mask.setColor(1, Qt::color1); |
|
675 |
||
676 |
QVERIFY(!image.pixel(0, 0)); |
|
677 |
QVERIFY(!image.pixel(2, 0)); |
|
678 |
QVERIFY(image.pixel(1, 1)); |
|
679 |
} |
|
680 |
||
681 |
void tst_QPixmap::setGetMask_data() |
|
682 |
{ |
|
683 |
QTest::addColumn<QPixmap>("pixmap"); |
|
684 |
QTest::addColumn<QBitmap>("mask"); |
|
685 |
QTest::addColumn<QBitmap>("expected"); |
|
686 |
||
687 |
QPixmap pixmap(10, 10); |
|
688 |
QBitmap mask(10, 10); |
|
689 |
QPainter p; |
|
690 |
||
691 |
p.begin(&pixmap); |
|
692 |
p.fillRect(0, 0, 10, 10, QColor(Qt::black)); |
|
693 |
p.end(); |
|
694 |
||
695 |
QTest::newRow("nullmask 0") << QPixmap() << QBitmap() << QBitmap(); |
|
696 |
QTest::newRow("nullmask 1") << pixmap << QBitmap() << QBitmap(); |
|
697 |
mask.clear(); |
|
698 |
QTest::newRow("nullmask 2") << pixmap << mask << mask; |
|
699 |
QTest::newRow("nullmask 3") << QPixmap(QBitmap()) << QBitmap() << QBitmap(); |
|
700 |
||
701 |
p.begin(&mask); |
|
702 |
p.fillRect(1, 1, 5, 5, QColor(Qt::color1)); |
|
703 |
p.end(); |
|
704 |
QTest::newRow("simple mask 0") << pixmap << mask << mask; |
|
705 |
} |
|
706 |
||
707 |
void tst_QPixmap::setGetMask() |
|
708 |
{ |
|
709 |
QFETCH(QPixmap, pixmap); |
|
710 |
QFETCH(QBitmap, mask); |
|
711 |
QFETCH(QBitmap, expected); |
|
712 |
||
713 |
pixmap.setMask(mask); |
|
714 |
QBitmap result = pixmap.mask(); |
|
715 |
||
716 |
QImage resultImage = result.toImage(); |
|
717 |
QImage expectedImage = expected.toImage(); |
|
718 |
QCOMPARE(resultImage.convertToFormat(expectedImage.format()), |
|
719 |
expectedImage); |
|
720 |
} |
|
721 |
||
722 |
void tst_QPixmap::testMetrics() |
|
723 |
{ |
|
724 |
QPixmap pixmap(100, 100); |
|
725 |
||
726 |
QCOMPARE(pixmap.width(), 100); |
|
727 |
QCOMPARE(pixmap.height(), 100); |
|
728 |
QVERIFY(pixmap.depth() >= QPixmap::defaultDepth()); |
|
729 |
||
730 |
QBitmap bitmap(100, 100); |
|
731 |
||
732 |
QCOMPARE(bitmap.width(), 100); |
|
733 |
QCOMPARE(bitmap.height(), 100); |
|
734 |
QCOMPARE(bitmap.depth(), 1); |
|
735 |
} |
|
736 |
||
737 |
void tst_QPixmap::createMaskFromColor() |
|
738 |
{ |
|
739 |
QImage image(3, 3, QImage::Format_Indexed8); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
image.setColorCount(10); |
0 | 741 |
image.setColor(0, 0xffffffff); |
742 |
image.setColor(1, 0xff000000); |
|
743 |
image.setColor(2, 0xffff0000); |
|
744 |
image.setColor(3, 0xff0000ff); |
|
745 |
image.fill(0); |
|
746 |
image.setPixel(1, 0, 1); |
|
747 |
image.setPixel(0, 1, 2); |
|
748 |
image.setPixel(1, 1, 3); |
|
749 |
||
750 |
QImage im_mask = image.createMaskFromColor(0xffff0000); |
|
751 |
QCOMPARE((uint) im_mask.pixel(0, 1), QColor(Qt::color0).rgba()); |
|
752 |
QCOMPARE((uint) im_mask.pixel(0, 1), QColor(Qt::color0).rgba()); |
|
753 |
||
754 |
QPixmap pixmap = QPixmap::fromImage(image); |
|
755 |
QBitmap mask = pixmap.createMaskFromColor(Qt::red); |
|
756 |
QBitmap inv_mask = pixmap.createMaskFromColor(Qt::red, Qt::MaskOutColor); |
|
757 |
QCOMPARE((uint) mask.toImage().pixel(0, 1), QColor(Qt::color0).rgba()); |
|
758 |
QCOMPARE((uint) inv_mask.toImage().pixel(0, 1), QColor(Qt::color1).rgba()); |
|
759 |
} |
|
760 |
||
761 |
||
762 |
void tst_QPixmap::cacheKey() |
|
763 |
{ |
|
764 |
QPixmap pixmap1(1, 1); |
|
765 |
QPixmap pixmap2(1, 1); |
|
766 |
qint64 pixmap1_key = pixmap1.cacheKey(); |
|
767 |
||
768 |
QVERIFY(pixmap1.cacheKey() != pixmap2.cacheKey()); |
|
769 |
||
770 |
pixmap2 = pixmap1; |
|
771 |
QVERIFY(pixmap2.cacheKey() == pixmap1.cacheKey()); |
|
772 |
||
773 |
pixmap2.detach(); |
|
774 |
QVERIFY(pixmap2.cacheKey() != pixmap1.cacheKey()); |
|
775 |
QVERIFY(pixmap1.cacheKey() == pixmap1_key); |
|
776 |
} |
|
777 |
||
778 |
// Test drawing a bitmap on a pixmap. |
|
779 |
void tst_QPixmap::drawBitmap() |
|
780 |
{ |
|
781 |
QBitmap bitmap(10,10); |
|
782 |
bitmap.fill(Qt::color1); |
|
783 |
||
784 |
QPixmap pixmap(10,10); |
|
785 |
QPainter painter2(&pixmap); |
|
786 |
painter2.fillRect(0,0,10,10, QBrush(Qt::green)); |
|
787 |
painter2.setPen(Qt::red); |
|
788 |
painter2.drawPixmap(0,0,10,10, bitmap); |
|
789 |
painter2.end(); |
|
790 |
||
791 |
QPixmap expected(10, 10); |
|
792 |
expected.fill(Qt::red); |
|
793 |
||
794 |
QVERIFY(lenientCompare(pixmap, expected)); |
|
795 |
} |
|
796 |
||
797 |
void tst_QPixmap::grabWidget() |
|
798 |
{ |
|
799 |
QWidget widget; |
|
800 |
widget.setPalette(Qt::green); |
|
801 |
widget.resize(128, 128); |
|
802 |
||
803 |
QPixmap expected(64, 64); |
|
804 |
expected.fill(Qt::green); |
|
805 |
||
806 |
QPixmap actual = QPixmap::grabWidget(&widget, QRect(64, 64, 64, 64)); |
|
807 |
QVERIFY(lenientCompare(actual, expected)); |
|
808 |
} |
|
809 |
||
810 |
void tst_QPixmap::grabWindow() |
|
811 |
{ |
|
812 |
#ifdef Q_OS_WINCE |
|
813 |
// We get out of memory, if the desktop itself is too big. |
|
814 |
if (QApplication::desktop()->width() <= 480) |
|
815 |
#endif |
|
816 |
QVERIFY(QPixmap::grabWindow(QApplication::desktop()->winId()).isNull() == false); |
|
817 |
QWidget w; |
|
818 |
w.resize(640, 480); |
|
819 |
w.show(); |
|
820 |
QTest::qWait(100); |
|
821 |
#ifdef Q_WS_X11 |
|
822 |
qt_x11_wait_for_window_manager(&w); |
|
823 |
#endif |
|
824 |
QVERIFY(QPixmap::grabWindow(w.winId()).isNull() == false); |
|
825 |
||
826 |
QWidget child(&w); |
|
827 |
child.setGeometry(50, 50, 100, 100); |
|
828 |
child.setPalette(Qt::red); |
|
829 |
child.setAutoFillBackground(true); |
|
830 |
child.show(); |
|
831 |
QTest::qWait(100); |
|
832 |
#ifdef Q_WS_X11 |
|
833 |
qt_x11_wait_for_window_manager(&child); |
|
834 |
#endif |
|
835 |
||
836 |
QPixmap grabWindowPixmap = QPixmap::grabWindow(child.winId()); |
|
837 |
QPixmap grabWidgetPixmap = QPixmap::grabWidget(&child); |
|
838 |
lenientCompare(grabWindowPixmap, grabWidgetPixmap); |
|
839 |
} |
|
840 |
||
841 |
void tst_QPixmap::isNull() |
|
842 |
{ |
|
843 |
{ |
|
844 |
QPixmap pixmap(1,1); |
|
845 |
QVERIFY(pixmap.isNull() == false); |
|
846 |
} |
|
847 |
{ |
|
848 |
QPixmap pixmap(0,0); |
|
849 |
QVERIFY(pixmap.isNull()); |
|
850 |
} |
|
851 |
||
852 |
{ |
|
853 |
QPixmap pixmap(0,1); |
|
854 |
QVERIFY(pixmap.isNull()); |
|
855 |
} |
|
856 |
{ |
|
857 |
QPixmap pixmap(1,0); |
|
858 |
QVERIFY(pixmap.isNull()); |
|
859 |
} |
|
860 |
{ |
|
861 |
QPixmap pixmap(-1,-1); |
|
862 |
QVERIFY(pixmap.isNull()); |
|
863 |
} |
|
864 |
{ |
|
865 |
QPixmap pixmap(-1,5); |
|
866 |
QVERIFY(pixmap.isNull()); |
|
867 |
} |
|
868 |
} |
|
869 |
||
870 |
#ifdef Q_WS_QWS |
|
871 |
void tst_QPixmap::convertFromImageNoDetach() |
|
872 |
{ |
|
873 |
//first get the screen format |
|
874 |
QPixmap randomPixmap(10,10); |
|
875 |
QImage::Format screenFormat = randomPixmap.toImage().format(); |
|
876 |
QVERIFY(screenFormat != QImage::Format_Invalid); |
|
877 |
||
878 |
QImage orig(100,100, screenFormat); |
|
879 |
||
880 |
QPixmap pix = QPixmap::fromImage(orig); |
|
881 |
QImage copy = pix.toImage(); |
|
882 |
||
883 |
QVERIFY(copy.format() == screenFormat); |
|
884 |
||
885 |
const QImage constOrig = orig; |
|
886 |
const QImage constCopy = copy; |
|
887 |
QVERIFY(constOrig.bits() == constCopy.bits()); |
|
888 |
} |
|
889 |
#endif //Q_WS_QWS |
|
890 |
||
891 |
void tst_QPixmap::convertFromImageDetach() |
|
892 |
{ |
|
893 |
QImage img(10,10, QImage::Format_RGB32); |
|
894 |
img.fill(0); |
|
895 |
QVERIFY(!img.isNull()); |
|
896 |
QPixmap p = QPixmap::fromImage(img); |
|
897 |
QVERIFY(p.isDetached()); |
|
898 |
QPixmap copy = p; |
|
899 |
QVERIFY(!copy.isDetached()); |
|
900 |
QVERIFY(!p.isDetached()); |
|
901 |
img.fill(1); |
|
902 |
p = QPixmap::fromImage(img); |
|
903 |
QVERIFY(copy.isDetached()); |
|
904 |
} |
|
905 |
||
906 |
#if defined(Q_WS_WIN) |
|
907 |
void tst_QPixmap::toWinHBITMAP_data() |
|
908 |
{ |
|
909 |
QTest::addColumn<int>("red"); |
|
910 |
QTest::addColumn<int>("green"); |
|
911 |
QTest::addColumn<int>("blue"); |
|
912 |
||
913 |
QTest::newRow("red") << 255 << 0 << 0; |
|
914 |
QTest::newRow("green") << 0 << 255 << 0; |
|
915 |
QTest::newRow("blue") << 0 << 0 << 255; |
|
916 |
} |
|
917 |
||
918 |
void tst_QPixmap::toWinHBITMAP() |
|
919 |
{ |
|
920 |
QFETCH(int, red); |
|
921 |
QFETCH(int, green); |
|
922 |
QFETCH(int, blue); |
|
923 |
||
924 |
QPixmap pm(100, 100); |
|
925 |
pm.fill(QColor(red, green, blue)); |
|
926 |
||
927 |
HBITMAP bitmap = pm.toWinHBITMAP(); |
|
928 |
||
929 |
QVERIFY(bitmap != 0); |
|
930 |
||
931 |
// Verify size |
|
932 |
BITMAP bitmap_info; |
|
933 |
memset(&bitmap_info, 0, sizeof(BITMAP)); |
|
934 |
||
935 |
int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info); |
|
936 |
QVERIFY(res); |
|
937 |
||
938 |
QCOMPARE(100, (int) bitmap_info.bmWidth); |
|
939 |
QCOMPARE(100, (int) bitmap_info.bmHeight); |
|
940 |
||
941 |
HDC display_dc = GetDC(0); |
|
942 |
HDC bitmap_dc = CreateCompatibleDC(display_dc); |
|
943 |
||
944 |
HBITMAP null_bitmap = (HBITMAP) SelectObject(bitmap_dc, bitmap); |
|
945 |
||
946 |
COLORREF pixel = GetPixel(bitmap_dc, 0, 0); |
|
947 |
QCOMPARE((int)GetRValue(pixel), red); |
|
948 |
QCOMPARE((int)GetGValue(pixel), green); |
|
949 |
QCOMPARE((int)GetBValue(pixel), blue); |
|
950 |
||
951 |
// Clean up |
|
952 |
SelectObject(bitmap_dc, null_bitmap); |
|
953 |
DeleteObject(bitmap); |
|
954 |
DeleteDC(bitmap_dc); |
|
955 |
ReleaseDC(0, display_dc); |
|
956 |
||
957 |
} |
|
958 |
||
959 |
void tst_QPixmap::fromWinHBITMAP_data() |
|
960 |
{ |
|
961 |
toWinHBITMAP_data(); |
|
962 |
} |
|
963 |
||
964 |
void tst_QPixmap::fromWinHBITMAP() |
|
965 |
{ |
|
966 |
QFETCH(int, red); |
|
967 |
QFETCH(int, green); |
|
968 |
QFETCH(int, blue); |
|
969 |
||
970 |
HDC display_dc = GetDC(0); |
|
971 |
HDC bitmap_dc = CreateCompatibleDC(display_dc); |
|
972 |
HBITMAP bitmap = CreateCompatibleBitmap(display_dc, 100, 100); |
|
973 |
SelectObject(bitmap_dc, bitmap); |
|
974 |
||
975 |
SelectObject(bitmap_dc, GetStockObject(NULL_PEN)); |
|
976 |
HGDIOBJ old_brush = SelectObject(bitmap_dc, CreateSolidBrush(RGB(red, green, blue))); |
|
977 |
Rectangle(bitmap_dc, 0, 0, 100, 100); |
|
978 |
||
979 |
#ifdef Q_OS_WINCE //the device context has to be deleted before QPixmap::fromWinHBITMAP() |
|
980 |
DeleteDC(bitmap_dc); |
|
981 |
#endif |
|
982 |
QPixmap pixmap = QPixmap::fromWinHBITMAP(bitmap); |
|
983 |
QCOMPARE(pixmap.width(), 100); |
|
984 |
QCOMPARE(pixmap.height(), 100); |
|
985 |
||
986 |
QImage image = pixmap.toImage(); |
|
987 |
QRgb pixel = image.pixel(0, 0); |
|
988 |
QCOMPARE(qRed(pixel), red); |
|
989 |
QCOMPARE(qGreen(pixel), green); |
|
990 |
QCOMPARE(qBlue(pixel), blue); |
|
991 |
||
992 |
DeleteObject(SelectObject(bitmap_dc, old_brush)); |
|
993 |
DeleteObject(SelectObject(bitmap_dc, bitmap)); |
|
994 |
#ifndef Q_OS_WINCE |
|
995 |
DeleteDC(bitmap_dc); |
|
996 |
#endif |
|
997 |
ReleaseDC(0, display_dc); |
|
998 |
} |
|
999 |
||
1000 |
static void compareImages(const QImage &image1, const QImage &image2) |
|
1001 |
{ |
|
1002 |
QCOMPARE(image1.width(), image2.width()); |
|
1003 |
QCOMPARE(image1.height(), image2.height()); |
|
1004 |
QCOMPARE(image1.format(), image2.format()); |
|
1005 |
||
1006 |
static const int fuzz = 1; |
|
1007 |
||
1008 |
for (int y = 0; y < image1.height(); y++) |
|
1009 |
{ |
|
1010 |
for (int x = 0; x < image2.width(); x++) |
|
1011 |
{ |
|
1012 |
QRgb p1 = image1.pixel(x, y); |
|
1013 |
QRgb p2 = image2.pixel(x, y); |
|
1014 |
||
1015 |
bool pixelMatches = |
|
1016 |
qAbs(qRed(p1) - qRed(p2)) <= fuzz |
|
1017 |
&& qAbs(qGreen(p1) - qGreen(p2)) <= fuzz |
|
1018 |
&& qAbs(qBlue(p1) - qBlue(p2)) <= fuzz |
|
1019 |
&& qAbs(qAlpha(p1) - qAlpha(p2)) <= fuzz; |
|
1020 |
||
1021 |
QVERIFY(pixelMatches); |
|
1022 |
} |
|
1023 |
} |
|
1024 |
} |
|
1025 |
||
1026 |
void tst_QPixmap::toWinHICON_data() |
|
1027 |
{ |
|
1028 |
QTest::addColumn<QString>("image"); |
|
1029 |
QTest::addColumn<int>("width"); |
|
1030 |
QTest::addColumn<int>("height"); |
|
1031 |
||
1032 |
const QString prefix = QLatin1String(SRCDIR) + "/convertFromToHICON"; |
|
1033 |
||
1034 |
QTest::newRow("32bpp_16x16") << prefix + QLatin1String("/icon_32bpp") << 16 << 16; |
|
1035 |
QTest::newRow("32bpp_32x32") << prefix + QLatin1String("/icon_32bpp") << 32 << 32; |
|
1036 |
QTest::newRow("32bpp_48x48") << prefix + QLatin1String("/icon_32bpp") << 48 << 48; |
|
1037 |
QTest::newRow("32bpp_256x256") << prefix + QLatin1String("/icon_32bpp") << 256 << 256; |
|
1038 |
||
1039 |
QTest::newRow("8bpp_16x16") << prefix + QLatin1String("/icon_8bpp") << 16 << 16; |
|
1040 |
QTest::newRow("8bpp_32x32") << prefix + QLatin1String("/icon_8bpp") << 32 << 32; |
|
1041 |
QTest::newRow("8bpp_48x48") << prefix + QLatin1String("/icon_8bpp") << 48 << 48; |
|
1042 |
} |
|
1043 |
||
1044 |
void tst_QPixmap::toWinHICON() |
|
1045 |
{ |
|
1046 |
#ifdef Q_OS_WINCE |
|
1047 |
QSKIP("Test shall be enabled for Windows CE shortly.", SkipAll); |
|
1048 |
#endif |
|
1049 |
||
1050 |
QFETCH(int, width); |
|
1051 |
QFETCH(int, height); |
|
1052 |
QFETCH(QString, image); |
|
1053 |
||
1054 |
QPixmap empty(width, height); |
|
1055 |
empty.fill(Qt::transparent); |
|
1056 |
||
1057 |
HDC display_dc = GetDC(0); |
|
1058 |
HDC bitmap_dc = CreateCompatibleDC(display_dc); |
|
1059 |
HBITMAP bitmap = empty.toWinHBITMAP(QPixmap::Alpha); |
|
1060 |
SelectObject(bitmap_dc, bitmap); |
|
1061 |
||
1062 |
QImage imageFromFile(image + QString(QLatin1String("_%1x%2.png")).arg(width).arg(height)); |
|
1063 |
imageFromFile = imageFromFile.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
1064 |
||
1065 |
HICON icon = QPixmap::fromImage(imageFromFile).toWinHICON(); |
|
1066 |
||
1067 |
DrawIconEx(bitmap_dc, 0, 0, icon, width, height, 0, 0, DI_NORMAL); |
|
1068 |
||
1069 |
DestroyIcon(icon); |
|
1070 |
DeleteDC(bitmap_dc); |
|
1071 |
||
1072 |
QImage imageFromHICON = QPixmap::fromWinHBITMAP(bitmap, QPixmap::Alpha).toImage(); |
|
1073 |
||
1074 |
ReleaseDC(0, display_dc); |
|
1075 |
||
1076 |
// fuzzy comparison must be used, as the pixel values change slightly during conversion |
|
1077 |
// between QImage::Format_ARGB32 and QImage::Format_ARGB32_Premultiplied, or elsewhere |
|
1078 |
||
1079 |
// QVERIFY(imageFromHICON == imageFromFile); |
|
1080 |
compareImages(imageFromHICON, imageFromFile); |
|
1081 |
} |
|
1082 |
||
1083 |
void tst_QPixmap::fromWinHICON_data() |
|
1084 |
{ |
|
1085 |
toWinHICON_data(); |
|
1086 |
} |
|
1087 |
||
1088 |
void tst_QPixmap::fromWinHICON() |
|
1089 |
{ |
|
1090 |
#ifdef Q_OS_WINCE |
|
1091 |
QSKIP("Test shall be enabled for Windows CE shortly.", SkipAll); |
|
1092 |
||
1093 |
#else |
|
1094 |
QFETCH(int, width); |
|
1095 |
QFETCH(int, height); |
|
1096 |
QFETCH(QString, image); |
|
1097 |
||
1098 |
HICON icon = (HICON)LoadImage(0, (wchar_t*)(image + QLatin1String(".ico")).utf16(), IMAGE_ICON, width, height, LR_LOADFROMFILE); |
|
1099 |
QImage imageFromHICON = QPixmap::fromWinHICON(icon).toImage(); |
|
1100 |
DestroyIcon(icon); |
|
1101 |
||
1102 |
QImage imageFromFile(image + QString(QLatin1String("_%1x%2.png")).arg(width).arg(height)); |
|
1103 |
imageFromFile = imageFromFile.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
1104 |
||
1105 |
// fuzzy comparison must be used, as the pixel values change slightly during conversion |
|
1106 |
// between QImage::Format_ARGB32 and QImage::Format_ARGB32_Premultiplied, or elsewhere |
|
1107 |
||
1108 |
// QVERIFY(imageFromHICON == imageFromFile); |
|
1109 |
compareImages(imageFromHICON, imageFromFile); |
|
1110 |
#endif |
|
1111 |
} |
|
1112 |
||
1113 |
#endif // Q_WS_WIN |
|
1114 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1115 |
#if defined(Q_OS_SYMBIAN) |
0 | 1116 |
Q_DECLARE_METATYPE(TDisplayMode) |
1117 |
||
1118 |
void tst_QPixmap::fromSymbianCFbsBitmap_data() |
|
1119 |
{ |
|
1120 |
QTest::addColumn<TDisplayMode>("format"); |
|
1121 |
QTest::addColumn<int>("width"); |
|
1122 |
QTest::addColumn<int>("height"); |
|
1123 |
QTest::addColumn<QColor>("color"); |
|
1124 |
||
1125 |
const int smallWidth = 20; |
|
1126 |
const int smallHeight = 20; |
|
1127 |
const int largeWidth = 240; |
|
1128 |
const int largeHeight = 320; |
|
1129 |
||
1130 |
// Indexed Color Formats - Disabled since images seem to be blank -> no palette? |
|
1131 |
// QTest::newRow("EGray2 small") << EGray2 << smallWidth << smallHeight << QColor(Qt::black); |
|
1132 |
// QTest::newRow("EGray2 big") << EGray2 << largeWidth << largeHeight << QColor(Qt::black); |
|
1133 |
// QTest::newRow("EGray256 small") << EGray256 << smallWidth << smallHeight << QColor(Qt::blue); |
|
1134 |
// QTest::newRow("EGray256 big") << EGray256 << largeWidth << largeHeight << QColor(Qt::blue); |
|
1135 |
// QTest::newRow("EColor256 small") << EColor256 << smallWidth << smallHeight << QColor(Qt::red); |
|
1136 |
// QTest::newRow("EColor256 big") << EColor256 << largeWidth << largeHeight << QColor(Qt::red); |
|
1137 |
||
1138 |
// Direct Color Formats |
|
1139 |
QTest::newRow("EColor4K small") << EColor4K << smallWidth << smallHeight << QColor(Qt::red); |
|
1140 |
QTest::newRow("EColor4K big") << EColor4K << largeWidth << largeHeight << QColor(Qt::red); |
|
1141 |
QTest::newRow("EColor64K small") << EColor64K << smallWidth << smallHeight << QColor(Qt::green); |
|
1142 |
QTest::newRow("EColor64K big") << EColor64K << largeWidth << largeHeight << QColor(Qt::green); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1143 |
QTest::newRow("EColor16M small") << EColor16M << smallWidth << smallHeight << QColor(Qt::yellow); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1144 |
QTest::newRow("EColor16M big") << EColor16M << largeWidth << largeHeight << QColor(Qt::yellow); |
0 | 1145 |
QTest::newRow("EColor16MU small") << EColor16MU << smallWidth << smallHeight << QColor(Qt::red); |
1146 |
QTest::newRow("EColor16MU big") << EColor16MU << largeWidth << largeHeight << QColor(Qt::red); |
|
1147 |
QTest::newRow("EColor16MA small opaque") << EColor16MA << smallWidth << smallHeight << QColor(255, 255, 0); |
|
1148 |
QTest::newRow("EColor16MA big opaque") << EColor16MA << largeWidth << largeHeight << QColor(255, 255, 0); |
|
1149 |
||
1150 |
// Semi-transparent Colors - Disabled for now, since the QCOMPARE fails, but visually confirmed to work |
|
1151 |
// QTest::newRow("EColor16MA small semi") << EColor16MA << smallWidth << smallHeight << QColor(255, 255, 0, 127); |
|
1152 |
// QTest::newRow("EColor16MA big semi") << EColor16MA << largeWidth << largeHeight << QColor(255, 255, 0, 127); |
|
1153 |
// QTest::newRow("EColor16MA small trans") << EColor16MA << smallWidth << smallHeight << QColor(255, 255, 0, 0); |
|
1154 |
// QTest::newRow("EColor16MA big trans") << EColor16MA << largeWidth << largeHeight << QColor(255, 255, 0, 0); |
|
1155 |
||
1156 |
#if !defined(__SERIES60_31__) |
|
1157 |
QTest::newRow("EColor16MAP small") << EColor16MAP << smallWidth << smallHeight << QColor(Qt::red); |
|
1158 |
QTest::newRow("EColor16MAP big") << EColor16MAP << largeWidth << largeHeight << QColor(Qt::red); |
|
1159 |
#endif |
|
1160 |
} |
|
1161 |
||
1162 |
void tst_QPixmap::fromSymbianCFbsBitmap() |
|
1163 |
{ |
|
1164 |
QFETCH(TDisplayMode, format); |
|
1165 |
QFETCH(int, width); |
|
1166 |
QFETCH(int, height); |
|
1167 |
QFETCH(QColor, color); |
|
1168 |
int expectedDepth = TDisplayModeUtils::NumDisplayModeBitsPerPixel(format); |
|
1169 |
||
1170 |
CFbsBitmap *nativeBitmap = 0; |
|
1171 |
CFbsBitmapDevice *bitmapDevice = 0; |
|
1172 |
CBitmapContext *bitmapContext = 0; |
|
1173 |
||
1174 |
nativeBitmap = new (ELeave) CFbsBitmap(); |
|
1175 |
TInt err = nativeBitmap->Create(TSize(width, height), format); |
|
1176 |
CleanupStack::PushL(nativeBitmap); |
|
1177 |
QVERIFY(err == KErrNone); |
|
1178 |
bitmapDevice = CFbsBitmapDevice::NewL(nativeBitmap); |
|
1179 |
CleanupStack::PushL(bitmapDevice); |
|
1180 |
||
1181 |
err = bitmapDevice->CreateBitmapContext(bitmapContext); |
|
1182 |
CleanupStack::PushL(bitmapContext); |
|
1183 |
QVERIFY(err == KErrNone); |
|
1184 |
TRgb symbianColor = TRgb(color.red(), color.green(), color.blue(), color.alpha()); |
|
1185 |
bitmapContext->SetBrushColor(symbianColor); |
|
1186 |
bitmapContext->Clear(); |
|
1187 |
||
1188 |
__UHEAP_MARK; |
|
1189 |
{ // Test the null case |
|
1190 |
CFbsBitmap *bitmap = 0; |
|
1191 |
QPixmap pixmap = QPixmap::fromSymbianCFbsBitmap(bitmap); |
|
1192 |
QVERIFY(pixmap.isNull()); |
|
1193 |
} |
|
1194 |
__UHEAP_MARKEND; |
|
1195 |
||
1196 |
__UHEAP_MARK; |
|
1197 |
{ // Test the normal case |
|
1198 |
QPixmap pixmap = QPixmap::fromSymbianCFbsBitmap(nativeBitmap); |
|
1199 |
// QCOMPARE(pixmap.depth(), expectedDepth); // Depth is not preserved now |
|
1200 |
QCOMPARE(pixmap.width(), width); |
|
1201 |
QCOMPARE(pixmap.height(), height); |
|
1202 |
QImage image = pixmap.toImage(); |
|
1203 |
||
1204 |
QColor actualColor(image.pixel(1, 1)); |
|
1205 |
QCOMPARE(actualColor, color); |
|
1206 |
} |
|
1207 |
__UHEAP_MARKEND; |
|
1208 |
||
1209 |
CleanupStack::PopAndDestroy(3); |
|
1210 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1211 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1212 |
void tst_QPixmap::toSymbianCFbsBitmap_data() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1213 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1214 |
QTest::addColumn<int>("red"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1215 |
QTest::addColumn<int>("green"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1216 |
QTest::addColumn<int>("blue"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1217 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1218 |
QTest::newRow("red") << 255 << 0 << 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1219 |
QTest::newRow("green") << 0 << 255 << 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1220 |
QTest::newRow("blue") << 0 << 0 << 255; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1221 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1222 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1223 |
void tst_QPixmap::toSymbianCFbsBitmap() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1224 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1225 |
QFETCH(int, red); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1226 |
QFETCH(int, green); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1227 |
QFETCH(int, blue); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1228 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1229 |
QPixmap pm(100, 100); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1230 |
pm.fill(QColor(red, green, blue)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1231 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1232 |
CFbsBitmap *bitmap = pm.toSymbianCFbsBitmap(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1233 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1234 |
QVERIFY(bitmap != 0); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1235 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1236 |
// Verify size |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1237 |
QCOMPARE(100, (int) bitmap->SizeInPixels().iWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1238 |
QCOMPARE(100, (int) bitmap->SizeInPixels().iHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1239 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1240 |
// Verify pixel color |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1241 |
TRgb pixel; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1242 |
bitmap->GetPixel(pixel, TPoint(0,0)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1243 |
QCOMPARE((int)pixel.Red(), red); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1244 |
QCOMPARE((int)pixel.Green(), green); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1245 |
QCOMPARE((int)pixel.Blue(), blue); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1246 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1247 |
// Clean up |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1248 |
delete bitmap; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1249 |
} |
0 | 1250 |
#endif |
1251 |
||
1252 |
void tst_QPixmap::onlyNullPixmapsOutsideGuiThread() |
|
1253 |
{ |
|
1254 |
#if !defined(Q_WS_WIN) |
|
1255 |
class Thread : public QThread |
|
1256 |
{ |
|
1257 |
public: |
|
1258 |
void run() |
|
1259 |
{ |
|
1260 |
QTest::ignoreMessage(QtWarningMsg, |
|
1261 |
"QPixmap: It is not safe to use pixmaps outside the GUI thread"); |
|
1262 |
QPixmap pixmap; |
|
1263 |
QVERIFY(pixmap.isNull()); |
|
1264 |
||
1265 |
QTest::ignoreMessage(QtWarningMsg, |
|
1266 |
"QPixmap: It is not safe to use pixmaps outside the GUI thread"); |
|
1267 |
QPixmap pixmap1(100, 100); |
|
1268 |
QVERIFY(pixmap1.isNull()); |
|
1269 |
||
1270 |
QTest::ignoreMessage(QtWarningMsg, |
|
1271 |
"QPixmap: It is not safe to use pixmaps outside the GUI thread"); |
|
1272 |
QPixmap pixmap2(pixmap1); |
|
1273 |
QVERIFY(pixmap2.isNull()); |
|
1274 |
} |
|
1275 |
}; |
|
1276 |
Thread thread; |
|
1277 |
#if defined(Q_OS_SYMBIAN) |
|
1278 |
thread.setStackSize(0x10000); |
|
1279 |
#endif |
|
1280 |
thread.start(); |
|
1281 |
#if defined(Q_OS_SYMBIAN) |
|
1282 |
QVERIFY(thread.wait(10000)); |
|
1283 |
#else |
|
1284 |
thread.wait(); |
|
1285 |
#endif |
|
1286 |
||
1287 |
#endif // !defined(Q_WS_WIN) |
|
1288 |
} |
|
1289 |
||
1290 |
void tst_QPixmap::refUnref() |
|
1291 |
{ |
|
1292 |
// Simple ref/unref |
|
1293 |
{ |
|
1294 |
QPixmap p; |
|
1295 |
} |
|
1296 |
{ |
|
1297 |
QBitmap b; |
|
1298 |
} |
|
1299 |
||
1300 |
// Get a copy of a pixmap that goes out of scope |
|
1301 |
{ |
|
1302 |
QPixmap b; |
|
1303 |
{ |
|
1304 |
QPixmap a(10, 10); |
|
1305 |
a.fill(Qt::color0); |
|
1306 |
b = a; |
|
1307 |
} |
|
1308 |
} |
|
1309 |
{ |
|
1310 |
QBitmap mask; |
|
1311 |
{ |
|
1312 |
QBitmap bitmap(10, 10); |
|
1313 |
bitmap.fill(Qt::color1); |
|
1314 |
mask = bitmap.mask(); |
|
1315 |
} |
|
1316 |
mask.fill(Qt::color0); |
|
1317 |
} |
|
1318 |
||
1319 |
} |
|
1320 |
||
1321 |
void tst_QPixmap::copy() |
|
1322 |
{ |
|
1323 |
QPixmap src(32, 32); |
|
1324 |
{ |
|
1325 |
QPainter p(&src); |
|
1326 |
p.fillRect(0, 0, 32, 32, Qt::red); |
|
1327 |
p.fillRect(10, 10, 10, 10, Qt::blue); |
|
1328 |
} |
|
1329 |
||
1330 |
QPixmap dest = src.copy(10, 10, 10, 10); |
|
1331 |
||
1332 |
QPixmap expected(10, 10); |
|
1333 |
expected.fill(Qt::blue); |
|
1334 |
QVERIFY(lenientCompare(dest, expected)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1335 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1336 |
QPixmap trans; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1337 |
trans.fill(Qt::transparent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
QPixmap transCopy = trans.copy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
QVERIFY(pixmapsAreEqual(&trans, &transCopy)); |
0 | 1341 |
} |
1342 |
||
1343 |
#ifdef QT3_SUPPORT |
|
1344 |
void tst_QPixmap::resize() |
|
1345 |
{ |
|
1346 |
QPixmap p1(10, 10); |
|
1347 |
p1.fill(Qt::red); |
|
1348 |
||
1349 |
QPixmap p2 = p1; |
|
1350 |
QPixmap p3(50, 50); |
|
1351 |
p3.fill(Qt::red); |
|
1352 |
||
1353 |
p1.resize(p3.size()); |
|
1354 |
p1.resize(p2.size()); |
|
1355 |
p3.resize(p2.size()); |
|
1356 |
QCOMPARE(p1.toImage(), p2.toImage()); |
|
1357 |
QCOMPARE(p1.toImage(), p3.toImage()); |
|
1358 |
||
1359 |
QBitmap b1; |
|
1360 |
b1.resize(10, 10); |
|
1361 |
QVERIFY(b1.depth() == 1); |
|
1362 |
QPixmap p4; |
|
1363 |
p4.resize(10, 10); |
|
1364 |
QVERIFY(p4.depth() != 0); |
|
1365 |
} |
|
1366 |
||
1367 |
void tst_QPixmap::resizePreserveMask() |
|
1368 |
{ |
|
1369 |
QPixmap pm(100, 100); |
|
1370 |
pm.fill(Qt::transparent); |
|
1371 |
QPainter p(&pm); |
|
1372 |
p.fillRect(10, 10, 80, 80, Qt::red); |
|
1373 |
p.drawRect(0, 0, 99, 99); |
|
1374 |
p.end(); |
|
1375 |
||
1376 |
QBitmap mask = pm.mask(); |
|
1377 |
pm.resize(50, 50); |
|
1378 |
||
1379 |
QCOMPARE(pm.mask().toImage(), mask.toImage().copy(0, 0, 50, 50)); |
|
1380 |
||
1381 |
pm = QPixmap(100, 100); |
|
1382 |
pm.fill(Qt::red); |
|
1383 |
pm.setMask(mask); |
|
1384 |
pm.resize(50, 50); |
|
1385 |
||
1386 |
QCOMPARE(pm.mask().toImage(), mask.toImage().copy(0, 0, 50, 50)); |
|
1387 |
} |
|
1388 |
#endif |
|
1389 |
||
1390 |
void tst_QPixmap::depthOfNullObjects() |
|
1391 |
{ |
|
1392 |
QBitmap b1; |
|
1393 |
QVERIFY(b1.depth() == 0); |
|
1394 |
QPixmap p4; |
|
1395 |
QVERIFY(p4.depth() == 0); |
|
1396 |
} |
|
1397 |
||
1398 |
void tst_QPixmap::transformed() |
|
1399 |
{ |
|
1400 |
QPixmap p1(20, 10); |
|
1401 |
p1.fill(Qt::red); |
|
1402 |
{ |
|
1403 |
QPainter p(&p1); |
|
1404 |
p.drawRect(0, 0, p1.width() - 1, p1.height() - 1); |
|
1405 |
} |
|
1406 |
||
1407 |
QPixmap p2(10, 20); |
|
1408 |
{ |
|
1409 |
QPainter p(&p2); |
|
1410 |
p.rotate(90); |
|
1411 |
p.drawPixmap(0, -p1.height(), p1); |
|
1412 |
} |
|
1413 |
||
1414 |
QPixmap p3(20, 10); |
|
1415 |
{ |
|
1416 |
QPainter p(&p3); |
|
1417 |
p.rotate(180); |
|
1418 |
p.drawPixmap(-p1.width(), -p1.height(), p1); |
|
1419 |
} |
|
1420 |
||
1421 |
QPixmap p4(10, 20); |
|
1422 |
{ |
|
1423 |
QPainter p(&p4); |
|
1424 |
p.rotate(270); |
|
1425 |
p.drawPixmap(-p1.width(), 0, p1); |
|
1426 |
} |
|
1427 |
||
1428 |
QPixmap p1_90 = p1.transformed(QTransform().rotate(90)); |
|
1429 |
QPixmap p1_180 = p1.transformed(QTransform().rotate(180)); |
|
1430 |
QPixmap p1_270 = p1.transformed(QTransform().rotate(270)); |
|
1431 |
||
1432 |
QVERIFY(lenientCompare(p1_90, p2)); |
|
1433 |
QVERIFY(lenientCompare(p1_180, p3)); |
|
1434 |
QVERIFY(lenientCompare(p1_270, p4)); |
|
1435 |
} |
|
1436 |
||
1437 |
void tst_QPixmap::transformed2() |
|
1438 |
{ |
|
1439 |
QPixmap pm(3, 3); |
|
1440 |
pm.fill(Qt::red); |
|
1441 |
QPainter p(&pm); |
|
1442 |
p.fillRect(0, 0, 3, 3, QBrush(Qt::Dense4Pattern)); |
|
1443 |
p.end(); |
|
1444 |
||
1445 |
QTransform transform; |
|
1446 |
transform.rotate(-90); |
|
1447 |
transform.scale(3, 3); |
|
1448 |
||
1449 |
QPixmap actual = pm.transformed(transform); |
|
1450 |
||
1451 |
QPixmap expected(9, 9); |
|
1452 |
expected.fill(Qt::red); |
|
1453 |
p.begin(&expected); |
|
1454 |
p.setBrush(Qt::black); |
|
1455 |
p.setPen(Qt::NoPen); |
|
1456 |
p.drawRect(3, 0, 3, 3); |
|
1457 |
p.drawRect(0, 3, 3, 3); |
|
1458 |
p.drawRect(6, 3, 3, 3); |
|
1459 |
p.drawRect(3, 6, 3, 3); |
|
1460 |
p.end(); |
|
1461 |
||
1462 |
QVERIFY(lenientCompare(actual, expected)); |
|
1463 |
} |
|
1464 |
||
1465 |
void tst_QPixmap::fromImage_crash() |
|
1466 |
{ |
|
1467 |
QImage *img = new QImage(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
1468 |
||
1469 |
QPixmap pm = QPixmap::fromImage(*img); |
|
1470 |
QPainter painter(&pm); |
|
1471 |
||
1472 |
delete img; |
|
1473 |
} |
|
1474 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1475 |
//This is testing QPixmapData::createCompatiblePixmapData - see QTBUG-5977 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1476 |
void tst_QPixmap::splash_crash() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1477 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1478 |
QPixmap pix; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1479 |
pix = QPixmap(":/images/designer.png"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1480 |
QSplashScreen splash(pix); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1481 |
splash.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1482 |
QCoreApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1483 |
splash.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1484 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1485 |
|
0 | 1486 |
void tst_QPixmap::fromData() |
1487 |
{ |
|
1488 |
unsigned char bits[] = { 0xaa, 0x55 }; |
|
1489 |
||
1490 |
QBitmap bm = QBitmap::fromData(QSize(8, 2), bits); |
|
1491 |
QImage img = bm.toImage(); |
|
1492 |
||
1493 |
QSet<QRgb> colors; |
|
1494 |
for (int y = 0; y < img.height(); ++y) |
|
1495 |
for (int x = 0; x < img.width(); ++x) |
|
1496 |
colors << img.pixel(x, y); |
|
1497 |
||
1498 |
QCOMPARE(colors.size(), 2); |
|
1499 |
||
1500 |
QCOMPARE(img.pixel(0, 0), QRgb(0xffffffff)); |
|
1501 |
QCOMPARE(img.pixel(0, 1), QRgb(0xff000000)); |
|
1502 |
} |
|
1503 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1504 |
void tst_QPixmap::loadFromDataNullValues() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1505 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1506 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1507 |
QPixmap pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1508 |
pixmap.loadFromData(QByteArray()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1509 |
QVERIFY(pixmap.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1510 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1511 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1512 |
QPixmap pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1513 |
pixmap.loadFromData(0, 123); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1514 |
QVERIFY(pixmap.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1515 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1516 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1517 |
QPixmap pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1518 |
const uchar bla[] = "bla"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1519 |
pixmap.loadFromData(bla, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1520 |
QVERIFY(pixmap.isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1521 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1522 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1523 |
|
0 | 1524 |
void tst_QPixmap::task_246446() |
1525 |
{ |
|
1526 |
// This crashed without the bugfix in 246446 |
|
1527 |
QPixmap pm(10, 10); |
|
1528 |
pm.fill(Qt::transparent); // force 32-bit depth |
|
1529 |
QBitmap bm; |
|
1530 |
pm.setMask(bm); |
|
1531 |
{ |
|
1532 |
QPixmap pm2(pm); |
|
1533 |
} |
|
1534 |
QVERIFY(pm.width() == 10); |
|
1535 |
QVERIFY(pm.mask().isNull()); |
|
1536 |
} |
|
1537 |
||
1538 |
void tst_QPixmap::preserveDepth() |
|
1539 |
{ |
|
1540 |
QPixmap target(64, 64); |
|
1541 |
target.fill(Qt::transparent); |
|
1542 |
||
1543 |
QPixmap source(64, 64); |
|
1544 |
source.fill(Qt::white); |
|
1545 |
||
1546 |
int depth = source.depth(); |
|
1547 |
||
1548 |
QPainter painter(&target); |
|
1549 |
painter.setBrush(source); |
|
1550 |
painter.drawRect(target.rect()); |
|
1551 |
painter.end(); |
|
1552 |
||
1553 |
QCOMPARE(depth, source.depth()); |
|
1554 |
} |
|
1555 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1556 |
void tst_QPixmap::loadAsBitmapOrPixmap() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1557 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1558 |
QImage tmp(10, 10, QImage::Format_RGB32); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1559 |
tmp.save("tmp.png"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1560 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1561 |
bool ok; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1562 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1563 |
// Check that we can load the pixmap as a pixmap and that it then turns into a pixmap |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1564 |
QPixmap pixmap("tmp.png"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1565 |
QVERIFY(!pixmap.isNull()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1566 |
QVERIFY(pixmap.depth() > 1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1567 |
QVERIFY(!pixmap.isQBitmap()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1568 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1569 |
pixmap = QPixmap(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1570 |
ok = pixmap.load("tmp.png"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1571 |
QVERIFY(ok); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1572 |
QVERIFY(!pixmap.isNull()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1573 |
QVERIFY(pixmap.depth() > 1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1574 |
QVERIFY(!pixmap.isQBitmap()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1575 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1576 |
// The do the same check for bitmaps.. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1577 |
QBitmap bitmap("tmp.png"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1578 |
QVERIFY(!bitmap.isNull()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1579 |
QVERIFY(bitmap.depth() == 1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1580 |
QVERIFY(bitmap.isQBitmap()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1581 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1582 |
bitmap = QBitmap(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1583 |
ok = bitmap.load("tmp.png"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1584 |
QVERIFY(ok); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1585 |
QVERIFY(!bitmap.isNull()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1586 |
QVERIFY(bitmap.depth() == 1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1587 |
QVERIFY(bitmap.isQBitmap()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1588 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1589 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1590 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1591 |
|
0 | 1592 |
QTEST_MAIN(tst_QPixmap) |
1593 |
#include "tst_qpixmap.moc" |