diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index b1531cc9c..af513536e 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -415,7 +415,7 @@ void ImProcFunctions::transform (Imagefloat* original, Imagefloat* transformed, std::unique_ptr pLCPMap; if (needsLensfun()) { - pLCPMap = LFDatabase::findModifier(params->lensProf, metadata, oW, oH, params->coarse, rawRotationDeg); + pLCPMap = LFDatabase::getInstance()->findModifier(params->lensProf, metadata, oW, oH, params->coarse, rawRotationDeg); } else if (needsLCP()) { // don't check focal length to allow distortion correction for lenses without chip const std::shared_ptr pLCPProf = LCPStore::getInstance()->getProfile (params->lensProf.lcpFile); diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 4cfa84434..265c226b3 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -1385,7 +1385,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le if (!hasFlatField && lensProf.useVign && lensProf.lcMode != LensProfParams::LcMode::NONE) { std::unique_ptr pmap; if (lensProf.useLensfun()) { - pmap = LFDatabase::findModifier(lensProf, idata, W, H, coarse, -1); + pmap = LFDatabase::getInstance()->findModifier(lensProf, idata, W, H, coarse, -1); } else { const std::shared_ptr pLCPProf = LCPStore::getInstance()->getProfile(lensProf.lcpFile); diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index 7b959ce8b..51b98080a 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -500,14 +500,20 @@ std::unique_ptr LFDatabase::getModifier(const LFCamera &camera, cons return ret; } -std::set LFDatabase::notFound; - -std::unique_ptr LFDatabase::findModifier(const procparams::LensProfParams &lensProf, const FramesMetaData *idata, int width, int height, const procparams::CoarseTransformParams &coarse, int rawRotationDeg) +std::unique_ptr LFDatabase::findModifier( + const procparams::LensProfParams &lensProf, + const FramesMetaData *idata, + int width, + int height, + const procparams::CoarseTransformParams &coarse, + int rawRotationDeg +) const { + const float focallen = idata->getFocalLen(); + Glib::ustring make, model, lens; - float focallen = idata->getFocalLen(); if (lensProf.lfAutoMatch()) { - if (focallen <= 0) { + if (focallen <= 0.f) { return nullptr; } make = idata->getMake(); @@ -518,6 +524,7 @@ std::unique_ptr LFDatabase::findModifier(const procparams::LensProfP model = lensProf.lfCameraModel; lens = lensProf.lfLens; } + if (make.empty() || model.empty() || lens.empty()) { return nullptr; } @@ -527,15 +534,15 @@ std::unique_ptr LFDatabase::findModifier(const procparams::LensProfP // This combination was not found => do not search again return nullptr; } - const LFDatabase *db = getInstance(); - LFCamera c = db->findCamera(make, model); - LFLens l = db->findLens(lensProf.lfAutoMatch() ? c : LFCamera(), lens); - if (focallen <= 0 && l.data_ && l.data_->MinFocal == l.data_->MaxFocal) { - focallen = l.data_->MinFocal; - } - if (focallen <= 0) { - return nullptr; - } + + const LFCamera c = findCamera(make, model); + const LFLens l = findLens( + lensProf.lfAutoMatch() + ? c + : LFCamera(), + lens + ); + bool swap_xy = false; if (rawRotationDeg >= 0) { int rot = (coarse.rotate + rawRotationDeg) % 360; @@ -545,18 +552,28 @@ std::unique_ptr LFDatabase::findModifier(const procparams::LensProfP } } - std::unique_ptr ret = db->getModifier(c, l, idata->getFocalLen(), idata->getFNumber(), idata->getFocusDist(), width, height, swap_xy); + std::unique_ptr ret = getModifier( + c, + l, + idata->getFocalLen(), + idata->getFNumber(), + idata->getFocusDist(), + width, + height, + swap_xy + ); if (settings->verbose) { std::cout << "LENSFUN:\n" << " camera: " << c.getDisplayString() << "\n" << " lens: " << l.getDisplayString() << "\n" << " correction: " - << (ret ? ret->getDisplayString() : "NONE") << std::endl; + << (ret ? ret->getDisplayString() : "NONE") + << std::endl; } if (!ret) { - notFound.emplace(key); + notFound.insert(key); } return ret; diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h index 573b93fca..06434c358 100644 --- a/rtengine/rtlensfun.h +++ b/rtengine/rtlensfun.h @@ -124,7 +124,13 @@ public: LFCamera findCamera(const Glib::ustring &make, const Glib::ustring &model) const; LFLens findLens(const LFCamera &camera, const Glib::ustring &name) const; - static std::unique_ptr findModifier(const procparams::LensProfParams &lensProf, const FramesMetaData *idata, int width, int height, const procparams::CoarseTransformParams &coarse, int rawRotationDeg); + std::unique_ptr findModifier( + const procparams::LensProfParams &lensProf, + const FramesMetaData *idata, + int width, int height, + const procparams::CoarseTransformParams &coarse, + int rawRotationDeg + ) const; private: std::unique_ptr getModifier(const LFCamera &camera, const LFLens &lens, @@ -136,7 +142,7 @@ private: mutable MyMutex lfDBMutex; static LFDatabase instance_; lfDatabase *data_; - static std::set notFound; + mutable std::set notFound; }; } // namespace rtengine diff --git a/rtgui/lensprofile.cc b/rtgui/lensprofile.cc index e2cdb5649..be21512d5 100644 --- a/rtgui/lensprofile.cc +++ b/rtgui/lensprofile.cc @@ -761,7 +761,7 @@ bool LensProfilePanel::checkLensfunCanCorrect(bool automatch) rtengine::procparams::ProcParams lpp; write(&lpp); - const std::unique_ptr mod(LFDatabase::findModifier(lpp.lensProf, metadata, 100, 100, lpp.coarse, -1)); + const std::unique_ptr mod(LFDatabase::getInstance()->findModifier(lpp.lensProf, metadata, 100, 100, lpp.coarse, -1)); return static_cast(mod); }