From 66979d290a6fc66adc556ca19048adcb9ba27915 Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Sat, 9 Sep 2017 00:54:28 +0200 Subject: [PATCH] lensfun: further tweaks on the matching logic and the UI --- rtengine/rtlensfun.cc | 10 +++++----- rtgui/lensprofile.cc | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index 4e2216fc0..7a2e94bb3 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -262,7 +262,7 @@ LFCamera LFDatabase::findCamera(const Glib::ustring &make, const Glib::ustring & { LFCamera ret; if (data_) { - auto found = data_->FindCamerasExt(make.c_str(), model.c_str(), LF_SEARCH_LOOSE); + auto found = data_->FindCamerasExt(make.c_str(), model.c_str()); if (found) { ret.data_ = found[0]; lf_free(found); @@ -276,12 +276,12 @@ LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name) c { LFLens ret; if (data_) { - const char *lname = name.c_str(); + Glib::ustring lname = name; bool stdlens = camera.ok() && (name.empty() || name.find("Unknown ") == 0); if (stdlens) { - lname = "Standard"; + lname = camera.getModel(); // "Standard" } - auto found = data_->FindLenses(camera.data_, nullptr, lname, LF_SEARCH_LOOSE); + auto found = data_->FindLenses(camera.data_, nullptr, lname.c_str()); if (!found) { // try to split the maker from the model of the lens Glib::ustring make, model; @@ -289,7 +289,7 @@ LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name) c if (i != Glib::ustring::npos) { make = name.substr(0, i); model = name.substr(i+1); - found = data_->FindLenses(camera.data_, make.c_str(), model.c_str(), LF_SEARCH_LOOSE); + found = data_->FindLenses(camera.data_, make.c_str(), model.c_str()); } } if (found) { diff --git a/rtgui/lensprofile.cc b/rtgui/lensprofile.cc index 1386469a9..5f98ef4af 100644 --- a/rtgui/lensprofile.cc +++ b/rtgui/lensprofile.cc @@ -174,25 +174,31 @@ void LensProfilePanel::read(const rtengine::procparams::ProcParams* pp, const Pa ckbUseVign->set_active (pp->lensProf.useVign && isRaw); ckbUseCA->set_active (pp->lensProf.useCA && isRaw); - setLensfunCamera(pp->lensProf.lfCameraMake, pp->lensProf.lfCameraModel); - setLensfunLens(pp->lensProf.lfLens); + const LFDatabase *db = LFDatabase::getInstance(); + LFCamera c; + LFLens l; + if (metadata) { + c = db->findCamera(metadata->getMake(), metadata->getModel()); + l = db->findLens(c, metadata->getLens()); + } + + if (!setLensfunCamera(pp->lensProf.lfCameraMake, pp->lensProf.lfCameraModel) && pp->lensProf.lfAutoMatch) { + setLensfunCamera(c.getMake(), c.getModel()); + } + if (!setLensfunLens(pp->lensProf.lfLens) && pp->lensProf.lfAutoMatch) { + setLensfunLens(l.getLens()); + } lcpFileChanged = useDistChanged = useVignChanged = useCAChanged = false; useLensfunChanged = lensfunAutoChanged = lensfunCameraChanged = lensfunLensChanged = false; - if (!batchMode && metadata && pp->lensProf.useLensfun) { + if (metadata) { std::unique_ptr mod(LFDatabase::findModifier(pp->lensProf, metadata, 100, 100, pp->coarse, -1)); if (!mod) { - corrOff->set_active(true); - if (pp->lensProf.lfAutoMatch) { - corrLensfunAuto->set_sensitive(false); + if (pp->lensProf.useLensfun) { + corrOff->set_active(true); } - } else if (pp->lensProf.lfAutoMatch) { - const LFDatabase *db = LFDatabase::getInstance(); - LFCamera c = db->findCamera(metadata->getMake(), metadata->getModel()); - LFLens l = db->findLens(c, metadata->getLens()); - setLensfunCamera(c.getMake(), c.getModel()); - setLensfunLens(l.getLens()); + corrLensfunAuto->set_sensitive(false); } } @@ -366,6 +372,11 @@ void LensProfilePanel::fillLensfunLenses() bool LensProfilePanel::setLensfunCamera(const Glib::ustring &make, const Glib::ustring &model) { if (!make.empty() && !model.empty()) { + auto it = lensfunCameras->get_active(); + if (it && (*it)[lensfunModelCam.make] == make && (*it)[lensfunModelCam.model] == model) { + return true; + } + // search for the active row for (auto row : lensfunCameraModel->children()) { if (row[lensfunModelCam.make] == make) { @@ -381,6 +392,7 @@ bool LensProfilePanel::setLensfunCamera(const Glib::ustring &make, const Glib::u } } } + lensfunCameras->set_active(-1); return false; } @@ -388,6 +400,11 @@ bool LensProfilePanel::setLensfunCamera(const Glib::ustring &make, const Glib::u bool LensProfilePanel::setLensfunLens(const Glib::ustring &lens) { if (!lens.empty()) { + auto it = lensfunLenses->get_active(); + if (it && (*it)[lensfunModelLens.lens] == lens) { + return true; + } + // search for the active row auto pos = lens.find_first_of(' '); Glib::ustring make = "(Unknown)"; @@ -409,6 +426,7 @@ bool LensProfilePanel::setLensfunLens(const Glib::ustring &lens) } } } + lensfunLenses->set_active(-1); return false; }