From a4672468344632233d792505a20e481f1436e353 Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Sat, 16 Sep 2017 10:54:00 +0200 Subject: [PATCH] fix compilation failure when using lensfun 0.2.x Fixes #4085 --- CMakeLists.txt | 13 ++++++++++++ rtengine/CMakeLists.txt | 5 +++++ rtengine/rtlensfun.cc | 44 ++++++++++++++++++++++++++++++++++++++++- rtengine/rtlensfun.h | 2 ++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13ba209bf..c75b02288 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -445,6 +445,19 @@ if(UNIX) install(FILES rawtherapee.appdata.xml DESTINATION "${APPDATADIR}") endif() +# check whether the used version of lensfun has lfDatabase::LoadDirectory +include(CheckCXXSourceCompiles) +set(CMAKE_REQUIRED_INCLUDES ${LENSFUN_INCLUDE_DIRS}) +check_cxx_source_compiles( + "#include +int main() +{ + lfDatabase *db = 0; + bool b = db->LoadDirectory(0); + return 0; +}" LENSFUN_HAS_LOAD_DIRECTORY) + + add_subdirectory(rtexif) add_subdirectory(rtengine) add_subdirectory(rtgui) diff --git a/rtengine/CMakeLists.txt b/rtengine/CMakeLists.txt index 32d99cb8f..3d87c552d 100644 --- a/rtengine/CMakeLists.txt +++ b/rtengine/CMakeLists.txt @@ -113,6 +113,11 @@ set(RTENGINESOURCEFILES rtlensfun.cc ) +if(LENSFUN_HAS_LOAD_DIRECTORY) + set_source_files_properties(rtlensfun.cc PROPERTIES COMPILE_DEFINITIONS RT_LENSFUN_HAS_LOAD_DIRECTORY) +endif() + + if(NOT WITH_SYSTEM_KLT) set(RTENGINESOURCEFILES ${RTENGINESOURCEFILES} klt/convolve.cc diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index a352613ab..ae027da56 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -267,7 +267,12 @@ bool LFDatabase::init(const Glib::ustring &dbdir) std::cout << "..." << std::flush; } - bool ok = dbdir.empty() ? (instance_.data_->Load() == LF_NO_ERROR) : instance_.data_->LoadDirectory(dbdir.c_str()); + bool ok = false; + if (dbdir.empty()) { + ok = (instance_.data_->Load() == LF_NO_ERROR); + } else { + ok = instance_.LoadDirectory(dbdir.c_str()); + } if (settings->verbose) { std::cout << (ok ? "OK" : "FAIL") << std::endl; @@ -277,6 +282,43 @@ bool LFDatabase::init(const Glib::ustring &dbdir) } +bool LFDatabase::LoadDirectory(const char *dirname) +{ +#if RT_LENSFUN_HAS_LOAD_DIRECTORY + instance_.data_->LoadDirectory(dirname); +#else + // backported from lensfun 0.3.x + bool database_found = false; + + GDir *dir = g_dir_open (dirname, 0, NULL); + if (dir) + { + GPatternSpec *ps = g_pattern_spec_new ("*.xml"); + if (ps) + { + const gchar *fn; + while ((fn = g_dir_read_name (dir))) + { + size_t sl = strlen (fn); + if (g_pattern_match (ps, sl, fn, NULL)) + { + gchar *ffn = g_build_filename (dirname, fn, NULL); + /* Ignore errors */ + if (data_->Load (ffn) == LF_NO_ERROR) + database_found = true; + g_free (ffn); + } + } + g_pattern_spec_free (ps); + } + g_dir_close (dir); + } + + return database_found; +#endif +} + + LFDatabase::LFDatabase(): data_(nullptr) { diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h index a4ff17ae9..d1cfd0ec4 100644 --- a/rtengine/rtlensfun.h +++ b/rtengine/rtlensfun.h @@ -117,6 +117,8 @@ private: float focalLen, float aperture, float focusDist, int width, int height, bool swap_xy) const; LFDatabase(); + bool LoadDirectory(const char *dirname); + static LFDatabase instance_; lfDatabase *data_; };