From d06818c1f8573c186cf58e9a21a8500262568ad9 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Mon, 9 Nov 2015 16:48:12 +0100
Subject: [PATCH] Store Thumbnails with image hashes

This drastically improves the time it takes to select a dive
with several pictures at the expense of longer startup and
bigger hash files.

Signed-off-by: Robert C. Helling <[email protected]>
---
 qt-models/divepicturemodel.cpp | 10 ++++++----
 subsurface-core/qthelper.cpp   |  3 +++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp
index 55f20ce..602663e 100644
--- a/qt-models/divepicturemodel.cpp
+++ b/qt-models/divepicturemodel.cpp
@@ -6,19 +6,21 @@
 
 #include <QtConcurrent>
 
+extern QHash <QString, QImage > thumbnailCache;
+
+
 SPixmap scaleImages(picturepointer picture)
 {
-       static QHash <QString, QImage > cache;
        SPixmap ret;
        ret.first = picture;
-       if (cache.contains(picture->filename) && 
!cache.value(picture->filename).isNull()) {
-               ret.second = cache.value(picture->filename);
+       if (thumbnailCache.contains(picture->filename) && 
!thumbnailCache.value(picture->filename).isNull()) {
+               ret.second = thumbnailCache.value(picture->filename);
        } else {
                int dim = defaultIconMetrics().sz_pic;
                QImage p = SHashedImage(picture);
                if(!p.isNull()) {
                        p = p.scaled(dim, dim, Qt::KeepAspectRatio);
-                       cache.insert(picture->filename, p);
+                       thumbnailCache.insert(picture->filename, p);
                }
                ret.second = p;
        }
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp
index 40c507a..63248f6 100644
--- a/subsurface-core/qthelper.cpp
+++ b/subsurface-core/qthelper.cpp
@@ -1129,6 +1129,7 @@ extern "C" void reverseGeoLookup(degrees_t latitude, 
degrees_t longitude, uint32
 QHash<QString, QByteArray> hashOf;
 QMutex hashOfMutex;
 QHash<QByteArray, QString> localFilenameOf;
+QHash <QString, QImage > thumbnailCache;
 
 extern "C" char * hashstring(char * filename)
 {
@@ -1152,6 +1153,7 @@ void read_hashes()
                QDataStream stream(&hashfile);
                stream >> localFilenameOf;
                stream >> hashOf;
+               stream >> thumbnailCache;
                hashfile.close();
        }
 }
@@ -1163,6 +1165,7 @@ void write_hashes()
                QDataStream stream(&hashfile);
                stream << localFilenameOf;
                stream << hashOf;
+               stream << thumbnailCache;
                hashfile.commit();
        } else {
                qDebug() << "cannot open" << hashfile.fileName();
-- 
1.9.5 (Apple Git-50.3)


So far, when selecting a dive, it can take several seconds to display it (about 
10 in my test case) if the images have to be loaded from the file system. We 
only use very small versions of them anyway, so this patch stores the cached 
thumbnails in the image hash files which drastically improves this time. Of 
course, this increases the hash file size and makes start-up a but slower, but 
at least in my case only by a tiny bit.

Best
Robert

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to