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#if QT_DEPRECATED_SINCE(5, 13)
73 QT_DEPRECATED_X("Use QImageIOHandler::format() instead")
74 virtual QByteArray name() const;
75#endif
76
77 virtual bool canRead() const = 0;
78 virtual bool read(QImage *image) = 0;
79 virtual bool write(const QImage &image);
80
81 enum ImageOption {
82 Size,
83 ClipRect,
84 Description,
85 ScaledClipRect,
86 ScaledSize,
87 CompressionRatio,
88 Gamma,
89 Quality,
90 Name,
91 SubType,
92 IncrementalReading,
93 Endianness,
94 Animation,
95 BackgroundColor,
96 ImageFormat,
97 SupportedSubTypes,
98 OptimizedWrite,
99 ProgressiveScanWrite,
100 ImageTransformation
101#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
102 , TransformedByDefault
103#endif
104 };
105
106 enum Transformation {
107 TransformationNone = 0,
108 TransformationMirror = 1,
109 TransformationFlip = 2,
110 TransformationRotate180 = TransformationMirror | TransformationFlip,
111 TransformationRotate90 = 4,
112 TransformationMirrorAndRotate90 = TransformationMirror | TransformationRotate90,
113 TransformationFlipAndRotate90 = TransformationFlip | TransformationRotate90,
114 TransformationRotate270 = TransformationRotate180 | TransformationRotate90
115 };
116 Q_DECLARE_FLAGS(Transformations, Transformation)
117
118 virtual QVariant option(ImageOption option) const;
119 virtual void setOption(ImageOption option, const QVariant &value);
120 virtual bool supportsOption(ImageOption option) const;
121
122 // incremental loading
123 virtual bool jumpToNextImage();
124 virtual bool jumpToImage(int imageNumber);
125 virtual int loopCount() const;
126 virtual int imageCount() const;
127 virtual int nextImageDelay() const;
128 virtual int currentImageNumber() const;
129 virtual QRect currentImageRect() const;
130
131protected:
132 QImageIOHandler(QImageIOHandlerPrivate &dd);
133 QScopedPointer<QImageIOHandlerPrivate> d_ptr;
134private:
135 Q_DISABLE_COPY(QImageIOHandler)
136};
137
138#ifndef QT_NO_IMAGEFORMATPLUGIN
139
140#define QImageIOHandlerFactoryInterface_iid "org.qt-project.Qt.QImageIOHandlerFactoryInterface"
141
142class Q_GUI_EXPORT QImageIOPlugin : public QObject
143{
144 Q_OBJECT
145public:
146 explicit QImageIOPlugin(QObject *parent = nullptr);
147 ~QImageIOPlugin();
148
149 enum Capability {
150 CanRead = 0x1,
151 CanWrite = 0x2,
152 CanReadIncremental = 0x4
153 };
154 Q_DECLARE_FLAGS(Capabilities, Capability)
155
156 virtual Capabilities capabilities(QIODevice *device, const QByteArray &format) const = 0;
157 virtual QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const = 0;
158};
159
160Q_DECLARE_OPERATORS_FOR_FLAGS(QImageIOPlugin::Capabilities)
161
162#endif // QT_NO_IMAGEFORMATPLUGIN
163
164QT_END_NAMESPACE
165
166#endif // QIMAGEIOHANDLER_H
167