summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-09-15 07:48:43 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-09-15 08:39:16 (GMT)
commitb94d6354cb0b24a92e674fc994919394c7549b5a (patch)
tree91c7b685b426accbc6e0657ab5e1e67f820ceaa4 /src/gui/image
parent62fe4f11e49025156f9f5de2ffcbb9ad65198bc4 (diff)
downloadQt-b94d6354cb0b24a92e674fc994919394c7549b5a.zip
Qt-b94d6354cb0b24a92e674fc994919394c7549b5a.tar.gz
Qt-b94d6354cb0b24a92e674fc994919394c7549b5a.tar.bz2
Added support in qimagereader to base plugin selection on stream content
Reviewed-by: Trond
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qimagereader.cpp56
-rw-r--r--src/gui/image/qimagereader.h3
2 files changed, 49 insertions, 10 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index 41df852..5cd768f 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -195,7 +195,9 @@ static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[] = {
};
static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
- const QByteArray &format, bool autoDetectImageFormat)
+ const QByteArray &format,
+ bool autoDetectImageFormat,
+ bool ignoresFormatAndExtension)
{
if (!autoDetectImageFormat && format.isEmpty())
return 0;
@@ -217,7 +219,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
int suffixPluginIndex = -1;
- if (device && format.isEmpty() && autoDetectImageFormat) {
+ if (device && format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
// if there's no format, see if \a device is a file, and if so, find
// the file suffix and find support for that format among our plugins.
// this allows plugins to override our built-in handlers.
@@ -241,6 +243,9 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
QByteArray testFormat = !form.isEmpty() ? form : suffix;
+ if (ignoresFormatAndExtension)
+ testFormat = QByteArray();
+
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
if (suffixPluginIndex != -1) {
// check if the plugin that claims support for this format can load
@@ -258,7 +263,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
device->seek(pos);
}
- if (!handler && !testFormat.isEmpty() && autoDetectImageFormat) {
+ if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !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;
@@ -315,7 +320,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
}
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- if (!handler && autoDetectImageFormat) {
+ if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
// check if any of our plugins recognize the file from its contents.
const qint64 pos = device ? device->pos() : 0;
for (int i = 0; i < keys.size(); ++i) {
@@ -335,7 +340,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
}
#endif
- if (!handler && autoDetectImageFormat) {
+ if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
// check if any of our built-in handlers recognize the file from its
// contents.
int currentFormat = 0;
@@ -434,6 +439,7 @@ public:
// device
QByteArray format;
bool autoDetectImageFormat;
+ bool ignoresFormatAndExtension;
QIODevice *device;
bool deleteDevice;
QImageIOHandler *handler;
@@ -458,7 +464,7 @@ public:
\internal
*/
QImageReaderPrivate::QImageReaderPrivate(QImageReader *qq)
- : autoDetectImageFormat(true)
+ : autoDetectImageFormat(true), ignoresFormatAndExtension(false)
{
device = 0;
deleteDevice = false;
@@ -522,7 +528,7 @@ bool QImageReaderPrivate::initHandler()
}
// assign a handler
- if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat)) == 0) {
+ if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
imageReaderError = QImageReader::UnsupportedFormatError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
return false;
@@ -664,7 +670,7 @@ QByteArray QImageReader::format() const
\o Finally, if all above approaches fail, QImageReader will report failure
when trying to read the image.
- \endlist
+ \endlist
By disabling image format autodetection, QImageReader will only query the
plugins and built-in handlers based on the format string (i.e., no file
@@ -681,13 +687,43 @@ void QImageReader::setAutoDetectImageFormat(bool enabled)
Returns true if image format autodetection is enabled on this image
reader; otherwise returns false. By default, autodetection is enabled.
- \sa setAutoDetectImageFormat()
+ \sa setAutoDetectImageFormat()
*/
bool QImageReader::autoDetectImageFormat() const
{
return d->autoDetectImageFormat;
}
+
+/*!
+
+ Specifies that the image reader should decide which plugin to use
+ solely based on the contents in the datastream.
+
+ Setting this flag means that all image plugins gets loaded. Each
+ plugin will read the first bytes in the image data and decide if
+ the plugin is compatible or not.
+
+ This also disables auto detecting image format.
+*/
+
+void QImageReader::setDecideFormatFromContent(bool ignored)
+{
+ d->ignoresFormatAndExtension = ignored;
+}
+
+
+/*!
+ Returns wether the image reader should decide which plugin to use
+ sloley based on the contents of the datastream
+*/
+
+bool QImageReader::decideFormatFromContent() const
+{
+ return d->ignoresFormatAndExtension;
+}
+
+
/*!
Sets QImageReader's device to \a device. If a device has already
been set, the old device is removed from QImageReader and is
@@ -1309,7 +1345,7 @@ QByteArray QImageReader::imageFormat(const QString &fileName)
QByteArray QImageReader::imageFormat(QIODevice *device)
{
QByteArray format;
- QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true);
+ QImageIOHandler *handler = createReadHandlerHelper(device, format, /* autoDetectImageFormat = */ true, false);
if (handler) {
if (handler->canRead())
format = handler->format();
diff --git a/src/gui/image/qimagereader.h b/src/gui/image/qimagereader.h
index 86031ec..11affb8 100644
--- a/src/gui/image/qimagereader.h
+++ b/src/gui/image/qimagereader.h
@@ -81,6 +81,9 @@ public:
void setAutoDetectImageFormat(bool enabled);
bool autoDetectImageFormat() const;
+ void setDecideFormatFromContent(bool ignored);
+ bool decideFormatFromContent() const;
+
void setDevice(QIODevice *device);
QIODevice *device() const;