@@ -17,7 +17,7 @@
1717#include <QDateTime>
1818#include <QDebug>
1919#include <QDir>
20−#include <QImageReader>
20+#include <QUrl>
2121#include <QUrlQuery>
2222
2323#include "ImageCache.h"
@@ -52,7 +52,7 @@ QFileInfo ImageCache::imagePath(const QUrl &image)
5252 return QFileInfo(imageCacheRoot() + name);
5353}
5454
55−bool ImageCache::needsUpdate(const QUrl &image, const QFileInfo &cachePath, const QSize &requestedSize, QSize &finalSize)
55+bool ImageCache::needsUpdate(const QUrl &image, const QFileInfo &cachePath, const QSize &imageSize, const QSize &requestedSize, QSize &finalSize)
5656{
5757 if (!cachePath.exists())
5858 return true;
@@ -62,7 +62,6 @@ bool ImageCache::needsUpdate(const QUrl &image, const QFileInfo &cachePath, cons
6262 return true;
6363
6464 QSize cacheSize(QImageReader(cachePath.filePath()).size());
65− QSize imageSize(QImageReader(imageInfo.filePath()).size());
6665 finalSize = calculateSize(imageSize, requestedSize);
6766 if (finalSize.isValid() && cacheSize != finalSize)
6867 return true;
@@ -83,16 +82,15 @@ QSize ImageCache::calculateSize(const QSize &imageSize, const QSize &requestedSi
8382 return finalSize;
8483}
8584
86−QImage ImageCache::loadAndCacheImage(const QUrl &image, const QFileInfo &cachePath, const QSize &finalSize)
85+QImage ImageCache::loadAndCacheImage(QImageReader &reader, const QFileInfo &cachePath, const QSize &finalSize)
8786{
88− QImageReader reader(image.toLocalFile());
8987 reader.setQuality(100);
9088 reader.setScaledSize(finalSize);
9189 auto format = reader.format(); // can't get this after reading
9290
9391 QImage loadedImage(reader.read());
9492 if (loadedImage.isNull()) {
95− qWarning() << "ImageCache could not read image" << image.path();
93+ qWarning() << "ImageCache could not read image" << reader.fileName() << ":" << reader.errorString();
9694 return QImage();
9795 }
9896
@@ -105,7 +103,8 @@ QImage ImageCache::loadAndCacheImage(const QUrl &image, const QFileInfo &cachePa
105103QImage ImageCache::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
106104{
107105 QUrl image(id);
108− QSize imageSize(QImageReader(image.toLocalFile()).size());
106+ QImageReader imageReader(image.toLocalFile());
107+ QSize imageSize(imageReader.size());
109108 QImage result;
110109
111110 // Early exit here, with no sourceSize, scaled-up sourceSize, or bad source image
@@ -114,7 +113,7 @@ QImage ImageCache::requestImage(const QString &id, QSize *size, const QSize &req
114113 requestedSize.height() >= imageSize.height() ||
115114 requestedSize.width() >= imageSize.width()) {
116115 // We're only interested in scaling down, not up.
117− result = QImage(image.toLocalFile());
116+ result = imageReader.read();
118117 *size = result.size();
119118 return result;
120119 }
@@ -122,11 +121,11 @@ QImage ImageCache::requestImage(const QString &id, QSize *size, const QSize &req
122121 auto cachePath = imagePath(image);
123122 QSize finalSize;
124123
125− if (needsUpdate(image, cachePath, requestedSize, finalSize)) {
124+ if (needsUpdate(image, cachePath, imageSize, requestedSize, finalSize)) {
126125 if (finalSize.isEmpty()) {
127126 finalSize = calculateSize(imageSize, requestedSize);
128127 }
129− result = loadAndCacheImage(image, cachePath, finalSize);
128+ result = loadAndCacheImage(imageReader, cachePath, finalSize);
130129 } else {
131130 result = QImage(cachePath.filePath());
132131 }