Improve Lensfun auto lens matching
Handle lens names with spaces surrounding dashes.
This commit is contained in:
parent
11240bc97d
commit
4e57202bf6
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
#include "imagedata.h"
|
||||
#include "procparams.h"
|
||||
@ -475,25 +476,38 @@ 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(); ) {
|
||||
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 (name.find("f/", pos) == 0) {
|
||||
if (lens_name.find("f/", pos) == 0) {
|
||||
break; // no need to search further
|
||||
}
|
||||
Glib::ustring make, model;
|
||||
auto i = name.find(' ', pos);
|
||||
auto i = lens_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());
|
||||
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;
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
found = data_->FindLenses(camera.data_, nullptr, "");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user