QImageIOHandler Class Reference

#include <qimageiohandler.h>

Inheritance diagram for QImageIOHandler:

Inheritance graph
[legend]
Collaboration diagram for QImageIOHandler:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.

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.

See also:
QImageIOPlugin, QImageReader, QImageWriter

Definition at line 40 of file qimageiohandler.h.

Public Types

enum  ImageOption

Public Member Functions

 QImageIOHandler ()
virtual ~QImageIOHandler ()
void setDevice (QIODevice *device)
QIODevicedevice () const
void setFormat (const QByteArray &format)
void setFormat (const QByteArray &format) const
QByteArray format () const
virtual QByteArray name () const
virtual bool canRead () const=0
virtual bool read (QImage *image)=0
virtual bool write (const QImage &image)
virtual QVariant option (ImageOption option) const
virtual void setOption (ImageOption option, const QVariant &value)
virtual bool supportsOption (ImageOption option) const
virtual bool jumpToNextImage ()
virtual bool jumpToImage (int imageNumber)
virtual int loopCount () const
virtual int imageCount () const
virtual int nextImageDelay () const
virtual int currentImageNumber () const
virtual QRect currentImageRect () const

Protected Member Functions

 QImageIOHandler (QImageIOHandlerPrivate &dd)

Protected Attributes

QImageIOHandlerPrivated_ptr


Member Enumeration Documentation

enum QImageIOHandler::ImageOption

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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".

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.

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.

Animation Image formats that support animation return true for this value in supportsOption(); otherwise, false is returned.

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.

Definition at line 60 of file qimageiohandler.h.

00060                      {
00061         Size,
00062         ClipRect,
00063         Description,
00064         ScaledClipRect,
00065         ScaledSize,
00066         CompressionRatio,
00067         Gamma,
00068         Quality,
00069         Name,
00070         SubType,
00071         IncrementalReading,
00072         Endianness,
00073         Animation,
00074         BackgroundColor
00075     };


Constructor & Destructor Documentation

QImageIOHandler::QImageIOHandler (  ) 

Constructs a QImageIOHandler object.

Definition at line 229 of file qimageiohandler.cpp.

00230     : d_ptr(new QImageIOHandlerPrivate(this))
00231 {
00232 }

QImageIOHandler::~QImageIOHandler (  )  [virtual]

Destructs the QImageIOHandler object.

Definition at line 247 of file qimageiohandler.cpp.

References d_ptr.

00248 {
00249     delete d_ptr;
00250 }

QImageIOHandler::QImageIOHandler ( QImageIOHandlerPrivate dd  )  [protected]

Definition at line 239 of file qimageiohandler.cpp.

00240     : d_ptr(&dd)
00241 {
00242 }


Member Function Documentation

void QImageIOHandler::setDevice ( QIODevice device  ) 

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.

See also:
device()

Definition at line 263 of file qimageiohandler.cpp.

References d, and device().

Referenced by QSvgPlugin::create(), and QMngPlugin::create().

00264 {
00265     Q_D(QImageIOHandler);
00266     d->device = device;
00267 }

Here is the call graph for this function:

QIODevice * QImageIOHandler::device (  )  const

Returns the device currently assigned to the QImageIOHandler. If not device has been assigned, 0 is returned.

Definition at line 273 of file qimageiohandler.cpp.

References d.

Referenced by QJpegHandler::canRead(), QXbmHandler::canRead(), QGifHandler::canRead(), QPngHandler::canRead(), QXpmHandler::canRead(), QMngHandler::canRead(), QSvgIOHandler::canRead(), QBmpHandler::canRead(), QPpmHandler::canRead(), QGifHandler::imageIsComing(), QJpegHandler::option(), QXbmHandler::read(), QSvgIOHandler::read(), QGifHandler::read(), QJpegHandler::read(), QBmpHandler::read(), QPpmHandler::read(), QPpmHandler::readHeader(), QBmpHandler::readHeader(), QXbmHandler::readHeader(), QXpmHandler::readHeader(), QXpmHandler::readImage(), QPngHandlerPrivate::readPngHeader(), setDevice(), QPpmHandler::write(), QPngHandler::write(), QXpmHandler::write(), QBmpHandler::write(), QJpegHandler::write(), and QXbmHandler::write().

00274 {
00275     Q_D(const QImageIOHandler);
00276     return d->device;
00277 }

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.

See also:
format()

Definition at line 285 of file qimageiohandler.cpp.

References d, and format().

Referenced by QJpegHandler::canRead(), QXbmHandler::canRead(), QGifHandler::canRead(), QPngHandler::canRead(), QXpmHandler::canRead(), QMngHandler::canRead(), QBmpHandler::canRead(), QPpmHandler::canRead(), QSvgPlugin::create(), and QMngPlugin::create().

00286 {
00287     Q_D(QImageIOHandler);
00288     d->format = format;
00289 }

Here is the call graph for this function:

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().

See also:
format()

Definition at line 299 of file qimageiohandler.cpp.

References d, and format().

00300 {
00301     Q_D(const QImageIOHandler);
00302     d->format = format;
00303 }

Here is the call graph for this function:

QByteArray QImageIOHandler::format (  )  const

Returns the format that is currently assigned to QImageIOHandler. If no format has been assigned, an empty string is returned.

See also:
setFormat()

Definition at line 312 of file qimageiohandler.cpp.

References d.

Referenced by QImageReader::format(), name(), and setFormat().

00313 {
00314     Q_D(const QImageIOHandler);
00315     return d->format;
00316 }

QByteArray QImageIOHandler::name (  )  const [virtual]

Use format() instead.

Definition at line 353 of file qimageiohandler.cpp.

References format().

00354 {
00355     return format();
00356 }

Here is the call graph for this function:

bool QImageIOHandler::canRead (  )  const [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()).

See also:
read(), QIODevice::peek()

Referenced by QImageReader::canRead(), QImageReader::format(), and imageCount().

bool QImageIOHandler::read ( QImage image  )  [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.

See also:
canRead()

Referenced by QImageReader::read().

bool QImageIOHandler::write ( const QImage image  )  [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.

Definition at line 364 of file qimageiohandler.cpp.

References image.

00365 {
00366     Q_UNUSED(image);
00367     return false;
00368 }

QVariant QImageIOHandler::option ( ImageOption  option  )  const [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.

See also:
setOption(), supportsOption()

Definition at line 388 of file qimageiohandler.cpp.

Referenced by QImageReader::backgroundColor(), QImageReaderPrivate::getText(), QImageReader::size(), and QImageReader::supportsAnimation().

00389 {
00390     Q_UNUSED(option);
00391     return QVariant();
00392 }

void QImageIOHandler::setOption ( ImageOption  option,
const QVariant value 
) [virtual]

Sets the option option with the value value.

See also:
option(), ImageOption

Definition at line 375 of file qimageiohandler.cpp.

References value.

Referenced by QImageReader::read(), and QImageReader::setBackgroundColor().

00376 {
00377     Q_UNUSED(option);
00378     Q_UNUSED(value);
00379 }

bool QImageIOHandler::supportsOption ( ImageOption  option  )  const [virtual]

Returns true if the QImageIOHandler supports the option option; otherwise returns false. For example, if the QImageIOHandler supports the Size option, supportsOption(Size) must return true.

See also:
setOption(), option()

Definition at line 402 of file qimageiohandler.cpp.

Referenced by QImageReader::backgroundColor(), QImageReaderPrivate::getText(), QImageReader::read(), QImageReader::setBackgroundColor(), QImageReader::size(), QImageReader::supportsAnimation(), and QImageReader::supportsOption().

00403 {
00404     Q_UNUSED(option);
00405     return false;
00406 }

bool QImageIOHandler::jumpToNextImage (  )  [virtual]

For image formats that support animation, this function jumps to the next image.

The default implementation does nothing, and returns false.

Definition at line 451 of file qimageiohandler.cpp.

Referenced by QImageReader::jumpToNextImage().

00452 {
00453     return false;
00454 }

bool QImageIOHandler::jumpToImage ( int  imageNumber  )  [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.

Definition at line 463 of file qimageiohandler.cpp.

Referenced by QImageReader::jumpToImage().

00464 {
00465     Q_UNUSED(imageNumber);
00466     return false;
00467 }

int QImageIOHandler::loopCount (  )  const [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.

Definition at line 474 of file qimageiohandler.cpp.

Referenced by QImageReader::loopCount().

00475 {
00476     return 0;
00477 }

int QImageIOHandler::imageCount (  )  const [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.

Definition at line 440 of file qimageiohandler.cpp.

References canRead().

Referenced by QImageReader::imageCount().

00441 {
00442     return canRead() ? 1 : 0;
00443 }

Here is the call graph for this function:

int QImageIOHandler::nextImageDelay (  )  const [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.

Definition at line 485 of file qimageiohandler.cpp.

Referenced by QImageReader::nextImageDelay().

00486 {
00487     return 0;
00488 }

int QImageIOHandler::currentImageNumber (  )  const [virtual]

For image formats that support animation, this function returns the sequence number of the current image in the animation. If the image format does not support animation, or if it is unable to determine the current sequence number, 0 is returned.

Definition at line 414 of file qimageiohandler.cpp.

Referenced by QImageReader::currentImageNumber().

00415 {
00416     return 0;
00417 }

QRect QImageIOHandler::currentImageRect (  )  const [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.

Definition at line 426 of file qimageiohandler.cpp.

Referenced by QImageReader::currentImageRect().

00427 {
00428     return QRect();
00429 }


Member Data Documentation

QImageIOHandlerPrivate* QImageIOHandler::d_ptr [protected]

Definition at line 91 of file qimageiohandler.h.

Referenced by ~QImageIOHandler().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:02:44 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1