@@ -17,7 +17,7 @@
17#include <QDateTime>
17#include <QDateTime>
18#include <QDebug>
18#include <QDebug>
19#include <QDir>
19#include <QDir>
20−#include <QImageReader>
20+#include <QUrl>
21#include <QUrlQuery>
21#include <QUrlQuery>
23#include "ImageCache.h"
23#include "ImageCache.h"
@@ -52,7 +52,7 @@ QFileInfo ImageCache::imagePath(const QUrl &image)
52 return QFileInfo(imageCacheRoot() + name);
52 return QFileInfo(imageCacheRoot() + name);
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)
57 if (!cachePath.exists())
57 if (!cachePath.exists())
58 return true;
58 return true;
@@ -62,7 +62,6 @@ bool ImageCache::needsUpdate(const QUrl &image, const QFileInfo &cachePath, cons
62 return true;
62 return true;
64 QSize cacheSize(QImageReader(cachePath.filePath()).size());
64 QSize cacheSize(QImageReader(cachePath.filePath()).size());
65− QSize imageSize(QImageReader(imageInfo.filePath()).size());
66 finalSize = calculateSize(imageSize, requestedSize);
65 finalSize = calculateSize(imageSize, requestedSize);
67 if (finalSize.isValid() && cacheSize != finalSize)
66 if (finalSize.isValid() && cacheSize != finalSize)
68 return true;
67 return true;
@@ -83,16 +82,15 @@ QSize ImageCache::calculateSize(const QSize &imageSize, const QSize &requestedSi
83 return finalSize;
82 return finalSize;
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)
88− QImageReader reader(image.toLocalFile());
89 reader.setQuality(100);
87 reader.setQuality(100);
90 reader.setScaledSize(finalSize);
88 reader.setScaledSize(finalSize);
91 auto format = reader.format(); // can't get this after reading
89 auto format = reader.format(); // can't get this after reading
93 QImage loadedImage(reader.read());
91 QImage loadedImage(reader.read());
94 if (loadedImage.isNull()) {
92 if (loadedImage.isNull()) {
95− qWarning() << "ImageCache could not read image" << image.path();
93+ qWarning() << "ImageCache could not read image" << reader.fileName() << ":" << reader.errorString();
96 return QImage();
94 return QImage();
@@ -105,7 +103,8 @@ QImage ImageCache::loadAndCacheImage(const QUrl &image, const QFileInfo &cachePa
105QImage ImageCache::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
103QImage ImageCache::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
107 QUrl image(id);
105 QUrl image(id);
108− QSize imageSize(QImageReader(image.toLocalFile()).size());
106+ QImageReader imageReader(image.toLocalFile());
107+ QSize imageSize(imageReader.size());
109 QImage result;
108 QImage result;
111 // Early exit here, with no sourceSize, scaled-up sourceSize, or bad source image
110 // 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
114 requestedSize.height() >= imageSize.height() ||
113 requestedSize.height() >= imageSize.height() ||
115 requestedSize.width() >= imageSize.width()) {
114 requestedSize.width() >= imageSize.width()) {
116 // We're only interested in scaling down, not up.
115 // We're only interested in scaling down, not up.
117− result = QImage(image.toLocalFile());
116+ result = imageReader.read();
118 *size = result.size();
117 *size = result.size();
119 return result;
118 return result;
@@ -122,11 +121,11 @@ QImage ImageCache::requestImage(const QString &id, QSize *size, const QSize &req
122 auto cachePath = imagePath(image);
121 auto cachePath = imagePath(image);
123 QSize finalSize;
122 QSize finalSize;
125− if (needsUpdate(image, cachePath, requestedSize, finalSize)) {
124+ if (needsUpdate(image, cachePath, imageSize, requestedSize, finalSize)) {
126 if (finalSize.isEmpty()) {
125 if (finalSize.isEmpty()) {
127 finalSize = calculateSize(imageSize, requestedSize);
126 finalSize = calculateSize(imageSize, requestedSize);
129− result = loadAndCacheImage(image, cachePath, finalSize);
128+ result = loadAndCacheImage(imageReader, cachePath, finalSize);
131 result = QImage(cachePath.filePath());
130 result = QImage(cachePath.filePath());