aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-04-29 23:07:05 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-13 13:52:35 -0700
commit6618c9ebfc6a7cebbef687fcb3aa74c70f504ff2 (patch)
treefcb8930645e83c79236bb5a5a0b0a77bf0210f6e /core
parentc0bca3ad04762a7178bda37be4c2ed87ae7e5f4e (diff)
downloadsubsurface-6618c9ebfc6a7cebbef687fcb3aa74c70f504ff2.tar.gz
Dive pictures: save thumbnails to individual files
The old code loaded all thumbnails into memory at once. This does not scale to logs with thousands of pictures. Therefore, save the pictures to individual files and only load the currently needed pictures. Currently, this will make changing switching between dives slower, because the thumbnails are loaded from disk. In the future, it is planned to do this in a background thread without blocking the user interface. A notable difference to the old code: Thumbnails are now indexed by the image-hash (i.e. the content of the raw image) and not by the filename of the image. Thus, different paths to the same image should only be saved once. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/qthelper.cpp22
-rw-r--r--core/qthelper.h1
2 files changed, 20 insertions, 3 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index fb32fabe5..55015d226 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -1054,7 +1054,6 @@ 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;
static QByteArray getHash(const QString &filename)
{
@@ -1077,6 +1076,19 @@ const QString hashfile_name()
return QString(system_default_directory()).append("/hashes");
}
+static QString thumbnailDir()
+{
+ return QString(system_default_directory()) + "/thumbnails/";
+}
+
+// Return filename of thumbnail if it is known to us.
+// If this is an unknown thumbnail, return an empty string.
+QString thumbnailFileName(const QString &filename)
+{
+ QString hash = getHash(filename).toHex();
+ return hash.isEmpty() ? QString() : thumbnailDir() + hash;
+}
+
extern "C" char *hashfile_name_string()
{
return copy_qstring(hashfile_name());
@@ -1090,7 +1102,8 @@ void read_hashes()
QDataStream stream(&hashfile);
stream >> localFilenameOf;
stream >> hashOf;
- stream >> thumbnailCache;
+ QHash <QString, QImage> thumbnailCache;
+ stream >> thumbnailCache; // For backwards compatibility
hashfile.close();
}
localFilenameOf.remove("");
@@ -1100,6 +1113,9 @@ void read_hashes()
if (iter.value().isEmpty())
iter.remove();
}
+
+ // Make sure that the thumbnail directory exists
+ QDir().mkpath(thumbnailDir());
}
void write_hashes()
@@ -1111,7 +1127,7 @@ void write_hashes()
QDataStream stream(&hashfile);
stream << localFilenameOf;
stream << hashOf;
- stream << thumbnailCache;
+ stream << QHash<QString,QImage>(); // Empty thumbnailCache - for backwards compatibility
hashfile.commit();
} else {
qWarning() << "Cannot open hashfile for writing: " << hashfile.fileName();
diff --git a/core/qthelper.h b/core/qthelper.h
index 4c0dcda66..ac1de4df8 100644
--- a/core/qthelper.h
+++ b/core/qthelper.h
@@ -30,6 +30,7 @@ void write_hashes();
void updateHash(struct picture *picture);
QByteArray hashFile(const QString &filename);
QString hashString(const char *filename);
+QString thumbnailFileName(const QString &filename);
void learnImages(const QDir dir, int max_recursions);
void add_hash(const QString &filename, const QByteArray &hash);
void hashPicture(struct picture *picture);