1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QIMAGEIOHANDLER_H
41#define QIMAGEIOHANDLER_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qiodevice.h>
45#include <QtCore/qplugin.h>
46#include <QtCore/qfactoryinterface.h>
47#include <QtCore/qscopedpointer.h>
48
49QT_BEGIN_NAMESPACE
50
51
52class QImage;
53class QRect;
54class QSize;
55class QVariant;
56
57class QImageIOHandlerPrivate;
58class Q_GUI_EXPORT QImageIOHandler
59{
60 Q_DECLARE_PRIVATE(QImageIOHandler)
61public:
62 QImageIOHandler();
63 virtual ~QImageIOHandler();
64
65 void setDevice(QIODevice *device);
66 QIODevice *device() const;
67
68 void setFormat(const QByteArray &format);
69 void setFormat(const QByteArray &format) const;
70 QByteArray format() const;
71
72 QT_DEPRECATED_X("Use QImageIOHandler::format() instead")
73 virtual QByteArray name() const;
74
75 virtual bool canRead() const = 0;
76 virtual bool read(QImage *image) = 0;
77 virtual bool write(const QImage &image);
78
79 enum ImageOption {
80 Size,
81 ClipRect,
82 Description,
83 ScaledClipRect,
84 ScaledSize,
85 CompressionRatio,
86 Gamma,
87 Quality,
88 Name,
89 SubType,
90 IncrementalReading,
91 Endianness,
92 Animation,
93 BackgroundColor,
94 ImageFormat,
95 SupportedSubTypes,
96 OptimizedWrite,
97 ProgressiveScanWrite,
98 ImageTransformation
99#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
100 , TransformedByDefault
101#endif
102 };
103
104 enum Transformation {
105 TransformationNone = 0,
106 TransformationMirror = 1,
107 TransformationFlip = 2,
108 TransformationRotate180 = TransformationMirror | TransformationFlip,
109 TransformationRotate90 = 4,
110 TransformationMirrorAndRotate90 = TransformationMirror | TransformationRotate90,
111 TransformationFlipAndRotate90 = TransformationFlip | TransformationRotate90,
112 TransformationRotate270 = TransformationRotate180 | TransformationRotate90
113 };
114 Q_DECLARE_FLAGS(Transformations, Transformation)
115
116 virtual QVariant option(ImageOption option) const;
117 virtual void setOption(ImageOption option, const QVariant &value);
118 virtual bool supportsOption(ImageOption option) const;
119
120 // incremental loading
121 virtual bool jumpToNextImage();
122 virtual bool jumpToImage(int imageNumber);
123 virtual int loopCount() const;
124 virtual int imageCount() const;
125 virtual int nextImageDelay() const;
126 virtual int currentImageNumber() const;
127 virtual QRect currentImageRect() const;
128
129protected:
130 QImageIOHandler(QImageIOHandlerPrivate &dd);
131 QScopedPointer<QImageIOHandlerPrivate> d_ptr;
132private:
133 Q_DISABLE_COPY(QImageIOHandler)
134};
135
136#ifndef QT_NO_IMAGEFORMATPLUGIN
137
138#define QImageIOHandlerFactoryInterface_iid "org.qt-project.Qt.QImageIOHandlerFactoryInterface"
139
140class Q_GUI_EXPORT QImageIOPlugin : public QObject
141{
142 Q_OBJECT
143public:
144 explicit QImageIOPlugin(QObject *parent = nullptr);
145 ~QImageIOPlugin();
146
147 enum Capability {
148 CanRead = 0x1,
149 CanWrite = 0x2,
150 CanReadIncremental = 0x4
151 };
152 Q_DECLARE_FLAGS(Capabilities, Capability)
153
154 virtual Capabilities capabilities(QIODevice *device, const QByteArray &format) const = 0;
155 virtual QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const = 0;
156};
157
158Q_DECLARE_OPERATORS_FOR_FLAGS(QImageIOPlugin::Capabilities)
159
160#endif // QT_NO_IMAGEFORMATPLUGIN
161
162QT_END_NAMESPACE
163
164#endif // QIMAGEIOHANDLER_H
165