diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-06-29 17:47:53 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-06-30 12:45:58 (GMT) |
commit | 176024dfea7d354451a65b61fa2e82dd422b4dfb (patch) | |
tree | a631b5be0010489f645b7ca553929ec1361437a2 /tests/auto/qpixmap | |
parent | c16162214eb8757a62e221c34d38cefc402e5b05 (diff) | |
download | Qt-176024dfea7d354451a65b61fa2e82dd422b4dfb.zip Qt-176024dfea7d354451a65b61fa2e82dd422b4dfb.tar.gz Qt-176024dfea7d354451a65b61fa2e82dd422b4dfb.tar.bz2 |
Add the conversion in-place for QPixmap::fromImageReader() on raster.
Since raster uses QImage internal, QPixmap::fromImageReader() can use
conversion in-place of the image. This avoid a memory peak during the
conversion and is a bit faster.
Reviewed-by: Samuel Rødal
Diffstat (limited to 'tests/auto/qpixmap')
-rw-r--r-- | tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif | bin | 0 -> 4138 bytes | |||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 61 |
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif b/tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif Binary files differnew file mode 100644 index 0000000..f813c05 --- /dev/null +++ b/tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 179f068..f22edf6 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -44,6 +44,7 @@ #include <qpixmap.h> #include <qbitmap.h> #include <qimage.h> +#include <qimagereader.h> #include <qmatrix.h> #include <qdesktopwidget.h> #include <qpaintengine.h> @@ -175,6 +176,11 @@ private slots: void loadFromDataImage_data(); void loadFromDataImage(); + void fromImageReader_data(); + void fromImageReader(); + + void fromImageReaderAnimatedGif(); + void preserveDepth(); void splash_crash(); @@ -1577,6 +1583,61 @@ void tst_QPixmap::loadFromDataImage() QVERIFY(pixmapsAreEqual(&pixmapWithCopy, &directLoadingPixmap)); } +void tst_QPixmap::fromImageReader_data() +{ + QTest::addColumn<QString>("imagePath"); +#ifdef Q_OS_SYMBIAN + const QString prefix = QLatin1String(SRCDIR) + "loadFromData"; +#else + const QString prefix = QLatin1String(SRCDIR) + "/loadFromData"; +#endif + QTest::newRow("designer_argb32.png") << prefix + "/designer_argb32.png"; + QTest::newRow("designer_indexed8_no_alpha.png") << prefix + "/designer_indexed8_no_alpha.png"; + QTest::newRow("designer_indexed8_with_alpha.png") << prefix + "/designer_indexed8_with_alpha.png"; + QTest::newRow("designer_rgb32.png") << prefix + "/designer_rgb32.png"; + QTest::newRow("designer_indexed8_no_alpha.gif") << prefix + "/designer_indexed8_no_alpha.gif"; + QTest::newRow("designer_indexed8_with_alpha.gif") << prefix + "/designer_indexed8_with_alpha.gif"; + QTest::newRow("designer_rgb32.jpg") << prefix + "/designer_rgb32.jpg"; +} + +void tst_QPixmap::fromImageReader() +{ + QFETCH(QString, imagePath); + + QImage imageRef(imagePath); + QPixmap pixmapWithCopy = QPixmap::fromImage(imageRef); + + QImageReader imageReader(imagePath); + + QPixmap directLoadingPixmap = QPixmap::fromImageReader(&imageReader); + + QVERIFY(pixmapsAreEqual(&pixmapWithCopy, &directLoadingPixmap)); +} + +void tst_QPixmap::fromImageReaderAnimatedGif() +{ +#ifdef Q_OS_SYMBIAN + const QString prefix = QLatin1String(SRCDIR) + "loadFromData"; +#else + const QString prefix = QLatin1String(SRCDIR) + "/loadFromData"; +#endif + const QString path = prefix + QString::fromLatin1("/designer_indexed8_with_alpha_animated.gif"); + + QImageReader referenceReader(path); + QImageReader pixmapReader(path); + + Q_ASSERT(referenceReader.canRead()); + Q_ASSERT(referenceReader.imageCount() > 1); + + for (int i = 0; i < referenceReader.imageCount(); ++i) { + QImage refImage = referenceReader.read(); + QPixmap refPixmap = QPixmap::fromImage(refImage); + + QPixmap directLoadingPixmap = QPixmap::fromImageReader(&pixmapReader); + QVERIFY(pixmapsAreEqual(&refPixmap, &directLoadingPixmap)); + } +} + void tst_QPixmap::task_246446() { // This crashed without the bugfix in 246446 |