1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include <qimageiohandler.h> |
5 | #include <qstringlist.h> |
6 | |
7 | #ifndef QT_NO_IMAGEFORMATPLUGIN |
8 | |
9 | #include "qwebphandler_p.h" |
10 | |
11 | #include <qiodevice.h> |
12 | #include <qbytearray.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QWebpPlugin : public QImageIOPlugin |
17 | { |
18 | Q_OBJECT |
19 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface"FILE "webp.json") |
20 | |
21 | public: |
22 | Capabilities capabilities(QIODevice *device, const QByteArray &format) const override; |
23 | QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override; |
24 | }; |
25 | |
26 | QWebpPlugin::Capabilities QWebpPlugin::capabilities(QIODevice *device, const QByteArray &format) const |
27 | { |
28 | if (format == "webp") |
29 | return Capabilities(CanRead | CanWrite); |
30 | |
31 | Capabilities cap; |
32 | if (!format.isEmpty()) |
33 | return cap; |
34 | if (!device->isOpen()) |
35 | return cap; |
36 | |
37 | if (device->isReadable() && QWebpHandler::canRead(device)) |
38 | cap |= CanRead; |
39 | if (device->isWritable()) |
40 | cap |= CanWrite; |
41 | |
42 | return cap; |
43 | } |
44 | |
45 | QImageIOHandler *QWebpPlugin::create(QIODevice *device, const QByteArray &format) const |
46 | { |
47 | QImageIOHandler *handler = new QWebpHandler; |
48 | handler->setDevice(device); |
49 | handler->setFormat(format); |
50 | return handler; |
51 | } |
52 | |
53 | QT_END_NAMESPACE |
54 | |
55 | #include "main.moc" |
56 | |
57 | #endif // !QT_NO_IMAGEFORMATPLUGIN |
58 |