From 008f280e2918cce406c270161f825c96b7421eba Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Thu, 14 Sep 2017 11:34:41 +0200 Subject: [PATCH] lensfun: added possibility to use a private copy of the LF database --- CMakeLists.txt | 4 ++++ rtengine/init.cc | 2 +- rtengine/rtlensfun.cc | 21 +++++++++++++++++++-- rtengine/rtlensfun.h | 2 +- rtengine/settings.h | 3 +++ rtgui/config.h.in | 1 + rtgui/options.cc | 11 +++++++++++ 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 333e292f0..13ba209bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,10 @@ if(NOT DEFINED APPDATADIR) endif() endif() +if(DEFINED LENSFUNDBDIR AND NOT IS_ABSOLUTE "${LENSFUNDBDIR}") + set(LENSFUNDBDIR "${DATADIR}/${LENSFUNDBDIR}") +endif() + # Enforce absolute paths for non-bundle builds: if(NOT BUILD_BUNDLE) foreach(path BINDIR DATADIR LIBDIR DOCDIR CREDITSDIR LICENCEDIR) diff --git a/rtengine/init.cc b/rtengine/init.cc index 7ef40f43a..7ac4ca35b 100644 --- a/rtengine/init.cc +++ b/rtengine/init.cc @@ -51,7 +51,7 @@ int init (const Settings* s, Glib::ustring baseDir, Glib::ustring userSettingsDi Color::init (); PerceptualToneCurve::init (); RawImageSource::init (); - LFDatabase::init(); + LFDatabase::init(s->lensfunDbDirectory); delete lcmsMutex; lcmsMutex = new MyMutex; dfm.init( s->darkFramesPath ); diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index b42be9424..06c01f975 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -253,10 +253,27 @@ bool LFLens::hasDistortionCorrection() const LFDatabase LFDatabase::instance_; -bool LFDatabase::init() +bool LFDatabase::init(const Glib::ustring &dbdir) { instance_.data_ = lfDatabase::Create(); - return instance_.data_->Load() != LF_NO_ERROR; + + if (settings->verbose) { + std::cout << "Loading lensfun database from "; + if (dbdir.empty()) { + std::cout << "the default directories"; + } else { + std::cout << "'" << dbdir << "'"; + } + std::cout << "..." << std::flush; + } + + bool ok = instance_.data_->Load(dbdir.empty() ? nullptr : dbdir.c_str()) == LF_NO_ERROR; + + if (settings->verbose) { + std::cout << (ok ? "OK" : "FAIL") << std::endl; + } + + return ok; } diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h index 5774968ee..a4ff17ae9 100644 --- a/rtengine/rtlensfun.h +++ b/rtengine/rtlensfun.h @@ -100,7 +100,7 @@ class LFDatabase final : public NonCopyable { public: - static bool init(); + static bool init(const Glib::ustring &dbdir); static const LFDatabase *getInstance(); ~LFDatabase(); diff --git a/rtengine/settings.h b/rtengine/settings.h index ada63400a..225503777 100644 --- a/rtengine/settings.h +++ b/rtengine/settings.h @@ -92,6 +92,9 @@ public: double ed_low; double ed_lipinfl; double ed_lipampl; + + Glib::ustring lensfunDbDirectory; ///< The directory containing the lensfun database. If empty, the system defaults will be used (as described in http://lensfun.sourceforge.net/manual/dbsearch.html) + /** Creates a new instance of Settings. * @return a pointer to the new Settings instance. */ static Settings* create (); diff --git a/rtgui/config.h.in b/rtgui/config.h.in index cab481278..fdf64b73c 100644 --- a/rtgui/config.h.in +++ b/rtgui/config.h.in @@ -25,5 +25,6 @@ #define DOC_SEARCH_PATH "${DOCDIR}" #define CREDITS_SEARCH_PATH "${CREDITSDIR}" #define LICENCE_SEARCH_PATH "${LICENCEDIR}" +#define LENSFUN_DB_PATH "${LENSFUNDBDIR}" #endif diff --git a/rtgui/options.cc b/rtgui/options.cc index 2b504a2de..c2e2b586b 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -24,6 +24,7 @@ #include "addsetids.h" #include "guiutils.h" #include "version.h" +#include "config.h" #ifdef _OPENMP #include @@ -727,6 +728,8 @@ void Options::setDefaults () lastLensProfileDir = ""; gimpPluginShowInfoDialog = true; maxRecentFolders = 15; + + rtSettings.lensfunDbDirectory = LENSFUN_DB_PATH; } Options* Options::copyFrom (Options* other) @@ -1868,6 +1871,12 @@ void Options::readFromFile (Glib::ustring fname) } } + if (keyFile.has_group ("Lensfun")) { + if (keyFile.has_key ("Lensfun", "DBDirectory")) { + rtSettings.lensfunDbDirectory = keyFile.get_string ("Lensfun", "DBDirectory"); + } + } + // -------------------------------------------------------------------------------------------------------- filterOutParsedExtensions (); @@ -2239,6 +2248,8 @@ void Options::saveToFile (Glib::ustring fname) keyFile.set_string ("Dialogs", "LastLensProfileDir", lastLensProfileDir); keyFile.set_boolean ("Dialogs", "GimpPluginShowInfoDialog", gimpPluginShowInfoDialog); + keyFile.set_string ("Lensfun", "DBDirectory", rtSettings.lensfunDbDirectory); + keyData = keyFile.to_data (); } catch (Glib::KeyFileError &e) {