From 5d5c51d200b43a23adc289c42da27c6ac68c7dc0 Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Wed, 7 Feb 2018 09:34:19 +0100 Subject: [PATCH] added support for user-specific DCP and input ICC profiles dirs Look for direcories dcpprofiles/ and iccprofiles/input/ under Options::rtdir (typically something like $HOME/.config/RawTherapee) --- rtengine/dcp.cc | 73 ++++++++++++++++++++++---------------------- rtengine/dcp.h | 2 +- rtengine/iccstore.cc | 2 ++ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index fe798cb99..01929c9db 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -1737,51 +1737,50 @@ void DCPStore::init(const Glib::ustring& rt_profile_dir, bool loadAll) file_std_profiles.clear(); if (!loadAll) { - profileDir.assign (rt_profile_dir); + profileDir = { rt_profile_dir, Glib::build_filename(options.rtdir, "dcpprofiles") }; return; } - if (!rt_profile_dir.empty()) { - std::deque dirs = { - rt_profile_dir - }; + std::deque dirs = { + rt_profile_dir, + Glib::build_filename(options.rtdir, "dcpprofiles") + }; - while (!dirs.empty()) { - // Process directory - Glib::ustring dirname = dirs.back(); - dirs.pop_back(); + while (!dirs.empty()) { + // Process directory + Glib::ustring dirname = dirs.back(); + dirs.pop_back(); - std::unique_ptr dir; + std::unique_ptr dir; - try { - if (!Glib::file_test(dirname, Glib::FILE_TEST_IS_DIR)) { - return; - } - - dir.reset(new Glib::Dir(dirname)); - } catch (Glib::Exception& exception) { + try { + if (!Glib::file_test(dirname, Glib::FILE_TEST_IS_DIR)) { return; } - for (const Glib::ustring& sname : *dir) { - const Glib::ustring fname = Glib::build_filename(dirname, sname); + dir.reset(new Glib::Dir(dirname)); + } catch (Glib::Exception& exception) { + return; + } - if (!Glib::file_test(fname, Glib::FILE_TEST_IS_DIR)) { - // File - const auto lastdot = sname.rfind('.'); + for (const Glib::ustring& sname : *dir) { + const Glib::ustring fname = Glib::build_filename(dirname, sname); - if ( - lastdot != Glib::ustring::npos - && lastdot <= sname.size() - 4 - && !sname.casefold().compare(lastdot, 4, ".dcp") + if (!Glib::file_test(fname, Glib::FILE_TEST_IS_DIR)) { + // File + const auto lastdot = sname.rfind('.'); + + if ( + lastdot != Glib::ustring::npos + && lastdot <= sname.size() - 4 + && !sname.casefold().compare(lastdot, 4, ".dcp") ) { - const Glib::ustring cam_short_name = sname.substr(0, lastdot).uppercase(); - file_std_profiles[cam_short_name] = fname; // They will be loaded and cached on demand - } - } else { - // Directory - dirs.push_front(fname); + const Glib::ustring cam_short_name = sname.substr(0, lastdot).uppercase(); + file_std_profiles[cam_short_name] = fname; // They will be loaded and cached on demand } + } else { + // Directory + dirs.push_front(fname); } } } @@ -1839,11 +1838,13 @@ DCPProfile* DCPStore::getStdProfile(const Glib::ustring& requested_cam_short_nam } // profile not found, looking if we're in loadAll=false mode - if (!profileDir.empty()) { - const Glib::ustring fname = Glib::build_filename(profileDir, requested_cam_short_name + Glib::ustring(".dcp")); + for (const auto &dir : profileDir) { + if (!dir.empty()) { + const Glib::ustring fname = Glib::build_filename(dir, requested_cam_short_name + Glib::ustring(".dcp")); - if (Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) { - return getProfile(fname); + if (Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) { + return getProfile(fname); + } } } diff --git a/rtengine/dcp.h b/rtengine/dcp.h index 10bbf8f7e..bedc7f76d 100644 --- a/rtengine/dcp.h +++ b/rtengine/dcp.h @@ -166,7 +166,7 @@ private: DCPStore() = default; mutable MyMutex mutex; - Glib::ustring profileDir; + std::vector profileDir; // these contain standard profiles from RT. keys are all in uppercase, file path is value std::map file_std_profiles; diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 50ff58878..51c77b719 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -334,6 +334,8 @@ public: fileStdProfilesFileNames.clear(); if (loadAll) { loadProfiles(stdProfilesDir, nullptr, nullptr, &fileStdProfilesFileNames, true); + Glib::ustring user_input_icc_dir = Glib::build_filename(options.rtdir, "iccprofiles", "input"); + loadProfiles(user_input_icc_dir, nullptr, nullptr, &fileStdProfilesFileNames, true); } defaultMonitorProfile = settings->monitorProfile;