qt/qt-everywhere-opensource-src-4.8.1-qtgahandle.patch

54 lines
2.3 KiB
Diff

diff -up qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.cpp.me qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.cpp
--- qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.cpp.me 2012-03-30 21:54:59.921331145 +0200
+++ qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.cpp 2012-03-30 21:58:14.516042067 +0200
@@ -41,6 +41,7 @@
#include "qtgafile.h"
+#include <QtCore/QBuffer>
#include <QtCore/QIODevice>
#include <QtCore/QDebug>
#include <QtCore/QDateTime>
@@ -264,3 +265,16 @@ QImage QTgaFile::readImage()
// TODO: add processing of TGA extension information - ie TGA 2.0 files
return im;
}
+/**
+ * Checks if device contains a valid tga image, *without* changing device
+ * position.
+ */
+bool QTgaFile::canRead(QIODevice *device)
+{
+ QByteArray header = device->peek(HeaderSize);
+ if (header.size() < HeaderSize)
+ return false;
+ QBuffer buffer(&header);
+ QTgaFile tga(&buffer);
+ return tga.isValid();
+}
diff -up qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.h.me qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.h
--- qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.h.me 2012-03-30 21:58:39.670023189 +0200
+++ qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgafile.h 2012-03-30 21:59:06.202317384 +0200
@@ -93,6 +93,8 @@ public:
inline QSize size() const;
inline Compression compression() const;
+ static bool canRead(QIODevice *device);
+
private:
static inline quint16 littleEndianInt(const unsigned char *d);
diff -up qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgahandler.cpp.me qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgahandler.cpp
--- qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgahandler.cpp.me 2012-03-30 21:59:17.373303356 +0200
+++ qt-everywhere-opensource-src-4.8.1/src/plugins/imageformats/tga/qtgahandler.cpp 2012-03-30 22:00:13.817226439 +0200
@@ -77,8 +77,7 @@ bool QTgaHandler::canRead(QIODevice *dev
qWarning("QTgaHandler::canRead() called with no device");
return false;
}
- QTgaFile tga(device);
- return tga.isValid();
+ return QTgaFile::canRead(device);
}
bool QTgaHandler::read(QImage *image)