summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraavit <qt-info@nokia.com>2010-05-05 08:20:03 (GMT)
committeraavit <qt-info@nokia.com>2010-05-05 08:20:03 (GMT)
commit87f7444d2af1299460bdbfc1cbfa903ea504b7e3 (patch)
tree99c5f997f91704d47620607a8b1a6373b1ab6fb3
parent171d77c62f857bf6fc0761bb62af24251c36053c (diff)
downloadQt-87f7444d2af1299460bdbfc1cbfa903ea504b7e3.zip
Qt-87f7444d2af1299460bdbfc1cbfa903ea504b7e3.tar.gz
Qt-87f7444d2af1299460bdbfc1cbfa903ea504b7e3.tar.bz2
Fixes regression: SVG image loading would fail from QBuffer with pos!=0
Was introduced with 2fe059c. Also now updates pos() as expected after reading in these cases. Autotest added to catch issues where pos != 0, or wrong pos after read. Reviewed-by: Kim
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.cpp10
-rw-r--r--tests/auto/qimagereader/tst_qimagereader.cpp63
2 files changed, 69 insertions, 4 deletions
diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp
index 8155569..7b8463d 100644
--- a/src/plugins/imageformats/svg/qsvgiohandler.cpp
+++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp
@@ -82,15 +82,19 @@ bool QSvgIOHandlerPrivate::load(QIODevice *device)
if (q->format().isEmpty())
q->canRead();
+ // # The SVG renderer doesn't handle trailing, unrelated data, so we must
+ // assume that all available data in the device is to be read.
bool res = false;
QBuffer *buf = qobject_cast<QBuffer *>(device);
if (buf) {
- res = r.load(buf->data());
+ const QByteArray &ba = buf->data();
+ res = r.load(QByteArray::fromRawData(ba.constData() + buf->pos(), ba.size() - buf->pos()));
+ buf->seek(ba.size());
} else if (q->format() == "svgz") {
- res = r.load(device->readAll()); // ### can't stream svgz
+ res = r.load(device->readAll());
} else {
xmlReader.setDevice(device);
- res = r.load(&xmlReader); //### doesn't leave pos() correctly
+ res = r.load(&xmlReader);
}
if (res) {
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp
index 1b4c502..aadee5b 100644
--- a/tests/auto/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/qimagereader/tst_qimagereader.cpp
@@ -114,6 +114,9 @@ private slots:
void readFromFileAfterJunk_data();
void readFromFileAfterJunk();
+ void devicePosition_data();
+ void devicePosition();
+
void setBackgroundColor_data();
void setBackgroundColor();
@@ -1117,7 +1120,7 @@ void tst_QImageReader::readFromFileAfterJunk()
QByteArray imageData = imageFile.readAll();
QVERIFY(!imageData.isNull());
- int iterations = 10;
+ int iterations = 3;
if (format == "ppm" || format == "pbm" || format == "pgm" || format == "svg" || format == "svgz")
iterations = 1;
@@ -1147,6 +1150,64 @@ void tst_QImageReader::readFromFileAfterJunk()
}
}
+void tst_QImageReader::devicePosition_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QByteArray>("format");
+
+ QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm");
+ QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm");
+ QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm");
+#ifdef QTEST_HAVE_JPEG
+ QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg");
+#endif
+#if defined QTEST_HAVE_GIF
+ QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif");
+#endif
+ QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm");
+ QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm");
+ QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp");
+ QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp");
+ QTest::newRow("png") << QString("kollada.png") << QByteArray("png");
+// QTest::newRow("mng-1") << QString("images/ball.mng") << QByteArray("mng");
+// QTest::newRow("mng-2") << QString("images/fire.mng") << QByteArray("mng");
+#if defined QTEST_HAVE_SVG
+ QTest::newRow("svg") << QString("rect.svg") << QByteArray("svg");
+ QTest::newRow("svgz") << QString("rect.svgz") << QByteArray("svgz");
+#endif
+}
+
+void tst_QImageReader::devicePosition()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QByteArray, format);
+
+ QImage expected(prefix + fileName);
+ QVERIFY(!expected.isNull());
+
+ QFile imageFile(prefix + fileName);
+ QVERIFY(imageFile.open(QFile::ReadOnly));
+ QByteArray imageData = imageFile.readAll();
+ QVERIFY(!imageData.isNull());
+ int imageDataSize = imageData.size();
+
+ const char *preStr = "prebeef\n";
+ int preLen = qstrlen(preStr);
+ imageData.prepend(preStr);
+ if (format != "svg" && format != "svgz") // Doesn't handle trailing data
+ imageData.append("\npostbeef");
+ QBuffer buf(&imageData);
+ buf.open(QIODevice::ReadOnly);
+ buf.seek(preLen);
+ QImageReader reader(&buf, format);
+ QCOMPARE(expected, reader.read());
+ if (format != "ppm" && format != "gif") // Known not to work
+ QCOMPARE(buf.pos(), qint64(preLen+imageDataSize));
+}
+
+
void tst_QImageReader::description_data()
{
QTest::addColumn<QString>("fileName");