diff options
author | Trond Kjernåsen <trond@trolltech.com> | 2010-02-08 13:55:40 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond@trolltech.com> | 2010-02-08 14:31:28 (GMT) |
commit | 43a9c48554579d76e1f1267fbd70f488f22fd408 (patch) | |
tree | cb0c34a8708933118cdb1354c5ebb14c4d73d659 | |
parent | 95f8f814f2f77654d846660644f0e8a5c48eeb26 (diff) | |
download | Qt-43a9c48554579d76e1f1267fbd70f488f22fd408.zip Qt-43a9c48554579d76e1f1267fbd70f488f22fd408.tar.gz Qt-43a9c48554579d76e1f1267fbd70f488f22fd408.tar.bz2 |
Fixed QImagReader::setAutoDetectImageFormat() to work with plugins.
Only the compiled in formats where checked when
setAutoDetectImageFormat(false) was set on a QImageReader object.
Task-number: QTBUG-7980
Reviewed-by: aavit
-rw-r--r-- | src/gui/image/qimagereader.cpp | 28 | ||||
-rw-r--r-- | tests/auto/qimagereader/tst_qimagereader.cpp | 29 |
2 files changed, 49 insertions, 8 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index c9e015c..9320cfc 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -263,25 +263,37 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, device->seek(pos); } - if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) { + if (!handler && !testFormat.isEmpty() && !ignoresFormatAndExtension) { // check if any plugin supports the format (they are not allowed to // read from the device yet). const qint64 pos = device ? device->pos() : 0; - for (int i = 0; i < keys.size(); ++i) { - if (i != suffixPluginIndex) { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); - if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { + + if (autoDetectImageFormat) { + for (int i = 0; i < keys.size(); ++i) { + if (i != suffixPluginIndex) { + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); + if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { #ifdef QIMAGEREADER_DEBUG - qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format"; + qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format"; #endif - handler = plugin->create(device, testFormat); - break; + handler = plugin->create(device, testFormat); + break; + } } } + } else { + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QLatin1String(testFormat))); + if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { +#ifdef QIMAGEREADER_DEBUG + qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format"; +#endif + handler = plugin->create(device, testFormat); + } } if (device && !device->isSequential()) device->seek(pos); } + #endif // QT_NO_LIBRARY // if we don't have a handler yet, check if we have built-in support for diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 121a8fa..99244c2 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -1633,6 +1633,35 @@ void tst_QImageReader::autoDetectImageFormat() QVERIFY(reader.canRead()); QVERIFY(!reader.read().isNull()); } + +#ifdef QTEST_HAVE_JPEG + { + QImageReader io(prefix + "YCbCr_rgb.jpg"); + io.setAutoDetectImageFormat(false); + // This should fail since no format string is given + QImage image; + QVERIFY(!io.read(&image)); + } + { + QImageReader io(prefix + "YCbCr_rgb.jpg", "jpg"); + io.setAutoDetectImageFormat(false); + QImage image; + QVERIFY(io.read(&image)); + } +#endif + { + QImageReader io(prefix + "tst7.png"); + io.setAutoDetectImageFormat(false); + // This should fail since no format string is given + QImage image; + QVERIFY(!io.read(&image)); + } + { + QImageReader io(prefix + "tst7.png", "png"); + io.setAutoDetectImageFormat(false); + QImage image; + QVERIFY(io.read(&image)); + } } void tst_QImageReader::fileNameProbing() |