|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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 #include <qtest.h> |
|
43 #include <QImage> |
|
44 |
|
45 Q_DECLARE_METATYPE(QImage) |
|
46 |
|
47 class tst_QImageConversion : public QObject |
|
48 { |
|
49 Q_OBJECT |
|
50 private slots: |
|
51 void convertRgb888ToRGB32_data(); |
|
52 void convertRgb888ToRGB32(); |
|
53 |
|
54 private: |
|
55 QImage generateImageRgb888(int width, int height); |
|
56 }; |
|
57 |
|
58 void tst_QImageConversion::convertRgb888ToRGB32_data() |
|
59 { |
|
60 QTest::addColumn<QImage>("inputImage"); |
|
61 // height = 5000 to get interesting timing. |
|
62 |
|
63 // 3 pixels wide -> smaller than regular vector of 128bits |
|
64 QTest::newRow("width: 3px; height: 5000px;") << generateImageRgb888(3, 5000); |
|
65 |
|
66 // 8 pixels wide -> potential for 2 vectors |
|
67 QTest::newRow("width: 8px; height: 5000px;") << generateImageRgb888(3, 5000); |
|
68 |
|
69 // 16 pixels, minimum for the SSSE3 implementation |
|
70 QTest::newRow("width: 16px; height: 5000px;") << generateImageRgb888(16, 5000); |
|
71 |
|
72 // 50 pixels, more realistic use case |
|
73 QTest::newRow("width: 50px; height: 5000px;") << generateImageRgb888(50, 5000); |
|
74 |
|
75 // 2000 pixels -> typical values for pictures |
|
76 QTest::newRow("width: 2000px; height: 5000px;") << generateImageRgb888(2000, 5000); |
|
77 } |
|
78 |
|
79 void tst_QImageConversion::convertRgb888ToRGB32() |
|
80 { |
|
81 QFETCH(QImage, inputImage); |
|
82 |
|
83 QBENCHMARK { |
|
84 volatile QImage output = inputImage.convertToFormat(QImage::Format_RGB32); |
|
85 // we need the volatile and the following to make sure the compiler does not do |
|
86 // anything stupid :) |
|
87 (void)output; |
|
88 } |
|
89 } |
|
90 |
|
91 /* |
|
92 Fill a RGB888 image with "random" pixel values. |
|
93 */ |
|
94 QImage tst_QImageConversion::generateImageRgb888(int width, int height) |
|
95 { |
|
96 QImage image(width, height, QImage::Format_RGB888); |
|
97 const int byteWidth = width * 3; |
|
98 |
|
99 for (int y = 0; y < image.height(); ++y) { |
|
100 uchar *scanline = image.scanLine(y); |
|
101 for (int x = 0; x < byteWidth; ++x) |
|
102 scanline[x] = x ^ y; |
|
103 } |
|
104 return image; |
|
105 } |
|
106 |
|
107 QTEST_MAIN(tst_QImageConversion) |
|
108 #include "tst_qimageconversion.moc" |