From c9a5ab5fd506663c5a7cd587d1b963c067d334bf Mon Sep 17 00:00:00 2001 From: aavit Date: Fri, 24 Sep 2010 17:51:14 +0200 Subject: Avoid creating copy of an image in memory when storing as png Task-number: QT-3871 Reviewed-by: Kim --- tests/auto/qimagereader/tst_qimagereader.cpp | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests/auto/qimagereader') diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 3bee5d98aa..4b4bdd6a3b 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -178,6 +178,8 @@ private slots: void testIgnoresFormatAndExtension_data(); void testIgnoresFormatAndExtension(); + void saveFormat_data(); + void saveFormat(); }; static const QLatin1String prefix(SRCDIR "/images/"); @@ -1905,5 +1907,46 @@ void tst_QImageReader::testIgnoresFormatAndExtension() } } + +void tst_QImageReader::saveFormat_data() +{ + QTest::addColumn("format"); + + QTest::newRow("Format_Mono") << QImage::Format_Mono; + QTest::newRow("Format_MonoLSB") << QImage::Format_MonoLSB; + QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8; + QTest::newRow("Format_RGB32") << QImage::Format_RGB32; + QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32; + QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; + QTest::newRow("Format_RGB16") << QImage::Format_RGB16; + QTest::newRow("Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied; + QTest::newRow("Format_RGB666") << QImage::Format_RGB666; + QTest::newRow("Format_ARGB6666_Premultiplied") << QImage::Format_ARGB6666_Premultiplied; + QTest::newRow("Format_RGB555") << QImage::Format_RGB555; + QTest::newRow("Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied; + QTest::newRow("Format_RGB888") << QImage::Format_RGB888; + QTest::newRow("Format_RGB444") << QImage::Format_RGB444; + QTest::newRow("Format_ARGB4444_Premultiplied") << QImage::Format_ARGB4444_Premultiplied; +} + +void tst_QImageReader::saveFormat() +{ + QFETCH(QImage::Format, format); + + QImage orig(":/images/kollada.png"); + + QImage converted = orig.convertToFormat(format); + QBuffer buf; + buf.open(QIODevice::WriteOnly); + QVERIFY(converted.save(&buf, "png")); + buf.close(); + QImage stored = QImage::fromData(buf.buffer(), "png"); + + stored = stored.convertToFormat(QImage::Format_ARGB32); + converted = converted.convertToFormat(QImage::Format_ARGB32); + QCOMPARE(stored, converted); +} + + QTEST_MAIN(tst_QImageReader) #include "tst_qimagereader.moc" -- cgit v1.2.3