diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | LGPL_EXCEPTION.txt | 22 | ||||
-rw-r--r-- | src/plugins/imageformats/webp/qwebphandler.cpp | 38 | ||||
-rw-r--r-- | tests/auto/webp/images/kollada_noalpha.webp | bin | 0 -> 3570 bytes | |||
-rw-r--r-- | tests/auto/webp/tst_qwebp.cpp | 23 | ||||
-rw-r--r-- | tests/auto/webp/webp.qrc | 1 |
6 files changed, 42 insertions, 44 deletions
diff --git a/.qmake.conf b/.qmake.conf index 67c54ee..097d8b9 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.11.1 +MODULE_VERSION = 5.12.0 diff --git a/LGPL_EXCEPTION.txt b/LGPL_EXCEPTION.txt deleted file mode 100644 index 5cdacb9..0000000 --- a/LGPL_EXCEPTION.txt +++ /dev/null @@ -1,22 +0,0 @@ -The Qt Company Qt LGPL Exception version 1.1 - -As an additional permission to the GNU Lesser General Public License version -2.1, the object code form of a "work that uses the Library" may incorporate -material from a header file that is part of the Library. You may distribute -such object code under terms of your choice, provided that: - (i) the header files of the Library have not been modified; and - (ii) the incorporated material is limited to numerical parameters, data - structure layouts, accessors, macros, inline functions and - templates; and - (iii) you comply with the terms of Section 6 of the GNU Lesser General - Public License version 2.1. - -Moreover, you may apply this exception to a modified version of the Library, -provided that such modification does not involve copying material from the -Library into the modified Library's header files unless such material is -limited to (i) numerical parameters; (ii) data structure layouts; -(iii) accessors; and (iv) small macros, templates and inline functions of -five lines or less in length. - -Furthermore, you are not required to apply this additional permission to a -modified version of the Library. diff --git a/src/plugins/imageformats/webp/qwebphandler.cpp b/src/plugins/imageformats/webp/qwebphandler.cpp index 3a7bf43..578a701 100644 --- a/src/plugins/imageformats/webp/qwebphandler.cpp +++ b/src/plugins/imageformats/webp/qwebphandler.cpp @@ -174,7 +174,8 @@ bool QWebpHandler::read(QImage *image) if (status != VP8_STATUS_OK) return false; - QImage frame(m_iter.width, m_iter.height, QImage::Format_ARGB32); + QImage::Format format = m_features.has_alpha ? QImage::Format_ARGB32 : QImage::Format_RGB32; + QImage frame(m_iter.width, m_iter.height, format); uint8_t *output = frame.bits(); size_t output_size = frame.sizeInBytes(); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN @@ -219,13 +220,10 @@ bool QWebpHandler::write(const QImage &image) } QImage srcImage = image; -#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - if (srcImage.format() != QImage::Format_ARGB32) - srcImage = srcImage.convertToFormat(QImage::Format_ARGB32); -#else /* Q_BIG_ENDIAN */ - if (srcImage.format() != QImage::Format_RGBA8888) - srcImage = srcImage.convertToFormat(QImage::Format_RGBA8888); -#endif + bool alpha = srcImage.hasAlphaChannel(); + QImage::Format newFormat = alpha ? QImage::Format_RGBA8888 : QImage::Format_RGB888; + if (srcImage.format() != newFormat) + srcImage = srcImage.convertToFormat(newFormat); WebPPicture picture; WebPConfig config; @@ -238,19 +236,27 @@ bool QWebpHandler::write(const QImage &image) picture.width = srcImage.width(); picture.height = srcImage.height(); picture.use_argb = 1; -#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - if (!WebPPictureImportBGRA(&picture, srcImage.bits(), srcImage.bytesPerLine())) { -#else /* Q_BIG_ENDIAN */ - if (!WebPPictureImportRGBA(&picture, srcImage.bits(), srcImage.bytesPerLine())) { -#endif - qWarning() << "failed to import image data to webp picture."; + bool failed = false; + if (alpha) + failed = !WebPPictureImportRGBA(&picture, srcImage.bits(), srcImage.bytesPerLine()); + else + failed = !WebPPictureImportRGB(&picture, srcImage.bits(), srcImage.bytesPerLine()); + if (failed) { + qWarning() << "failed to import image data to webp picture."; WebPPictureFree(&picture); return false; } - config.quality = m_quality < 0 ? 75 : qMin(m_quality, 100); - config.lossless = (config.quality >= 100); + int reqQuality = m_quality < 0 ? 75 : qMin(m_quality, 100); + if (reqQuality < 100) { + config.lossless = 0; + config.quality = reqQuality; + } else { + config.lossless = 1; + config.quality = 70; // For lossless, specifies compression effort; 70 is libwebp default + } + config.alpha_quality = config.quality; picture.writer = pictureWriter; picture.custom_ptr = device(); diff --git a/tests/auto/webp/images/kollada_noalpha.webp b/tests/auto/webp/images/kollada_noalpha.webp Binary files differnew file mode 100644 index 0000000..b5abe5d --- /dev/null +++ b/tests/auto/webp/images/kollada_noalpha.webp 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> |