124 #ifdef QIMAGEREADER_DEBUG 140 #include <private/qfactoryloader_p.h> 143 #include <private/qbmphandler_p.h> 144 #include <private/qppmhandler_p.h> 145 #include <private/qxbmhandler_p.h> 146 #include <private/qxpmhandler_p.h> 147 #ifndef QT_NO_IMAGEFORMAT_PNG 148 #include <private/qpnghandler_p.h> 150 #ifndef QT_NO_IMAGEFORMAT_JPEG 151 #include <private/qjpeghandler_p.h> 153 #ifndef QT_NO_IMAGEFORMAT_MNG 154 #include <private/qmnghandler_p.h> 156 #ifndef QT_NO_IMAGEFORMAT_TIFF 157 #include <private/qtiffhandler_p.h> 159 #ifdef QT_BUILTIN_GIF_READER 160 #include <private/qgifhandler_p.h> 165 #ifndef QT_NO_LIBRARY 170 enum _qt_BuiltInFormatType {
171 #ifndef QT_NO_IMAGEFORMAT_PNG 174 #ifndef QT_NO_IMAGEFORMAT_JPEG 177 #ifndef QT_NO_IMAGEFORMAT_MNG 180 #ifndef QT_NO_IMAGEFORMAT_TIFF 183 #ifdef QT_BUILTIN_GIF_READER 187 #ifndef QT_NO_IMAGEFORMAT_PPM 192 #ifndef QT_NO_IMAGEFORMAT_XBM 195 #ifndef QT_NO_IMAGEFORMAT_XPM 209 #ifndef QT_NO_IMAGEFORMAT_PNG 210 {_qt_PngFormat,
"png"},
212 #ifndef QT_NO_IMAGEFORMAT_JPEG 213 {_qt_JpgFormat,
"jpg"},
215 #ifndef QT_NO_IMAGEFORMAT_MNG 216 {_qt_MngFormat,
"mng"},
218 #ifndef QT_NO_IMAGEFORMAT_TIFF 219 {_qt_TifFormat,
"tif"},
221 #ifdef QT_BUILTIN_GIF_READER 222 {_qt_GifFormat,
"gif"},
224 {_qt_BmpFormat,
"bmp"},
225 #ifndef QT_NO_IMAGEFORMAT_PPM 226 {_qt_PpmFormat,
"ppm"},
227 {_qt_PgmFormat,
"pgm"},
228 {_qt_PbmFormat,
"pbm"},
230 #ifndef QT_NO_IMAGEFORMAT_XBM 231 {_qt_XbmFormat,
"xbm"},
233 #ifndef QT_NO_IMAGEFORMAT_XPM 234 {_qt_XpmFormat,
"xpm"},
241 bool autoDetectImageFormat,
242 bool ignoresFormatAndExtension)
244 if (!autoDetectImageFormat && format.
isEmpty())
250 #ifndef QT_NO_LIBRARY 257 #ifdef QIMAGEREADER_DEBUG 258 qDebug() <<
"QImageReader::createReadHandler( device =" << (
void *)device <<
", format =" << format <<
")," 259 << keys.
size() <<
"plugins available: " <<
keys;
262 #ifndef QT_NO_LIBRARY 264 if (device && format.
isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
268 if (
QFile *file = qobject_cast<QFile *>(device)) {
269 #ifdef QIMAGEREADER_DEBUG 270 qDebug() <<
"QImageReader::createReadHandler: device is a file:" << file->fileName();
275 #ifdef QIMAGEREADER_DEBUG 276 qDebug() <<
"QImageReader::createReadHandler: suffix recognized; the" 277 << suffix <<
"plugin might be able to read this";
279 suffixPluginIndex =
index;
284 #endif // QT_NO_LIBRARY 288 if (ignoresFormatAndExtension)
291 #ifndef QT_NO_LIBRARY 292 if (suffixPluginIndex != -1) {
295 const qint64 pos = device ? device->
pos() : 0;
298 handler = plugin->
create(device, testFormat);
299 #ifdef QIMAGEREADER_DEBUG 300 qDebug() <<
"QImageReader::createReadHandler: using the" << suffix
308 if (!handler && !testFormat.
isEmpty() && !ignoresFormatAndExtension) {
311 const qint64 pos = device ? device->
pos() : 0;
313 if (autoDetectImageFormat) {
314 for (
int i = 0; i < keys.
size(); ++i) {
315 if (i != suffixPluginIndex) {
318 #ifdef QIMAGEREADER_DEBUG 319 qDebug() <<
"QImageReader::createReadHandler: the" << keys.
at(i) <<
"plugin can read this format";
321 handler = plugin->
create(device, testFormat);
329 #ifdef QIMAGEREADER_DEBUG 330 qDebug() <<
"QImageReader::createReadHandler: the" << testFormat <<
"plugin can read this format";
332 handler = plugin->
create(device, testFormat);
339 #endif // QT_NO_LIBRARY 343 if (!handler && !testFormat.
isEmpty()) {
345 #ifndef QT_NO_IMAGEFORMAT_PNG 346 }
else if (testFormat ==
"png") {
349 #ifndef QT_NO_IMAGEFORMAT_JPEG 350 }
else if (testFormat ==
"jpg" || testFormat ==
"jpeg") {
353 #ifndef QT_NO_IMAGEFORMAT_MNG 354 }
else if (testFormat ==
"mng") {
357 #ifndef QT_NO_IMAGEFORMAT_TIFF 358 }
else if (testFormat ==
"tif" || testFormat ==
"tiff") {
361 #ifdef QT_BUILTIN_GIF_READER 362 }
else if (testFormat ==
"gif") {
365 #ifndef QT_NO_IMAGEFORMAT_BMP 366 }
else if (testFormat ==
"bmp") {
369 #ifndef QT_NO_IMAGEFORMAT_XPM 370 }
else if (testFormat ==
"xpm") {
373 #ifndef QT_NO_IMAGEFORMAT_XBM 374 }
else if (testFormat ==
"xbm") {
378 #ifndef QT_NO_IMAGEFORMAT_PPM 379 }
else if (testFormat ==
"pbm" || testFormat ==
"pbmraw" || testFormat ==
"pgm" 380 || testFormat ==
"pgmraw" || testFormat ==
"ppm" || testFormat ==
"ppmraw") {
386 #ifdef QIMAGEREADER_DEBUG 388 qDebug() <<
"QImageReader::createReadHandler: using the built-in handler for" <<
testFormat;
392 #ifndef QT_NO_LIBRARY 393 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
395 const qint64 pos = device ? device->
pos() : 0;
396 for (
int i = 0; i < keys.
size(); ++i) {
397 if (i != suffixPluginIndex) {
400 handler = plugin->
create(device, testFormat);
401 #ifdef QIMAGEREADER_DEBUG 402 qDebug() <<
"QImageReader::createReadHandler: the" << keys.
at(i) <<
"plugin can read this data";
411 #endif // QT_NO_LIBRARY 413 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
416 int currentFormat = 0;
420 for (
int i = 0; i < _qt_NumFormats; ++i) {
421 if (_qt_BuiltInFormats[i].
extension == suffix) {
429 int numFormats = _qt_NumFormats;
430 while (device && numFormats >= 0) {
434 switch (formatStruct->
type) {
435 #ifndef QT_NO_IMAGEFORMAT_PNG 441 #ifndef QT_NO_IMAGEFORMAT_JPEG 447 #ifndef QT_NO_IMAGEFORMAT_MNG 453 #ifndef QT_NO_IMAGEFORMAT_TIFF 459 #ifdef QT_BUILTIN_GIF_READER 465 #ifndef QT_NO_IMAGEFORMAT_BMP 471 #ifndef QT_NO_IMAGEFORMAT_XPM 477 #ifndef QT_NO_IMAGEFORMAT_PPM 487 #ifndef QT_NO_IMAGEFORMAT_XBM 500 #ifdef QIMAGEREADER_DEBUG 501 qDebug() <<
"QImageReader::createReadHandler: the" << formatStruct->
extension 502 <<
"built-in handler can read this data";
509 currentFormat %= _qt_NumFormats;
514 #ifdef QIMAGEREADER_DEBUG 515 qDebug() <<
"QImageReader::createReadHandler: no handlers found. giving up.";
561 : autoDetectImageFormat(true), ignoresFormatAndExtension(false)
599 int currentFormatIndex = extensions.
indexOf(
format.toLower());
600 if (currentFormatIndex > 0)
601 extensions.
swap(0, currentFormatIndex);
604 int currentExtension = 0;
613 }
while (!file->
isOpen() && currentExtension < extensions.
size());
1213 qWarning(
"QImageReader::read: cannot read into null pointer");
1466 QFile file(fileName);
1485 format = handler->
format();
1533 for (
int i = 0; i < _qt_NumFormats; ++i)
1534 formats << _qt_BuiltInFormats[i].extension;
1536 #ifndef QT_NO_LIBRARY 1540 for (
int i = 0; i < keys.
count(); ++i) {
1545 #endif // QT_NO_LIBRARY 1549 sortedFormats << *
it;
1551 qSort(sortedFormats);
1552 return sortedFormats;
T qobject_cast(QObject *object)
QColor backgroundColor() const
Returns the background color that's used when reading an image.
The QColor class provides colors based on RGB, HSV or CMYK values.
QString fileName() const
Returns the name set by setFileName() or to the QFile constructors.
bool canRead() const
Returns true if an image can be read from the device (i.
Format
The following image formats are available in Qt.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
static void getText(QString &text, QTextDocumentPrivate *priv, const QString &docText, int pos, int end)
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
virtual Capabilities capabilities(QIODevice *device, const QByteArray &format) const =0
Returns the capabilities on the plugin, based on the data in device and the format format...
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
#define QImageIOHandlerFactoryInterface_iid
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageReader.
#define QT_END_NAMESPACE
This macro expands to.
QRect currentImageRect() const
For image formats that support animation, this function returns the rect for the current frame...
QRect scaledClipRect() const
Returns the scaled clip rect of the image.
void setDevice(QIODevice *device)
Sets QImageReader's device to device.
~QImageReader()
Destructs the QImageReader object.
#define it(className, varName)
void setScaledSize(const QSize &size)
Sets the scaled size of the image to size.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QImage::Format imageFormat() const
Returns the format of the image, without actually reading the image contents.
QImageReaderPrivate(QImageReader *qq)
const_iterator constEnd() const
The QByteArray class provides an array of bytes.
virtual bool read(QImage *image)=0
Read an image from the device, and stores it in image.
virtual bool jumpToNextImage()
For image formats that support animation, this function jumps to the next image.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
bool canRead() const
Returns true if an image can be read from the device (i.
QString text(const QString &key) const
Returns the image text associated with key.
virtual bool jumpToImage(int imageNumber)
For image formats that support animation, this function jumps to the image whose sequence number is i...
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
void setClipRect(const QRect &rect)
Sets the image clip rect (also known as the ROI, or Region Of Interest) to rect.
QByteArray toLower() const
Returns a lowercase copy of the byte array.
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
bool jumpToImage(int imageNumber)
For image formats that support animation, this function skips to the image whose sequence number is i...
int count(const T &t) const
Returns the number of occurrences of value in the list.
void setQuality(int quality)
This is an image format specific function that sets the quality level of the image to quality...
The QString class provides a Unicode character string.
QImageReader::ImageReaderError imageReaderError
Q_GUI_EXPORT QString extensions()
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
void setFormat(const QByteArray &format)
Sets the format QImageReader will use when reading images, to format.
bool autoDetectImageFormat
Q_CORE_EXPORT void qDebug(const char *,...)
QMap< QString, QString > text
virtual void setOption(ImageOption option, const QVariant &value)
Sets the option option with the value value.
void setScaledClipRect(const QRect &rect)
Sets the scaled clip rect to rect.
bool decideFormatFromContent() const
Returns whether the image reader should decide which plugin to use only based on the contents of the ...
QString errorString() const
Returns a human readable description of the last error that occurred.
bool supportsAnimation() const
Returns true if the image format supports animation; otherwise, false is returned.
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
bool autoDetectImageFormat() const
Returns true if image format autodetection is enabled on this image reader; otherwise returns false...
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
static bool isEmpty(const char *str)
bool canRead() const
Returns true if an image can be read from the device (i.
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
ImageOption
This enum describes the different options supported by QImageIOHandler.
int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current fr...
const T value(const Key &key) const
Returns the value associated with the key key.
void setFileName(const QString &fileName)
Sets the file name of QImageReader to fileName.
const T & at(int i) const
Returns the item at index position i in the list.
int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
The QStringList class provides a list of strings.
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
bool canRead() const
Returns true if an image can be read from the device (i.
virtual int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
virtual int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
QByteArray format() const
Returns the format QImageReader uses for reading images.
QSize toSize() const
Returns the variant as a QSize if the variant has type() Size ; otherwise returns an invalid QSize...
void qSort(RandomAccessIterator start, RandomAccessIterator end)
The QImageReader class provides a format independent interface for reading images from files or other...
virtual int imageCount() const
For image formats that support animation, this function returns the number of images in the animation...
bool ignoresFormatAndExtension
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
virtual QImageIOHandler * create(QIODevice *device, const QByteArray &format=QByteArray()) const =0
Creates and returns a QImageIOHandler subclass, with device and format set.
bool canRead() const
Returns true if an image can be read for the device (i.e., the image format is supported, and the device seems to contain valid data); otherwise returns false.
const char * constData() const
Returns a pointer to the data stored in the byte array.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
void setDevice(QIODevice *device)
Sets the device of the QImageIOHandler to device.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
The QFile class provides an interface for reading from and writing to files.
QImageReader()
Constructs an empty QImageReader object.
bool canRead() const
Returns true if an image can be read from the device (i.
The QImageIOPlugin class defines an interface for writing an image format plugin. ...
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt...
static QImageIOHandler * createReadHandlerHelper(QIODevice *device, const QByteArray &format, bool autoDetectImageFormat, bool ignoresFormatAndExtension)
QIODevice * device() const
Returns the device currently assigned to QImageReader, or 0 if no device has been assigned...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QObject * instance(const QString &key) const
QSize scaledSize() const
Returns the scaled size of the image.
QRect clipRect() const
Returns the clip rect (also known as the ROI, or Region Of Interest) of the image.
void setAutoDetectImageFormat(bool enabled)
If enabled is true, image format autodetection is enabled; otherwise, it is disabled.
int size() const
Returns the number of items in the list.
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
ImageReaderError
This enum describes the different types of errors that can occur when reading images with QImageReade...
bool canRead() const
Returns true if an image can be read from the device (i.
The QRect class defines a rectangle in the plane using integer precision.
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
const_iterator constBegin() const
virtual int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current im...
QImageIOHandler * handler
static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[]
QStringList textKeys() const
Returns the text keys for this image.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
The QSize class defines the size of a two-dimensional object using integer point precision.
int quality() const
Returns the quality level of the image.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
QSize size() const
Returns the size of the image, without actually reading the image contents.
virtual QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
ImageReaderError error() const
Returns the type of error that occurred last.
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
bool supportsOption(QImageIOHandler::ImageOption option) const
Returns true if the reader supports option; otherwise returns false.
The QFileInfo class provides system-independent file information.
QImageIOHandler * handler
bool canRead() const
Returns true if an image can be read from the device (i.
virtual bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false...
virtual bool canRead() const
Reimplemented Function
void setBackgroundColor(const QColor &color)
Sets the background color to color.
The QIODevice class is the base interface class of all I/O devices in Qt.
bool canRead() const
Returns true if an image can be read from the device (i.
void setDecideFormatFromContent(bool ignored)
If ignored is set to true, then the image reader will ignore specified formats or file extensions and...
bool jumpToNextImage()
For image formats that support animation, this function steps over the current image, returning true if successful or false if there is no following image in the animation.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void swap(QList< T > &other)
Swaps list other with this list.
QImage read()
Reads an image from the device.
void clear()
Removes all items from the map.
void setFileName(const QString &name)
Sets the name of the file.
int imageCount() const
For image formats that support animation, this function returns the total number of images in the ani...
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,(QImageIOHandlerFactoryInterface_iid, QLatin1String("/imageformats"))) enum _qt_BuiltInFormatType
virtual bool canRead() const =0
Returns true if an image can be read from the device (i.
virtual QRect currentImageRect() const
Returns the rect of the current image.
QString fileName() const
If the currently assigned device is a QFile, or if setFileName() has been called, this function retur...