summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorSarah Smith <sarah.j.smith@nokia.com>2011-11-17 05:06:17 (GMT)
committerSarah Smith <sarah.j.smith@nokia.com>2011-11-17 05:10:31 (GMT)
commit665bc3951709f0d726cb82501a5bca684f3347a5 (patch)
treeb0fe4bb3cb14676b7663e66fcd1b864ab12f82bd /src/plugins
parentd8aad8299125da82d95406577b281dfab5c12853 (diff)
downloadQt-665bc3951709f0d726cb82501a5bca684f3347a5.zip
Qt-665bc3951709f0d726cb82501a5bca684f3347a5.tar.gz
Qt-665bc3951709f0d726cb82501a5bca684f3347a5.tar.bz2
Fix failing unit tests.
The test that was failing was the readFromDevice one - where the extension is not known. Looks as though image detection is required in a positive way, that is it is not enough to say I think I can read this file, and then fail if the format is "corrupt", you must be certain that the file was intended to be that format. In the case of TGA the original format has no magic byte header, and no consistent way to check if it really is a TGA file. With 2.0 the footer was added at the end, so that can be checked for confirming the file is TGA. However rejecting files which do not have this means that old TGA files will not be read. On a quick survey TGA files that have been used in applications so far all seem to be 2.0 TrueVision, so for now, lets just reject earlier files and see how it goes. Also add reading the tga test file to the readFromDevice test.
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/imageformats/tga/qtgafile.cpp27
-rw-r--r--src/plugins/imageformats/tga/qtgafile.h7
2 files changed, 34 insertions, 0 deletions
diff --git a/src/plugins/imageformats/tga/qtgafile.cpp b/src/plugins/imageformats/tga/qtgafile.cpp
index dfb5a01..885a63c 100644
--- a/src/plugins/imageformats/tga/qtgafile.cpp
+++ b/src/plugins/imageformats/tga/qtgafile.cpp
@@ -158,6 +158,33 @@ QTgaFile::QTgaFile(QIODevice *device)
mErrorMessage = QObject::tr("Image type not supported");
return;
}
+ int bitsPerPixel = mHeader[PixelDepth];
+ bool validDepth = (bitsPerPixel == 16 || bitsPerPixel == 24 || bitsPerPixel == 32);
+ if (!validDepth)
+ {
+ mErrorMessage = QObject::tr("Image dpeth not valid");
+ }
+ int curPos = mDevice->pos();
+ int fileBytes = mDevice->size();
+ if (!mDevice->seek(fileBytes - FooterSize))
+ {
+ mErrorMessage = QObject::tr("Could not seek to image read footer");
+ return;
+ }
+ char footer[FooterSize];
+ bytes = mDevice->read((char*)footer, FooterSize);
+ if (bytes != FooterSize)
+ {
+ mErrorMessage = QObject::tr("Could not read footer");
+ }
+ if (qstrncmp(&footer[SignatureOffset], "TRUEVISION-XFILE", 16) != 0)
+ {
+ mErrorMessage = QObject::tr("Image type (non-TrueVision 2.0) not supported");
+ }
+ if (!mDevice->seek(curPos))
+ {
+ mErrorMessage = QObject::tr("Could not reset to read data");
+ }
}
/*!
diff --git a/src/plugins/imageformats/tga/qtgafile.h b/src/plugins/imageformats/tga/qtgafile.h
index 68c5a0c..264c18b 100644
--- a/src/plugins/imageformats/tga/qtgafile.h
+++ b/src/plugins/imageformats/tga/qtgafile.h
@@ -73,6 +73,13 @@ public:
HeaderSize = 18
};
+ enum FooterOffset {
+ ExtensionOffset = 0,
+ DeveloperOffset = 4,
+ SignatureOffset = 8,
+ FooterSize = 26
+ };
+
QTgaFile(QIODevice *);
~QTgaFile();