summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSarah Smith <sarah.j.smith@nokia.com>2011-11-14 03:51:50 (GMT)
committerSarah Smith <sarah.j.smith@nokia.com>2011-11-14 03:55:38 (GMT)
commit951a997893407b0a26f21fe0acec4701fa3d4279 (patch)
treeff2967fdd6ba6d6685ebe820fce575c557960860 /tests
parent739e705150ad114eb92a1fac34a51d30322ffc31 (diff)
downloadQt-951a997893407b0a26f21fe0acec4701fa3d4279.zip
Qt-951a997893407b0a26f21fe0acec4701fa3d4279.tar.gz
Qt-951a997893407b0a26f21fe0acec4701fa3d4279.tar.bz2
Move tga support from Qt3d to Qt.
Rev-By: Samuel Rodal Fix-for: QTBUG-21955 Part of fix for https://bugreports.qt.nokia.com/browse/QTBUG-21955 Having tga plugin inside a Qt add-on causes packaging problems. There have been many queries over the years for tga support even tho it is a niche image format. It is particularly useful for OpenGL work as a texture format since it is a blittable bitmap, but it is very innefficient compared to png or jpg. For this reason only read support is added, and this is documented. Also add some unit tests. The unit tests are in the qimagereader suite, and this is the right place for them as the other formats are tested there. Noticed that there was an annoying bug with tiff files and chased it down, in the hope of getting a clean test case PASS. Looks as tho there is a bit of work for someone to fix the other FAILs, but the ones for tga are all passing.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qimagereader/images/test-flag-rle.tgabin0 -> 7971 bytes
-rw-r--r--tests/auto/qimagereader/images/test-flag.tgabin0 -> 480044 bytes
-rw-r--r--tests/auto/qimagereader/qimagereader.pro1
-rw-r--r--tests/auto/qimagereader/qimagereader.qrc2
-rw-r--r--tests/auto/qimagereader/tst_qimagereader.cpp51
5 files changed, 50 insertions, 4 deletions
diff --git a/tests/auto/qimagereader/images/test-flag-rle.tga b/tests/auto/qimagereader/images/test-flag-rle.tga
new file mode 100644
index 0000000..c14c712
--- /dev/null
+++ b/tests/auto/qimagereader/images/test-flag-rle.tga
Binary files differ
diff --git a/tests/auto/qimagereader/images/test-flag.tga b/tests/auto/qimagereader/images/test-flag.tga
new file mode 100644
index 0000000..c6d0c89
--- /dev/null
+++ b/tests/auto/qimagereader/images/test-flag.tga
Binary files differ
diff --git a/tests/auto/qimagereader/qimagereader.pro b/tests/auto/qimagereader/qimagereader.pro
index 827819d..a9bfa1d 100644
--- a/tests/auto/qimagereader/qimagereader.pro
+++ b/tests/auto/qimagereader/qimagereader.pro
@@ -10,6 +10,7 @@ RESOURCES += qimagereader.qrc
!contains(QT_CONFIG, no-mng):DEFINES += QTEST_HAVE_MNG
!contains(QT_CONFIG, no-tiff):DEFINES += QTEST_HAVE_TIFF
!contains(QT_CONFIG, no-svg):DEFINES += QTEST_HAVE_SVG
+!contains(QT_CONFIG, no-tga):DEFINES += QTEST_HAVE_TGA
win32-msvc:QMAKE_CXXFLAGS -= -Zm200
win32-msvc:QMAKE_CXXFLAGS += -Zm800
diff --git a/tests/auto/qimagereader/qimagereader.qrc b/tests/auto/qimagereader/qimagereader.qrc
index 2c70652..03c03d6 100644
--- a/tests/auto/qimagereader/qimagereader.qrc
+++ b/tests/auto/qimagereader/qimagereader.qrc
@@ -67,5 +67,7 @@
<file>images/corrupt.svgz</file>
<file>images/qtbug13653-no_eoi.jpg</file>
<file>images/txts.png</file>
+ <file>images/test-flag.tga</file>
+ <file>images/test-flag-rle.tga</file>
</qresource>
</RCC>
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp
index 5d958d7..5bf9d19 100644
--- a/tests/auto/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/qimagereader/tst_qimagereader.cpp
@@ -168,6 +168,10 @@ private slots:
void tiffGrayscale();
#endif
+#if defined QTEST_HAVE_TGA
+ void tgaTestImages();
+#endif
+
void autoDetectImageFormat();
void fileNameProbing();
@@ -569,6 +573,10 @@ void tst_QImageReader::imageFormat_data()
QTest::newRow("mng-2") << QString("fire.mng") << QByteArray("mng") << QImage::Format_Invalid;
QTest::newRow("svg") << QString("rect.svg") << QByteArray("svg") << QImage::Format_ARGB32_Premultiplied;
QTest::newRow("svgz") << QString("rect.svgz") << QByteArray("svgz") << QImage::Format_ARGB32_Premultiplied;
+#if defined QTEST_HAVE_TGA
+ QTest::newRow("tga") << QString("test-flag.tga") << QByteArray("tga") << QImage::Format_ARGB32;
+ QTest::newRow("tga-rle") << QString("test-flag-rle.tga") << QByteArray("tga") << QImage::Format_ARGB32;
+#endif
}
void tst_QImageReader::imageFormat()
@@ -578,22 +586,31 @@ void tst_QImageReader::imageFormat()
QFETCH(QImage::Format, imageFormat);
if (QImageReader::imageFormat(prefix + fileName).isEmpty()) {
- if (QByteArray("jpeg") == format)
+ if (QByteArray("jpeg") == format) {
#ifndef QTEST_HAVE_JPEG
return;
#endif // !QTEST_HAVE_JPEG
- if (QByteArray("gif") == format)
+ }
+ if (QByteArray("gif") == format) {
#ifndef QTEST_HAVE_GIF
return;
#endif // !QTEST_HAVE_GIF
- if (QByteArray("mng") == format)
+ }
+ if (QByteArray("mng") == format) {
#ifndef QTEST_HAVE_MNG
return;
#endif // !QTEST_HAVE_MNG
- if (QByteArray("svg") == format || QByteArray("svgz") == format)
+ }
+ if (QByteArray("svg") == format || QByteArray("svgz") == format) {
#ifndef QTEST_HAVE_SVG
return;
#endif // !QTEST_HAVE_SVG
+ }
+ if (QByteArray("tga") == format) {
+#ifndef QTEST_HAVE_TGA
+ return;
+#endif // !QTEST_HAVE_TGA
+ }
QSKIP(("Qt does not support the " + format + " format.").constData(), SkipSingle);
} else {
QCOMPARE(QImageReader::imageFormat(prefix + fileName), format);
@@ -734,6 +751,11 @@ void tst_QImageReader::sizeBeforeRead()
{
QFETCH(QString, fileName);
QFETCH(QByteArray, format);
+
+ if (fileName == QLatin1String("test-flag-rle.tga")) {
+ QSKIP("Qt does not support reading RLE compressed TGA files", SkipSingle);
+ }
+
QImageReader reader(prefix + fileName);
QVERIFY(reader.canRead());
if (format == "mng") {
@@ -1711,6 +1733,27 @@ void tst_QImageReader::tiffGrayscale()
}
#endif
+#if defined QTEST_HAVE_TGA
+void tst_QImageReader::tgaTestImages()
+{
+ QImage tgaTest(prefix + "test-flag.tga");
+
+ // Test image is 400x400 of a "flag" with a blue circle in the middle
+ // and a green square top left, and red rectangle on the bottom so
+ // so we test for pixels in those areas to ensure the image is not
+ // inverted or the palette is not messed up.
+ QVERIFY(!tgaTest.isNull());
+ QCOMPARE(tgaTest.size().width(), 400);
+ QCOMPARE(tgaTest.size().height(), 400);
+ QRgb pixel = tgaTest.pixel(200,200);
+ QCOMPARE(qRgb(0, 0, 255), pixel);
+ pixel = tgaTest.pixel(0, 0);
+ QCOMPARE(qRgb(0, 255, 0), pixel);
+ pixel = tgaTest.pixel(0, 399);
+ QCOMPARE(qRgb(255, 0, 0), pixel);
+}
+#endif
+
void tst_QImageReader::dotsPerMeter_data()
{
QTest::addColumn<QString>("fileName");