summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJorgen Lind <jorgen.lind@gmail.com>2014-03-21 23:05:33 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-23 21:43:50 +0200
commiteb88aaa3a2aed3235cf837e858f530f6a521349f (patch)
tree3b2dad5884ffd9dddd64cc1e35d6311f33f52a4e /tests
parent33fae8b147eccec9b97629fe84a0b0753d446cf3 (diff)
Introducing QPixelFormat
Its purpose in life will be to describe pixel formats [ChangeLog][QtGui] Added QPixelFormat class Change-Id: I74d8f974606520efb3935110ff3d6ddb5ea805a8 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp44
-rw-r--r--tests/auto/gui/kernel/kernel.pro1
-rw-r--r--tests/auto/gui/kernel/qpixelformat/qpixelformat.pro6
-rw-r--r--tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp243
4 files changed, 294 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 95a9b142ec..d2072e0e56 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -170,6 +170,10 @@ private slots:
void scaled_QTBUG35972();
+ void convertToPixelFormat();
+ void convertToImageFormat_data();
+ void convertToImageFormat();
+
void cleanupFunctions();
};
@@ -2460,6 +2464,46 @@ void tst_QImage::scaled_QTBUG35972()
QCOMPARE(pixels[i], 0xffffffff);
}
+void tst_QImage::convertToPixelFormat()
+{
+ QPixelFormat rgb565 = QPixelFormatRgb(5,6,5,0,QPixelFormat::IgnoresAlpha, QPixelFormat::AtBeginning, QPixelFormat::NotPremultiplied, QPixelFormat::UnsignedShort);
+ QPixelFormat rgb565ImageFormat = QImage::toPixelFormat(QImage::Format_RGB16);
+ QCOMPARE(rgb565, rgb565ImageFormat);
+}
+
+void tst_QImage::convertToImageFormat_data()
+{
+ QTest::addColumn<QImage::Format>("image_format");
+ QTest::newRow("Convert Format_Invalid") << QImage::Format_Invalid;
+ QTest::newRow("Convert Format_Mono") << QImage::Format_Mono;
+ //This ends up being a QImage::Format_Mono since we cant specify LSB in QPixelFormat
+ //QTest::newRow("Convert Format_MonoLSB") << QImage::Format_MonoLSB;
+ QTest::newRow("Convert Format_Indexed8") << QImage::Format_Indexed8;
+ QTest::newRow("Convert Format_RGB32") << QImage::Format_RGB32;
+ QTest::newRow("Convert Format_ARGB32") << QImage::Format_ARGB32;
+ QTest::newRow("Convert Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("Convert Format_RGB16") << QImage::Format_RGB16;
+ QTest::newRow("Convert Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied;
+ QTest::newRow("Convert Format_RGB666") << QImage::Format_RGB666;
+ QTest::newRow("Convert Format_ARGB6666_Premultiplied") << QImage::Format_ARGB6666_Premultiplied;
+ QTest::newRow("Convert Format_RGB555") << QImage::Format_RGB555;
+ QTest::newRow("Convert Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied;
+ QTest::newRow("Convert Format_RGB888") << QImage::Format_RGB888;
+ QTest::newRow("Convert Format_RGB444") << QImage::Format_RGB444;
+ QTest::newRow("Convert Format_ARGB4444_Premultiplied") << QImage::Format_ARGB4444_Premultiplied;
+ QTest::newRow("Convert Format_RGBX8888") << QImage::Format_RGBX8888;
+ QTest::newRow("Convert Format_RGBA8888") << QImage::Format_RGBA8888;
+ QTest::newRow("Convert Format_RGBA8888_Premultiplied") << QImage::Format_RGBA8888_Premultiplied;
+}
+void tst_QImage::convertToImageFormat()
+{
+ QFETCH(QImage::Format, image_format);
+
+ QPixelFormat pixel_format = QImage::toPixelFormat(image_format);
+ QImage::Format format = QImage::toImageFormat(pixel_format);
+ QCOMPARE(format, image_format);
+}
+
static void cleanupFunction(void* info)
{
bool *called = static_cast<bool*>(info);
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro
index e4d9ce9d27..bbcdd91ea3 100644
--- a/tests/auto/gui/kernel/kernel.pro
+++ b/tests/auto/gui/kernel/kernel.pro
@@ -20,6 +20,7 @@ SUBDIRS=\
qtouchevent \
qwindow \
qguiapplication \
+ qpixelformat \
!qtHaveModule(widgets): SUBDIRS -= \
qmouseevent_modal \
diff --git a/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro b/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro
new file mode 100644
index 0000000000..970e5c7c2d
--- /dev/null
+++ b/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro
@@ -0,0 +1,6 @@
+CONFIG += testcase
+TARGET = tst_qpixelformat
+
+QT += gui testlib
+
+SOURCES += tst_qpixelformat.cpp
diff --git a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
new file mode 100644
index 0000000000..c3b19a3b44
--- /dev/null
+++ b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
@@ -0,0 +1,243 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 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.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt 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.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtTest/QtTest>
+
+#include <QtGui/qpixelformat.h>
+
+class tst_QPixelFormat : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testOperators();
+ void testQVectorOfFormats();
+ void testRGB();
+ void testCMYK();
+ void testHSLandHSV();
+ void testYUV_data();
+ void testYUV();
+ void testEnums();
+};
+
+void tst_QPixelFormat::testOperators()
+{
+ QPixelFormat first = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtBeginning, QPixelFormat::Premultiplied);
+ QPixelFormat second = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtBeginning, QPixelFormat::Premultiplied);
+ QVERIFY(first == second);
+
+ QPixelFormat third = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtEnd, QPixelFormat::NotPremultiplied);
+ QVERIFY(first != third);
+}
+
+void tst_QPixelFormat::testQVectorOfFormats()
+{
+ QVector<QPixelFormat> reallocedVector;
+ QVector<QPixelFormat> reservedVector;
+ reservedVector.reserve(QImage::NImageFormats);
+ for (int i = 0; i < QImage::NImageFormats; i++) {
+ if (i == 0 || i == 2) // skip invalid and monolsb
+ continue;
+ QImage::Format image_format = static_cast<QImage::Format>(i);
+ QPixelFormat format = QImage::toPixelFormat(image_format);
+ reallocedVector.append(format);
+ reservedVector.append(format);
+ }
+
+ for (int i = 0; i < reallocedVector.size(); i++) {
+ QCOMPARE(reallocedVector.at(i), reservedVector.at(i));
+ }
+}
+
+void tst_QPixelFormat::testRGB()
+{
+ QPixelFormat argb8888 = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha,QPixelFormat::AtBeginning, QPixelFormat::Premultiplied);
+ QCOMPARE(argb8888.redSize(), uchar(8));
+ QCOMPARE(argb8888.greenSize(), uchar(8));
+ QCOMPARE(argb8888.blueSize(), uchar(8));
+ QCOMPARE(argb8888.alphaSize(), uchar(8));
+
+ QPixelFormat rgb565 = QPixelFormatRgb(5,6,5,0,QPixelFormat::IgnoresAlpha,QPixelFormat::AtBeginning, QPixelFormat::NotPremultiplied);
+ QCOMPARE(rgb565.redSize(), uchar(5));
+ QCOMPARE(rgb565.greenSize(), uchar(6));
+ QCOMPARE(rgb565.blueSize(), uchar(5));
+ QCOMPARE(rgb565.alphaSize(), uchar(0));
+ QCOMPARE(rgb565.bitsPerPixel(), uchar(16));
+
+ QPixelFormat rgba1235 = QPixelFormatRgb(1,2,3,5,QPixelFormat::IgnoresAlpha, QPixelFormat::AtEnd, QPixelFormat::Premultiplied);
+ QCOMPARE(rgba1235.redSize(), uchar(1));
+ QCOMPARE(rgba1235.greenSize(), uchar(2));
+ QCOMPARE(rgba1235.blueSize(), uchar(3));
+ QCOMPARE(rgba1235.alphaSize(), uchar(5));
+ QCOMPARE(rgba1235.bitsPerPixel(), uchar(1 + 2 + 3 + 5));
+}
+
+void tst_QPixelFormat::testCMYK()
+{
+ QPixelFormat cmyk6 = QPixelFormatCmyk(6);
+ QCOMPARE(cmyk6.cyanSize(), uchar(6));
+ QCOMPARE(cmyk6.magentaSize(), uchar(6));
+ QCOMPARE(cmyk6.yellowSize(), uchar(6));
+ QCOMPARE(cmyk6.blackSize(), uchar(6));
+ QCOMPARE(cmyk6.bitsPerPixel(), uchar(6*4));
+
+ QPixelFormat cmykWithAlpha = QPixelFormatCmyk(8,8);
+ QCOMPARE(cmykWithAlpha.bitsPerPixel(), uchar(8*5));
+}
+void tst_QPixelFormat::testHSLandHSV()
+{
+ QPixelFormat hsl = QPixelFormatHsl(3,5);
+
+ QCOMPARE(hsl.hueSize(), uchar(3));
+ QCOMPARE(hsl.saturationSize(), uchar(3));
+ QCOMPARE(hsl.lightnessSize(), uchar(3));
+ QCOMPARE(hsl.bitsPerPixel(), uchar(3 * 3 + 5));
+
+ QPixelFormat hsv = QPixelFormatHsv(5,7);
+
+ QCOMPARE(hsv.hueSize(), uchar(5));
+ QCOMPARE(hsv.saturationSize(), uchar(5));
+ QCOMPARE(hsv.brightnessSize(), uchar(5));
+ QCOMPARE(hsv.bitsPerPixel(), uchar(5 * 3 + 7));
+}
+
+Q_DECLARE_METATYPE(QPixelFormat::YUVLayout)
+void tst_QPixelFormat::testYUV_data()
+{
+ QTest::addColumn<QPixelFormat::YUVLayout>("yuv_layout");
+ QTest::newRow("YUV Layout YUV444") << QPixelFormat::YUV444;
+ QTest::newRow("YUV Layout YUV422") << QPixelFormat::YUV422;
+ QTest::newRow("YUV Layout YUV411") << QPixelFormat::YUV411;
+ QTest::newRow("YUV Layout YUV420P") << QPixelFormat::YUV420P;
+ QTest::newRow("YUV Layout YUV420SP") << QPixelFormat::YUV420SP;
+ QTest::newRow("YUV Layout YV12") << QPixelFormat::YV12;
+ QTest::newRow("YUV Layout UYVY") << QPixelFormat::UYVY;
+ QTest::newRow("YUV Layout YUYV") << QPixelFormat::YUYV;
+ QTest::newRow("YUV Layout NV12") << QPixelFormat::NV12;
+ QTest::newRow("YUV Layout NV21") << QPixelFormat::NV21;
+ QTest::newRow("YUV Layout IMC1") << QPixelFormat::IMC1;
+ QTest::newRow("YUV Layout IMC2") << QPixelFormat::IMC2;
+ QTest::newRow("YUV Layout IMC3") << QPixelFormat::IMC3;
+ QTest::newRow("YUV Layout IMC4") << QPixelFormat::IMC4;
+ QTest::newRow("YUV Layout Y8") << QPixelFormat::Y8;
+ QTest::newRow("YUV Layout Y16") << QPixelFormat::Y16;
+}
+
+void tst_QPixelFormat::testYUV()
+{
+ QFETCH(QPixelFormat::YUVLayout, yuv_layout);
+
+ QPixelFormat format = QPixelFormatYuv(yuv_layout, 0);
+
+ switch (yuv_layout) {
+ case QPixelFormat::YUV444:
+ QCOMPARE(format.bitsPerPixel(), uchar(24));
+ break;
+ case QPixelFormat::YUV422:
+ QCOMPARE(format.bitsPerPixel(), uchar(16));
+ break;
+ case QPixelFormat::YUV411:
+ case QPixelFormat::YUV420P:
+ case QPixelFormat::YUV420SP:
+ case QPixelFormat::YV12:
+ QCOMPARE(format.bitsPerPixel(), uchar(12));
+ break;
+ case QPixelFormat::UYVY:
+ case QPixelFormat::YUYV:
+ QCOMPARE(format.bitsPerPixel(), uchar(16));
+ break;
+ case QPixelFormat::NV12:
+ case QPixelFormat::NV21:
+ QCOMPARE(format.bitsPerPixel(), uchar(12));
+ break;
+ case QPixelFormat::IMC1:
+ case QPixelFormat::IMC2:
+ case QPixelFormat::IMC3:
+ case QPixelFormat::IMC4:
+ QCOMPARE(format.bitsPerPixel(), uchar(12));
+ break;
+ case QPixelFormat::Y8:
+ QCOMPARE(format.bitsPerPixel(), uchar(8));
+ break;
+ case QPixelFormat::Y16:
+ QCOMPARE(format.bitsPerPixel(), uchar(16));
+ break;
+ default:
+ QVERIFY(!"the value stored for the yuvLayout is wrong!");
+ }
+
+}
+
+void tst_QPixelFormat::testEnums()
+{
+ QPixelFormat allSet = QPixelFormat(QPixelFormat::BGR,1,2,3,4,5,6,
+ QPixelFormat::UsesAlpha,
+ QPixelFormat::AtEnd,
+ QPixelFormat::Premultiplied,
+ QPixelFormat::FloatingPoint,
+ QPixelFormat::BigEndian,
+ (1 << 6) - 1);
+
+ QCOMPARE(allSet.alphaUsage(), QPixelFormat::UsesAlpha);
+ QCOMPARE(allSet.alphaPosition(), QPixelFormat::AtEnd);
+ QCOMPARE(allSet.premultiplied(), QPixelFormat::Premultiplied);
+ QCOMPARE(allSet.byteOrder(), QPixelFormat::BigEndian);
+ QCOMPARE(allSet.typeInterpretation(), QPixelFormat::FloatingPoint);
+ QCOMPARE(allSet.byteOrder(), QPixelFormat::BigEndian);
+ QCOMPARE(allSet.subEnum(), uchar(63));
+
+ QPixelFormat nonSet = QPixelFormat(QPixelFormat::RGB,6,5,4,3,2,1,
+ QPixelFormat::IgnoresAlpha,
+ QPixelFormat::AtBeginning,
+ QPixelFormat::NotPremultiplied,
+ QPixelFormat::UnsignedInteger,
+ QPixelFormat::LittleEndian);
+
+ QCOMPARE(nonSet.alphaUsage(), QPixelFormat::IgnoresAlpha);
+ QCOMPARE(nonSet.alphaPosition(), QPixelFormat::AtBeginning);
+ QCOMPARE(nonSet.premultiplied(), QPixelFormat::NotPremultiplied);
+ QCOMPARE(nonSet.byteOrder(), QPixelFormat::LittleEndian);
+ QCOMPARE(nonSet.typeInterpretation(), QPixelFormat::UnsignedInteger);
+ QCOMPARE(nonSet.byteOrder(), QPixelFormat::LittleEndian);
+ QCOMPARE(nonSet.subEnum(), uchar(0));
+}
+
+#include <tst_qpixelformat.moc>
+QTEST_MAIN(tst_QPixelFormat);