summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2018-05-25 16:15:14 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2018-05-28 11:15:48 +0000
commitb9ba2217566531b51f3c5c5158bfcc386539d810 (patch)
tree9922d820dcebdc3eec29e2a8f4416ce0de1896bd /tests
parentaa332026488e8e441a4187898534c59cd657e70e (diff)
webp handler: support alpha-less reading and writing
Webp files can be with or without alpha channel. The handler would ignore this and read all as Format_ARGB32 images, and write all as having alpha, in both cases losing that important bit of information. As a driveby, simplify the endianness handling in write(). By always converting the source image to an endianness-independent QImage format, no special handling is required. Task-number: QTBUG-48628 Change-Id: I624ed72b18a8b59a542979efcb4e8ff81214e0d7 Reviewed-by: Liang Qi <liang.qi@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/webp/images/kollada_noalpha.webpbin0 -> 3570 bytes
-rw-r--r--tests/auto/webp/tst_qwebp.cpp23
-rw-r--r--tests/auto/webp/webp.qrc1
3 files changed, 19 insertions, 5 deletions
diff --git a/tests/auto/webp/images/kollada_noalpha.webp b/tests/auto/webp/images/kollada_noalpha.webp
new file mode 100644
index 0000000..b5abe5d
--- /dev/null
+++ b/tests/auto/webp/images/kollada_noalpha.webp
Binary files differ
diff --git a/tests/auto/webp/tst_qwebp.cpp b/tests/auto/webp/tst_qwebp.cpp
index ad4a376..17289a5 100644
--- a/tests/auto/webp/tst_qwebp.cpp
+++ b/tests/auto/webp/tst_qwebp.cpp
@@ -53,15 +53,18 @@ void tst_qwebp::readImage_data()
{
QTest::addColumn<QString>("fileName");
QTest::addColumn<QSize>("size");
+ QTest::addColumn<bool>("alpha");
- QTest::newRow("kollada") << QString("kollada") << QSize(436, 160);
- QTest::newRow("kollada_lossless") << QString("kollada_lossless") << QSize(436, 160);
+ QTest::newRow("kollada") << QString("kollada") << QSize(436, 160) << true;
+ QTest::newRow("kollada_lossless") << QString("kollada_lossless") << QSize(436, 160) << true;
+ QTest::newRow("kollada_noalpha") << QString("kollada_noalpha") << QSize(436, 160) << false;
}
void tst_qwebp::readImage()
{
QFETCH(QString, fileName);
QFETCH(QSize, size);
+ QFETCH(bool, alpha);
const QString path = QStringLiteral(":/images/") + fileName + QStringLiteral(".webp");
QImageReader reader(path);
@@ -69,6 +72,7 @@ void tst_qwebp::readImage()
QImage image = reader.read();
QVERIFY2(!image.isNull(), qPrintable(reader.errorString()));
QCOMPARE(image.size(), size);
+ QCOMPARE(image.hasAlphaChannel(), alpha);
}
void tst_qwebp::readAnimation_data()
@@ -136,10 +140,13 @@ void tst_qwebp::writeImage_data()
QTest::addColumn<QString>("postfix");
QTest::addColumn<int>("quality");
QTest::addColumn<QSize>("size");
+ QTest::addColumn<bool>("alpha");
QTest::addColumn<bool>("needcheck");
- QTest::newRow("kollada-75") << QString("kollada") << QString(".png") << 75 << QSize(436, 160) << false;
- QTest::newRow("kollada-100") << QString("kollada") << QString(".png") << 100 << QSize(436, 160) << true;
+ QTest::newRow("kollada-75") << QString("kollada") << QString(".png") << 75 << QSize(436, 160) << true << false;
+ QTest::newRow("kollada-100") << QString("kollada") << QString(".png") << 100 << QSize(436, 160) << true << true;
+ QTest::newRow("kollada_noalpha-75") << QString("kollada_noalpha") << QString(".webp") << 75 << QSize(436, 160) << false << false;
+ QTest::newRow("kollada_noalpha-100") << QString("kollada_noalpha") << QString(".webp") << 100 << QSize(436, 160) << false << true;
}
void tst_qwebp::writeImage()
@@ -148,6 +155,7 @@ void tst_qwebp::writeImage()
QFETCH(QString, postfix);
QFETCH(int, quality);
QFETCH(QSize, size);
+ QFETCH(bool, alpha);
QFETCH(bool, needcheck);
const QString path = QString("%1-%2.webp").arg(fileName).arg(quality);
@@ -162,8 +170,13 @@ void tst_qwebp::writeImage()
writer.setQuality(quality);
QVERIFY2(writer.write(image), qPrintable(writer.errorString()));
+ QImage reread(path);
+ QVERIFY(!reread.isNull());
+ QVERIFY(reread.size() == size);
+ QVERIFY(reread.hasAlphaChannel() == alpha);
+
if (needcheck)
- QVERIFY(image == QImage(path));
+ QVERIFY(image == reread);
}
QTEST_MAIN(tst_qwebp)
diff --git a/tests/auto/webp/webp.qrc b/tests/auto/webp/webp.qrc
index 6519e58..7d0c626 100644
--- a/tests/auto/webp/webp.qrc
+++ b/tests/auto/webp/webp.qrc
@@ -4,5 +4,6 @@
<file>images/kollada.webp</file>
<file>images/kollada_lossless.webp</file>
<file>images/kollada_animation.webp</file>
+ <file>images/kollada_noalpha.webp</file>
</qresource>
</RCC>