mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Implement a cache for the scaled images
No point in scaling them every time the user looks at the dive. Over time this may waste some memory (especially if people have a ton of pictures and let the process run a very long time). For now I won't worry about that. Fixes #577 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2af7aefd73
commit
6548773ad6
1 changed files with 9 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <dive.h>
|
||||
#include <QtConcurrentMap>
|
||||
#include <QDir>
|
||||
#include <QHash>
|
||||
|
||||
DivePictureModel *DivePictureModel::instance()
|
||||
{
|
||||
|
@ -18,10 +19,16 @@ typedef QList<SPixmap> SPixmapList;
|
|||
|
||||
SPixmap scaleImages(const QString &s)
|
||||
{
|
||||
QImage p = QImage(s).scaled(128, 128, Qt::KeepAspectRatio);
|
||||
static QHash <QString, QImage > cache;
|
||||
SPixmap ret;
|
||||
ret.first = s;
|
||||
ret.second = p;
|
||||
if (cache.contains(s)) {
|
||||
ret.second = cache.value(s);
|
||||
} else {
|
||||
QImage p = QImage(s).scaled(128, 128, Qt::KeepAspectRatio);
|
||||
cache.insert(s, p);
|
||||
ret.second = p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue