2016-02-01 03:33:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
2021-02-05 06:13:36 +02:00
|
|
|
** Copyright (C) 2016 Ivailo Monev
|
2016-02-01 03:33:31 +02:00
|
|
|
**
|
2019-06-03 13:38:02 +00:00
|
|
|
** This file is part of the test suite of the Katie Toolkit.
|
2016-02-01 03:33:31 +02:00
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2019-12-29 23:21:34 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2016-02-01 03:33:31 +02:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <qtest.h>
|
|
|
|
#include <QImage>
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QImage)
|
|
|
|
|
|
|
|
class tst_QImageConversion : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
2020-08-21 03:15:46 +03:00
|
|
|
void convertRgb16ToRGB32_data();
|
|
|
|
void convertRgb16ToRGB32();
|
2016-02-01 03:33:31 +02:00
|
|
|
|
|
|
|
private:
|
2020-08-21 03:15:46 +03:00
|
|
|
QImage generateImage(int width, int height);
|
2016-02-01 03:33:31 +02:00
|
|
|
};
|
|
|
|
|
2020-08-21 03:15:46 +03:00
|
|
|
void tst_QImageConversion::convertRgb16ToRGB32_data()
|
2016-02-01 03:33:31 +02:00
|
|
|
{
|
|
|
|
QTest::addColumn<QImage>("inputImage");
|
|
|
|
// height = 5000 to get interesting timing.
|
|
|
|
|
|
|
|
// 3 pixels wide -> smaller than regular vector of 128bits
|
2020-08-21 03:15:46 +03:00
|
|
|
QTest::newRow("width: 3px; height: 5000px;") << generateImage(3, 5000);
|
2016-02-01 03:33:31 +02:00
|
|
|
|
|
|
|
// 8 pixels wide -> potential for 2 vectors
|
2020-08-21 03:15:46 +03:00
|
|
|
QTest::newRow("width: 8px; height: 5000px;") << generateImage(3, 5000);
|
2016-02-01 03:33:31 +02:00
|
|
|
|
|
|
|
// 16 pixels, minimum for the SSSE3 implementation
|
2020-08-21 03:15:46 +03:00
|
|
|
QTest::newRow("width: 16px; height: 5000px;") << generateImage(16, 5000);
|
2016-02-01 03:33:31 +02:00
|
|
|
|
|
|
|
// 50 pixels, more realistic use case
|
2020-08-21 03:15:46 +03:00
|
|
|
QTest::newRow("width: 50px; height: 5000px;") << generateImage(50, 5000);
|
2016-02-01 03:33:31 +02:00
|
|
|
|
|
|
|
// 2000 pixels -> typical values for pictures
|
2020-08-21 03:15:46 +03:00
|
|
|
QTest::newRow("width: 2000px; height: 5000px;") << generateImage(2000, 5000);
|
2016-02-01 03:33:31 +02:00
|
|
|
}
|
|
|
|
|
2020-08-21 03:15:46 +03:00
|
|
|
void tst_QImageConversion::convertRgb16ToRGB32()
|
2016-02-01 03:33:31 +02:00
|
|
|
{
|
|
|
|
QFETCH(QImage, inputImage);
|
|
|
|
|
|
|
|
QBENCHMARK {
|
|
|
|
volatile QImage output = inputImage.convertToFormat(QImage::Format_RGB32);
|
|
|
|
// we need the volatile and the following to make sure the compiler does not do
|
|
|
|
// anything stupid :)
|
|
|
|
(void)output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-08-21 03:15:46 +03:00
|
|
|
Fill a RGB16 image with "random" pixel values.
|
2016-02-01 03:33:31 +02:00
|
|
|
*/
|
2020-08-21 03:15:46 +03:00
|
|
|
QImage tst_QImageConversion::generateImage(int width, int height)
|
2016-02-01 03:33:31 +02:00
|
|
|
{
|
2020-08-21 03:15:46 +03:00
|
|
|
QImage image(width, height, QImage::Format_RGB16);
|
2021-01-04 02:01:58 +02:00
|
|
|
const int byteWidth = width * 2;
|
2016-02-01 03:33:31 +02:00
|
|
|
|
|
|
|
for (int y = 0; y < image.height(); ++y) {
|
|
|
|
uchar *scanline = image.scanLine(y);
|
|
|
|
for (int x = 0; x < byteWidth; ++x)
|
|
|
|
scanline[x] = x ^ y;
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_QImageConversion)
|
2016-02-01 20:12:04 +02:00
|
|
|
|
|
|
|
#include "moc_tst_qimageconversion.cpp"
|