summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorSarah Smith <sarah.j.smith@nokia.com>2011-12-21 12:35:58 +1000
committerSarah Jane Smith <sarah.j.smith@nokia.com>2011-12-21 04:50:27 +0100
commitaf1ee55e6aa503d6c9c3998d9167b522e6d69e9e (patch)
treeee438d18f586816c56333a0132cc25f7f77b2edd /src/plugins
parent9048bf6efb8f5ba3eb4164c0350113c7e3a1b005 (diff)
Fix failing unit tests (TGA formats/qimagreader).
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. (patched and cherry-picked from original) Change-Id: Iae99dc457c269362c1dbd77e7bec588373ee94f2 Reviewed-by: Sarah Jane Smith <sarah.j.smith@nokia.com>
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 912fef65b..63aab2a7e 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 6dc9fa739..b71c7f5fe 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();