diff options
Diffstat (limited to 'tests/auto/gui/image/qimage/tst_qimage.cpp')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 121 |
1 files changed, 84 insertions, 37 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index e8e1cd1896..91df1ca520 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -112,6 +107,7 @@ private slots: void smoothScale2_data(); void smoothScale2(); void smoothScale3(); + void smoothScale4(); void smoothScaleBig(); void smoothScaleAlpha(); @@ -973,13 +969,17 @@ void tst_QImage::createAlphaMask_data() int alphas[] = { 0, 127, 255 }; for (unsigned a1 = 0; a1 < sizeof(alphas) / sizeof(int); ++a1) { + const QByteArray a1B = QByteArray::number(alphas[a1]); for (unsigned a2 = 0; a2 < sizeof(alphas) / sizeof(int); ++a2) { if (a1 == a2) continue; + const QByteArray a2B = QByteArray::number(alphas[a2]); for (int x=10; x<18; x+=3) { + const QByteArray xB = QByteArray::number(x); for (int y=100; y<108; y+=3) { - QTest::newRow(qPrintable(QString::fromLatin1("x=%1, y=%2, a1=%3, a2=%4").arg(x).arg(y).arg(alphas[a1]).arg(alphas[a2]))) - << x << y << alphas[a1] << alphas[a2]; + const QByteArray testName = "x=" + xB + ", y=" + QByteArray::number(y) + + ", a1=" + a1B + ", a2=" + a2B; + QTest::newRow(testName.constData()) << x << y << alphas[a1] << alphas[a2]; } } } @@ -1076,34 +1076,34 @@ void tst_QImage::rotate_data() degrees << 0 << 90 << 180 << 270; foreach (int d, degrees) { - QString title = QString("%1 %2").arg(d); - QTest::newRow(qPrintable(title.arg("Format_RGB32"))) + const QByteArray dB = QByteArray::number(d); + QTest::newRow((dB + " Format_RGB32").constData()) << QImage::Format_RGB32 << d; - QTest::newRow(qPrintable(title.arg("Format_ARGB32"))) + QTest::newRow((dB + " Format_ARGB32").constData()) << QImage::Format_ARGB32 << d; - QTest::newRow(qPrintable(title.arg("Format_ARGB32_Premultiplied"))) + QTest::newRow((dB + " Format_ARGB32_Premultiplied").constData()) << QImage::Format_ARGB32_Premultiplied << d; - QTest::newRow(qPrintable(title.arg("Format_RGB16"))) + QTest::newRow((dB + " Format_RGB16").constData()) << QImage::Format_RGB16 << d; - QTest::newRow(qPrintable(title.arg("Format_ARGB8565_Premultiplied"))) + QTest::newRow((dB + " Format_ARGB8565_Premultiplied").constData()) << QImage::Format_ARGB8565_Premultiplied << d; - QTest::newRow(qPrintable(title.arg("Format_RGB666"))) + QTest::newRow((dB + " Format_RGB666").constData()) << QImage::Format_RGB666 << d; - QTest::newRow(qPrintable(title.arg("Format_RGB555"))) + QTest::newRow((dB + " Format_RGB555").constData()) << QImage::Format_RGB555 << d; - QTest::newRow(qPrintable(title.arg("Format_ARGB8555_Premultiplied"))) + QTest::newRow((dB + " Format_ARGB8555_Premultiplied").constData()) << QImage::Format_ARGB8555_Premultiplied << d; - QTest::newRow(qPrintable(title.arg("Format_RGB888"))) + QTest::newRow((dB + " Format_RGB888").constData()) << QImage::Format_RGB888 << d; - QTest::newRow(qPrintable(title.arg("Format_Indexed8"))) + QTest::newRow((dB + " Format_Indexed8").constData()) << QImage::Format_Indexed8 << d; - QTest::newRow(qPrintable(title.arg("Format_RGBX8888"))) + QTest::newRow((dB + " Format_RGBX8888").constData()) << QImage::Format_RGBX8888 << d; - QTest::newRow(qPrintable(title.arg("Format_RGBA8888_Premultiplied"))) + QTest::newRow((dB + " Format_RGBA8888_Premultiplied").constData()) << QImage::Format_RGBA8888_Premultiplied << d; - QTest::newRow(qPrintable(title.arg("Format_Alpha8"))) + QTest::newRow((dB + " Format_Alpha8").constData()) << QImage::Format_Alpha8 << d; - QTest::newRow(qPrintable(title.arg("Format_Grayscale8"))) + QTest::newRow((dB + " Format_Grayscale8").constData()) << QImage::Format_Grayscale8 << d; } } @@ -1627,9 +1627,11 @@ void tst_QImage::smoothScale2_data() int sizes[] = { 2, 3, 4, 6, 7, 8, 10, 16, 20, 32, 40, 64, 100, 101, 128, 0 }; QImage::Format formats[] = { QImage::Format_RGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Invalid }; for (int j = 0; formats[j] != QImage::Format_Invalid; ++j) { - QString formatstr = formats[j] == QImage::Format_RGB32 ? QStringLiteral("rgb32") : QStringLiteral("argb32pm"); + QByteArray formatstr = formats[j] == QImage::Format_RGB32 ? QByteArrayLiteral("rgb32") : QByteArrayLiteral("argb32pm"); for (int i = 0; sizes[i] != 0; ++i) { - QTest::newRow(QString("%1 %2x%2").arg(formatstr).arg(sizes[i]).toUtf8()) << (int)formats[j] << sizes[i]; + const QByteArray sizeB = QByteArray::number(sizes[i]); + QTest::newRow((formatstr + ' ' + sizeB + 'x' + sizeB).constData()) + << (int)formats[j] << sizes[i]; } } } @@ -1672,6 +1674,30 @@ void tst_QImage::smoothScale2() QCOMPARE(qBlue(pixel), qBlue(expected)); } + // scale x up + scaled = img.scaled(QSize(size, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + for (int x = 0; x < scaled.width(); ++x) { + pixel = scaled.pixel(x, y); + QCOMPARE(qAlpha(pixel), qAlpha(expected)); + QCOMPARE(qRed(pixel), qRed(expected)); + QCOMPARE(qGreen(pixel), qGreen(expected)); + QCOMPARE(qBlue(pixel), qBlue(expected)); + } + } + + // scale y up + scaled = img.scaled(QSize(size * 2, size), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + for (int x = 0; x < scaled.width(); ++x) { + pixel = scaled.pixel(x, y); + QCOMPARE(qAlpha(pixel), qAlpha(expected)); + QCOMPARE(qRed(pixel), qRed(expected)); + QCOMPARE(qGreen(pixel), qGreen(expected)); + QCOMPARE(qBlue(pixel), qBlue(expected)); + } + } + // scale x up, y up scaled = img.scaled(QSize(size * 2, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); for (int y = 0; y < scaled.height(); ++y) { @@ -1737,6 +1763,26 @@ void tst_QImage::smoothScale3() } } +// Tests smooth upscale is smooth +void tst_QImage::smoothScale4() +{ + QImage img(4, 4, QImage::Format_RGB32); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + img.setPixel(x, y, qRgb(x * 255 / 3, y * 255 / 3, 0)); + } + } + QImage scaled = img.scaled(37, 23, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + for (int x = 0; x < scaled.width(); ++x) { + if (x > 0) + QVERIFY(qRed(scaled.pixel(x, y)) >= qRed(scaled.pixel(x - 1, y))); + if (y > 0) + QVERIFY(qGreen(scaled.pixel(x, y)) >= qGreen(scaled.pixel(x, y - 1))); + } + } +} + void tst_QImage::smoothScaleBig() { #if defined(Q_OS_WINCE) @@ -2601,10 +2647,11 @@ void tst_QImage::genericRgbConversion_data() QTest::addColumn<QImage::Format>("dest_format"); for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) { + const QString formatI = formatToString(QImage::Format(i)); for (int j = QImage::Format_RGB32; j < QImage::Format_Alpha8; ++j) { if (i == j) continue; - QString test = QString::fromLatin1("%1 -> %2").arg(formatToString(QImage::Format(i))).arg(formatToString(QImage::Format(j))); + const QString test = formatI + QLatin1String(" -> ") + formatToString(QImage::Format(j)); QTest::newRow(qPrintable(test)) << QImage::Format(i) << QImage::Format(j); } } |