Allow relative CLUT paths (#3639) by @agriggio

Kudos to Alberto Griggio for this contribution! 👍
This commit is contained in:
Flössie
2017-02-14 20:19:00 +01:00
parent 6b6c08028d
commit 6bcac40306
2 changed files with 28 additions and 5 deletions

View File

@@ -307,12 +307,17 @@ std::shared_ptr<rtengine::HaldCLUT> rtengine::CLUTStore::getClut(const Glib::ust
{ {
std::shared_ptr<rtengine::HaldCLUT> result; std::shared_ptr<rtengine::HaldCLUT> result;
if (!cache.get(filename, result)) { Glib::ustring full_filename = filename;
if ( !Glib::path_is_absolute(full_filename) ) {
full_filename = Glib::build_filename(options.clutsDir, filename);
}
if (!cache.get(full_filename, result)) {
std::unique_ptr<rtengine::HaldCLUT> clut(new rtengine::HaldCLUT); std::unique_ptr<rtengine::HaldCLUT> clut(new rtengine::HaldCLUT);
if (clut->load(filename)) { if (clut->load(full_filename)) {
result = std::move(clut); result = std::move(clut);
cache.insert(filename, result); cache.insert(full_filename, result);
} }
} }

View File

@@ -11,6 +11,18 @@ using namespace rtengine::procparams;
namespace namespace
{ {
Glib::ustring stripPrefixDir(const Glib::ustring &filename,
Glib::ustring dir)
{
if (!Glib::str_has_suffix(dir, G_DIR_SEPARATOR_S)) {
dir += G_DIR_SEPARATOR_S;
}
if (Glib::str_has_prefix(filename, dir)) {
return filename.substr(dir.size());
}
return filename;
}
bool notifySlowParseDir (const std::chrono::system_clock::time_point& startedAt) bool notifySlowParseDir (const std::chrono::system_clock::time_point& startedAt)
{ {
static enum static enum
@@ -116,7 +128,12 @@ void FilmSimulation::read( const rtengine::procparams::ProcParams* pp, const Par
setEnabled (pp->filmSimulation.enabled); setEnabled (pp->filmSimulation.enabled);
if ( !pp->filmSimulation.clutFilename.empty() ) { if ( !pp->filmSimulation.clutFilename.empty() ) {
m_clutComboBox->setSelectedClut( pp->filmSimulation.clutFilename ); Glib::ustring full_filename(pp->filmSimulation.clutFilename);
if ( !Glib::path_is_absolute(full_filename) ) {
full_filename = Glib::build_filename(options.clutsDir,
full_filename);
}
m_clutComboBox->setSelectedClut( full_filename );
} }
m_strength->setValue( pp->filmSimulation.strength ); m_strength->setValue( pp->filmSimulation.strength );
@@ -157,7 +174,8 @@ void FilmSimulation::write( rtengine::procparams::ProcParams* pp, ParamsEdited*
Glib::ustring clutFName = m_clutComboBox->getSelectedClut(); Glib::ustring clutFName = m_clutComboBox->getSelectedClut();
if ( clutFName != "NULL" ) { // We do not want to set "NULL" in clutFilename, even if "unedited" if ( clutFName != "NULL" ) { // We do not want to set "NULL" in clutFilename, even if "unedited"
pp->filmSimulation.clutFilename = clutFName; pp->filmSimulation.clutFilename = stripPrefixDir(clutFName,
options.clutsDir);
} }
pp->filmSimulation.strength = m_strength->getValue(); pp->filmSimulation.strength = m_strength->getValue();