diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-08-15 13:09:55 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-08-15 16:53:19 +0200 |
commit | c7ec7cd2a1ae9bec31113fae1f1e549b2bf98e0b (patch) | |
tree | fc81fba4e7815ea061da277cf3bcf3102866932f /src/gui/image/qimagereader.cpp | |
parent | 7947032e2d1d68b2c0f79874db7adcf560851f29 (diff) | |
parent | 6132260da394a9627947f0fe6a279c20863b6ad2 (diff) |
Merge branch 'wip/qt6' into wip/cmake
Change-Id: I50ac36b8803c296998149e98cc61e38687cdd14b
Diffstat (limited to 'src/gui/image/qimagereader.cpp')
-rw-r--r-- | src/gui/image/qimagereader.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 2762b702b2..6a0763e696 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -197,7 +197,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, #ifdef QIMAGEREADER_DEBUG qDebug() << "QImageReader::createReadHandler( device =" << (void *)device << ", format =" << format << ")," - << keyMap.size() << "plugins available: " << keyMap.values(); + << keyMap.uniqueKeys().size() << "plugins available: " << keyMap; #endif int suffixPluginIndex = -1; @@ -325,6 +325,29 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, #endif } + if (handler && device && !suffix.isEmpty()) { + Q_ASSERT(qobject_cast<QFile *>(device)); + // We have a file claiming to be of a recognized format. Now confirm that + // the handler also recognizes the file contents. + const qint64 pos = device->pos(); + handler->setDevice(device); + if (!form.isEmpty()) + handler->setFormat(form); + bool canRead = handler->canRead(); + device->seek(pos); + if (canRead) { + // ok, we're done. + return handler; + } +#ifdef QIMAGEREADER_DEBUG + qDebug() << "QImageReader::createReadHandler: the" << suffix << "handler can not read this file"; +#endif + // File may still be valid, just with wrong suffix, so fall back to + // finding a handler based on contents, below. + delete handler; + handler = nullptr; + } + #ifndef QT_NO_IMAGEFORMATPLUGIN if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) { // check if any of our plugins recognize the file from its contents. @@ -336,7 +359,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, if (plugin && plugin->capabilities(device, QByteArray()) & QImageIOPlugin::CanRead) { handler = plugin->create(device, testFormat); #ifdef QIMAGEREADER_DEBUG - qDebug() << "QImageReader::createReadHandler: the" << keyMap.keys().at(i) << "plugin can read this data"; + qDebug() << "QImageReader::createReadHandler: the" << keyMap.value(i) << "plugin can read this data"; #endif break; } @@ -1074,7 +1097,7 @@ QList<QByteArray> QImageReader::supportedSubTypes() const \since 5.5 Returns the transformation metadata of the image, including image orientation. If the format - does not support transformation metadata \c QImageIOHandler::Transformation_None is returned. + does not support transformation metadata, QImageIOHandler::TransformationNone is returned. \sa setAutoTransform(), autoTransform() */ |