Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Lensfun automatic lens matching with extra spaces in the name #7022

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions rtengine/rtlensfun.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <iostream>
#include <regex>

#include "imagedata.h"
#include "procparams.h"
Expand Down Expand Up @@ -475,23 +476,36 @@ LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name) c
}
}
}
auto found = data_->FindLenses(camera.data_, nullptr, name.c_str());
for (size_t pos = 0; !found && pos < name.size(); ) {
// try to split the maker from the model of the lens -- we have to
// guess a bit here, since there are makers with a multi-word name
// (e.g. "Leica Camera AG")
if (name.find("f/", pos) == 0) {
break; // no need to search further
const auto find_lens_from_name = [](const lfDatabase *database, const lfCamera *cam, const Glib::ustring &lens_name) {
auto found = database->FindLenses(cam, nullptr, lens_name.c_str());
for (size_t pos = 0; !found && pos < lens_name.size(); ) {
// try to split the maker from the model of the lens -- we have to
// guess a bit here, since there are makers with a multi-word name
// (e.g. "Leica Camera AG")
if (lens_name.find("f/", pos) == 0) {
break; // no need to search further
}
Glib::ustring make, model;
auto i = lens_name.find(' ', pos);
if (i != Glib::ustring::npos) {
make = lens_name.substr(0, i);
model = lens_name.substr(i+1);
found = database->FindLenses(cam, make.c_str(), model.c_str());
pos = i+1;
} else {
break;
}
}
Glib::ustring make, model;
auto i = name.find(' ', pos);
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());
pos = i+1;
} else {
break;
return found;
};
auto found = find_lens_from_name(data_, camera.data_, name);
if (!found) {
// Some names have white-space around the dash(s) while Lensfun does
// not have any.
const std::regex pattern("\\s*-\\s*");
const auto formatted_name = std::regex_replace(name.raw(), pattern, "-");
if (name != formatted_name) {
found = find_lens_from_name(data_, camera.data_, formatted_name);
}
}
if (!found && camera && camera.isFixedLens()) {
Expand Down
Loading