From ab2cc4ba45ba7cbac62b387c306ff457ac506c82 Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Sat, 15 Jul 2023 18:36:26 -0700 Subject: [PATCH] Fix auto DCP detection when using US English For systems where the locale is not English but the language in preferences is manually set to "English (US)", the Color Management Auto-matched camera profile option is not selectable even if a DCP exists for the camera. This is because the Glib::ustring casefold_collate_key() method returns a locale-dependent value. When initializing the list of DCP files, the system locale is used. When finding a matching DCP profile for an image, a different locale is used because the LANG environment variable is set while initializing the RawTherapee GUI language. --- rtengine/dcp.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index b65bb5f72..e949a808b 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -430,6 +430,16 @@ std::map getAliases(const Glib::ustring& profile_dir) return res; } +/** + * Returns a locale-independent case-insensitive collate key. Differs from + * Glib::ustring::casefold_collate_key() in that the Glib method may return + * different results depending on the current locale. + */ +std::string casefold_collate_key(const Glib::ustring &str) +{ + return str.casefold().raw(); +} + } struct DCPProfileApplyState::Data { @@ -1831,7 +1841,7 @@ void DCPStore::init(const Glib::ustring& rt_profile_dir, bool loadAll) && lastdot <= sname.size() - 4 && !sname.casefold().compare(lastdot, 4, ".dcp") ) { - file_std_profiles[sname.substr(0, lastdot).casefold_collate_key()] = fname; // They will be loaded and cached on demand + file_std_profiles[casefold_collate_key(sname.substr(0, lastdot))] = fname; // They will be loaded and cached on demand } } else { // Directory @@ -1842,10 +1852,10 @@ void DCPStore::init(const Glib::ustring& rt_profile_dir, bool loadAll) for (const auto& alias : getAliases(rt_profile_dir)) { const Glib::ustring alias_name = Glib::ustring(alias.first).uppercase(); - const std::map::const_iterator real = file_std_profiles.find(Glib::ustring(alias.second).casefold_collate_key()); + const std::map::const_iterator real = file_std_profiles.find(casefold_collate_key(alias.second)); if (real != file_std_profiles.end()) { - file_std_profiles[alias_name.casefold_collate_key()] = real->second; + file_std_profiles[casefold_collate_key(alias_name)] = real->second; } } } @@ -1892,7 +1902,7 @@ DCPProfile* DCPStore::getProfile(const Glib::ustring& filename) const DCPProfile* DCPStore::getStdProfile(const Glib::ustring& requested_cam_short_name) const { - const std::map::const_iterator iter = file_std_profiles.find(requested_cam_short_name.casefold_collate_key()); + const std::map::const_iterator iter = file_std_profiles.find(casefold_collate_key(requested_cam_short_name)); if (iter != file_std_profiles.end()) { return getProfile(iter->second); }