GithubHelp home page GithubHelp logo

Comments (5)

Lawrence37 avatar Lawrence37 commented on June 13, 2024

Confirmed. There is some suspicious usage, or rather non-usage, of the camera specifications when searching for a matching lens profile.

from rawtherapee.

acamari avatar acamari commented on June 13, 2024

Thanks for looking into it

from rawtherapee.

Lawrence37 avatar Lawrence37 commented on June 13, 2024

I did some testing with the code and managed to fix the problem. I need to clean the patch up and also understand why the camera details weren't used to look up the lens. It looks intentional, but the rationale is not clear.

Patch
diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc
index fc5bb0017..5bf154592 100644
--- a/rtengine/rtlensfun.cc
+++ b/rtengine/rtlensfun.cc
@@ -460,20 +460,38 @@ LFCamera LFDatabase::findCamera(const Glib::ustring &make, const Glib::ustring &
 }
 
 
-LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name) const
+LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name, bool autoMatch) const
 {
     LFLens ret;
     if (data_ && !name.empty()) {
         MyMutex::MyLock lock(lfDBMutex);
-        if (!camera.data_) {
+        if (!autoMatch) {
             // Only the lens name provided. Try to find exact match by name.
             LFLens candidate;
+            LFLens bestCandidate;
+            const auto isCStringIn = [](const char *str, const char *const *list) {
+                for (auto element = list[0]; element[0]; element++) {
+                    if (!strcmp(str, element)) {
+                        return true;
+                    }
+                }
+                return false;
+            };
             for (auto lens_list = data_->GetLenses(); lens_list[0]; lens_list++) {
                 candidate.data_ = lens_list[0];
-                if (name == candidate.getLens()) {
-                    return candidate;
+                if ((!bestCandidate.data_ ||
+                        (bestCandidate.data_->CropFactor > camera.data_->CropFactor
+                                ? bestCandidate.data_->CropFactor > candidate.data_->CropFactor
+                                : candidate.data_->CropFactor <= camera.data_->CropFactor &&
+                                      bestCandidate.data_->CropFactor < candidate.data_->CropFactor)) &&
+                    name == candidate.getLens() &&
+                    isCStringIn(camera.data_->Mount, candidate.data_->Mounts)) {
+                    bestCandidate.data_ = candidate.data_;
                 }
             }
+            if (bestCandidate.data_) {
+                return bestCandidate;
+            }
         }
         auto found = data_->FindLenses(camera.data_, nullptr, name.c_str());
         for (size_t pos = 0; !found && pos < name.size(); ) {
@@ -562,12 +580,7 @@ std::unique_ptr<LFModifier> LFDatabase::findModifier(
     }
 
     const LFCamera c = findCamera(make, model, lensProf.lfAutoMatch());
-    const LFLens l = findLens(
-        lensProf.lfAutoMatch()
-            ? c
-            : LFCamera(),
-        lens
-    );
+    const LFLens l = findLens(c, lens, lensProf.lfAutoMatch());
 
     bool swap_xy = false;
     if (rawRotationDeg >= 0) {
diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h
index bcce77f34..1d941246f 100644
--- a/rtengine/rtlensfun.h
+++ b/rtengine/rtlensfun.h
@@ -121,7 +121,7 @@ public:
     std::vector<LFCamera> getCameras() const;
     std::vector<LFLens> getLenses() const;
     LFCamera findCamera(const Glib::ustring &make, const Glib::ustring &model, bool autoMatch) const;
-    LFLens findLens(const LFCamera &camera, const Glib::ustring &name) const;
+    LFLens findLens(const LFCamera &camera, const Glib::ustring &name, bool autoMatch) const;
 
     std::unique_ptr<LFModifier> findModifier(
         const procparams::LensProfParams &lensProf,
diff --git a/rtgui/lensprofile.cc b/rtgui/lensprofile.cc
index 0e17b3f40..5f42a1cde 100644
--- a/rtgui/lensprofile.cc
+++ b/rtgui/lensprofile.cc
@@ -251,7 +251,7 @@ void LensProfilePanel::read(const rtengine::procparams::ProcParams* pp, const Pa
 
     if (pp->lensProf.lfAutoMatch()) {
         if (metadata) {
-            const LFLens l = db->findLens(c, metadata->getLens());
+            const LFLens l = db->findLens(c, metadata->getLens(), true);
             setLensfunLens(l.getLens());
         }
     } else if (pp->lensProf.lfManual()) {
@@ -522,7 +522,7 @@ void LensProfilePanel::onCorrModeChanged(const Gtk::RadioButton* rbChanged)
             } else if (metadata) {
                 const LFDatabase* const db = LFDatabase::getInstance();
                 const LFCamera c = db->findCamera(metadata->getMake(), metadata->getModel(), true);
-                const LFLens l = db->findLens(c, metadata->getLens());
+                const LFLens l = db->findLens(c, metadata->getLens(), true);
                 setLensfunCamera(c.getMake(), c.getModel());
                 setLensfunLens(l.getLens());
             }
@@ -808,7 +808,7 @@ void LensProfilePanel::updateLensfunWarning()
             return;
         }
 
-        const LFLens l = db->findLens(LFCamera(), (*itl)[lf->lensfunModelLens.lens]);
+        const LFLens l = db->findLens(c, (*itl)[lf->lensfunModelLens.lens], false);
         const float lenscrop = l.getCropFactor();
         const float camcrop = c.getCropFactor();

from rawtherapee.

acamari avatar acamari commented on June 13, 2024

hi, I don't have that much experience with rawtherapee development, should I apply this to head or can I apply this over v5.10? is there any kind of nightly build available? regards

from rawtherapee.

Lawrence37 avatar Lawrence37 commented on June 13, 2024

The patch is intended to be a progress report and solicit feedback from other developers who are interested. If you want to try it, I created the patch on top of the dev branch. However, it might also work on v5.10. There's no automated build available until I create a pull request.

from rawtherapee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.