| 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 <QtGui/qimage.h> |
| 45 | #include <QtCore/qiodevice.h> |
| 46 | #include <QtCore/qplugin.h> |
| 47 | #include <QtCore/qfactoryinterface.h> |
| 48 | #include <QtCore/qscopedpointer.h> |
| 49 | |
| 50 | QT_BEGIN_NAMESPACE |
| 51 | |
| 52 | |
| 53 | class QImage; |
| 54 | class QRect; |
| 55 | class QSize; |
| 56 | class QVariant; |
| 57 | |
| 58 | class QImageIOHandlerPrivate; |
| 59 | class Q_GUI_EXPORT QImageIOHandler |
| 60 | { |
| 61 | Q_DECLARE_PRIVATE(QImageIOHandler) |
| 62 | public: |
| 63 | QImageIOHandler(); |
| 64 | virtual ~QImageIOHandler(); |
| 65 | |
| 66 | void setDevice(QIODevice *device); |
| 67 | QIODevice *device() const; |
| 68 | |
| 69 | void setFormat(const QByteArray &format); |
| 70 | void setFormat(const QByteArray &format) const; |
| 71 | QByteArray format() const; |
| 72 | |
| 73 | virtual bool canRead() const = 0; |
| 74 | virtual bool read(QImage *image) = 0; |
| 75 | virtual bool write(const QImage &image); |
| 76 | |
| 77 | enum ImageOption { |
| 78 | Size, |
| 79 | ClipRect, |
| 80 | Description, |
| 81 | ScaledClipRect, |
| 82 | ScaledSize, |
| 83 | CompressionRatio, |
| 84 | Gamma, |
| 85 | Quality, |
| 86 | Name, |
| 87 | SubType, |
| 88 | IncrementalReading, |
| 89 | Endianness, |
| 90 | Animation, |
| 91 | BackgroundColor, |
| 92 | ImageFormat, |
| 93 | SupportedSubTypes, |
| 94 | OptimizedWrite, |
| 95 | ProgressiveScanWrite, |
| 96 | ImageTransformation |
| 97 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 98 | , TransformedByDefault |
| 99 | #endif |
| 100 | }; |
| 101 | |
| 102 | enum Transformation { |
| 103 | TransformationNone = 0, |
| 104 | TransformationMirror = 1, |
| 105 | TransformationFlip = 2, |
| 106 | TransformationRotate180 = TransformationMirror | TransformationFlip, |
| 107 | TransformationRotate90 = 4, |
| 108 | TransformationMirrorAndRotate90 = TransformationMirror | TransformationRotate90, |
| 109 | TransformationFlipAndRotate90 = TransformationFlip | TransformationRotate90, |
| 110 | TransformationRotate270 = TransformationRotate180 | TransformationRotate90 |
| 111 | }; |
| 112 | Q_DECLARE_FLAGS(Transformations, Transformation) |
| 113 | |
| 114 | virtual QVariant option(ImageOption option) const; |
| 115 | virtual void setOption(ImageOption option, const QVariant &value); |
| 116 | virtual bool supportsOption(ImageOption option) const; |
| 117 | |
| 118 | // incremental loading |
| 119 | virtual bool jumpToNextImage(); |
| 120 | virtual bool jumpToImage(int imageNumber); |
| 121 | virtual int loopCount() const; |
| 122 | virtual int imageCount() const; |
| 123 | virtual int nextImageDelay() const; |
| 124 | virtual int currentImageNumber() const; |
| 125 | virtual QRect currentImageRect() const; |
| 126 | |
| 127 | static bool allocateImage(QSize size, QImage::Format format, QImage *image); |
| 128 | |
| 129 | protected: |
| 130 | QImageIOHandler(QImageIOHandlerPrivate &dd); |
| 131 | QScopedPointer<QImageIOHandlerPrivate> d_ptr; |
| 132 | private: |
| 133 | Q_DISABLE_COPY(QImageIOHandler) |
| 134 | }; |
| 135 | |
| 136 | #ifndef QT_NO_IMAGEFORMATPLUGIN |
| 137 | |
| 138 | #define QImageIOHandlerFactoryInterface_iid "org.qt-project.Qt.QImageIOHandlerFactoryInterface" |
| 139 | |
| 140 | class Q_GUI_EXPORT QImageIOPlugin : public QObject |
| 141 | { |
| 142 | Q_OBJECT |
| 143 | public: |
| 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 | |
| 158 | Q_DECLARE_OPERATORS_FOR_FLAGS(QImageIOPlugin::Capabilities) |
| 159 | |
| 160 | #endif // QT_NO_IMAGEFORMATPLUGIN |
| 161 | |
| 162 | QT_END_NAMESPACE |
| 163 | |
| 164 | #endif // QIMAGEIOHANDLER_H |
| 165 | |