aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/scenegraph/util/qsgtexturereader.cpp6
-rw-r--r--src/quick/scenegraph/util/qsgtexturereader_p.h2
-rw-r--r--src/quick/util/qquickpixmapcache.cpp43
-rw-r--r--tests/auto/quick/qquickimage/data/pattern.pkmbin0 -> 2064 bytes
-rw-r--r--tests/auto/quick/qquickimage/tst_qquickimage.cpp8
5 files changed, 56 insertions, 3 deletions
diff --git a/src/quick/scenegraph/util/qsgtexturereader.cpp b/src/quick/scenegraph/util/qsgtexturereader.cpp
index 168afb9e56..eb0caa59e4 100644
--- a/src/quick/scenegraph/util/qsgtexturereader.cpp
+++ b/src/quick/scenegraph/util/qsgtexturereader.cpp
@@ -92,6 +92,12 @@ bool QSGTextureReader::isTexture()
#endif
}
+QList<QByteArray> QSGTextureReader::supportedFileFormats()
+{
+ // Hardcoded for now
+ return {QByteArrayLiteral("pkm"), QByteArrayLiteral("ktx")};
+}
+
bool QSGTextureReader::init()
{
if (!m_device)
diff --git a/src/quick/scenegraph/util/qsgtexturereader_p.h b/src/quick/scenegraph/util/qsgtexturereader_p.h
index 8251e4c696..1d874f840c 100644
--- a/src/quick/scenegraph/util/qsgtexturereader_p.h
+++ b/src/quick/scenegraph/util/qsgtexturereader_p.h
@@ -71,6 +71,8 @@ public:
// TBD access function to params
// TBD ask for identified fmt
+ static QList<QByteArray> supportedFileFormats();
+
private:
bool init();
QIODevice *m_device = nullptr;
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index 6712b01476..7097bcc156 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -414,6 +414,34 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
}
}
+static QStringList fromLatin1List(const QList<QByteArray> &list)
+{
+ QStringList res;
+ res.reserve(list.size());
+ for (const QByteArray &item : list)
+ res.append(QString::fromLatin1(item));
+ return res;
+}
+
+static QString existingImageFileForPath(const QString &localFile)
+{
+ // Do nothing if given filepath exists or already has a suffix
+ QFileInfo fi(localFile);
+ if (!fi.suffix().isEmpty() || fi.exists())
+ return localFile;
+
+ static const QStringList suffixes = fromLatin1List(QSGTextureReader::supportedFileFormats() +
+ QImageReader::supportedImageFormats());
+ QString tryFile = localFile + QStringLiteral(".xxxx");
+ const int suffixIdx = localFile.length() + 1;
+ for (const QString &suffix : suffixes) {
+ tryFile.replace(suffixIdx, 10, suffix);
+ if (QFileInfo::exists(tryFile))
+ return tryFile;
+ }
+ return localFile;
+}
+
QQuickPixmapReader::QQuickPixmapReader(QQmlEngine *eng)
: QThread(eng), engine(eng), threadObject(0)
#if QT_CONFIG(qml_network)
@@ -769,7 +797,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
QImage image;
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
- QFile f(localFile);
+ QFile f(existingImageFileForPath(localFile));
QSize readSize;
if (f.open(QIODevice::ReadOnly)) {
QSGTextureReader texReader(&f, localFile);
@@ -779,6 +807,8 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
readSize = factory->textureSize();
} else {
errorStr = QQuickPixmap::tr("Error decoding: %1").arg(url.toString());
+ if (f.fileName() != localFile)
+ errorStr += QString::fromLatin1(" (%1)").arg(f.fileName());
errorCode = QQuickPixmapReply::Decoding;
}
mutex.lock();
@@ -787,8 +817,11 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
mutex.unlock();
return;
} else {
- if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, runningJob->providerOptions))
+ if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, runningJob->providerOptions)) {
errorCode = QQuickPixmapReply::Loading;
+ if (f.fileName() != localFile)
+ errorStr += QString::fromLatin1(" (%1)").arg(f.fileName());
+ }
}
} else {
errorStr = QQuickPixmap::tr("Cannot open: %1").arg(url.toString());
@@ -1245,7 +1278,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
if (localFile.isEmpty())
return 0;
- QFile f(localFile);
+ QFile f(existingImageFileForPath(localFile));
QSize readSize;
QString errorString;
@@ -1258,6 +1291,8 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
return new QQuickPixmapData(declarativePixmap, url, factory, factory->textureSize(), requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
} else {
errorString = QQuickPixmap::tr("Error decoding: %1").arg(url.toString());
+ if (f.fileName() != localFile)
+ errorString += QString::fromLatin1(" (%1)").arg(f.fileName());
}
} else {
QImage image;
@@ -1265,6 +1300,8 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
if (readImage(url, &f, &image, &errorString, &readSize, requestSize, providerOptions, &appliedTransform)) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, appliedTransform);
+ } else if (f.fileName() != localFile) {
+ errorString += QString::fromLatin1(" (%1)").arg(f.fileName());
}
}
} else {
diff --git a/tests/auto/quick/qquickimage/data/pattern.pkm b/tests/auto/quick/qquickimage/data/pattern.pkm
new file mode 100644
index 0000000000..d986e89b2d
--- /dev/null
+++ b/tests/auto/quick/qquickimage/data/pattern.pkm
Binary files differ
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp
index 256e667980..f458bdcf5b 100644
--- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp
+++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp
@@ -152,6 +152,14 @@ void tst_qquickimage::imageSource_data()
QTest::newRow("remote svgz") << "/heart.svgz" << 595.0 << 841.0 << true << false << false << "";
QTest::newRow("remote not found") << "/no-such-file.png" << 0.0 << 0.0 << true
<< false << true << "<Unknown File>:2:1: QML Image: Error transferring {{ServerBaseUrl}}/no-such-file.png - server replied: Not found";
+ QTest::newRow("extless") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << true << "";
+ QTest::newRow("extless no cache") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << false << "";
+ QTest::newRow("extless async") << testFileUrl("colors1").toString() << 120.0 << 120.0 << false << true << true << "";
+ QTest::newRow("extless not found") << testFileUrl("no-such-file").toString() << 0.0 << 0.0 << false
+ << false << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file").toString();
+ // Test that pkm is preferred over png. As pattern.pkm has different size than pattern.png, these tests verify that the right file has been loaded
+ QTest::newRow("extless prefer-tex") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << false << true << "";
+ QTest::newRow("extless prefer-tex async") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << true << true << "";
}