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