summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Yao <yaodong1974@hotmail.com>2013-04-25 09:26:53 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-13 08:41:33 +0100
commit4522b350e53471c2ebc6d4692736ee4708445b66 (patch)
tree3dd204d86d012eda94045516a2fec25b366bf256
parentd8d421ce5b2c218f0075ef457139cd4f17505de7 (diff)
Added webp image format plugin
Also added auto test and config test. This plugin was disabled on winrt and android. [ChangeLog] Added webp image format plugin. Task-number: QTBUG-14205 Done-with: Liang Qi <liang.qi@digia.com> Change-Id: I9409e894d7fc1aef9dce4ffdff8bdf483d689774 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--config.tests/libwebp/libwebp.cpp51
-rw-r--r--config.tests/libwebp/libwebp.pro6
-rw-r--r--qtimageformats.pro1
-rw-r--r--src/plugins/imageformats/imageformats.pro5
-rw-r--r--src/plugins/imageformats/webp/main.cpp98
-rw-r--r--src/plugins/imageformats/webp/qwebphandler.cpp213
-rw-r--r--src/plugins/imageformats/webp/qwebphandler_p.h86
-rw-r--r--src/plugins/imageformats/webp/webp.json4
-rw-r--r--src/plugins/imageformats/webp/webp.pro16
-rw-r--r--tests/auto/auto.pro3
-rw-r--r--tests/auto/webp/images/kollada.pngbin0 -> 13907 bytes
-rw-r--r--tests/auto/webp/images/kollada.webpbin0 -> 11628 bytes
-rw-r--r--tests/auto/webp/images/kollada_lossless.webpbin0 -> 20488 bytes
-rw-r--r--tests/auto/webp/images/lena.jpgbin0 -> 7326 bytes
-rw-r--r--tests/auto/webp/images/lena.webpbin0 -> 2790 bytes
-rw-r--r--tests/auto/webp/images/lena_lossless.webpbin0 -> 9062 bytes
-rw-r--r--tests/auto/webp/tst_qwebp.cpp119
-rw-r--r--tests/auto/webp/webp.pro8
-rw-r--r--tests/auto/webp/webp.qrc10
19 files changed, 618 insertions, 2 deletions
diff --git a/config.tests/libwebp/libwebp.cpp b/config.tests/libwebp/libwebp.cpp
new file mode 100644
index 0000000..33d5e13
--- /dev/null
+++ b/config.tests/libwebp/libwebp.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the config.tests in the Qt ImageFormats module.
+**
+** $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 <webp/decode.h>
+
+int main(int, char **)
+{
+ WebPDecoderConfig config;
+ WebPDecBuffer *output_buffer = &config.output;
+ WebPBitstreamFeatures *bitstream = &config.input;
+
+ return 0;
+}
diff --git a/config.tests/libwebp/libwebp.pro b/config.tests/libwebp/libwebp.pro
new file mode 100644
index 0000000..d69b9be
--- /dev/null
+++ b/config.tests/libwebp/libwebp.pro
@@ -0,0 +1,6 @@
+SOURCES = libwebp.cpp
+CONFIG -= qt dylib
+mac:CONFIG -= app_bundle
+win32:CONFIG += console
+unix|mingw: LIBS += -lwebp
+else:win32: LIBS += libwebp.lib
diff --git a/qtimageformats.pro b/qtimageformats.pro
index 659e508..8382e5c 100644
--- a/qtimageformats.pro
+++ b/qtimageformats.pro
@@ -4,5 +4,6 @@ load(configure)
qtCompileTest(jasper)
qtCompileTest(libmng)
qtCompileTest(libtiff)
+qtCompileTest(libwebp)
load(qt_parts)
diff --git a/src/plugins/imageformats/imageformats.pro b/src/plugins/imageformats/imageformats.pro
index 01d2ac0..62feea7 100644
--- a/src/plugins/imageformats/imageformats.pro
+++ b/src/plugins/imageformats/imageformats.pro
@@ -6,7 +6,8 @@ SUBDIRS = \
mng \
tga \
tiff \
- wbmp
+ wbmp \
+ webp
wince:SUBDIRS -= jp2
@@ -14,3 +15,5 @@ winrt {
SUBDIRS -= tiff \
tga
}
+
+winrt|android: SUBDIRS -= webp
diff --git a/src/plugins/imageformats/webp/main.cpp b/src/plugins/imageformats/webp/main.cpp
new file mode 100644
index 0000000..6b6b5a9
--- /dev/null
+++ b/src/plugins/imageformats/webp/main.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the WebP plugins in the Qt ImageFormats module.
+**
+** $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 <qimageiohandler.h>
+#include <qstringlist.h>
+
+#ifndef QT_NO_IMAGEFORMATPLUGIN
+
+#ifdef QT_NO_IMAGEFORMAT_WEBP
+#undef QT_NO_IMAGEFORMAT_WEBP
+#endif
+#include "qwebphandler_p.h"
+
+#include <qiodevice.h>
+#include <qbytearray.h>
+
+QT_BEGIN_NAMESPACE
+
+class QWebpPlugin : public QImageIOPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "webp.json")
+
+public:
+ Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
+ QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
+};
+
+QWebpPlugin::Capabilities QWebpPlugin::capabilities(QIODevice *device, const QByteArray &format) const
+{
+ if (format == "webp")
+ return Capabilities(CanRead | CanWrite);
+
+ if (!format.isEmpty())
+ return 0;
+ if (!device->isOpen())
+ return 0;
+
+ Capabilities cap;
+ if (device->isReadable() && QWebpHandler::canRead(device))
+ cap |= CanRead;
+ if (device->isWritable())
+ cap |= CanWrite;
+
+ return cap;
+}
+
+QImageIOHandler *QWebpPlugin::create(QIODevice *device, const QByteArray &format) const
+{
+ QImageIOHandler *handler = new QWebpHandler;
+ handler->setDevice(device);
+ handler->setFormat(format);
+ return handler;
+}
+
+QT_END_NAMESPACE
+
+#include "main.moc"
+
+#endif // !QT_NO_IMAGEFORMATPLUGIN
diff --git a/src/plugins/imageformats/webp/qwebphandler.cpp b/src/plugins/imageformats/webp/qwebphandler.cpp
new file mode 100644
index 0000000..8834820
--- /dev/null
+++ b/src/plugins/imageformats/webp/qwebphandler.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the WebP plugins in the Qt ImageFormats module.
+**
+** $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 "qwebphandler_p.h"
+#include "webp/encode.h"
+#include <qimage.h>
+#include <qdebug.h>
+#include <qvariant.h>
+
+static const int riffHeaderSize = 12; // RIFF_HEADER_SIZE from webp/format_constants.h
+
+QWebpHandler::QWebpHandler() :
+ m_lossless(false),
+ m_quality(75),
+ m_scanState(ScanNotScanned)
+{
+}
+
+bool QWebpHandler::canRead() const
+{
+ if (m_scanState == ScanNotScanned && !canRead(device()))
+ return false;
+
+ if (m_scanState != ScanError) {
+ setFormat(QByteArrayLiteral("webp"));
+ return true;
+ }
+ return false;
+}
+
+bool QWebpHandler::canRead(QIODevice *device)
+{
+ if (!device) {
+ qWarning("QWebpHandler::canRead() called with no device");
+ return false;
+ }
+
+ QByteArray header = device->peek(riffHeaderSize);
+ return header.startsWith("RIFF") && header.endsWith("WEBP");
+}
+
+bool QWebpHandler::ensureScanned() const
+{
+ if (m_scanState != ScanNotScanned)
+ return m_scanState == ScanSuccess;
+
+ m_scanState = ScanError;
+
+ if (device()->isSequential()) {
+ qWarning() << "Sequential devices are not supported";
+ return false;
+ }
+
+ qint64 oldPos = device()->pos();
+ device()->seek(0);
+
+ QWebpHandler *that = const_cast<QWebpHandler *>(this);
+ QByteArray header = device()->peek(sizeof(WebPBitstreamFeatures));
+ if (WebPGetFeatures((const uint8_t*)header.constData(), header.size(), &(that->m_features)) == VP8_STATUS_OK)
+ m_scanState = ScanSuccess;
+
+ device()->seek(oldPos);
+
+ return m_scanState == ScanSuccess;
+}
+
+bool QWebpHandler::read(QImage *image)
+{
+ if (!ensureScanned() || device()->isSequential())
+ return false;
+
+ QByteArray data = device()->readAll();
+ QImage result(m_features.width, m_features.height, QImage::Format_ARGB32);
+ uint8_t *output = result.bits();
+ size_t output_size = result.byteCount();
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ if (!WebPDecodeBGRAInto(reinterpret_cast<const uint8_t*>(data.constData()), data.size(), output, output_size, result.bytesPerLine()))
+#else
+ if (!WebPDecodeARGBInto(reinterpret_cast<const uint8_t*>(data.constData()), data.size(), output, output_size, result.bytesPerLine()))
+#endif
+ return false;
+
+ *image = result;
+ return true;
+}
+
+static int pictureWriter(const quint8 *data, size_t data_size, const WebPPicture *const pic)
+{
+ QIODevice *io = reinterpret_cast<QIODevice*>(pic->custom_ptr);
+
+ return data_size ? ((quint64)(io->write((const char*)data, data_size)) == data_size) : 1;
+}
+
+bool QWebpHandler::write(const QImage &image)
+{
+ if (image.isNull()) {
+ qWarning() << "source image is null.";
+ return false;
+ }
+
+ QImage srcImage = image;
+ if (srcImage.format() != QImage::Format_ARGB32)
+ srcImage = srcImage.convertToFormat(QImage::Format_ARGB32);
+
+ WebPPicture picture;
+ WebPConfig config;
+
+ if (!WebPPictureInit(&picture) || !WebPConfigInit(&config)) {
+ qWarning() << "failed to init webp picture and config";
+ return false;
+ }
+
+ picture.width = srcImage.width();
+ picture.height = srcImage.height();
+ picture.use_argb = 1;
+ if (!WebPPictureImportBGRA(&picture, srcImage.bits(), srcImage.bytesPerLine())) {
+ qWarning() << "failed to import image data to webp picture.";
+
+ WebPPictureFree(&picture);
+ return false;
+ }
+
+ config.lossless = m_lossless;
+ config.quality = m_quality;
+ picture.writer = pictureWriter;
+ picture.custom_ptr = device();
+
+ if (!WebPEncode(&config, &picture)) {
+ qWarning() << "failed to encode webp picture, error code: " << picture.error_code;
+ WebPPictureFree(&picture);
+ return false;
+ }
+
+ WebPPictureFree(&picture);
+
+ return true;
+}
+
+QVariant QWebpHandler::option(ImageOption option) const
+{
+ if (!supportsOption(option) || !ensureScanned())
+ return QVariant();
+
+ switch (option) {
+ case Quality:
+ return m_quality;
+ case Size:
+ return QSize(m_features.width, m_features.height);
+ default:
+ return QVariant();
+ }
+}
+
+void QWebpHandler::setOption(ImageOption option, const QVariant &value)
+{
+ switch (option) {
+ case Quality:
+ m_quality = qBound(0, value.toInt(), 100);
+ m_lossless = (m_quality >= 100);
+ return;
+ default:
+ break;
+ }
+ return QImageIOHandler::setOption(option, value);
+}
+
+bool QWebpHandler::supportsOption(ImageOption option) const
+{
+ return option == Quality || option == Size;
+}
+
+QByteArray QWebpHandler::name() const
+{
+ return QByteArrayLiteral("webp");
+}
diff --git a/src/plugins/imageformats/webp/qwebphandler_p.h b/src/plugins/imageformats/webp/qwebphandler_p.h
new file mode 100644
index 0000000..a3e85a9
--- /dev/null
+++ b/src/plugins/imageformats/webp/qwebphandler_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the WebP plugins in the Qt ImageFormats module.
+**
+** $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$
+**
+****************************************************************************/
+
+#ifndef QWEBPHANDLER_P_H
+#define QWEBPHANDLER_P_H
+
+#include <QtGui/qimageiohandler.h>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qsize.h>
+
+#include "webp/decode.h"
+
+class QWebpHandler : public QImageIOHandler
+{
+public:
+ QWebpHandler();
+ ~QWebpHandler() {}
+
+public:
+ QByteArray name() const;
+
+ bool canRead() const;
+ bool read(QImage *image);
+
+ static bool canRead(QIODevice *device);
+
+ bool write(const QImage &image);
+ QVariant option(ImageOption option) const;
+ void setOption(ImageOption option, const QVariant &value);
+ bool supportsOption(ImageOption option) const;
+
+private:
+ bool ensureScanned() const;
+
+private:
+ enum ScanState {
+ ScanError = -1,
+ ScanNotScanned = 0,
+ ScanSuccess = 1,
+ };
+
+ bool m_lossless;
+ int m_quality;
+ mutable ScanState m_scanState;
+ WebPBitstreamFeatures m_features;
+};
+
+#endif // WEBPHANDLER_H
diff --git a/src/plugins/imageformats/webp/webp.json b/src/plugins/imageformats/webp/webp.json
new file mode 100644
index 0000000..ff82d60
--- /dev/null
+++ b/src/plugins/imageformats/webp/webp.json
@@ -0,0 +1,4 @@
+{
+ "Keys": [ "webp" ],
+ "MimeTypes": [ "image/webp" ]
+}
diff --git a/src/plugins/imageformats/webp/webp.pro b/src/plugins/imageformats/webp/webp.pro
new file mode 100644
index 0000000..850c35d
--- /dev/null
+++ b/src/plugins/imageformats/webp/webp.pro
@@ -0,0 +1,16 @@
+TARGET = qwebp
+
+PLUGIN_TYPE = imageformats
+PLUGIN_CLASS_NAME = QWebpPlugin
+load(qt_plugin)
+
+HEADERS += qwebphandler_p.h
+SOURCES += main.cpp qwebphandler.cpp
+OTHER_FILES += webp.json
+
+config_libwebp {
+ unix|win32-g++*: LIBS += -lwebp
+ else:win32: LIBS += libwebp.lib
+} else {
+ include($$PWD/../../../3rdparty/libwebp.pri)
+}
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 73f1014..deda6cb 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -4,6 +4,7 @@ SUBDIRS = \
wbmp \
dds \
icns \
- jp2
+ jp2 \
+ webp
contains(QT_CONFIG, system-zlib): SUBDIRS += mng tiff
diff --git a/tests/auto/webp/images/kollada.png b/tests/auto/webp/images/kollada.png
new file mode 100644
index 0000000..2abd4bb
--- /dev/null
+++ b/tests/auto/webp/images/kollada.png
Binary files differ
diff --git a/tests/auto/webp/images/kollada.webp b/tests/auto/webp/images/kollada.webp
new file mode 100644
index 0000000..7bbfe98
--- /dev/null
+++ b/tests/auto/webp/images/kollada.webp
Binary files differ
diff --git a/tests/auto/webp/images/kollada_lossless.webp b/tests/auto/webp/images/kollada_lossless.webp
new file mode 100644
index 0000000..fc6a353
--- /dev/null
+++ b/tests/auto/webp/images/kollada_lossless.webp
Binary files differ
diff --git a/tests/auto/webp/images/lena.jpg b/tests/auto/webp/images/lena.jpg
new file mode 100644
index 0000000..7add3fc
--- /dev/null
+++ b/tests/auto/webp/images/lena.jpg
Binary files differ
diff --git a/tests/auto/webp/images/lena.webp b/tests/auto/webp/images/lena.webp
new file mode 100644
index 0000000..4e1d816
--- /dev/null
+++ b/tests/auto/webp/images/lena.webp
Binary files differ
diff --git a/tests/auto/webp/images/lena_lossless.webp b/tests/auto/webp/images/lena_lossless.webp
new file mode 100644
index 0000000..250f945
--- /dev/null
+++ b/tests/auto/webp/images/lena_lossless.webp
Binary files differ
diff --git a/tests/auto/webp/tst_qwebp.cpp b/tests/auto/webp/tst_qwebp.cpp
new file mode 100644
index 0000000..2f84037
--- /dev/null
+++ b/tests/auto/webp/tst_qwebp.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtAddOn.ImageFormats module 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/QtGui>
+
+class tst_qwebp : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void readImage_data();
+ void readImage();
+ void writeImage_data();
+ void writeImage();
+};
+
+void tst_qwebp::readImage_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QSize>("size");
+
+ QTest::newRow("lena") << QString("lena") << QSize(103, 103);
+ QTest::newRow("lena_lossless") << QString("lena_lossless") << QSize(103, 103);
+ QTest::newRow("kollada") << QString("kollada") << QSize(436, 160);
+ QTest::newRow("kollada_lossless") << QString("kollada_lossless") << QSize(436, 160);
+}
+
+void tst_qwebp::readImage()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QSize, size);
+
+ const QString path = QStringLiteral(":/images/") + fileName + QStringLiteral(".webp");
+ QImageReader reader(path);
+ QVERIFY(reader.canRead());
+ QImage image = reader.read();
+ QVERIFY2(!image.isNull(), qPrintable(reader.errorString()));
+ QCOMPARE(image.size(), size);
+}
+
+void tst_qwebp::writeImage_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QString>("postfix");
+ QTest::addColumn<int>("quality");
+ QTest::addColumn<QSize>("size");
+ QTest::addColumn<bool>("needcheck");
+
+ QTest::newRow("lena-90") << QString("lena") << QString(".jpg") << 90 << QSize(103, 103) << false;
+ QTest::newRow("lena-100") << QString("lena") << QString(".jpg") << 100 << QSize(103, 103) << false;
+ 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;
+}
+
+void tst_qwebp::writeImage()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QString, postfix);
+ QFETCH(int, quality);
+ QFETCH(QSize, size);
+ QFETCH(bool, needcheck);
+
+ const QString path = QString("%1-%2.webp").arg(fileName).arg(quality);
+ const QString sourcePath = QStringLiteral(":/images/") + fileName + postfix;
+
+ QImage image(sourcePath);
+ QVERIFY(!image.isNull());
+ QVERIFY(image.size() == size);
+
+ QImageWriter writer(path, QByteArrayLiteral("webp"));
+ QVERIFY2(writer.canWrite(), qPrintable(writer.errorString()));
+ writer.setQuality(quality);
+ QVERIFY2(writer.write(image), qPrintable(writer.errorString()));
+
+ if (needcheck)
+ QVERIFY(image == QImage(path));
+}
+
+QTEST_MAIN(tst_qwebp)
+#include "tst_qwebp.moc"
diff --git a/tests/auto/webp/webp.pro b/tests/auto/webp/webp.pro
new file mode 100644
index 0000000..666ab51
--- /dev/null
+++ b/tests/auto/webp/webp.pro
@@ -0,0 +1,8 @@
+TARGET = tst_qwebp
+
+QT = core gui testlib
+CONFIG -= app_bundle
+CONFIG += testcase
+
+SOURCES += tst_qwebp.cpp
+RESOURCES += $$PWD/webp.qrc
diff --git a/tests/auto/webp/webp.qrc b/tests/auto/webp/webp.qrc
new file mode 100644
index 0000000..6cf0ea0
--- /dev/null
+++ b/tests/auto/webp/webp.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/lena.jpg</file>
+ <file>images/lena.webp</file>
+ <file>images/lena_lossless.webp</file>
+ <file>images/kollada.png</file>
+ <file>images/kollada.webp</file>
+ <file>images/kollada_lossless.webp</file>
+ </qresource>
+</RCC>