| 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 | class QWebpHandler : public QImageIOHandler | 
| 18 | { | 
| 19 | public: | 
| 20 | QWebpHandler(); | 
| 21 | ~QWebpHandler(); | 
| 22 | |
| 23 | public: | 
| 24 | bool canRead() const override; | 
| 25 | bool read(QImage *image) override; | 
| 26 | |
| 27 | static bool canRead(QIODevice *device); | 
| 28 | |
| 29 | bool write(const QImage &image) override; | 
| 30 | QVariant option(ImageOption option) const override; | 
| 31 | void setOption(ImageOption option, const QVariant &value) override; | 
| 32 | bool supportsOption(ImageOption option) const override; | 
| 33 | |
| 34 | int imageCount() const override; | 
| 35 | int currentImageNumber() const override; | 
| 36 | QRect currentImageRect() const override; | 
| 37 | int loopCount() const override; | 
| 38 | int nextImageDelay() const override; | 
| 39 | |
| 40 | private: | 
| 41 | bool ensureScanned() const; | 
| 42 | bool ensureDemuxer(); | 
| 43 | |
| 44 | private: | 
| 45 | enum ScanState { | 
| 46 | ScanError = -1, | 
| 47 | ScanNotScanned = 0, | 
| 48 | ScanSuccess = 1, | 
| 49 | }; | 
| 50 | |
| 51 | int m_quality; | 
| 52 | mutable ScanState m_scanState; | 
| 53 | WebPBitstreamFeatures m_features; | 
| 54 | uint32_t m_formatFlags; | 
| 55 | int m_loop; | 
| 56 | int m_frameCount; | 
| 57 | QColor m_bgColor; | 
| 58 | QByteArray m_rawData; | 
| 59 | WebPData m_webpData; | 
| 60 | WebPDemuxer *m_demuxer; | 
| 61 | WebPIterator m_iter; | 
| 62 | QColorSpace m_colorSpace; | 
| 63 | QImage *m_composited; // For animation frames composition | 
| 64 | }; | 
| 65 | |
| 66 | #endif // WEBPHANDLER_H | 
| 67 | 
