| 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 | #ifndef QWEBPHANDLER_P_H |
| 5 | #define QWEBPHANDLER_P_H |
| 6 | |
| 7 | #include <QtGui/qcolor.h> |
| 8 | #include <QtGui/qcolorspace.h> |
| 9 | #include <QtGui/qimage.h> |
| 10 | #include <QtGui/qimageiohandler.h> |
| 11 | #include <QtCore/qbytearray.h> |
| 12 | #include <QtCore/qsize.h> |
| 13 | |
| 14 | #include "webp/decode.h" |
| 15 | #include "webp/demux.h" |
| 16 | |
| 17 | QT_BEGIN_NAMESPACE |
| 18 | |
| 19 | class QWebpHandler : public QImageIOHandler |
| 20 | { |
| 21 | public: |
| 22 | QWebpHandler(); |
| 23 | ~QWebpHandler(); |
| 24 | |
| 25 | public: |
| 26 | bool canRead() const override; |
| 27 | bool read(QImage *image) override; |
| 28 | |
| 29 | static bool canRead(QIODevice *device); |
| 30 | |
| 31 | bool write(const QImage &image) override; |
| 32 | QVariant option(ImageOption option) const override; |
| 33 | void setOption(ImageOption option, const QVariant &value) override; |
| 34 | bool supportsOption(ImageOption option) const override; |
| 35 | |
| 36 | int imageCount() const override; |
| 37 | int currentImageNumber() const override; |
| 38 | QRect currentImageRect() const override; |
| 39 | int loopCount() const override; |
| 40 | int nextImageDelay() const override; |
| 41 | |
| 42 | private: |
| 43 | bool ensureScanned() const; |
| 44 | bool ensureDemuxer(); |
| 45 | |
| 46 | private: |
| 47 | enum ScanState { |
| 48 | ScanError = -1, |
| 49 | ScanNotScanned = 0, |
| 50 | ScanSuccess = 1, |
| 51 | }; |
| 52 | |
| 53 | int m_quality; |
| 54 | mutable ScanState m_scanState; |
| 55 | WebPBitstreamFeatures m_features; |
| 56 | uint32_t m_formatFlags; |
| 57 | int m_loop; |
| 58 | int m_frameCount; |
| 59 | QColor m_bgColor; |
| 60 | QByteArray m_rawData; |
| 61 | WebPData m_webpData; |
| 62 | WebPDemuxer *m_demuxer; |
| 63 | WebPIterator m_iter; |
| 64 | QColorSpace m_colorSpace; |
| 65 | QImage *m_composited; // For animation frames composition |
| 66 | }; |
| 67 | |
| 68 | QT_END_NAMESPACE |
| 69 | |
| 70 | #endif // WEBPHANDLER_H |
| 71 | |