1 /*
2     High Efficiency Image File Format (HEIF) support for QImage.
3 
4     SPDX-FileCopyrightText: 2020 Sirius Bakke <sirius@bakke.co>
5     SPDX-FileCopyrightText: 2021 Daniel Novomesky <dnovomesky@gmail.com>
6 
7     SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KIMG_HEIF_P_H
11 #define KIMG_HEIF_P_H
12 
13 #include <QByteArray>
14 #include <QImage>
15 #include <QImageIOPlugin>
16 
17 class HEIFHandler : public QImageIOHandler
18 {
19 public:
20     HEIFHandler();
21 
22     bool canRead() const override;
23     bool read(QImage *image) override;
24     bool write(const QImage &image) override;
25 
26     static bool canRead(QIODevice *device);
27 
28     QVariant option(ImageOption option) const override;
29     void setOption(ImageOption option, const QVariant &value) override;
30     bool supportsOption(ImageOption option) const override;
31 
32 private:
33     static bool isSupportedBMFFType(const QByteArray &header);
34     bool ensureParsed() const;
35     bool ensureDecoder();
36 
37     enum ParseHeicState {
38         ParseHeicError = -1,
39         ParseHeicNotParsed = 0,
40         ParseHeicSuccess = 1,
41     };
42 
43     ParseHeicState m_parseState;
44     int m_quality;
45     QImage m_current_image;
46 };
47 
48 class HEIFPlugin : public QImageIOPlugin
49 {
50     Q_OBJECT
51     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "heif.json")
52 
53 public:
54     Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
55     QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
56 };
57 
58 #endif // KIMG_HEIF_P_H
59