diff options
-rw-r--r-- | src/plugins/imageformats/tga/qtgafile.cpp | 27 | ||||
-rw-r--r-- | src/plugins/imageformats/tga/qtgafile.h | 7 | ||||
-rw-r--r-- | tests/auto/qimagereader/tst_qimagereader.cpp | 3 |
3 files changed, 37 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(); diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 2b867c3..54e8714 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -1107,6 +1107,9 @@ void tst_QImageReader::readFromDevice_data() QTest::newRow("svg") << QString("rect.svg") << QByteArray("svg"); QTest::newRow("svgz") << QString("rect.svgz") << QByteArray("svgz"); #endif +#if defined QTEST_HAVE_TGA + QTest::newRow("tga") << QString("test-flag.tga") << QByteArray("tga"); +#endif } void tst_QImageReader::readFromDevice() |