summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/image/qpixmap_raster.cpp11
-rw-r--r--src/gui/image/qpixmap_raster_p.h1
-rw-r--r--tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gifbin0 -> 4138 bytes
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp61
4 files changed, 73 insertions, 0 deletions
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index e188745..53f3559 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -152,6 +152,17 @@ void QRasterPixmapData::fromImage(const QImage &sourceImage,
createPixmapForImage(image, flags, /* inplace = */false);
}
+void QRasterPixmapData::fromImageReader(QImageReader *imageReader,
+ Qt::ImageConversionFlags flags)
+{
+ Q_UNUSED(flags);
+ QImage image = imageReader->read();
+ if (image.isNull())
+ return;
+
+ createPixmapForImage(image, flags, /* inplace = */true);
+}
+
// from qwindowsurface.cpp
extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
diff --git a/src/gui/image/qpixmap_raster_p.h b/src/gui/image/qpixmap_raster_p.h
index a46e054..36a9b2f 100644
--- a/src/gui/image/qpixmap_raster_p.h
+++ b/src/gui/image/qpixmap_raster_p.h
@@ -74,6 +74,7 @@ public:
void fromFile(const QString &filename, Qt::ImageConversionFlags flags);
bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
+ void fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
bool scroll(int dx, int dy, const QRect &rect);
diff --git a/tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif b/tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif
new file mode 100644
index 0000000..f813c05
--- /dev/null
+++ b/tests/auto/qpixmap/loadFromData/designer_indexed8_with_alpha_animated.gif
Binary files differ
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