author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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 |
||
45 |
#include <qimage.h> |
|
46 |
#include <qimagereader.h> |
|
47 |
#include <qlist.h> |
|
48 |
#include <qmatrix.h> |
|
49 |
#include <stdio.h> |
|
50 |
||
51 |
#include <qpainter.h> |
|
52 |
#include <private/qdrawhelper_p.h> |
|
53 |
||
54 |
||
55 |
//TESTED_CLASS= |
|
56 |
//TESTED_FILES= |
|
57 |
#if defined(Q_OS_SYMBIAN) |
|
58 |
# define SRCDIR "" |
|
59 |
#endif |
|
60 |
||
61 |
Q_DECLARE_METATYPE(QImage::Format) |
|
62 |
||
63 |
class tst_QImage : public QObject |
|
64 |
{ |
|
65 |
Q_OBJECT |
|
66 |
||
67 |
public: |
|
68 |
tst_QImage(); |
|
69 |
||
70 |
private slots: |
|
71 |
void create(); |
|
72 |
void createInvalidXPM(); |
|
73 |
void createFromUChar(); |
|
74 |
void convertBitOrder(); |
|
75 |
void formatHandlersInput_data(); |
|
76 |
void formatHandlersInput(); |
|
77 |
||
78 |
void setAlphaChannel_data(); |
|
79 |
void setAlphaChannel(); |
|
80 |
||
81 |
void alphaChannel(); |
|
82 |
||
83 |
void convertToFormat_data(); |
|
84 |
void convertToFormat(); |
|
85 |
||
86 |
void createAlphaMask_data(); |
|
87 |
void createAlphaMask(); |
|
88 |
#ifndef QT_NO_IMAGE_HEURISTIC_MASK |
|
89 |
void createHeuristicMask(); |
|
90 |
#endif |
|
91 |
||
92 |
void dotsPerMeterZero(); |
|
93 |
||
94 |
void convertToFormatPreserveDotsPrMeter(); |
|
95 |
#ifndef QT_NO_IMAGE_TEXT |
|
96 |
void convertToFormatPreserveText(); |
|
97 |
#endif |
|
98 |
||
99 |
void rotate_data(); |
|
100 |
void rotate(); |
|
101 |
||
102 |
void copy(); |
|
103 |
||
104 |
void setPixel_data(); |
|
105 |
void setPixel(); |
|
106 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
void setColorCount(); |
0 | 108 |
void setColor(); |
109 |
||
110 |
void rasterClipping(); |
|
111 |
||
112 |
void pointOverloads(); |
|
113 |
void destructor(); |
|
114 |
void cacheKey(); |
|
115 |
||
116 |
void smoothScale(); |
|
117 |
void smoothScale2(); |
|
118 |
void smoothScale3(); |
|
119 |
||
120 |
void smoothScaleBig(); |
|
121 |
void smoothScaleAlpha(); |
|
122 |
||
123 |
void transformed_data(); |
|
124 |
void transformed(); |
|
125 |
void transformed2(); |
|
126 |
||
127 |
void scaled(); |
|
128 |
||
129 |
void paintEngine(); |
|
130 |
void setAlphaChannelWhilePainting(); |
|
131 |
||
132 |
void smoothScaledSubImage(); |
|
133 |
||
134 |
void nullSize_data(); |
|
135 |
void nullSize(); |
|
136 |
||
137 |
void premultipliedAlphaConsistency(); |
|
138 |
||
139 |
void compareIndexed(); |
|
140 |
}; |
|
141 |
||
142 |
tst_QImage::tst_QImage() |
|
143 |
||
144 |
{ |
|
145 |
} |
|
146 |
||
147 |
// Test if QImage (or any functions called from QImage) throws an |
|
148 |
// exception when creating an extremely large image. |
|
149 |
// QImage::create() should return "false" in this case. |
|
150 |
void tst_QImage::create() |
|
151 |
{ |
|
152 |
bool cr = true; |
|
153 |
#if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) |
|
154 |
try { |
|
155 |
#endif |
|
156 |
//QImage image(7000000, 7000000, 8, 256, QImage::IgnoreEndian); |
|
157 |
QImage image(7000000, 7000000, QImage::Format_Indexed8); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
image.setColorCount(256); |
0 | 159 |
cr = !image.isNull(); |
160 |
#if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) |
|
161 |
} catch (...) { |
|
162 |
} |
|
163 |
#endif |
|
164 |
QVERIFY( !cr ); |
|
165 |
} |
|
166 |
||
167 |
void tst_QImage::createInvalidXPM() |
|
168 |
{ |
|
169 |
QTest::ignoreMessage(QtWarningMsg, "QImage::QImage(), XPM is not supported"); |
|
170 |
const char *xpm[] = {""}; |
|
171 |
QImage invalidXPM(xpm); |
|
172 |
QVERIFY(invalidXPM.isNull()); |
|
173 |
} |
|
174 |
||
175 |
void tst_QImage::createFromUChar() |
|
176 |
{ |
|
177 |
uchar data[] = { |
|
178 |
#if Q_BYTE_ORDER == Q_BIG_ENDIAN |
|
179 |
0xFF, |
|
180 |
#endif |
|
181 |
1,1,1, 0xFF, 2,2,2, 0xFF, 3,3,3, 0xFF, 4,4,4, |
|
182 |
#if Q_BYTE_ORDER != Q_BIG_ENDIAN |
|
183 |
0xFF, |
|
184 |
#endif |
|
185 |
}; |
|
186 |
||
187 |
// When the data is const, nothing you do to the image will change the source data. |
|
188 |
QImage i1((const uchar*)data, 2, 2, 8, QImage::Format_RGB32); |
|
189 |
QCOMPARE(i1.pixel(0,0), 0xFF010101U); |
|
190 |
QCOMPARE(i1.pixel(1,0), 0xFF020202U); |
|
191 |
QCOMPARE(i1.pixel(0,1), 0xFF030303U); |
|
192 |
QCOMPARE(i1.pixel(1,1), 0xFF040404U); |
|
193 |
{ |
|
194 |
QImage i(i1); |
|
195 |
i.setPixel(0,0,5); |
|
196 |
} |
|
197 |
QCOMPARE(i1.pixel(0,0), 0xFF010101U); |
|
198 |
QCOMPARE(*(QRgb*)data, 0xFF010101U); |
|
199 |
*((QRgb*)i1.bits()) = 7U; |
|
200 |
QCOMPARE(i1.pixel(0,0), 7U); |
|
201 |
QCOMPARE(*(QRgb*)data, 0xFF010101U); |
|
202 |
||
203 |
// Changing copies should not change the original image or data. |
|
204 |
{ |
|
205 |
QImage i(i1); |
|
206 |
i.setPixel(0,0,5); |
|
207 |
QCOMPARE(*(QRgb*)data, 0xFF010101U); |
|
208 |
i1.setPixel(0,0,9); |
|
209 |
QCOMPARE(i1.pixel(0,0), 0xFF000009U); |
|
210 |
QCOMPARE(i.pixel(0,0), 0xFF000005U); |
|
211 |
} |
|
212 |
QCOMPARE(i1.pixel(0,0), 0xFF000009U); |
|
213 |
||
214 |
// When the data is non-const, nothing you do to copies of the image will change the source data, |
|
215 |
// but changing the image (here via bits()) will change the source data. |
|
216 |
QImage i2((uchar*)data, 2, 2, 8, QImage::Format_RGB32); |
|
217 |
QCOMPARE(i2.pixel(0,0), 0xFF010101U); |
|
218 |
QCOMPARE(i2.pixel(1,0), 0xFF020202U); |
|
219 |
QCOMPARE(i2.pixel(0,1), 0xFF030303U); |
|
220 |
QCOMPARE(i2.pixel(1,1), 0xFF040404U); |
|
221 |
{ |
|
222 |
QImage i(i2); |
|
223 |
i.setPixel(0,0,5); |
|
224 |
} |
|
225 |
QCOMPARE(i2.pixel(0,0), 0xFF010101U); |
|
226 |
QCOMPARE(*(QRgb*)data, 0xFF010101U); |
|
227 |
*((QRgb*)i2.bits()) = 7U; |
|
228 |
QCOMPARE(i2.pixel(0,0), 7U); |
|
229 |
QCOMPARE(*(QRgb*)data, 7U); |
|
230 |
||
231 |
// Changing the data will change the image in either case. |
|
232 |
QImage i3((uchar*)data, 2, 2, 8, QImage::Format_RGB32); |
|
233 |
QImage i4((const uchar*)data, 2, 2, 8, QImage::Format_RGB32); |
|
234 |
*(QRgb*)data = 6U; |
|
235 |
QCOMPARE(i3.pixel(0,0), 6U); |
|
236 |
QCOMPARE(i4.pixel(0,0), 6U); |
|
237 |
} |
|
238 |
||
239 |
void tst_QImage::convertBitOrder() |
|
240 |
{ |
|
241 |
#if !defined(QT3_SUPPORT) |
|
242 |
QSKIP("Qt compiled without Qt3Support", SkipAll); |
|
243 |
#else |
|
244 |
QImage i(9,5,1,2,QImage::LittleEndian); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
qMemSet(i.bits(), 0, i.byteCount()); |
0 | 246 |
|
247 |
i.setDotsPerMeterX(9); |
|
248 |
i.setDotsPerMeterY(5); |
|
249 |
i.fill(0x12345678); |
|
250 |
QVERIFY(!i.isNull()); |
|
251 |
||
252 |
QImage ni = i.convertBitOrder(QImage::BigEndian); |
|
253 |
QVERIFY(!ni.isNull()); |
|
254 |
QVERIFY(ni.bitOrder() == QImage::BigEndian); |
|
255 |
||
256 |
// A bunch of verifies to make sure that nothing was lost |
|
257 |
QVERIFY(i.dotsPerMeterX() == ni.dotsPerMeterX()); |
|
258 |
QVERIFY(i.dotsPerMeterY() == ni.dotsPerMeterY()); |
|
259 |
QVERIFY(i.depth() == ni.depth()); |
|
260 |
QVERIFY(i.size() == ni.size()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
QVERIFY(i.colorCount() == ni.colorCount()); |
0 | 262 |
#endif |
263 |
} |
|
264 |
||
265 |
void tst_QImage::formatHandlersInput_data() |
|
266 |
{ |
|
267 |
QTest::addColumn<QString>("testFormat"); |
|
268 |
QTest::addColumn<QString>("testFile"); |
|
269 |
#ifdef Q_OS_SYMBIAN |
|
270 |
const QString prefix = QLatin1String(SRCDIR) + "images/"; |
|
271 |
#else |
|
272 |
const QString prefix = QLatin1String(SRCDIR) + "/images/"; |
|
273 |
#endif |
|
274 |
||
275 |
// add a new line here when a file is added |
|
276 |
QTest::newRow("ICO") << "ICO" << prefix + "image.ico"; |
|
277 |
QTest::newRow("PNG") << "PNG" << prefix + "image.png"; |
|
278 |
QTest::newRow("GIF") << "GIF" << prefix + "image.gif"; |
|
279 |
QTest::newRow("BMP") << "BMP" << prefix + "image.bmp"; |
|
280 |
QTest::newRow("JPEG") << "JPEG" << prefix + "image.jpg"; |
|
281 |
QTest::newRow("PBM") << "PBM" << prefix + "image.pbm"; |
|
282 |
QTest::newRow("PGM") << "PGM" << prefix + "image.pgm"; |
|
283 |
QTest::newRow("PPM") << "PPM" << prefix + "image.ppm"; |
|
284 |
QTest::newRow("XBM") << "XBM" << prefix + "image.xbm"; |
|
285 |
QTest::newRow("XPM") << "XPM" << prefix + "image.xpm"; |
|
286 |
#if defined QTEST_HAVE_TIFF |
|
287 |
QTest::newRow("TIFF") << "TIFF" << prefix + "image.tif"; |
|
288 |
#endif |
|
289 |
} |
|
290 |
||
291 |
void tst_QImage::formatHandlersInput() |
|
292 |
{ |
|
293 |
QFETCH(QString, testFormat); |
|
294 |
QFETCH(QString, testFile); |
|
295 |
QList<QByteArray> formats = QImageReader::supportedImageFormats(); |
|
296 |
// qDebug("Image input formats : %s", formats.join(" | ").latin1()); |
|
297 |
||
298 |
bool formatSupported = false; |
|
299 |
for (QList<QByteArray>::Iterator it = formats.begin(); it != formats.end(); ++it) { |
|
300 |
if (*it == testFormat.toLower()) { |
|
301 |
formatSupported = true; |
|
302 |
break; |
|
303 |
} |
|
304 |
} |
|
305 |
if (formatSupported) { |
|
306 |
// qDebug(QImage::imageFormat(testFile)); |
|
307 |
QCOMPARE(testFormat.toLatin1().toLower(), QImageReader::imageFormat(testFile)); |
|
308 |
} else { |
|
309 |
QString msg = "Format not supported : "; |
|
310 |
QSKIP(QString(msg + testFormat).toLatin1(), SkipSingle); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
void tst_QImage::setAlphaChannel_data() |
|
315 |
{ |
|
316 |
QTest::addColumn<int>("red"); |
|
317 |
QTest::addColumn<int>("green"); |
|
318 |
QTest::addColumn<int>("blue"); |
|
319 |
QTest::addColumn<int>("alpha"); |
|
320 |
QTest::addColumn<bool>("gray"); |
|
321 |
||
322 |
QTest::newRow("red at 0%, gray") << 255 << 0 << 0 << 0 << true; |
|
323 |
QTest::newRow("red at 25%, gray") << 255 << 0 << 0 << 63 << true; |
|
324 |
QTest::newRow("red at 50%, gray") << 255 << 0 << 0 << 127 << true; |
|
325 |
QTest::newRow("red at 100%, gray") << 255 << 0 << 0 << 191 << true; |
|
326 |
QTest::newRow("red at 0%, 32bit") << 255 << 0 << 0 << 0 << false; |
|
327 |
QTest::newRow("red at 25%, 32bit") << 255 << 0 << 0 << 63 << false; |
|
328 |
QTest::newRow("red at 50%, 32bit") << 255 << 0 << 0 << 127 << false; |
|
329 |
QTest::newRow("red at 100%, 32bit") << 255 << 0 << 0 << 191 << false; |
|
330 |
||
331 |
QTest::newRow("green at 0%, gray") << 0 << 255 << 0 << 0 << true; |
|
332 |
QTest::newRow("green at 25%, gray") << 0 << 255 << 0 << 63 << true; |
|
333 |
QTest::newRow("green at 50%, gray") << 0 << 255 << 0 << 127 << true; |
|
334 |
QTest::newRow("green at 100%, gray") << 0 << 255 << 0 << 191 << true; |
|
335 |
QTest::newRow("green at 0%, 32bit") << 0 << 255 << 0 << 0 << false; |
|
336 |
QTest::newRow("green at 25%, 32bit") << 0 << 255 << 0 << 63 << false; |
|
337 |
QTest::newRow("green at 50%, 32bit") << 0 << 255 << 0 << 127 << false; |
|
338 |
QTest::newRow("green at 100%, 32bit") << 0 << 255 << 0 << 191 << false; |
|
339 |
||
340 |
QTest::newRow("blue at 0%, gray") << 0 << 0 << 255 << 0 << true; |
|
341 |
QTest::newRow("blue at 25%, gray") << 0 << 0 << 255 << 63 << true; |
|
342 |
QTest::newRow("blue at 50%, gray") << 0 << 0 << 255 << 127 << true; |
|
343 |
QTest::newRow("blue at 100%, gray") << 0 << 0 << 255 << 191 << true; |
|
344 |
QTest::newRow("blue at 0%, 32bit") << 0 << 0 << 255 << 0 << false; |
|
345 |
QTest::newRow("blue at 25%, 32bit") << 0 << 0 << 255 << 63 << false; |
|
346 |
QTest::newRow("blue at 50%, 32bit") << 0 << 0 << 255 << 127 << false; |
|
347 |
QTest::newRow("blue at 100%, 32bit") << 0 << 0 << 255 << 191 << false; |
|
348 |
} |
|
349 |
||
350 |
void tst_QImage::setAlphaChannel() |
|
351 |
{ |
|
352 |
QFETCH(int, red); |
|
353 |
QFETCH(int, green); |
|
354 |
QFETCH(int, blue); |
|
355 |
QFETCH(int, alpha); |
|
356 |
QFETCH(bool, gray); |
|
357 |
||
358 |
int width = 100; |
|
359 |
int height = 100; |
|
360 |
||
361 |
QImage image(width, height, QImage::Format_RGB32); |
|
362 |
image.fill(qRgb(red, green, blue)); |
|
363 |
||
364 |
// Create the alpha channel |
|
365 |
QImage alphaChannel; |
|
366 |
if (gray) { |
|
367 |
alphaChannel = QImage(width, height, QImage::Format_Indexed8); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
alphaChannel.setColorCount(256); |
0 | 369 |
for (int i=0; i<256; ++i) |
370 |
alphaChannel.setColor(i, qRgb(i, i, i)); |
|
371 |
alphaChannel.fill(alpha); |
|
372 |
} else { |
|
373 |
alphaChannel = QImage(width, height, QImage::Format_ARGB32); |
|
374 |
alphaChannel.fill(qRgb(alpha, alpha, alpha)); |
|
375 |
} |
|
376 |
||
377 |
image.setAlphaChannel(alphaChannel); |
|
378 |
image = image.convertToFormat(QImage::Format_ARGB32); |
|
379 |
QVERIFY(image.format() == QImage::Format_ARGB32); |
|
380 |
||
381 |
// alpha of 0 becomes black at a=0 due to premultiplication |
|
382 |
QRgb pixel = alpha == 0 ? 0 : qRgba(red, green, blue, alpha); |
|
383 |
bool allPixelsOK = true; |
|
384 |
for (int y=0; y<height; ++y) { |
|
385 |
for (int x=0; x<width; ++x) { |
|
386 |
allPixelsOK &= image.pixel(x, y) == pixel; |
|
387 |
} |
|
388 |
} |
|
389 |
QVERIFY(allPixelsOK); |
|
390 |
||
391 |
QImage outAlpha = image.alphaChannel(); |
|
392 |
QCOMPARE(outAlpha.size(), image.size()); |
|
393 |
||
394 |
bool allAlphaOk = true; |
|
395 |
for (int y=0; y<height; ++y) { |
|
396 |
for (int x=0; x<width; ++x) { |
|
397 |
allAlphaOk &= outAlpha.pixelIndex(x, y) == alpha; |
|
398 |
} |
|
399 |
} |
|
400 |
QVERIFY(allAlphaOk); |
|
401 |
||
402 |
} |
|
403 |
||
404 |
void tst_QImage::alphaChannel() |
|
405 |
{ |
|
406 |
QImage img(10, 10, QImage::Format_Mono); |
|
407 |
img.setColor(0, Qt::transparent); |
|
408 |
img.setColor(1, Qt::black); |
|
409 |
img.fill(0); |
|
410 |
||
411 |
QPainter p(&img); |
|
412 |
p.fillRect(2, 2, 6, 6, Qt::black); |
|
413 |
p.end(); |
|
414 |
||
415 |
QCOMPARE(img.alphaChannel(), img.convertToFormat(QImage::Format_ARGB32).alphaChannel()); |
|
416 |
} |
|
417 |
||
418 |
void tst_QImage::convertToFormat_data() |
|
419 |
{ |
|
420 |
QTest::addColumn<int>("inFormat"); |
|
421 |
QTest::addColumn<uint>("inPixel"); |
|
422 |
QTest::addColumn<int>("resFormat"); |
|
423 |
QTest::addColumn<uint>("resPixel"); |
|
424 |
||
425 |
QTest::newRow("red rgb32 -> argb32") << int(QImage::Format_RGB32) << 0xffff0000 |
|
426 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
427 |
QTest::newRow("green rgb32 -> argb32") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
428 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
429 |
QTest::newRow("blue rgb32 -> argb32") << int(QImage::Format_RGB32) << 0xff0000ff |
|
430 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
431 |
||
432 |
QTest::newRow("red rgb32 -> rgb16") << int(QImage::Format_RGB32) << 0xffff0000 |
|
433 |
<< int(QImage::Format_RGB16) << 0xffff0000; |
|
434 |
QTest::newRow("green rgb32 -> rgb16") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
435 |
<< int(QImage::Format_RGB16) << 0xff00ff00; |
|
436 |
QTest::newRow("blue rgb32 -> rgb16") << int(QImage::Format_RGB32) << 0xff0000ff |
|
437 |
<< int(QImage::Format_RGB16) << 0xff0000ff; |
|
438 |
QTest::newRow("funky rgb32 -> rgb16") << int(QImage::Format_RGB32) << 0xfff0c080 |
|
439 |
<< int(QImage::Format_RGB16) << 0xfff7c384; |
|
440 |
||
441 |
QTest::newRow("red rgb32 -> argb32_pm") << int(QImage::Format_RGB32) << 0xffff0000 |
|
442 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0xffff0000; |
|
443 |
QTest::newRow("green rgb32 -> argb32_pm") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
444 |
<< int(QImage::Format_ARGB32_Premultiplied) <<0xff00ff00; |
|
445 |
QTest::newRow("blue rgb32 -> argb32_pm") << int(QImage::Format_RGB32) << 0xff0000ff |
|
446 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0xff0000ff; |
|
447 |
||
448 |
QTest::newRow("semired argb32 -> pm") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
449 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u; |
|
450 |
QTest::newRow("semigreen argb32 -> pm") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
451 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u; |
|
452 |
QTest::newRow("semiblue argb32 -> pm") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
453 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu; |
|
454 |
QTest::newRow("semiwhite argb32 -> pm") << int(QImage::Format_ARGB32) << 0x7fffffffu |
|
455 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu; |
|
456 |
QTest::newRow("semiblack argb32 -> pm") << int(QImage::Format_ARGB32) << 0x7f000000u |
|
457 |
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u; |
|
458 |
||
459 |
QTest::newRow("semired pm -> argb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
460 |
<< int(QImage::Format_ARGB32) << 0x7fff0000u; |
|
461 |
QTest::newRow("semigreen pm -> argb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
462 |
<< int(QImage::Format_ARGB32) << 0x7f00ff00u; |
|
463 |
QTest::newRow("semiblue pm -> argb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
464 |
<< int(QImage::Format_ARGB32) << 0x7f0000ffu; |
|
465 |
QTest::newRow("semiwhite pm -> argb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
466 |
<< int(QImage::Format_ARGB32) << 0x7fffffffu; |
|
467 |
QTest::newRow("semiblack pm -> argb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
468 |
<< int(QImage::Format_ARGB32) << 0x7f000000u; |
|
469 |
||
470 |
QTest::newRow("semired pm -> rgb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
471 |
<< int(QImage::Format_RGB32) << 0xffff0000u; |
|
472 |
QTest::newRow("semigreen pm -> rgb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
473 |
<< int(QImage::Format_RGB32) << 0xff00ff00u; |
|
474 |
QTest::newRow("semiblue pm -> rgb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
475 |
<< int(QImage::Format_RGB32) << 0xff0000ffu; |
|
476 |
QTest::newRow("semiwhite pm -> rgb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
477 |
<< int(QImage::Format_RGB32) << 0xffffffffu; |
|
478 |
QTest::newRow("semiblack pm -> rgb32") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
479 |
<< int(QImage::Format_RGB32) << 0xff000000u; |
|
480 |
||
481 |
QTest::newRow("semired argb32 -> rgb32") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
482 |
<< int(QImage::Format_RGB32) << 0xffff0000u; |
|
483 |
QTest::newRow("semigreen argb32 -> rgb32") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
484 |
<< int(QImage::Format_RGB32) << 0xff00ff00u; |
|
485 |
QTest::newRow("semiblue argb32 -> rgb32") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
486 |
<< int(QImage::Format_RGB32) << 0xff0000ffu; |
|
487 |
QTest::newRow("semiwhite argb -> rgb32") << int(QImage::Format_ARGB32) << 0x7fffffffu |
|
488 |
<< int(QImage::Format_RGB32) << 0xffffffffu; |
|
489 |
QTest::newRow("semiblack argb -> rgb32") << int(QImage::Format_ARGB32) << 0x7f000000u |
|
490 |
<< int(QImage::Format_RGB32) << 0xff000000u; |
|
491 |
||
492 |
QTest::newRow("black mono -> rgb32") << int(QImage::Format_Mono) << 0x00000000u |
|
493 |
<< int(QImage::Format_RGB32) << 0xff000000u; |
|
494 |
||
495 |
QTest::newRow("white mono -> rgb32") << int(QImage::Format_Mono) << 0x00000001u |
|
496 |
<< int(QImage::Format_RGB32) << 0xffffffffu; |
|
497 |
QTest::newRow("red rgb16 -> argb32") << int(QImage::Format_RGB16) << 0xffff0000 |
|
498 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
499 |
QTest::newRow("green rgb16 -> argb32") << int(QImage::Format_RGB16) << 0xff00ff00 |
|
500 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
501 |
QTest::newRow("blue rgb16 -> argb32") << int(QImage::Format_RGB16) << 0xff0000ff |
|
502 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
503 |
QTest::newRow("red rgb16 -> rgb16") << int(QImage::Format_RGB32) << 0xffff0000 |
|
504 |
<< int(QImage::Format_RGB16) << 0xffff0000; |
|
505 |
QTest::newRow("green rgb16 -> rgb16") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
506 |
<< int(QImage::Format_RGB16) << 0xff00ff00; |
|
507 |
QTest::newRow("blue rgb16 -> rgb16") << int(QImage::Format_RGB32) << 0xff0000ff |
|
508 |
<< int(QImage::Format_RGB16) << 0xff0000ff; |
|
509 |
QTest::newRow("semired argb32 -> rgb16") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
510 |
<< int(QImage::Format_RGB16) << 0xffff0000; |
|
511 |
QTest::newRow("semigreen argb32 -> rgb16") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
512 |
<< int(QImage::Format_RGB16) << 0xff00ff00; |
|
513 |
QTest::newRow("semiblue argb32 -> rgb16") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
514 |
<< int(QImage::Format_RGB16) << 0xff0000ff; |
|
515 |
QTest::newRow("semired pm -> rgb16") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
516 |
<< int(QImage::Format_RGB16) << 0xffff0000u; |
|
517 |
||
518 |
QTest::newRow("semigreen pm -> rgb16") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
519 |
<< int(QImage::Format_RGB16) << 0xff00ff00u; |
|
520 |
QTest::newRow("semiblue pm -> rgb16") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
521 |
<< int(QImage::Format_RGB16) << 0xff0000ffu; |
|
522 |
QTest::newRow("semiwhite pm -> rgb16") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
523 |
<< int(QImage::Format_RGB16) << 0xffffffffu; |
|
524 |
QTest::newRow("semiblack pm -> rgb16") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
525 |
<< int(QImage::Format_RGB16) << 0xff000000u; |
|
526 |
||
527 |
QTest::newRow("mono -> mono lsb") << int(QImage::Format_Mono) << 1u |
|
528 |
<< int(QImage::Format_MonoLSB) << 0xffffffffu; |
|
529 |
QTest::newRow("mono lsb -> mono") << int(QImage::Format_MonoLSB) << 1u |
|
530 |
<< int(QImage::Format_Mono) << 0xffffffffu; |
|
531 |
||
532 |
QTest::newRow("red rgb32 -> rgb666") << int(QImage::Format_RGB32) << 0xffff0000 |
|
533 |
<< int(QImage::Format_RGB666) << 0xffff0000; |
|
534 |
QTest::newRow("green rgb32 -> rgb666") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
535 |
<< int(QImage::Format_RGB666) << 0xff00ff00; |
|
536 |
QTest::newRow("blue rgb32 -> rgb666") << int(QImage::Format_RGB32) << 0xff0000ff |
|
537 |
<< int(QImage::Format_RGB666) << 0xff0000ff; |
|
538 |
||
539 |
QTest::newRow("red rgb16 -> rgb666") << int(QImage::Format_RGB16) << 0xffff0000 |
|
540 |
<< int(QImage::Format_RGB666) << 0xffff0000; |
|
541 |
QTest::newRow("green rgb16 -> rgb666") << int(QImage::Format_RGB16) << 0xff00ff00 |
|
542 |
<< int(QImage::Format_RGB666) << 0xff00ff00; |
|
543 |
QTest::newRow("blue rgb16 -> rgb666") << int(QImage::Format_RGB16) << 0xff0000ff |
|
544 |
<< int(QImage::Format_RGB666) << 0xff0000ff; |
|
545 |
||
546 |
QTest::newRow("red rgb32 -> rgb15") << int(QImage::Format_RGB32) << 0xffff0000 |
|
547 |
<< int(QImage::Format_RGB555) << 0xffff0000; |
|
548 |
QTest::newRow("green rgb32 -> rgb15") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
549 |
<< int(QImage::Format_RGB555) << 0xff00ff00; |
|
550 |
QTest::newRow("blue rgb32 -> rgb15") << int(QImage::Format_RGB32) << 0xff0000ff |
|
551 |
<< int(QImage::Format_RGB555) << 0xff0000ff; |
|
552 |
QTest::newRow("funky rgb32 -> rgb15") << int(QImage::Format_RGB32) << 0xfff0c080 |
|
553 |
<< int(QImage::Format_RGB555) << 0xfff7c684; |
|
554 |
||
555 |
QTest::newRow("red rgb16 -> rgb15") << int(QImage::Format_RGB16) << 0xffff0000 |
|
556 |
<< int(QImage::Format_RGB555) << 0xffff0000; |
|
557 |
QTest::newRow("green rgb16 -> rgb15") << int(QImage::Format_RGB16) << 0xff00ff00 |
|
558 |
<< int(QImage::Format_RGB555) << 0xff00ff00; |
|
559 |
QTest::newRow("blue rgb16 -> rgb15") << int(QImage::Format_RGB16) << 0xff0000ff |
|
560 |
<< int(QImage::Format_RGB555) << 0xff0000ff; |
|
561 |
QTest::newRow("funky rgb16 -> rgb15") << int(QImage::Format_RGB16) << 0xfff0c080 |
|
562 |
<< int(QImage::Format_RGB555) << 0xfff7c684; |
|
563 |
||
564 |
QTest::newRow("red rgb32 -> argb8565") << int(QImage::Format_RGB32) << 0xffff0000 |
|
565 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0xffff0000; |
|
566 |
QTest::newRow("green rgb32 -> argb8565") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
567 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0xff00ff00; |
|
568 |
QTest::newRow("blue rgb32 -> argb8565") << int(QImage::Format_RGB32) << 0xff0000ff |
|
569 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0xff0000ff; |
|
570 |
||
571 |
QTest::newRow("red rgb16 -> argb8565") << int(QImage::Format_RGB16) << 0xffff0000 |
|
572 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0xffff0000; |
|
573 |
QTest::newRow("green rgb16 -> argb8565") << int(QImage::Format_RGB16) << 0xff00ff00 |
|
574 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0xff00ff00; |
|
575 |
QTest::newRow("blue rgb16 -> argb8565") << int(QImage::Format_RGB16) << 0xff0000ff |
|
576 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0xff0000ff; |
|
577 |
||
578 |
QTest::newRow("red argb8565 -> argb32") << int(QImage::Format_ARGB8565_Premultiplied) << 0xffff0000 |
|
579 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
580 |
QTest::newRow("green argb8565 -> argb32") << int(QImage::Format_ARGB8565_Premultiplied) << 0xff00ff00 |
|
581 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
582 |
QTest::newRow("blue argb8565 -> argb32") << int(QImage::Format_ARGB8565_Premultiplied) << 0xff0000ff |
|
583 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
584 |
||
585 |
QTest::newRow("semired argb32 -> argb8565") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
586 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f7b0000u; |
|
587 |
QTest::newRow("semigreen argb32 -> argb8565") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
588 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f007d00u; |
|
589 |
QTest::newRow("semiblue argb32 -> argb8565") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
590 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f00007bu; |
|
591 |
||
592 |
QTest::newRow("semired pm -> argb8565") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
593 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f7b0000u; |
|
594 |
QTest::newRow("semigreen pm -> argb8565") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
595 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f007d00u; |
|
596 |
QTest::newRow("semiblue pm -> argb8565") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
597 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f00007bu; |
|
598 |
QTest::newRow("semiwhite pm -> argb8565") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
599 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f7b7d7bu; |
|
600 |
QTest::newRow("semiblack pm -> argb8565") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
601 |
<< int(QImage::Format_ARGB8565_Premultiplied) << 0x7f000000u; |
|
602 |
||
603 |
QTest::newRow("red rgb666 -> argb32") << int(QImage::Format_RGB666) << 0xffff0000 |
|
604 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
605 |
QTest::newRow("green rgb666 -> argb32") << int(QImage::Format_RGB666) << 0xff00ff00 |
|
606 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
607 |
QTest::newRow("blue rgb666 -> argb32") << int(QImage::Format_RGB666) << 0xff0000ff |
|
608 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
609 |
||
610 |
QTest::newRow("semired argb32 -> rgb666") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
611 |
<< int(QImage::Format_RGB666) << 0xffff0000; |
|
612 |
QTest::newRow("semigreen argb32 -> rgb666") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
613 |
<< int(QImage::Format_RGB666) << 0xff00ff00; |
|
614 |
QTest::newRow("semiblue argb32 -> rgb666") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
615 |
<< int(QImage::Format_RGB666) << 0xff0000ff; |
|
616 |
||
617 |
QTest::newRow("semired pm -> rgb666") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
618 |
<< int(QImage::Format_RGB666) << 0xffff0000u; |
|
619 |
QTest::newRow("semigreen pm -> rgb666") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
620 |
<< int(QImage::Format_RGB666) << 0xff00ff00u; |
|
621 |
QTest::newRow("semiblue pm -> rgb666") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
622 |
<< int(QImage::Format_RGB666) << 0xff0000ffu; |
|
623 |
QTest::newRow("semiwhite pm -> rgb666") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
624 |
<< int(QImage::Format_RGB666) << 0xffffffffu; |
|
625 |
QTest::newRow("semiblack pm -> rgb666") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
626 |
<< int(QImage::Format_RGB666) << 0xff000000u; |
|
627 |
||
628 |
QTest::newRow("red rgb15 -> argb32") << int(QImage::Format_RGB555) << 0xffff0000 |
|
629 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
630 |
QTest::newRow("green rgb15 -> argb32") << int(QImage::Format_RGB555) << 0xff00ff00 |
|
631 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
632 |
QTest::newRow("blue rgb15 -> argb32") << int(QImage::Format_RGB555) << 0xff0000ff |
|
633 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
634 |
||
635 |
QTest::newRow("semired argb32 -> rgb15") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
636 |
<< int(QImage::Format_RGB555) << 0xffff0000; |
|
637 |
QTest::newRow("semigreen argb32 -> rgb15") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
638 |
<< int(QImage::Format_RGB555) << 0xff00ff00; |
|
639 |
QTest::newRow("semiblue argb32 -> rgb15") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
640 |
<< int(QImage::Format_RGB555) << 0xff0000ff; |
|
641 |
||
642 |
QTest::newRow("semired pm -> rgb15") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
643 |
<< int(QImage::Format_RGB555) << 0xffff0000u; |
|
644 |
QTest::newRow("semigreen pm -> rgb15") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
645 |
<< int(QImage::Format_RGB555) << 0xff00ff00u; |
|
646 |
QTest::newRow("semiblue pm -> rgb15") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
647 |
<< int(QImage::Format_RGB555) << 0xff0000ffu; |
|
648 |
QTest::newRow("semiwhite pm -> rgb15") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
649 |
<< int(QImage::Format_RGB555) << 0xffffffffu; |
|
650 |
QTest::newRow("semiblack pm -> rgb15") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
651 |
<< int(QImage::Format_RGB555) << 0xff000000u; |
|
652 |
||
653 |
||
654 |
QTest::newRow("red rgb32 -> argb8555") << int(QImage::Format_RGB32) << 0xffff0000 |
|
655 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0xffff0000; |
|
656 |
QTest::newRow("green rgb32 -> argb8555") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
657 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0xff00ff00; |
|
658 |
QTest::newRow("blue rgb32 -> argb8555") << int(QImage::Format_RGB32) << 0xff0000ff |
|
659 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0xff0000ff; |
|
660 |
||
661 |
QTest::newRow("red rgb16 -> argb8555") << int(QImage::Format_RGB16) << 0xffff0000 |
|
662 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0xffff0000; |
|
663 |
QTest::newRow("green rgb16 -> argb8555") << int(QImage::Format_RGB16) << 0xff00ff00 |
|
664 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0xff00ff00; |
|
665 |
QTest::newRow("blue rgb16 -> argb8555") << int(QImage::Format_RGB16) << 0xff0000ff |
|
666 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0xff0000ff; |
|
667 |
||
668 |
QTest::newRow("red argb8555 -> argb32") << int(QImage::Format_ARGB8555_Premultiplied) << 0xffff0000 |
|
669 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
670 |
QTest::newRow("green argb8555 -> argb32") << int(QImage::Format_ARGB8555_Premultiplied) << 0xff00ff00 |
|
671 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
672 |
QTest::newRow("blue argb8555 -> argb32") << int(QImage::Format_ARGB8555_Premultiplied) << 0xff0000ff |
|
673 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
674 |
||
675 |
QTest::newRow("semired argb32 -> argb8555") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
676 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f7b0000u; |
|
677 |
QTest::newRow("semigreen argb32 -> argb8555") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
678 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f007b00u; |
|
679 |
QTest::newRow("semiblue argb32 -> argb8555") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
680 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f00007bu; |
|
681 |
||
682 |
QTest::newRow("semired pm -> argb8555") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
683 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f7b0000u; |
|
684 |
QTest::newRow("semigreen pm -> argb8555") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
685 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f007b00u; |
|
686 |
QTest::newRow("semiblue pm -> argb8555") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
687 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f00007bu; |
|
688 |
QTest::newRow("semiwhite pm -> argb8555") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
689 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f7b7b7bu; |
|
690 |
QTest::newRow("semiblack pm -> argb8555") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
691 |
<< int(QImage::Format_ARGB8555_Premultiplied) << 0x7f000000u; |
|
692 |
||
693 |
QTest::newRow("red rgb32 -> rgb888") << int(QImage::Format_RGB32) << 0xffff0000 |
|
694 |
<< int(QImage::Format_RGB888) << 0xffff0000; |
|
695 |
QTest::newRow("green rgb32 -> rgb888") << int(QImage::Format_RGB32) << 0xff00ff00 |
|
696 |
<< int(QImage::Format_RGB888) << 0xff00ff00; |
|
697 |
QTest::newRow("blue rgb32 -> rgb888") << int(QImage::Format_RGB32) << 0xff0000ff |
|
698 |
<< int(QImage::Format_RGB888) << 0xff0000ff; |
|
699 |
||
700 |
QTest::newRow("red rgb16 -> rgb888") << int(QImage::Format_RGB16) << 0xffff0000 |
|
701 |
<< int(QImage::Format_RGB888) << 0xffff0000; |
|
702 |
QTest::newRow("green rgb16 -> rgb888") << int(QImage::Format_RGB16) << 0xff00ff00 |
|
703 |
<< int(QImage::Format_RGB888) << 0xff00ff00; |
|
704 |
QTest::newRow("blue rgb16 -> rgb888") << int(QImage::Format_RGB16) << 0xff0000ff |
|
705 |
<< int(QImage::Format_RGB888) << 0xff0000ff; |
|
706 |
||
707 |
QTest::newRow("red rgb888 -> argb32") << int(QImage::Format_RGB888) << 0xffff0000 |
|
708 |
<< int(QImage::Format_ARGB32) << 0xffff0000; |
|
709 |
QTest::newRow("green rgb888 -> argb32") << int(QImage::Format_RGB888) << 0xff00ff00 |
|
710 |
<< int(QImage::Format_ARGB32) << 0xff00ff00; |
|
711 |
QTest::newRow("blue rgb888 -> argb32") << int(QImage::Format_RGB888) << 0xff0000ff |
|
712 |
<< int(QImage::Format_ARGB32) << 0xff0000ff; |
|
713 |
||
714 |
QTest::newRow("semired argb32 -> rgb888") << int(QImage::Format_ARGB32) << 0x7fff0000u |
|
715 |
<< int(QImage::Format_RGB888) << 0xffff0000; |
|
716 |
QTest::newRow("semigreen argb32 -> rgb888") << int(QImage::Format_ARGB32) << 0x7f00ff00u |
|
717 |
<< int(QImage::Format_RGB888) << 0xff00ff00; |
|
718 |
QTest::newRow("semiblue argb32 -> rgb888") << int(QImage::Format_ARGB32) << 0x7f0000ffu |
|
719 |
<< int(QImage::Format_RGB888) << 0xff0000ff; |
|
720 |
||
721 |
QTest::newRow("semired pm -> rgb888") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f0000u |
|
722 |
<< int(QImage::Format_RGB888) << 0xffff0000u; |
|
723 |
QTest::newRow("semigreen pm -> rgb888") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f007f00u |
|
724 |
<< int(QImage::Format_RGB888) << 0xff00ff00u; |
|
725 |
QTest::newRow("semiblue pm -> rgb888") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f00007fu |
|
726 |
<< int(QImage::Format_RGB888) << 0xff0000ffu; |
|
727 |
QTest::newRow("semiwhite pm -> rgb888") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu |
|
728 |
<< int(QImage::Format_RGB888) << 0xffffffffu; |
|
729 |
QTest::newRow("semiblack pm -> rgb888") << int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u |
|
730 |
<< int(QImage::Format_RGB888) << 0xff000000u; |
|
731 |
} |
|
732 |
||
733 |
||
734 |
void tst_QImage::convertToFormat() |
|
735 |
{ |
|
736 |
QFETCH(int, inFormat); |
|
737 |
QFETCH(uint, inPixel); |
|
738 |
QFETCH(int, resFormat); |
|
739 |
QFETCH(uint, resPixel); |
|
740 |
||
741 |
QImage src(32, 32, QImage::Format(inFormat)); |
|
742 |
||
743 |
if (inFormat == QImage::Format_Mono) { |
|
744 |
src.setColor(0, qRgba(0,0,0,0xff)); |
|
745 |
src.setColor(1, qRgba(255,255,255,0xff)); |
|
746 |
} |
|
747 |
||
748 |
for (int y=0; y<src.height(); ++y) |
|
749 |
for (int x=0; x<src.width(); ++x) |
|
750 |
src.setPixel(x, y, inPixel); |
|
751 |
||
752 |
QImage result = src.convertToFormat(QImage::Format(resFormat)); |
|
753 |
||
754 |
QCOMPARE(src.width(), result.width()); |
|
755 |
QCOMPARE(src.height(), result.height()); |
|
756 |
||
757 |
bool same = true; |
|
758 |
for (int y=0; y<result.height(); ++y) { |
|
759 |
for (int x=0; x<result.width(); ++x) { |
|
760 |
QRgb pixel = result.pixel(x, y); |
|
761 |
same &= (pixel == resPixel); |
|
762 |
if (!same) { |
|
763 |
printf("expect=%08x, result=%08x\n", resPixel, pixel); |
|
764 |
y = 100000; |
|
765 |
break; |
|
766 |
} |
|
767 |
||
768 |
} |
|
769 |
} |
|
770 |
QVERIFY(same); |
|
771 |
||
772 |
// repeat tests converting from an image with nonstandard stride |
|
773 |
||
774 |
int dp = (src.depth() < 8 || result.depth() < 8) ? 8 : 1; |
|
775 |
QImage src2(src.bits() + (dp*src.depth())/8, |
|
776 |
src.width() - dp*2, |
|
777 |
src.height(), src.bytesPerLine(), |
|
778 |
src.format()); |
|
779 |
if (src.depth() < 8) |
|
780 |
src2.setColorTable(src.colorTable()); |
|
781 |
||
782 |
const QImage result2 = src2.convertToFormat(QImage::Format(resFormat)); |
|
783 |
||
784 |
QCOMPARE(src2.width(), result2.width()); |
|
785 |
QCOMPARE(src2.height(), result2.height()); |
|
786 |
||
787 |
QImage expected2(result.bits() + (dp*result.depth())/8, |
|
788 |
result.width() - dp*2, |
|
789 |
result.height(), result.bytesPerLine(), |
|
790 |
result.format()); |
|
791 |
if (result.depth() < 8) |
|
792 |
expected2.setColorTable(result.colorTable()); |
|
793 |
||
794 |
result2.save("result2.xpm", "XPM"); |
|
795 |
expected2.save("expected2.xpm", "XPM"); |
|
796 |
||
797 |
QCOMPARE(result2, expected2); |
|
798 |
QFile::remove(QLatin1String("result2.xpm")); |
|
799 |
QFile::remove(QLatin1String("expected2.xpm")); |
|
800 |
} |
|
801 |
||
802 |
void tst_QImage::createAlphaMask_data() |
|
803 |
{ |
|
804 |
QTest::addColumn<int>("x"); |
|
805 |
QTest::addColumn<int>("y"); |
|
806 |
QTest::addColumn<int>("alpha1"); |
|
807 |
QTest::addColumn<int>("alpha2"); |
|
808 |
||
809 |
int alphas[] = { 0, 127, 255 }; |
|
810 |
||
811 |
for (unsigned a1 = 0; a1 < sizeof(alphas) / sizeof(int); ++a1) { |
|
812 |
for (unsigned a2 = 0; a2 < sizeof(alphas) / sizeof(int); ++a2) { |
|
813 |
if (a1 == a2) |
|
814 |
continue; |
|
815 |
for (int x=10; x<18; x+=3) { |
|
816 |
for (int y=100; y<108; y+=3) { |
|
817 |
QTest::newRow(qPrintable(QString::fromLatin1("x=%1, y=%2, a1=%3, a2=%4").arg(x).arg(y).arg(alphas[a1]).arg(alphas[a2]))) |
|
818 |
<< x << y << alphas[a1] << alphas[a2]; |
|
819 |
} |
|
820 |
} |
|
821 |
} |
|
822 |
} |
|
823 |
} |
|
824 |
||
825 |
void tst_QImage::createAlphaMask() |
|
826 |
{ |
|
827 |
QFETCH(int, x); |
|
828 |
QFETCH(int, y); |
|
829 |
QFETCH(int, alpha1); |
|
830 |
QFETCH(int, alpha2); |
|
831 |
||
832 |
QSize size(255, 255); |
|
833 |
int pixelsInLines = size.width() + size.height() - 1; |
|
834 |
int pixelsOutofLines = size.width() * size.height() - pixelsInLines; |
|
835 |
||
836 |
// Generate an white image with two lines, horizontal at y and vertical at x. |
|
837 |
// Lines have alpha of alpha2, rest has alpha of alpha1 |
|
838 |
QImage image(size, QImage::Format_ARGB32); |
|
839 |
for (int cy=0; cy<image.height(); ++cy) { |
|
840 |
for (int cx=0; cx<image.width(); ++cx) { |
|
841 |
int alpha = (y == cy || x == cx) ? alpha2 : alpha1; |
|
842 |
image.setPixel(cx, cy, qRgba(255, 255, 255, alpha)); |
|
843 |
} |
|
844 |
} |
|
845 |
||
846 |
QImage mask = image.createAlphaMask(Qt::OrderedAlphaDither); |
|
847 |
||
848 |
// Sanity check... |
|
849 |
QCOMPARE(mask.width(), image.width()); |
|
850 |
QCOMPARE(mask.height(), image.height()); |
|
851 |
||
852 |
// Sum up the number of pixels set for both lines and other area |
|
853 |
int sumAlpha1 = 0; |
|
854 |
int sumAlpha2 = 0; |
|
855 |
for (int cy=0; cy<image.height(); ++cy) { |
|
856 |
for (int cx=0; cx<image.width(); ++cx) { |
|
857 |
int *alpha = (y == cy || x == cx) ? &sumAlpha2 : &sumAlpha1; |
|
858 |
*alpha += mask.pixelIndex(cx, cy); |
|
859 |
} |
|
860 |
} |
|
861 |
||
862 |
// Compare the set bits to whats expected for that alpha. |
|
863 |
const int threshold = 5; |
|
864 |
QVERIFY(qAbs(sumAlpha1 * 255 / pixelsOutofLines - alpha1) < threshold); |
|
865 |
QVERIFY(qAbs(sumAlpha2 * 255 / pixelsInLines - alpha2) < threshold); |
|
866 |
} |
|
867 |
||
868 |
void tst_QImage::dotsPerMeterZero() |
|
869 |
{ |
|
870 |
QImage img(100, 100, QImage::Format_RGB32); |
|
871 |
QVERIFY(!img.isNull()); |
|
872 |
||
873 |
int defaultDpmX = img.dotsPerMeterX(); |
|
874 |
int defaultDpmY = img.dotsPerMeterY(); |
|
875 |
QVERIFY(defaultDpmX != 0); |
|
876 |
QVERIFY(defaultDpmY != 0); |
|
877 |
||
878 |
img.setDotsPerMeterX(0); |
|
879 |
img.setDotsPerMeterY(0); |
|
880 |
||
881 |
QCOMPARE(img.dotsPerMeterX(), defaultDpmX); |
|
882 |
QCOMPARE(img.dotsPerMeterY(), defaultDpmY); |
|
883 |
} |
|
884 |
||
885 |
void tst_QImage::rotate_data() |
|
886 |
{ |
|
887 |
QTest::addColumn<QImage::Format>("format"); |
|
888 |
QTest::addColumn<int>("degrees"); |
|
889 |
||
890 |
QVector<int> degrees; |
|
891 |
degrees << 0 << 90 << 180 << 270; |
|
892 |
||
893 |
foreach (int d, degrees) { |
|
894 |
QString title = QString("%1 %2").arg(d); |
|
895 |
QTest::newRow(qPrintable(title.arg("Format_RGB32"))) |
|
896 |
<< QImage::Format_RGB32 << d; |
|
897 |
QTest::newRow(qPrintable(title.arg("Format_ARGB32"))) |
|
898 |
<< QImage::Format_ARGB32 << d; |
|
899 |
QTest::newRow(qPrintable(title.arg("Format_ARGB32_Premultiplied"))) |
|
900 |
<< QImage::Format_ARGB32_Premultiplied << d; |
|
901 |
QTest::newRow(qPrintable(title.arg("Format_RGB16"))) |
|
902 |
<< QImage::Format_RGB16 << d; |
|
903 |
QTest::newRow(qPrintable(title.arg("Format_ARGB8565_Premultiplied"))) |
|
904 |
<< QImage::Format_ARGB8565_Premultiplied << d; |
|
905 |
QTest::newRow(qPrintable(title.arg("Format_RGB666"))) |
|
906 |
<< QImage::Format_RGB666 << d; |
|
907 |
QTest::newRow(qPrintable(title.arg("Format_RGB555"))) |
|
908 |
<< QImage::Format_RGB555 << d; |
|
909 |
QTest::newRow(qPrintable(title.arg("Format_ARGB8555_Premultiplied"))) |
|
910 |
<< QImage::Format_ARGB8555_Premultiplied << d; |
|
911 |
QTest::newRow(qPrintable(title.arg("Format_RGB888"))) |
|
912 |
<< QImage::Format_RGB888 << d; |
|
913 |
QTest::newRow(qPrintable(title.arg("Format_Indexed8"))) |
|
914 |
<< QImage::Format_Indexed8 << d; |
|
915 |
} |
|
916 |
} |
|
917 |
||
918 |
void tst_QImage::rotate() |
|
919 |
{ |
|
920 |
QFETCH(QImage::Format, format); |
|
921 |
QFETCH(int, degrees); |
|
922 |
||
923 |
// test if rotate90 is lossless |
|
924 |
int w = 54; |
|
925 |
int h = 13; |
|
926 |
QImage original(w, h, format); |
|
927 |
original.fill(qRgb(255,255,255)); |
|
928 |
||
929 |
if (format == QImage::Format_Indexed8) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
930 |
original.setColorCount(256); |
0 | 931 |
for (int i = 0; i < 255; ++i) |
932 |
original.setColor(i, qRgb(0, i, i)); |
|
933 |
} |
|
934 |
||
935 |
if (original.colorTable().isEmpty()) { |
|
936 |
for (int x = 0; x < w; ++x) { |
|
937 |
original.setPixel(x,0, qRgb(x,0,128)); |
|
938 |
original.setPixel(x,h - 1, qRgb(0,255 - x,128)); |
|
939 |
} |
|
940 |
for (int y = 0; y < h; ++y) { |
|
941 |
original.setPixel(0, y, qRgb(y,0,255)); |
|
942 |
original.setPixel(w - 1, y, qRgb(0,255 - y,255)); |
|
943 |
} |
|
944 |
} else { |
|
945 |
const int n = original.colorTable().size(); |
|
946 |
for (int x = 0; x < w; ++x) { |
|
947 |
original.setPixel(x, 0, x % n); |
|
948 |
original.setPixel(x,h - 1, n - (x % n)); |
|
949 |
} |
|
950 |
for (int y = 0; y < h; ++y) { |
|
951 |
original.setPixel(0, y, y % n); |
|
952 |
original.setPixel(w - 1, y, n - (y % n)); |
|
953 |
} |
|
954 |
} |
|
955 |
||
956 |
// original.save("rotated90_original.png", "png"); |
|
957 |
||
958 |
// Initialize the matrix manually (do not use rotate) to avoid rounding errors |
|
959 |
QMatrix matRotate90; |
|
960 |
matRotate90.rotate(degrees); |
|
961 |
QImage dest = original; |
|
962 |
// And rotate it 4 times, then the image should be identical to the original |
|
963 |
for (int i = 0; i < 4 ; ++i) { |
|
964 |
dest = dest.transformed(matRotate90); |
|
965 |
} |
|
966 |
||
967 |
// Make sure they are similar in format before we compare them. |
|
968 |
dest = dest.convertToFormat(format); |
|
969 |
||
970 |
// dest.save("rotated90_result.png","png"); |
|
971 |
QCOMPARE(original, dest); |
|
972 |
||
973 |
// Test with QMatrix::rotate 90 also, since we trust that now |
|
974 |
matRotate90.rotate(degrees); |
|
975 |
dest = original; |
|
976 |
// And rotate it 4 times, then the image should be identical to the original |
|
977 |
for (int i = 0; i < 4 ; ++i) { |
|
978 |
dest = dest.transformed(matRotate90); |
|
979 |
} |
|
980 |
||
981 |
// Make sure they are similar in format before we compare them. |
|
982 |
dest = dest.convertToFormat(format); |
|
983 |
||
984 |
QCOMPARE(original, dest); |
|
985 |
} |
|
986 |
||
987 |
void tst_QImage::copy() |
|
988 |
{ |
|
989 |
// Task 99250 |
|
990 |
{ |
|
991 |
QImage img(16,16,QImage::Format_ARGB32); |
|
992 |
img.copy(QRect(1000,1,1,1)); |
|
993 |
} |
|
994 |
} |
|
995 |
||
996 |
void tst_QImage::setPixel_data() |
|
997 |
{ |
|
998 |
QTest::addColumn<int>("format"); |
|
999 |
QTest::addColumn<uint>("value"); |
|
1000 |
QTest::addColumn<uint>("expected"); |
|
1001 |
||
1002 |
QTest::newRow("ARGB32 red") << int(QImage::Format_ARGB32) |
|
1003 |
<< 0xffff0000 << 0xffff0000; |
|
1004 |
QTest::newRow("ARGB32 green") << int(QImage::Format_ARGB32) |
|
1005 |
<< 0xff00ff00 << 0xff00ff00; |
|
1006 |
QTest::newRow("ARGB32 blue") << int(QImage::Format_ARGB32) |
|
1007 |
<< 0xff0000ff << 0xff0000ff; |
|
1008 |
QTest::newRow("RGB16 red") << int(QImage::Format_RGB16) |
|
1009 |
<< 0xffff0000 << 0xf800u; |
|
1010 |
QTest::newRow("RGB16 green") << int(QImage::Format_RGB16) |
|
1011 |
<< 0xff00ff00 << 0x07e0u; |
|
1012 |
QTest::newRow("RGB16 blue") << int(QImage::Format_RGB16) |
|
1013 |
<< 0xff0000ff << 0x001fu; |
|
1014 |
QTest::newRow("ARGB8565_Premultiplied red") << int(QImage::Format_ARGB8565_Premultiplied) |
|
1015 |
<< 0xffff0000 << 0xffff0000; |
|
1016 |
QTest::newRow("ARGB8565_Premultiplied green") << int(QImage::Format_ARGB8565_Premultiplied) |
|
1017 |
<< 0xff00ff00 << 0xff00ff00; |
|
1018 |
QTest::newRow("ARGB8565_Premultiplied blue") << int(QImage::Format_ARGB8565_Premultiplied) |
|
1019 |
<< 0xff0000ff << 0xff0000ff; |
|
1020 |
QTest::newRow("RGB666 red") << int(QImage::Format_RGB666) |
|
1021 |
<< 0xffff0000 << 0xffff0000; |
|
1022 |
QTest::newRow("RGB666 green") << int(QImage::Format_RGB666) |
|
1023 |
<< 0xff00ff00 << 0xff00ff00;; |
|
1024 |
QTest::newRow("RGB666 blue") << int(QImage::Format_RGB666) |
|
1025 |
<< 0xff0000ff << 0xff0000ff; |
|
1026 |
QTest::newRow("RGB555 red") << int(QImage::Format_RGB555) |
|
1027 |
<< 0xffff0000 << 0x7c00u; |
|
1028 |
QTest::newRow("RGB555 green") << int(QImage::Format_RGB555) |
|
1029 |
<< 0xff00ff00 << 0x03e0u; |
|
1030 |
QTest::newRow("RGB555 blue") << int(QImage::Format_RGB555) |
|
1031 |
<< 0xff0000ff << 0x001fu; |
|
1032 |
QTest::newRow("ARGB8555_Premultiplied red") << int(QImage::Format_ARGB8555_Premultiplied) |
|
1033 |
<< 0xffff0000 << 0xffff0000; |
|
1034 |
QTest::newRow("ARGB8555_Premultiplied green") << int(QImage::Format_ARGB8555_Premultiplied) |
|
1035 |
<< 0xff00ff00 << 0xff00ff00; |
|
1036 |
QTest::newRow("ARGB8555_Premultiplied blue") << int(QImage::Format_ARGB8555_Premultiplied) |
|
1037 |
<< 0xff0000ff << 0xff0000ff; |
|
1038 |
QTest::newRow("RGB888 red") << int(QImage::Format_RGB888) |
|
1039 |
<< 0xffff0000 << 0xffff0000; |
|
1040 |
QTest::newRow("RGB888 green") << int(QImage::Format_RGB888) |
|
1041 |
<< 0xff00ff00 << 0xff00ff00; |
|
1042 |
QTest::newRow("RGB888 blue") << int(QImage::Format_RGB888) |
|
1043 |
<< 0xff0000ff << 0xff0000ff; |
|
1044 |
} |
|
1045 |
||
1046 |
void tst_QImage::setPixel() |
|
1047 |
{ |
|
1048 |
QFETCH(int, format); |
|
1049 |
QFETCH(uint, value); |
|
1050 |
QFETCH(uint, expected); |
|
1051 |
||
1052 |
const int w = 13; |
|
1053 |
const int h = 15; |
|
1054 |
||
1055 |
QImage img(w, h, QImage::Format(format)); |
|
1056 |
||
1057 |
// fill image |
|
1058 |
for (int y = 0; y < h; ++y) |
|
1059 |
for (int x = 0; x < w; ++x) |
|
1060 |
img.setPixel(x, y, value); |
|
1061 |
||
1062 |
// check pixel values |
|
1063 |
switch (format) { |
|
1064 |
case int(QImage::Format_RGB32): |
|
1065 |
case int(QImage::Format_ARGB32): |
|
1066 |
case int(QImage::Format_ARGB32_Premultiplied): |
|
1067 |
{ |
|
1068 |
for (int y = 0; y < h; ++y) { |
|
1069 |
const quint32 *row = (const quint32*)(img.scanLine(y)); |
|
1070 |
for (int x = 0; x < w; ++x) { |
|
1071 |
quint32 result = row[x]; |
|
1072 |
if (result != expected) |
|
1073 |
printf("[x,y]: %d,%d, expected=%08x, result=%08x\n", |
|
1074 |
x, y, expected, result); |
|
1075 |
QCOMPARE(uint(result), expected); |
|
1076 |
} |
|
1077 |
} |
|
1078 |
break; |
|
1079 |
} |
|
1080 |
case int(QImage::Format_RGB555): |
|
1081 |
case int(QImage::Format_RGB16): |
|
1082 |
{ |
|
1083 |
for (int y = 0; y < h; ++y) { |
|
1084 |
const quint16 *row = (const quint16*)(img.scanLine(y)); |
|
1085 |
for (int x = 0; x < w; ++x) { |
|
1086 |
quint16 result = row[x]; |
|
1087 |
if (result != expected) |
|
1088 |
printf("[x,y]: %d,%d, expected=%04x, result=%04x\n", |
|
1089 |
x, y, expected, result); |
|
1090 |
QCOMPARE(uint(result), expected); |
|
1091 |
} |
|
1092 |
} |
|
1093 |
break; |
|
1094 |
} |
|
1095 |
case int(QImage::Format_RGB666): |
|
1096 |
{ |
|
1097 |
for (int y = 0; y < h; ++y) { |
|
1098 |
const qrgb666 *row = (const qrgb666*)(img.scanLine(y)); |
|
1099 |
for (int x = 0; x < w; ++x) { |
|
1100 |
quint32 result = row[x]; |
|
1101 |
if (result != expected) |
|
1102 |
printf("[x,y]: %d,%d, expected=%04x, result=%04x\n", |
|
1103 |
x, y, expected, result); |
|
1104 |
QCOMPARE(result, expected); |
|
1105 |
} |
|
1106 |
} |
|
1107 |
break; |
|
1108 |
} |
|
1109 |
case int(QImage::Format_ARGB8565_Premultiplied): |
|
1110 |
{ |
|
1111 |
for (int y = 0; y < h; ++y) { |
|
1112 |
const qargb8565 *row = (const qargb8565*)(img.scanLine(y)); |
|
1113 |
for (int x = 0; x < w; ++x) { |
|
1114 |
quint32 result = row[x]; |
|
1115 |
if (result != expected) |
|
1116 |
printf("[x,y]: %d,%d, expected=%04x, result=%04x\n", |
|
1117 |
x, y, expected, result); |
|
1118 |
QCOMPARE(result, expected); |
|
1119 |
} |
|
1120 |
} |
|
1121 |
break; |
|
1122 |
} |
|
1123 |
case int(QImage::Format_ARGB8555_Premultiplied): |
|
1124 |
{ |
|
1125 |
for (int y = 0; y < h; ++y) { |
|
1126 |
const qargb8555 *row = (const qargb8555*)(img.scanLine(y)); |
|
1127 |
for (int x = 0; x < w; ++x) { |
|
1128 |
quint32 result = row[x]; |
|
1129 |
if (result != expected) |
|
1130 |
printf("[x,y]: %d,%d, expected=%04x, result=%04x\n", |
|
1131 |
x, y, expected, result); |
|
1132 |
QCOMPARE(result, expected); |
|
1133 |
} |
|
1134 |
} |
|
1135 |
break; |
|
1136 |
} |
|
1137 |
case int(QImage::Format_RGB888): |
|
1138 |
{ |
|
1139 |
for (int y = 0; y < h; ++y) { |
|
1140 |
const qrgb888 *row = (const qrgb888*)(img.scanLine(y)); |
|
1141 |
for (int x = 0; x < w; ++x) { |
|
1142 |
qrgb888 result = row[x]; |
|
1143 |
if (result != expected) |
|
1144 |
printf("[x,y]: %d,%d, expected=%04x, result=%04x\n", |
|
1145 |
x, y, expected, quint32(result)); |
|
1146 |
QCOMPARE(uint(result), expected); |
|
1147 |
} |
|
1148 |
} |
|
1149 |
break; |
|
1150 |
} |
|
1151 |
default: |
|
1152 |
qFatal("Test not implemented for format %d", format); |
|
1153 |
} |
|
1154 |
} |
|
1155 |
||
1156 |
void tst_QImage::convertToFormatPreserveDotsPrMeter() |
|
1157 |
{ |
|
1158 |
QImage img(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
1159 |
||
1160 |
int dpmx = 123; |
|
1161 |
int dpmy = 234; |
|
1162 |
img.setDotsPerMeterX(dpmx); |
|
1163 |
img.setDotsPerMeterY(dpmy); |
|
1164 |
img.fill(0x12345678); |
|
1165 |
||
1166 |
img = img.convertToFormat(QImage::Format_RGB32); |
|
1167 |
||
1168 |
QCOMPARE(img.dotsPerMeterX(), dpmx); |
|
1169 |
QCOMPARE(img.dotsPerMeterY(), dpmy); |
|
1170 |
} |
|
1171 |
||
1172 |
#ifndef QT_NO_IMAGE_TEXT |
|
1173 |
void tst_QImage::convertToFormatPreserveText() |
|
1174 |
{ |
|
1175 |
QImage img(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
1176 |
||
1177 |
img.setText("foo", "bar"); |
|
1178 |
img.setText("foo2", "bar2"); |
|
1179 |
img.fill(0x12345678); |
|
1180 |
||
1181 |
QStringList listResult; |
|
1182 |
listResult << "foo" << "foo2"; |
|
1183 |
QString result = "foo: bar\n\nfoo2: bar2"; |
|
1184 |
||
1185 |
QImage imgResult1 = img.convertToFormat(QImage::Format_RGB32); |
|
1186 |
QCOMPARE(imgResult1.text(), result); |
|
1187 |
QCOMPARE(imgResult1.textKeys(), listResult); |
|
1188 |
||
1189 |
QVector<QRgb> colorTable(4); |
|
1190 |
for (int i = 0; i < 4; ++i) |
|
1191 |
colorTable[i] = QRgb(42); |
|
1192 |
QImage imgResult2 = img.convertToFormat(QImage::Format_MonoLSB, |
|
1193 |
colorTable); |
|
1194 |
QCOMPARE(imgResult2.text(), result); |
|
1195 |
QCOMPARE(imgResult2.textKeys(), listResult); |
|
1196 |
} |
|
1197 |
#endif // QT_NO_IMAGE_TEXT |
|
1198 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1199 |
void tst_QImage::setColorCount() |
0 | 1200 |
{ |
1201 |
QImage img(0, 0, QImage::Format_Indexed8); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1202 |
QTest::ignoreMessage(QtWarningMsg, "QImage::setColorCount: null image"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1203 |
img.setColorCount(256); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
QCOMPARE(img.colorCount(), 0); |
0 | 1205 |
} |
1206 |
||
1207 |
void tst_QImage::setColor() |
|
1208 |
{ |
|
1209 |
QImage img(0, 0, QImage::Format_Indexed8); |
|
1210 |
img.setColor(0, qRgba(18, 219, 108, 128)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1211 |
QCOMPARE(img.colorCount(), 0); |
0 | 1212 |
|
1213 |
QImage img2(1, 1, QImage::Format_Indexed8); |
|
1214 |
img2.setColor(0, qRgba(18, 219, 108, 128)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
QCOMPARE(img2.colorCount(), 1); |
0 | 1216 |
} |
1217 |
||
1218 |
/* Just some sanity checking that we don't draw outside the buffer of |
|
1219 |
* the image. Hopefully this will create crashes or at least some |
|
1220 |
* random test fails when broken. |
|
1221 |
*/ |
|
1222 |
void tst_QImage::rasterClipping() |
|
1223 |
{ |
|
1224 |
QImage image(10, 10, QImage::Format_RGB32); |
|
1225 |
image.fill(0xffffffff); |
|
1226 |
||
1227 |
QPainter p(&image); |
|
1228 |
||
1229 |
p.drawLine(-1000, 5, 5, 5); |
|
1230 |
p.drawLine(-1000, 5, 1000, 5); |
|
1231 |
p.drawLine(5, 5, 1000, 5); |
|
1232 |
||
1233 |
p.drawLine(5, -1000, 5, 5); |
|
1234 |
p.drawLine(5, -1000, 5, 1000); |
|
1235 |
p.drawLine(5, 5, 5, 1000); |
|
1236 |
||
1237 |
p.setBrush(Qt::red); |
|
1238 |
||
1239 |
p.drawEllipse(3, 3, 4, 4); |
|
1240 |
p.drawEllipse(-100, -100, 210, 210); |
|
1241 |
||
1242 |
p.drawEllipse(-1000, 0, 2010, 2010); |
|
1243 |
p.drawEllipse(0, -1000, 2010, 2010); |
|
1244 |
p.drawEllipse(-2010, -1000, 2010, 2010); |
|
1245 |
p.drawEllipse(-1000, -2010, 2010, 2010); |
|
1246 |
QVERIFY(true); |
|
1247 |
} |
|
1248 |
||
1249 |
// Tests the new QPoint overloads in QImage in Qt 4.2 |
|
1250 |
void tst_QImage::pointOverloads() |
|
1251 |
{ |
|
1252 |
QImage image(100, 100, QImage::Format_RGB32); |
|
1253 |
image.fill(0xff00ff00); |
|
1254 |
||
1255 |
// IsValid |
|
1256 |
QVERIFY(image.valid(QPoint(0, 0))); |
|
1257 |
QVERIFY(image.valid(QPoint(99, 0))); |
|
1258 |
QVERIFY(image.valid(QPoint(0, 99))); |
|
1259 |
QVERIFY(image.valid(QPoint(99, 99))); |
|
1260 |
||
1261 |
QVERIFY(!image.valid(QPoint(50, -1))); // outside on the top |
|
1262 |
QVERIFY(!image.valid(QPoint(50, 100))); // outside on the bottom |
|
1263 |
QVERIFY(!image.valid(QPoint(-1, 50))); // outside on the left |
|
1264 |
QVERIFY(!image.valid(QPoint(100, 50))); // outside on the right |
|
1265 |
||
1266 |
// Test the pixel setter |
|
1267 |
image.setPixel(QPoint(10, 10), 0xff0000ff); |
|
1268 |
QCOMPARE(image.pixel(10, 10), 0xff0000ff); |
|
1269 |
||
1270 |
// pixel getter |
|
1271 |
QCOMPARE(image.pixel(QPoint(10, 10)), 0xff0000ff); |
|
1272 |
||
1273 |
// pixelIndex() |
|
1274 |
QImage indexed = image.convertToFormat(QImage::Format_Indexed8); |
|
1275 |
QCOMPARE(indexed.pixelIndex(10, 10), indexed.pixelIndex(QPoint(10, 10))); |
|
1276 |
} |
|
1277 |
||
1278 |
void tst_QImage::destructor() |
|
1279 |
{ |
|
1280 |
QPolygon poly(6); |
|
1281 |
poly.setPoint(0,-1455, 1435); |
|
1282 |
||
1283 |
QImage image(100, 100, QImage::Format_RGB32); |
|
1284 |
QPainter ptPix(&image); |
|
1285 |
ptPix.setPen(Qt::black); |
|
1286 |
ptPix.setBrush(Qt::black); |
|
1287 |
ptPix.drawPolygon(poly, Qt::WindingFill); |
|
1288 |
ptPix.end(); |
|
1289 |
||
1290 |
} |
|
1291 |
||
1292 |
||
1293 |
/* XPM */ |
|
1294 |
static const char *monoPixmap[] = { |
|
1295 |
/* width height ncolors chars_per_pixel */ |
|
1296 |
"4 4 2 1", |
|
1297 |
"x c #000000", |
|
1298 |
". c #ffffff", |
|
1299 |
/* pixels */ |
|
1300 |
"xxxx", |
|
1301 |
"x..x", |
|
1302 |
"x..x", |
|
1303 |
"xxxx" |
|
1304 |
}; |
|
1305 |
||
1306 |
||
1307 |
#ifndef QT_NO_IMAGE_HEURISTIC_MASK |
|
1308 |
void tst_QImage::createHeuristicMask() |
|
1309 |
{ |
|
1310 |
QImage img(monoPixmap); |
|
1311 |
img = img.convertToFormat(QImage::Format_MonoLSB); |
|
1312 |
QImage mask = img.createHeuristicMask(); |
|
1313 |
QImage newMask = mask.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
1314 |
||
1315 |
// line 2 |
|
1316 |
QVERIFY(newMask.pixel(0,1) != newMask.pixel(1,1)); |
|
1317 |
QVERIFY(newMask.pixel(1,1) == newMask.pixel(2,1)); |
|
1318 |
QVERIFY(newMask.pixel(2,1) != newMask.pixel(3,1)); |
|
1319 |
||
1320 |
// line 3 |
|
1321 |
QVERIFY(newMask.pixel(0,2) != newMask.pixel(1,2)); |
|
1322 |
QVERIFY(newMask.pixel(1,2) == newMask.pixel(2,2)); |
|
1323 |
QVERIFY(newMask.pixel(2,2) != newMask.pixel(3,2)); |
|
1324 |
} |
|
1325 |
#endif |
|
1326 |
||
1327 |
void tst_QImage::cacheKey() |
|
1328 |
{ |
|
1329 |
QImage image1(2, 2, QImage::Format_RGB32); |
|
1330 |
qint64 image1_key = image1.cacheKey(); |
|
1331 |
QImage image2 = image1; |
|
1332 |
||
1333 |
QVERIFY(image2.cacheKey() == image1.cacheKey()); |
|
1334 |
image2.detach(); |
|
1335 |
QVERIFY(image2.cacheKey() != image1.cacheKey()); |
|
1336 |
QVERIFY(image1.cacheKey() == image1_key); |
|
1337 |
} |
|
1338 |
||
1339 |
void tst_QImage::smoothScale() |
|
1340 |
{ |
|
1341 |
unsigned int data[2] = { qRgba(0, 0, 0, 0), qRgba(128, 128, 128, 128) }; |
|
1342 |
||
1343 |
QImage imgX((unsigned char *)data, 2, 1, QImage::Format_ARGB32_Premultiplied); |
|
1344 |
QImage imgY((unsigned char *)data, 1, 2, QImage::Format_ARGB32_Premultiplied); |
|
1345 |
||
1346 |
QImage scaledX = imgX.scaled(QSize(4, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1347 |
QImage scaledY = imgY.scaled(QSize(1, 4), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1348 |
||
1349 |
uint *scaled[2] = { |
|
1350 |
(unsigned int *)scaledX.bits(), |
|
1351 |
(unsigned int *)scaledY.bits() |
|
1352 |
}; |
|
1353 |
||
1354 |
int expected[4] = { 0, 32, 96, 128 }; |
|
1355 |
for (int image = 0; image < 2; ++image) { |
|
1356 |
for (int index = 0; index < 4; ++index) { |
|
1357 |
for (int component = 0; component < 4; ++component) { |
|
1358 |
int pixel = scaled[image][index]; |
|
1359 |
int val = (pixel >> (component * 8)) & 0xff; |
|
1360 |
||
1361 |
QCOMPARE(val, expected[index]); |
|
1362 |
} |
|
1363 |
} |
|
1364 |
} |
|
1365 |
} |
|
1366 |
||
1367 |
// test area sampling |
|
1368 |
void tst_QImage::smoothScale2() |
|
1369 |
{ |
|
1370 |
int sizes[] = { 2, 4, 8, 10, 16, 20, 32, 40, 64, 100, 101, 128, 0 }; |
|
1371 |
QImage::Format formats[] = { QImage::Format_ARGB32, QImage::Format_RGB32, QImage::Format_Invalid }; |
|
1372 |
for (int i = 0; sizes[i] != 0; ++i) { |
|
1373 |
for (int j = 0; formats[j] != QImage::Format_Invalid; ++j) { |
|
1374 |
int size = sizes[i]; |
|
1375 |
||
1376 |
QRgb expected = formats[j] == QImage::Format_ARGB32 ? qRgba(63, 127, 255, 255) : qRgb(63, 127, 255); |
|
1377 |
||
1378 |
QImage img(size, size, formats[j]); |
|
1379 |
img.fill(expected); |
|
1380 |
||
1381 |
// scale x down, y down |
|
1382 |
QImage scaled = img.scaled(QSize(1, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1383 |
QRgb pixel = scaled.pixel(0, 0); |
|
1384 |
QCOMPARE(qAlpha(pixel), qAlpha(expected)); |
|
1385 |
QCOMPARE(qRed(pixel), qRed(expected)); |
|
1386 |
QCOMPARE(qGreen(pixel), qGreen(expected)); |
|
1387 |
QCOMPARE(qBlue(pixel), qBlue(expected)); |
|
1388 |
||
1389 |
// scale x down, y up |
|
1390 |
scaled = img.scaled(QSize(1, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1391 |
for (int y = 0; y < scaled.height(); ++y) { |
|
1392 |
pixel = scaled.pixel(0, y); |
|
1393 |
QCOMPARE(qAlpha(pixel), qAlpha(expected)); |
|
1394 |
QCOMPARE(qRed(pixel), qRed(expected)); |
|
1395 |
QCOMPARE(qGreen(pixel), qGreen(expected)); |
|
1396 |
QCOMPARE(qBlue(pixel), qBlue(expected)); |
|
1397 |
} |
|
1398 |
||
1399 |
// scale x up, y down |
|
1400 |
scaled = img.scaled(QSize(size * 2, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1401 |
for (int x = 0; x < scaled.width(); ++x) { |
|
1402 |
pixel = scaled.pixel(x, 0); |
|
1403 |
QCOMPARE(qAlpha(pixel), qAlpha(expected)); |
|
1404 |
QCOMPARE(qRed(pixel), qRed(expected)); |
|
1405 |
QCOMPARE(qGreen(pixel), qGreen(expected)); |
|
1406 |
QCOMPARE(qBlue(pixel), qBlue(expected)); |
|
1407 |
} |
|
1408 |
||
1409 |
// scale x up, y up |
|
1410 |
scaled = img.scaled(QSize(size * 2, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1411 |
for (int y = 0; y < scaled.height(); ++y) { |
|
1412 |
for (int x = 0; x < scaled.width(); ++x) { |
|
1413 |
pixel = scaled.pixel(x, y); |
|
1414 |
QCOMPARE(qAlpha(pixel), qAlpha(expected)); |
|
1415 |
QCOMPARE(qRed(pixel), qRed(expected)); |
|
1416 |
QCOMPARE(qGreen(pixel), qGreen(expected)); |
|
1417 |
QCOMPARE(qBlue(pixel), qBlue(expected)); |
|
1418 |
} |
|
1419 |
} |
|
1420 |
} |
|
1421 |
} |
|
1422 |
} |
|
1423 |
||
1424 |
static inline int rand8() |
|
1425 |
{ |
|
1426 |
return int(256. * (qrand() / (RAND_MAX + 1.0))); |
|
1427 |
} |
|
1428 |
||
1429 |
static inline bool compare(int a, int b, int tolerance) |
|
1430 |
{ |
|
1431 |
return qAbs(a - b) <= tolerance; |
|
1432 |
} |
|
1433 |
||
1434 |
// compares img.scale against the bilinear filtering used by QPainter |
|
1435 |
void tst_QImage::smoothScale3() |
|
1436 |
{ |
|
1437 |
QImage img(128, 128, QImage::Format_RGB32); |
|
1438 |
for (int y = 0; y < img.height(); ++y) { |
|
1439 |
for (int x = 0; x < img.width(); ++x) { |
|
1440 |
const int red = rand8(); |
|
1441 |
const int green = rand8(); |
|
1442 |
const int blue = rand8(); |
|
1443 |
const int alpha = 255; |
|
1444 |
||
1445 |
img.setPixel(x, y, qRgba(red, green, blue, alpha)); |
|
1446 |
} |
|
1447 |
} |
|
1448 |
||
1449 |
qreal scales[2] = { .5, 2 }; |
|
1450 |
||
1451 |
for (int i = 0; i < 2; ++i) { |
|
1452 |
QImage a = img.scaled(img.size() * scales[i], Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1453 |
QImage b(a.size(), a.format()); |
|
1454 |
b.fill(0x0); |
|
1455 |
||
1456 |
QPainter p(&b); |
|
1457 |
p.setRenderHint(QPainter::SmoothPixmapTransform); |
|
1458 |
p.scale(scales[i], scales[i]); |
|
1459 |
p.drawImage(0, 0, img); |
|
1460 |
p.end(); |
|
1461 |
||
1462 |
for (int y = 0; y < a.height(); ++y) { |
|
1463 |
for (int x = 0; x < a.width(); ++x) { |
|
1464 |
QRgb ca = a.pixel(x, y); |
|
1465 |
QRgb cb = b.pixel(x, y); |
|
1466 |
||
1467 |
// tolerate a little bit of rounding errors |
|
1468 |
QVERIFY(compare(qRed(ca), qRed(cb), 3)); |
|
1469 |
QVERIFY(compare(qGreen(ca), qGreen(cb), 3)); |
|
1470 |
QVERIFY(compare(qBlue(ca), qBlue(cb), 3)); |
|
1471 |
} |
|
1472 |
} |
|
1473 |
} |
|
1474 |
} |
|
1475 |
||
1476 |
void tst_QImage::smoothScaleBig() |
|
1477 |
{ |
|
1478 |
#if defined(Q_OS_WINCE) |
|
1479 |
int bigValue = 2000; |
|
1480 |
#elif defined(Q_OS_SYMBIAN) |
|
1481 |
int bigValue = 2000; |
|
1482 |
#else |
|
1483 |
int bigValue = 200000; |
|
1484 |
#endif |
|
1485 |
QImage tall(4, bigValue, QImage::Format_ARGB32); |
|
1486 |
tall.fill(0x0); |
|
1487 |
||
1488 |
QImage wide(bigValue, 4, QImage::Format_ARGB32); |
|
1489 |
wide.fill(0x0); |
|
1490 |
||
1491 |
QImage tallScaled = tall.scaled(4, tall.height() / 4, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1492 |
QImage wideScaled = wide.scaled(wide.width() / 4, 4, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1493 |
||
1494 |
QCOMPARE(tallScaled.pixel(0, 0), QRgb(0x0)); |
|
1495 |
QCOMPARE(wideScaled.pixel(0, 0), QRgb(0x0)); |
|
1496 |
} |
|
1497 |
||
1498 |
void tst_QImage::smoothScaleAlpha() |
|
1499 |
{ |
|
1500 |
QImage src(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
1501 |
src.fill(0x0); |
|
1502 |
||
1503 |
QPainter srcPainter(&src); |
|
1504 |
srcPainter.setPen(Qt::NoPen); |
|
1505 |
srcPainter.setBrush(Qt::white); |
|
1506 |
srcPainter.drawEllipse(QRect(QPoint(), src.size())); |
|
1507 |
srcPainter.end(); |
|
1508 |
||
1509 |
QImage dst(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
1510 |
dst.fill(0xffffffff); |
|
1511 |
QImage expected = dst; |
|
1512 |
||
1513 |
QPainter dstPainter(&dst); |
|
1514 |
dstPainter.drawImage(0, 0, src.scaled(dst.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); |
|
1515 |
dstPainter.end(); |
|
1516 |
||
1517 |
QCOMPARE(dst, expected); |
|
1518 |
} |
|
1519 |
||
1520 |
static int count(const QImage &img, int x, int y, int dx, int dy, QRgb pixel) |
|
1521 |
{ |
|
1522 |
int i = 0; |
|
1523 |
while (x >= 0 && x < img.width() && y >= 0 && y < img.height()) { |
|
1524 |
i += (img.pixel(x, y) == pixel); |
|
1525 |
x += dx; |
|
1526 |
y += dy; |
|
1527 |
} |
|
1528 |
return i; |
|
1529 |
} |
|
1530 |
||
1531 |
const int transformed_image_width = 128; |
|
1532 |
const int transformed_image_height = 128; |
|
1533 |
||
1534 |
void tst_QImage::transformed_data() |
|
1535 |
{ |
|
1536 |
QTest::addColumn<QTransform>("transform"); |
|
1537 |
||
1538 |
{ |
|
1539 |
QTransform transform; |
|
1540 |
transform.translate(10.4, 10.4); |
|
1541 |
QTest::newRow("Translate") << transform; |
|
1542 |
} |
|
1543 |
{ |
|
1544 |
QTransform transform; |
|
1545 |
transform.scale(1.5, 1.5); |
|
1546 |
QTest::newRow("Scale") << transform; |
|
1547 |
} |
|
1548 |
{ |
|
1549 |
QTransform transform; |
|
1550 |
transform.rotate(30); |
|
1551 |
QTest::newRow("Rotate 30") << transform; |
|
1552 |
} |
|
1553 |
{ |
|
1554 |
QTransform transform; |
|
1555 |
transform.rotate(90); |
|
1556 |
QTest::newRow("Rotate 90") << transform; |
|
1557 |
} |
|
1558 |
{ |
|
1559 |
QTransform transform; |
|
1560 |
transform.rotate(180); |
|
1561 |
QTest::newRow("Rotate 180") << transform; |
|
1562 |
} |
|
1563 |
{ |
|
1564 |
QTransform transform; |
|
1565 |
transform.rotate(270); |
|
1566 |
QTest::newRow("Rotate 270") << transform; |
|
1567 |
} |
|
1568 |
{ |
|
1569 |
QTransform transform; |
|
1570 |
transform.translate(transformed_image_width/2, transformed_image_height/2); |
|
1571 |
transform.rotate(155, Qt::XAxis); |
|
1572 |
transform.translate(-transformed_image_width/2, -transformed_image_height/2); |
|
1573 |
QTest::newRow("Perspective 1") << transform; |
|
1574 |
} |
|
1575 |
{ |
|
1576 |
QTransform transform; |
|
1577 |
transform.rotate(155, Qt::XAxis); |
|
1578 |
transform.translate(-transformed_image_width/2, -transformed_image_height/2); |
|
1579 |
QTest::newRow("Perspective 2") << transform; |
|
1580 |
} |
|
1581 |
} |
|
1582 |
||
1583 |
void tst_QImage::transformed() |
|
1584 |
{ |
|
1585 |
QFETCH(QTransform, transform); |
|
1586 |
||
1587 |
QImage img(transformed_image_width, transformed_image_height, QImage::Format_ARGB32_Premultiplied); |
|
1588 |
QPainter p(&img); |
|
1589 |
p.fillRect(0, 0, img.width(), img.height(), Qt::red); |
|
1590 |
p.drawRect(0, 0, img.width()-1, img.height()-1); |
|
1591 |
p.end(); |
|
1592 |
||
1593 |
QImage transformed = img.transformed(transform, Qt::SmoothTransformation); |
|
1594 |
||
1595 |
// all borders should have touched pixels |
|
1596 |
||
1597 |
QVERIFY(count(transformed, 0, 0, 1, 0, 0x0) < transformed.width()); |
|
1598 |
QVERIFY(count(transformed, 0, 0, 0, 1, 0x0) < transformed.height()); |
|
1599 |
||
1600 |
QVERIFY(count(transformed, 0, img.height() - 1, 1, 0, 0x0) < transformed.width()); |
|
1601 |
QVERIFY(count(transformed, img.width() - 1, 0, 0, 1, 0x0) < transformed.height()); |
|
1602 |
||
1603 |
QImage transformedPadded(transformed.width() + 2, transformed.height() + 2, img.format()); |
|
1604 |
transformedPadded.fill(0x0); |
|
1605 |
||
1606 |
p.begin(&transformedPadded); |
|
1607 |
p.setRenderHint(QPainter::SmoothPixmapTransform); |
|
1608 |
p.setRenderHint(QPainter::Antialiasing); |
|
1609 |
p.setTransform(transformed.trueMatrix(transform, img.width(), img.height()) * QTransform().translate(1, 1)); |
|
1610 |
p.drawImage(0, 0, img); |
|
1611 |
p.end(); |
|
1612 |
||
1613 |
// no borders should have touched pixels since we have a one-pixel padding |
|
1614 |
||
1615 |
QCOMPARE(count(transformedPadded, 0, 0, 1, 0, 0x0), transformedPadded.width()); |
|
1616 |
QCOMPARE(count(transformedPadded, 0, 0, 0, 1, 0x0), transformedPadded.height()); |
|
1617 |
||
1618 |
QCOMPARE(count(transformedPadded, 0, transformedPadded.height() - 1, 1, 0, 0x0), transformedPadded.width()); |
|
1619 |
QCOMPARE(count(transformedPadded, transformedPadded.width() - 1, 0, 0, 1, 0x0), transformedPadded.height()); |
|
1620 |
} |
|
1621 |
||
1622 |
void tst_QImage::transformed2() |
|
1623 |
{ |
|
1624 |
QImage img(3, 3, QImage::Format_Mono); |
|
1625 |
QPainter p(&img); |
|
1626 |
p.fillRect(0, 0, 3, 3, Qt::white); |
|
1627 |
p.fillRect(0, 0, 3, 3, Qt::Dense4Pattern); |
|
1628 |
p.end(); |
|
1629 |
||
1630 |
QTransform transform; |
|
1631 |
transform.scale(3, 3); |
|
1632 |
||
1633 |
QImage expected(9, 9, QImage::Format_Mono); |
|
1634 |
p.begin(&expected); |
|
1635 |
p.fillRect(0, 0, 9, 9, Qt::white); |
|
1636 |
p.setBrush(Qt::black); |
|
1637 |
p.setPen(Qt::NoPen); |
|
1638 |
p.drawRect(3, 0, 3, 3); |
|
1639 |
p.drawRect(0, 3, 3, 3); |
|
1640 |
p.drawRect(6, 3, 3, 3); |
|
1641 |
p.drawRect(3, 6, 3, 3); |
|
1642 |
p.end(); |
|
1643 |
||
1644 |
{ |
|
1645 |
QImage actual = img.transformed(transform); |
|
1646 |
||
1647 |
QCOMPARE(actual.format(), expected.format()); |
|
1648 |
QCOMPARE(actual.size(), expected.size()); |
|
1649 |
QCOMPARE(actual, expected); |
|
1650 |
} |
|
1651 |
||
1652 |
{ |
|
1653 |
transform.rotate(-90); |
|
1654 |
QImage actual = img.transformed(transform); |
|
1655 |
||
1656 |
QCOMPARE(actual.convertToFormat(QImage::Format_ARGB32_Premultiplied), |
|
1657 |
expected.convertToFormat(QImage::Format_ARGB32_Premultiplied)); |
|
1658 |
} |
|
1659 |
} |
|
1660 |
||
1661 |
void tst_QImage::scaled() |
|
1662 |
{ |
|
1663 |
QImage img(102, 3, QImage::Format_Mono); |
|
1664 |
QPainter p(&img); |
|
1665 |
p.fillRect(0, 0, img.width(), img.height(), Qt::white); |
|
1666 |
p.end(); |
|
1667 |
||
1668 |
QImage scaled = img.scaled(1994, 10); |
|
1669 |
||
1670 |
QImage expected(1994, 10, QImage::Format_Mono); |
|
1671 |
p.begin(&expected); |
|
1672 |
p.fillRect(0, 0, expected.width(), expected.height(), Qt::white); |
|
1673 |
p.end(); |
|
1674 |
||
1675 |
QCOMPARE(scaled, expected); |
|
1676 |
} |
|
1677 |
||
1678 |
void tst_QImage::paintEngine() |
|
1679 |
{ |
|
1680 |
QImage img; |
|
1681 |
||
1682 |
QPaintEngine *engine; |
|
1683 |
{ |
|
1684 |
QImage temp(100, 100, QImage::Format_RGB32); |
|
1685 |
temp.fill(0xff000000); |
|
1686 |
||
1687 |
QPainter p(&temp); |
|
1688 |
p.fillRect(80,80,10,10,Qt::blue); |
|
1689 |
p.end(); |
|
1690 |
||
1691 |
img = temp; |
|
1692 |
||
1693 |
engine = temp.paintEngine(); |
|
1694 |
} |
|
1695 |
||
1696 |
{ |
|
1697 |
QPainter p(&img); |
|
1698 |
||
1699 |
p.fillRect(80,10,10,10,Qt::yellow); |
|
1700 |
p.end(); |
|
1701 |
} |
|
1702 |
||
1703 |
QImage expected(100, 100, QImage::Format_RGB32); |
|
1704 |
expected.fill(0xff000000); |
|
1705 |
||
1706 |
QPainter p(&expected); |
|
1707 |
p.fillRect(80,80,10,10,Qt::blue); |
|
1708 |
p.fillRect(80,10,10,10,Qt::yellow); |
|
1709 |
p.end(); |
|
1710 |
||
1711 |
QCOMPARE(engine, img.paintEngine()); |
|
1712 |
QCOMPARE(img, expected); |
|
1713 |
} |
|
1714 |
||
1715 |
void tst_QImage::setAlphaChannelWhilePainting() |
|
1716 |
{ |
|
1717 |
QImage image(100, 100, QImage::Format_ARGB32); |
|
1718 |
image.fill(Qt::black); |
|
1719 |
QPainter p(&image); |
|
1720 |
||
1721 |
image.setAlphaChannel(image.createMaskFromColor(QColor(Qt::black).rgb(), Qt::MaskInColor)); |
|
1722 |
} |
|
1723 |
||
1724 |
||
1725 |
// See task 240047 for details |
|
1726 |
void tst_QImage::smoothScaledSubImage() |
|
1727 |
{ |
|
1728 |
QImage original(128, 128, QImage::Format_RGB32); |
|
1729 |
QPainter p(&original); |
|
1730 |
p.fillRect(0, 0, 64, 128, Qt::black); |
|
1731 |
p.fillRect(64, 0, 64, 128, Qt::white); |
|
1732 |
p.end(); |
|
1733 |
||
1734 |
QImage subimage(((const QImage &) original).bits(), 32, 32, original.bytesPerLine(), QImage::Format_RGB32); // only in the black part of the source... |
|
1735 |
||
1736 |
QImage scaled = subimage.scaled(8, 8, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
|
1737 |
||
1738 |
for (int y=0; y<scaled.height(); ++y) |
|
1739 |
for (int x=0; x<scaled.width(); ++x) |
|
1740 |
QCOMPARE(scaled.pixel(x, y), 0xff000000); |
|
1741 |
} |
|
1742 |
||
1743 |
void tst_QImage::nullSize_data() |
|
1744 |
{ |
|
1745 |
QTest::addColumn<QImage>("image"); |
|
1746 |
QTest::newRow("null image") << QImage(); |
|
1747 |
QTest::newRow("zero-size image") << QImage(0, 0, QImage::Format_RGB32); |
|
1748 |
} |
|
1749 |
||
1750 |
void tst_QImage::nullSize() |
|
1751 |
{ |
|
1752 |
QFETCH(QImage, image); |
|
1753 |
QCOMPARE(image.isNull(), true); |
|
1754 |
QCOMPARE(image.width(), image.size().width()); |
|
1755 |
QCOMPARE(image.height(), image.size().height()); |
|
1756 |
} |
|
1757 |
||
1758 |
void tst_QImage::premultipliedAlphaConsistency() |
|
1759 |
{ |
|
1760 |
QImage img(256, 1, QImage::Format_ARGB32); |
|
1761 |
for (int x = 0; x < 256; ++x) |
|
1762 |
img.setPixel(x, 0, (x << 24) | 0xffffff); |
|
1763 |
||
1764 |
QImage converted = img.convertToFormat(QImage::Format_ARGB8565_Premultiplied); |
|
1765 |
QImage pm32 = converted.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
1766 |
||
1767 |
for (int i = 0; i < pm32.width(); ++i) { |
|
1768 |
QRgb pixel = pm32.pixel(i, 0); |
|
1769 |
QVERIFY(qRed(pixel) <= qAlpha(pixel)); |
|
1770 |
QVERIFY(qGreen(pixel) <= qAlpha(pixel)); |
|
1771 |
QVERIFY(qBlue(pixel) <= qAlpha(pixel)); |
|
1772 |
} |
|
1773 |
} |
|
1774 |
||
1775 |
void tst_QImage::compareIndexed() |
|
1776 |
{ |
|
1777 |
QImage img(256, 1, QImage::Format_Indexed8); |
|
1778 |
||
1779 |
QVector<QRgb> colorTable(256); |
|
1780 |
for (int i = 0; i < 256; ++i) |
|
1781 |
colorTable[i] = qRgb(i, i, i); |
|
1782 |
img.setColorTable(colorTable); |
|
1783 |
||
1784 |
for (int i = 0; i < 256; ++i) { |
|
1785 |
img.setPixel(i, 0, i); |
|
1786 |
} |
|
1787 |
||
1788 |
QImage imgInverted(256, 1, QImage::Format_Indexed8); |
|
1789 |
QVector<QRgb> invertedColorTable(256); |
|
1790 |
for (int i = 0; i < 256; ++i) |
|
1791 |
invertedColorTable[255-i] = qRgb(i, i, i); |
|
1792 |
imgInverted.setColorTable(invertedColorTable); |
|
1793 |
||
1794 |
for (int i = 0; i < 256; ++i) { |
|
1795 |
imgInverted.setPixel(i, 0, (255-i)); |
|
1796 |
} |
|
1797 |
||
1798 |
QCOMPARE(img, imgInverted); |
|
1799 |
} |
|
1800 |
||
1801 |
QTEST_MAIN(tst_QImage) |
|
1802 |
#include "tst_qimage.moc" |