summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2017-02-23 09:39:07 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2017-03-02 07:59:50 +0000
commitc4c8886a864d1058c3441a96556aa8b124b4f17f (patch)
tree8d1ba0d2c4bd8c8169325afc681cfc99a271bed0 /tests
parent593a707ba35c22c0a1061dce745deceed8837f80 (diff)
ppm/pgm image formats: fix reading 16bit and limited range
The color values of ppm and pgm images can be either 8 or 16 bits. They can also be scaled to a smaller max value, and they can be expressed either binary or ascii. For some of these permutations, Qt's image handler lacked implementation or would decode the wrong color value. This commit fixes that. Task-number: QTBUG-18262 Task-number: QTBUG-35990 Change-Id: I7cf11c2366244f3a9b31c1a565a81e2658bc6a51 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/image/qimagereader/tst_qimagereader.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
index bd02dc6255..18649b3de5 100644
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
@@ -133,6 +133,9 @@ private slots:
void gifImageCount();
void gifLoopCount();
+ void ppmMaxval_data();
+ void ppmMaxval();
+
void readCorruptImage_data();
void readCorruptImage();
void readCorruptBmp();
@@ -956,6 +959,79 @@ void tst_QImageReader::gifLoopCount()
}
}
+void tst_QImageReader::ppmMaxval_data()
+{
+ QTest::addColumn<bool>("hasColor");
+ QTest::addColumn<QByteArray>("bytes");
+
+ QTest::newRow("PGM plain 8bit full") << false << QByteArray("P2 3 1 255 255 0 127\n");
+ QTest::newRow("PGM plain 8bit lim.") << false << QByteArray("P2 3 1 50 50 0 25\n");
+ QTest::newRow("PGM plain 16bit full") << false << QByteArray("P2 3 1 65535 65535 0 32767\n");
+ QTest::newRow("PGM plain 16bit lim.") << false << QByteArray("P2 3 1 5000 5000 0 2500\n");
+ QTest::newRow("PGM raw 8bit full") << false << QByteArray("P5 3 1 255 \xff\x00\x7f", 13 + 3);
+ QTest::newRow("PGM raw 8bit lim.") << false << QByteArray("P5 3 1 50 \x32\x00\x19", 13 + 3);
+ QTest::newRow("PGM raw 16bit full") << false << QByteArray("P5 3 1 65535 \xff\xff\x00\x00\x7f\xff", 13 + 3 * 2);
+ QTest::newRow("PGM raw 16bit lim.") << false << QByteArray("P5 3 1 5000 \x13\x88\x00\x00\x09\xc4", 13 + 3 * 2);
+
+ QTest::newRow("PPM plain 8bit full") << true << QByteArray("P3 3 2 255 "
+ "255 255 255 0 0 0 127 127 127 "
+ "255 0 0 0 255 0 0 0 255\n");
+
+ QTest::newRow("PPM plain 8bit lim.") << true << QByteArray("P3 3 2 50 "
+ " 50 50 50 0 0 0 25 25 25 "
+ " 50 0 0 0 50 0 0 0 50\n");
+
+ QTest::newRow("PPM plain 16bit full") << true << QByteArray("P3 3 2 65535 "
+ "65535 65535 65535 0 0 0 32767 32767 32767 "
+ "65535 0 0 0 65535 0 0 0 65535\n");
+
+ QTest::newRow("PPM plain 16bit lim.") << true << QByteArray("P3 3 2 5000 "
+ " 5000 5000 5000 0 0 0 2500 2500 2500 "
+ " 5000 0 0 0 5000 0 0 0 5000\n");
+
+ QTest::newRow("PPM raw 8bit full") << true << QByteArray("P6 3 2 255 "
+ "\xff\xff\xff\x00\x00\x00\x7f\x7f\x7f"
+ "\xff\x00\x00\x00\xff\x00\x00\x00\xff", 13 + 6 * 3);
+
+ QTest::newRow("PPM raw 8bit lim.") << true << QByteArray("P6 3 2 50 "
+ "\x32\x32\x32\x00\x00\x00\x19\x19\x19"
+ "\x32\x00\x00\x00\x32\x00\x00\x00\x32", 13 + 6 * 3);
+
+ QTest::newRow("PPM raw 16bit full") << true << QByteArray("P6 3 2 65535 "
+ "\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x7f\xff\x7f\xff\x7f\xff"
+ "\xff\xff\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\xff\xff", 13 + 6 * 3 * 2);
+
+ QTest::newRow("PPM raw 16bit lim.") << true << QByteArray("P6 3 2 5000 "
+ "\x13\x88\x13\x88\x13\x88\x00\x00\x00\x00\x00\x00\x09\xc4\x09\xc4\x09\xc4"
+ "\x13\x88\x00\x00\x00\x00\x00\x00\x13\x88\x00\x00\x00\x00\x00\x00\x13\x88", 13 + 6 * 3 * 2);
+}
+
+void tst_QImageReader::ppmMaxval()
+{
+ SKIP_IF_UNSUPPORTED("ppm");
+
+ QFETCH(bool, hasColor);
+ QFETCH(QByteArray, bytes);
+
+ QImage img;
+ img.loadFromData(bytes);
+ QVERIFY(!img.isNull());
+ QCOMPARE(img.width(), 3);
+ QCOMPARE(img.height(), hasColor ? 2 : 1);
+
+ QCOMPARE(img.pixel(0,0), qRgb(0xff, 0xff, 0xff));
+ QCOMPARE(img.pixel(1,0), qRgb(0, 0, 0));
+ QRgb gray = img.pixel(2,0);
+ QVERIFY(qIsGray(gray));
+ QVERIFY(qRed(gray) > 0x70 && qRed(gray) < 0x90 );
+
+ if (hasColor) {
+ QCOMPARE(img.pixel(0,1), qRgb(0xff, 0, 0));
+ QCOMPARE(img.pixel(1,1), qRgb(0, 0xff, 0));
+ QCOMPARE(img.pixel(2,1), qRgb(0, 0, 0xff));
+ }
+}
+
class Server : public QObject
{
Q_OBJECT