![]() |
Qt 6.x
The Qt SDK
|
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt. More...
#include <qimageiohandler.h>
Public Types | |
enum | ImageOption { Size , ClipRect , Description , ScaledClipRect , ScaledSize , CompressionRatio , Gamma , Quality , Name , SubType , IncrementalReading , Endianness , Animation , BackgroundColor , ImageFormat , SupportedSubTypes , OptimizedWrite , ProgressiveScanWrite , ImageTransformation } |
This enum describes the different options supported by QImageIOHandler. More... | |
enum | Transformation { TransformationNone = 0 , TransformationMirror = 1 , TransformationFlip = 2 , TransformationRotate180 = TransformationMirror | TransformationFlip , TransformationRotate90 = 4 , TransformationMirrorAndRotate90 = TransformationMirror | TransformationRotate90 , TransformationFlipAndRotate90 = TransformationFlip | TransformationRotate90 , TransformationRotate270 = TransformationRotate180 | TransformationRotate90 } |
Public Member Functions | |
QImageIOHandler () | |
Constructs a QImageIOHandler object. | |
virtual | ~QImageIOHandler () |
Destructs the QImageIOHandler object. | |
void | setDevice (QIODevice *device) |
Sets the device of the QImageIOHandler to device. | |
QIODevice * | device () const |
Returns the device currently assigned to the QImageIOHandler. | |
void | setFormat (const QByteArray &format) |
Sets the format of the QImageIOHandler to format. | |
void | setFormat (const QByteArray &format) const |
Sets the format of the QImageIOHandler to format. | |
QByteArray | format () const |
Returns the format that is currently assigned to QImageIOHandler. | |
virtual bool | canRead () const =0 |
Returns true if an image can be read from the device (i.e., the image format is supported, the device can be read from and the initial header information suggests that the image can be read); otherwise returns false . | |
virtual bool | read (QImage *image)=0 |
Read an image from the device, and stores it in image. | |
virtual bool | write (const QImage &image) |
Writes the image image to the assigned device. | |
virtual QVariant | option (ImageOption option) const |
Returns the value assigned to option as a QVariant. | |
virtual void | setOption (ImageOption option, const QVariant &value) |
Sets the option option with the value value. | |
virtual bool | supportsOption (ImageOption option) const |
Returns true if the QImageIOHandler supports the option option; otherwise returns false . | |
virtual bool | jumpToNextImage () |
For image formats that support animation, this function jumps to the next image. | |
virtual bool | jumpToImage (int imageNumber) |
For image formats that support animation, this function jumps to the image whose sequence number is imageNumber. | |
virtual int | loopCount () const |
For image formats that support animation, this function returns the number of times the animation should loop. | |
virtual int | imageCount () const |
For image formats that support animation, this function returns the number of images in the animation. | |
virtual int | nextImageDelay () const |
For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. | |
virtual int | currentImageNumber () const |
For image formats that support animation, this function returns the sequence number of the current image in the animation. | |
virtual QRect | currentImageRect () const |
Returns the rect of the current image. | |
Static Public Member Functions | |
static bool | allocateImage (QSize size, QImage::Format format, QImage *image) |
Protected Member Functions | |
QImageIOHandler (QImageIOHandlerPrivate &dd) | |
Protected Attributes | |
QScopedPointer< QImageIOHandlerPrivate > | d_ptr |
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.
\reentrant \inmodule QtGui
Qt uses QImageIOHandler for reading and writing images through QImageReader and QImageWriter. You can also derive from this class to write your own image format handler using Qt's plugin mechanism.
Call setDevice() to assign a device to the handler, and setFormat() to assign a format to it. One QImageIOHandler may support more than one image format. canRead() returns true
if an image can be read from the device, and read() and write() return true if reading or writing an image was completed successfully.
QImageIOHandler also has support for animations formats, through the functions loopCount(), imageCount(), nextImageDelay() and currentImageNumber().
In order to determine what options an image handler supports, Qt will call supportsOption() and setOption(). Make sure to reimplement these functions if you can provide support for any of the options in the ImageOption enum.
To write your own image handler, you must at least reimplement canRead() and read(). Then create a QImageIOPlugin that can create the handler. Finally, install your plugin, and QImageReader and QImageWriter will then automatically load the plugin, and start using it.
Definition at line 23 of file qimageiohandler.h.
This enum describes the different options supported by QImageIOHandler.
Some options are used to query an image for properties, and others are used to toggle the way in which an image should be written.
\value Size The original size of an image. A handler that supports this option is expected to read the size of the image from the image metadata, and return this size from option() as a QSize.
\value ClipRect The clip rect, or ROI (Region Of Interest). A handler that supports this option is expected to only read the provided QRect area from the original image in read(), before any other transformation is applied.
\value ScaledSize The scaled size of the image. A handler that supports this option is expected to scale the image to the provided size (a QSize), after applying any clip rect transformation (ClipRect). If the handler does not support this option, QImageReader will perform the scaling after the image has been read.
\value ScaledClipRect The scaled clip rect (or ROI, Region Of Interest) of the image. A handler that supports this option is expected to apply the provided clip rect (a QRect), after applying any scaling (ScaleSize) or regular clipping (ClipRect). If the handler does not support this option, QImageReader will apply the scaled clip rect after the image has been read.
\value Description The image description. Some image formats, such as GIF and PNG, allow embedding of text or comments into the image data (e.g., for storing copyright information). It's common that the text is stored in key-value pairs, but some formats store all text in one continuous block. QImageIOHandler returns the text as one QString, where keys and values are separated by a ':', and keys-value pairs are separated by two newlines (\n\n). For example, "Title: Sunset\\n\\nAuthor: Jim Smith\\nSarah Jones\\n\\n". Formats that store text in a single block can use "Description" as the key.
\value CompressionRatio The compression ratio of the image data. A handler that supports this option is expected to set its compression rate depending on the value of this option (an int) when writing.
\value Gamma The gamma level of the image. A handler that supports this option is expected to set the image gamma level depending on the value of this option (a float) when writing.
\value Quality The quality level of the image. A handler that supports this option is expected to set the image quality level depending on the value of this option (an int) when writing.
\value Name The name of the image. A handler that supports this option is expected to read the name from the image metadata and return this as a QString, or when writing an image it is expected to store the name in the image metadata.
\value SubType The subtype of the image. A handler that supports this option can use the subtype value to help when reading and writing images. For example, a PPM handler may have a subtype value of "ppm" or "ppmraw".
\value IncrementalReading A handler that supports this option is expected to read the image in several passes, as if it was an animation. QImageReader will treat the image as an animation.
\value Endianness The endianness of the image. Certain image formats can be stored as BigEndian or LittleEndian. A handler that supports Endianness uses the value of this option to determine how the image should be stored.
\value Animation Image formats that support animation return true for this value in supportsOption(); otherwise, false is returned.
\value BackgroundColor Certain image formats allow the background color to be specified. A handler that supports BackgroundColor initializes the background color to this option (a QColor) when reading an image.
\value ImageFormat The image's data format returned by the handler. This can be any of the formats listed in QImage::Format.
\value SupportedSubTypes Image formats that support different saving variants should return a list of supported variant names (QList<QByteArray>) in this option.
\value OptimizedWrite. A handler which supports this option is expected to turn on optimization flags when writing.
\value ProgressiveScanWrite. A handler which supports this option is expected to write the image as a progressive scan image.
\value ImageTransformation. A handler which supports this option can read the transformation metadata of an image. A handler that supports this option should not apply the transformation itself.
Definition at line 41 of file qimageiohandler.h.
This enum describes the different transformations or orientations supported by some image formats, usually through EXIF.
\value TransformationNone No transformation should be applied.
\value TransformationMirror Mirror the image horizontally.
\value TransformationFlip Mirror the image vertically.
\value TransformationRotate180 Rotate the image 180 degrees. This is the same as mirroring it both horizontally and vertically.
\value TransformationRotate90 Rotate the image 90 degrees.
\value TransformationMirrorAndRotate90 Mirror the image horizontally and then rotate it 90 degrees.
\value TransformationFlipAndRotate90 Mirror the image vertically and then rotate it 90 degrees.
\value TransformationRotate270 Rotate the image 270 degrees. This is the same as mirroring it both horizontally, vertically and then rotating it 90 degrees.
Definition at line 63 of file qimageiohandler.h.
QImageIOHandler::QImageIOHandler | ( | ) |
Constructs a QImageIOHandler object.
Definition at line 267 of file qimageiohandler.cpp.
|
virtual |
Destructs the QImageIOHandler object.
Definition at line 285 of file qimageiohandler.cpp.
|
protected |
Constructs a QImageIOHandler object, using the private member dd.
Definition at line 277 of file qimageiohandler.cpp.
|
static |
This is a convenience method for the reading function in subclasses. Image format handlers must reject loading an image if the required allocation would exceeed the current allocation limit. This function checks the parameters and limit, and does the allocation if it is valid and required. Upon successful return, image will be a valid, detached QImage of the given size and format.
Definition at line 532 of file qimageiohandler.cpp.
References QImageReader::allocationLimit(), QImageData::calculateImageParameters(), QImageData::ImageSizeParameters::isValid(), QImage::NImageFormats, Q_ASSERT, qCWarning, qMax(), qt_depthForFormat(), and QImageData::ImageSizeParameters::totalSize.
Referenced by QGIFFormat::decode(), ensureValidImage(), ICOReader::iconAt(), QMngHandlerPrivate::processHeader(), QTiffHandler::read(), QWebpHandler::read(), QSvgIOHandler::read(), Jpeg2000JasperReader::read(), read32bitIcon(), read_dib_body(), read_pbm_body(), read_xbm_body(), read_xpm_body(), QTgaFile::readImage(), WBMPReader::readImage(), readLowDepthIcon(), readMask(), and setup_qt().
|
pure virtual |
Returns true
if an image can be read from the device (i.e., the image format is supported, the device can be read from and the initial header information suggests that the image can be read); otherwise returns false
.
When reimplementing canRead(), make sure that the I/O device (device()) is left in its original state (e.g., by using peek() rather than read()).
Implemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QtIcoHandler, QJpegHandler, QDDSHandler, QICNSHandler, QJp2Handler, QMacHeifHandler, QMacJp2Handler, QMngHandler, QTgaHandler, QTiffHandler, QWbmpHandler, QWebpHandler, QSvgIOHandler, and QPdfIOHandler.
Referenced by QImageReader::canRead(), createReadHandlerHelper(), QImageReader::format(), imageCount(), and QImageReader::imageFormat().
|
virtual |
For image formats that support animation, this function returns the sequence number of the current image in the animation.
If this function is called before any image is read(), -1 is returned. The number of the first image in the sequence is 0.
If the image format does not support animation, 0 is returned.
Reimplemented in QGifHandler, QMngHandler, QTiffHandler, QWebpHandler, and QPdfIOHandler.
Definition at line 444 of file qimageiohandler.cpp.
Referenced by QImageReader::currentImageNumber().
|
virtual |
Returns the rect of the current image.
If no rect is defined for the image, and empty QRect() is returned.
This function is useful for animations, where only parts of the frame may be updated at a time.
Reimplemented in QWebpHandler, and QPdfIOHandler.
Definition at line 456 of file qimageiohandler.cpp.
Referenced by QImageReader::currentImageRect().
QIODevice * QImageIOHandler::device | ( | ) | const |
Returns the device currently assigned to the QImageIOHandler.
If not device has been assigned, \nullptr is returned.
Definition at line 310 of file qimageiohandler.cpp.
References d.
Referenced by QtIcoHandler::QtIcoHandler(), QBmpHandler::canRead(), QPngHandler::canRead(), QPpmHandler::canRead(), QXbmHandler::canRead(), QXpmHandler::canRead(), QGifHandler::canRead(), QtIcoHandler::canRead(), QJpegHandler::canRead(), QDDSHandler::canRead(), QICNSHandler::canRead(), QJp2Handler::canRead(), QMacHeifHandler::canRead(), QMacJp2Handler::canRead(), QMngHandler::canRead(), QTgaHandler::canRead(), QTiffHandler::canRead(), QWbmpHandler::canRead(), QWebpHandler::canRead(), QSvgIOHandler::canRead(), QPdfIOHandler::canRead(), QBmpHandler::canRead(), QPngHandler::canRead(), QXbmHandler::canRead(), QXpmHandler::canRead(), QGifHandler::canRead(), QtIcoHandler::canRead(), QJpegHandler::canRead(), QDDSHandler::canRead(), QICNSHandler::canRead(), QMngHandler::canRead(), QTgaHandler::canRead(), QTiffHandler::canRead(), QWbmpHandler::canRead(), QWebpHandler::canRead(), QSvgIOHandler::canRead(), QPdfIOHandler::canRead(), QPpmHandler::canRead(), QGifHandler::imageCount(), QPdfIOHandler::imageCount(), QIIOFHelper::initRead(), QGifHandler::loopCount(), QGifHandler::option(), QJpegHandler::option(), QTiffHandler::option(), QWbmpHandler::option(), QSvgIOHandler::option(), QPdfIOHandler::option(), QBmpHandler::read(), QPpmHandler::read(), QXbmHandler::read(), QGifHandler::read(), QDDSHandler::read(), QICNSHandler::read(), QJp2Handler::read(), QTiffHandler::read(), QSvgIOHandler::read(), QPdfIOHandler::read(), setDevice(), QGifHandler::supportsOption(), QBmpHandler::write(), QPngHandler::write(), QPpmHandler::write(), QXbmHandler::write(), QXpmHandler::write(), QtIcoHandler::write(), QJpegHandler::write(), QDDSHandler::write(), QICNSHandler::write(), QJp2Handler::write(), QTiffHandler::write(), QWebpHandler::write(), and QIIOFHelper::writeImage().
QByteArray QImageIOHandler::format | ( | ) | const |
Returns the format that is currently assigned to QImageIOHandler.
If no format has been assigned, an empty string is returned.
Definition at line 349 of file qimageiohandler.cpp.
References d.
Referenced by QImageReader::format(), QImageReader::imageFormat(), QBmpHandler::option(), QPpmHandler::option(), setFormat(), and setFormat().
|
virtual |
For image formats that support animation, this function returns the number of images in the animation.
If the image format does not support animation, or if it is unable to determine the number of images, 0 is returned.
The default implementation returns 1 if canRead() returns true
; otherwise 0 is returned.
Reimplemented in QGifHandler, QtIcoHandler, QDDSHandler, QICNSHandler, QMngHandler, QTiffHandler, QWebpHandler, and QPdfIOHandler.
Definition at line 470 of file qimageiohandler.cpp.
References canRead().
Referenced by QImageReader::imageCount().
|
virtual |
For image formats that support animation, this function jumps to the image whose sequence number is imageNumber.
The next call to read() will attempt to read this image.
The default implementation does nothing, and returns false
.
Reimplemented in QPdfIOHandler, QtIcoHandler, QDDSHandler, QICNSHandler, QMngHandler, and QTiffHandler.
Definition at line 493 of file qimageiohandler.cpp.
References Q_UNUSED.
Referenced by QImageReader::jumpToImage().
|
virtual |
For image formats that support animation, this function jumps to the next image.
The default implementation does nothing, and returns false
.
Reimplemented in QtIcoHandler, QICNSHandler, QMngHandler, QTiffHandler, and QPdfIOHandler.
Definition at line 481 of file qimageiohandler.cpp.
Referenced by QImageReader::jumpToNextImage().
|
virtual |
For image formats that support animation, this function returns the number of times the animation should loop.
If the image format does not support animation, 0 is returned.
Reimplemented in QGifHandler, QMngHandler, and QWebpHandler.
Definition at line 504 of file qimageiohandler.cpp.
Referenced by QImageReader::loopCount().
|
virtual |
For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image.
If the image format does not support animation, 0 is returned.
Reimplemented in QGifHandler, QMngHandler, and QWebpHandler.
Definition at line 515 of file qimageiohandler.cpp.
Referenced by QImageReader::nextImageDelay().
|
virtual |
Returns the value assigned to option as a QVariant.
The type of the value depends on the option. For example, option(Size) returns a QSize variant.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QtIcoHandler, QJpegHandler, QICNSHandler, QJp2Handler, QMacHeifHandler, QMacJp2Handler, QMngHandler, QTgaHandler, QTiffHandler, QWbmpHandler, QWebpHandler, QSvgIOHandler, QPdfIOHandler, and QDDSHandler.
Definition at line 414 of file qimageiohandler.cpp.
References Q_UNUSED.
Referenced by QImageReader::backgroundColor(), QImageReaderPrivate::getText(), QImageReader::imageFormat(), QImageReader::size(), QImageReader::subType(), QImageReader::supportedSubTypes(), QImageWriter::supportedSubTypes(), QImageReader::supportsAnimation(), and QImageReader::transformation().
|
pure virtual |
Read an image from the device, and stores it in image.
Returns true
if the image is successfully read; otherwise returns false.
For image formats that support incremental loading, and for animation formats, the image handler can assume that image points to the previous frame.
Implemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QtIcoHandler, QJpegHandler, QDDSHandler, QICNSHandler, QJp2Handler, QMacHeifHandler, QMacJp2Handler, QMngHandler, QTgaHandler, QTiffHandler, QWbmpHandler, QWebpHandler, QSvgIOHandler, and QPdfIOHandler.
Referenced by QImageReader::read().
Sets the device of the QImageIOHandler to device.
The image handler will use this device when reading and writing images.
The device can only be set once and must be set before calling canRead(), read(), write(), etc. If you need to read multiple files, construct multiple instances of the appropriate QImageIOHandler subclass.
Definition at line 300 of file qimageiohandler.cpp.
Referenced by QtIcoHandler::QtIcoHandler(), QGifPlugin::create(), QJpegPlugin::create(), QDDSPlugin::create(), QICNSPlugin::create(), QJp2Plugin::create(), QMacHeifPlugin::create(), QMacJp2Plugin::create(), QMngPlugin::create(), QTgaPlugin::create(), QTiffPlugin::create(), QWebpPlugin::create(), QSvgPlugin::create(), QPdfPlugin::create(), createReadHandlerHelper(), and createWriteHandlerHelper().
void QImageIOHandler::setFormat | ( | const QByteArray & | format | ) |
Sets the format of the QImageIOHandler to format.
The format is most useful for handlers that support multiple image formats.
Definition at line 322 of file qimageiohandler.cpp.
Referenced by QBmpHandler::canRead(), QPngHandler::canRead(), QPpmHandler::canRead(), QXbmHandler::canRead(), QXpmHandler::canRead(), QGifHandler::canRead(), QtIcoHandler::canRead(), QJpegHandler::canRead(), QDDSHandler::canRead(), QICNSHandler::canRead(), QJp2Handler::canRead(), QMacHeifHandler::canRead(), QMacJp2Handler::canRead(), QMngHandler::canRead(), QTgaHandler::canRead(), QTiffHandler::canRead(), QWbmpHandler::canRead(), QWebpHandler::canRead(), QSvgIOHandler::canRead(), QPdfIOHandler::canRead(), QGifPlugin::create(), QICOPlugin::create(), QJpegPlugin::create(), QDDSPlugin::create(), QICNSPlugin::create(), QJp2Plugin::create(), QMacHeifPlugin::create(), QMacJp2Plugin::create(), QMngPlugin::create(), QTgaPlugin::create(), QTiffPlugin::create(), QWbmpPlugin::create(), QWebpPlugin::create(), QSvgPlugin::create(), QPdfPlugin::create(), createReadHandlerHelper(), and createWriteHandlerHelper().
void QImageIOHandler::setFormat | ( | const QByteArray & | format | ) | const |
Sets the format of the QImageIOHandler to format.
The format is most useful for handlers that support multiple image formats.
This function is declared const so that it can be called from canRead().
Definition at line 336 of file qimageiohandler.cpp.
|
virtual |
Sets the option option with the value value.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QJpegHandler, QDDSHandler, QJp2Handler, QMacHeifHandler, QMacJp2Handler, QMngHandler, QTgaHandler, QTiffHandler, QWebpHandler, QSvgIOHandler, and QPdfIOHandler.
Definition at line 401 of file qimageiohandler.cpp.
References Q_UNUSED.
Referenced by createReadHandlerHelper(), createWriteHandlerHelper(), QImageReader::read(), QImageReader::setBackgroundColor(), QWebpHandler::setOption(), and QImageWriter::write().
|
virtual |
Returns true
if the QImageIOHandler supports the option option; otherwise returns false
.
For example, if the QImageIOHandler supports the \l Size option, supportsOption(Size) must return true.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QtIcoHandler, QJpegHandler, QICNSHandler, QJp2Handler, QMacHeifHandler, QMacJp2Handler, QMngHandler, QTgaHandler, QTiffHandler, QWbmpHandler, QWebpHandler, QSvgIOHandler, QPdfIOHandler, and QDDSHandler.
Definition at line 428 of file qimageiohandler.cpp.
References Q_UNUSED.
Referenced by QImageReader::backgroundColor(), QImageReaderPrivate::getText(), QImageReader::imageFormat(), QImageReader::read(), QImageReader::setBackgroundColor(), QImageReader::size(), QImageReader::subType(), QImageReader::supportedSubTypes(), QImageReader::supportsAnimation(), QImageReader::supportsOption(), QImageWriter::supportsOption(), QImageReader::transformation(), QImageWriter::write(), and QIIOFHelper::writeImage().
|
virtual |
Writes the image image to the assigned device.
Returns true
on success; otherwise returns false
.
The default implementation does nothing, and simply returns false
.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QtIcoHandler, QJpegHandler, QDDSHandler, QICNSHandler, QJp2Handler, QMacHeifHandler, QMacJp2Handler, QMngHandler, QTiffHandler, QWbmpHandler, and QWebpHandler.
Definition at line 390 of file qimageiohandler.cpp.
References Q_UNUSED.
Referenced by QImageWriter::write().
|
protected |
Definition at line 92 of file qimageiohandler.h.