22#include <unordered_map>
57 bool contains(
const QString& key)
const;
58 QPixmap
get(
const QString& key);
59 void insert(
const QString& key,
const QPixmap& pixmap);
66 return hitCount_.load();
70 return missCount_.load();
75 void touchEntry(
const QString& key);
77 mutable QMutex mutex_;
78 std::unordered_map<QString, QPixmap> cache_;
79 std::deque<QString> lruOrder_;
83 mutable std::atomic<size_t> hitCount_{0};
84 mutable std::atomic<size_t> missCount_{0};
122 void requestImage(
const QString& cacheKey,
const QString& imagePath,
const QSize& targetSize,
123 bool useFastScaling =
true,
int priority = 0);
138 bool isCached(
const QString& cacheKey)
const;
144 QPixmap
getCached(
const QString& cacheKey);
154 void getCacheStats(
size_t& size,
size_t& hits,
size_t& misses)
const;
171 std::unique_ptr<ImageCache> cache_;
172 QThreadPool* threadPool_;
175 mutable QMutex pendingMutex_;
176 std::unordered_map<QString, bool> pendingRequests_;
179 std::atomic<uint64_t> generation_{0};
194 return QSize(((size.width() + step / 2) / step) * step,
195 ((size.height() + step / 2) / step) * step);
202 const QString& imageType = QString())
205 if (imageType.isEmpty())
206 return QStringLiteral(
"%1_%2x%3")
208 .arg(quantized.width())
209 .arg(quantized.height());
211 return QStringLiteral(
"%1_%2_%3x%4")
212 .arg(gameId, imageType)
213 .arg(quantized.width())
214 .arg(quantized.height());
QSize quantizeSize(const QSize &size, int step=16)
Round size to nearest quantization step for cache efficiency.
QString makeImageCacheKey(const QString &gameId, const QSize &size, const QString &imageType=QString())
Generate cache key for an image at a specific size.
void imageLoaded(const QString &cacheKey, const QPixmap &pixmap)
Emitted when an image has been loaded (on main thread).
QPixmap getCached(const QString &cacheKey)
Get cached image directly (for synchronous fallback).
bool isCached(const QString &cacheKey) const
Check if an image is already cached.
~AsyncImageLoader() override
void requestImage(const QString &cacheKey, const QString &imagePath, const QSize &targetSize, bool useFastScaling=true, int priority=0)
Request an image to be loaded asynchronously.
void clearCache()
Clear the image cache.
AsyncImageLoader(QObject *parent=nullptr)
void getCacheStats(size_t &size, size_t &hits, size_t &misses) const
Get cache statistics.
void cancelAll()
Cancel all pending requests (useful when changing views).
void setMaxCacheSize(size_t maxSize)
Set maximum cache size.
bool contains(const QString &key) const
ImageCache(size_t maxSize=300)
QPixmap get(const QString &key)
void insert(const QString &key, const QPixmap &pixmap)
Request for loading an image asynchronously.
Result of an async image load operation.