11#include <QImageReader>
15 std::lock_guard<std::mutex> lock(cacheMutex_);
18 auto it = cache_.find(path);
19 if (it != cache_.end())
22 *width = it->second.width;
24 *height = it->second.height;
29 QString qpath = QString::fromStdString(path);
30 if (!QFile::exists(qpath))
40 QPixmap pixmap(qpath);
52 cached.pixmap = pixmap;
53 cached.width = pixmap.width();
54 cached.height = pixmap.height();
55 cache_[path] = cached;
58 *width = cached.width;
60 *height = cached.height;
67 std::lock_guard<std::mutex> lock(cacheMutex_);
68 return cache_.find(path) != cache_.end();
73 std::lock_guard<std::mutex> lock(cacheMutex_);
79 std::lock_guard<std::mutex> lock(cacheMutex_);
85 std::lock_guard<std::mutex> lock(cacheMutex_);
87 auto it = cache_.find(path);
88 if (it == cache_.end())
98 *width = it->second.width;
100 *height = it->second.height;
106 std::lock_guard<std::mutex> lock(cacheMutex_);
108 auto it = cache_.find(path);
109 if (it != cache_.end())
111 return it->second.pixmap;
115 QString qpath = QString::fromStdString(path);
116 if (!QFile::exists(qpath))
121 QPixmap pixmap(qpath);
129 cached.pixmap = pixmap;
130 cached.width = pixmap.width();
131 cached.height = pixmap.height();
132 cache_[path] = cached;
140 if (original.isNull())
145 return original.scaled(maxWidth, maxHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
void unloadImage(const std::string &path) override
Unload a specific image and free resources.
bool loadImage(const std::string &path, int *width=nullptr, int *height=nullptr) override
Load an image from disk.
QPixmap getPixmap(const std::string &path)
void clearCache() override
Clear all cached images and free resources.
bool getImageDimensions(const std::string &path, int *width, int *height) const override
Get dimensions of a loaded image.
QPixmap getScaledPixmap(const std::string &path, int maxWidth, int maxHeight)
bool isImageLoaded(const std::string &path) const override
Check if an image is already loaded/cached.