Skip to content

Commit 79d402c

Browse files
committed
Improve lens identification for Sony ARWs
Let Exiv2 get the lens name if the lens spec is present. Otherwise, use the lens ID.
1 parent 98752a2 commit 79d402c

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

rtengine/imagedata.cc

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ auto to_long(const Iterator &iter, Integer n = Integer{0}) -> decltype(
6565
#endif
6666
}
6767

68+
/**
69+
* Returns if the values at the iterator are equal to the given values.
70+
*
71+
* @param iter The iterator.
72+
* @param compare_to The values to compare to.
73+
* @param get_value A function that accepts the iterator and an index and
74+
* returns the value at the index.
75+
* @return If the values are equal.
76+
*/
77+
template <typename Iterator, typename T>
78+
bool tag_values_equal(
79+
const Iterator &iter,
80+
const std::initializer_list<T> compare_to,
81+
std::function<T (const Iterator &, std::size_t)> get_value)
82+
{
83+
const auto size = compare_to.size();
84+
if (size != iter->count()) {
85+
return false;
86+
}
87+
std::size_t i = 0;
88+
for (const auto value : compare_to) {
89+
if (get_value(iter, i++) != value) {
90+
return false;
91+
}
92+
}
93+
return true;
94+
}
95+
6896
/**
6997
* Convenience class for reading data from a metadata tag's bytes value.
7098
*
@@ -604,14 +632,18 @@ FramesData::FramesData(const Glib::ustring &fname, time_t ts) :
604632
} else if (!make.compare(0, 4, "SONY")) {
605633
// ExifTool prefers LensType2 over LensType (called
606634
// Exif.Sony2.LensID by Exiv2). Exiv2 doesn't support LensType2 yet,
607-
// so we let Exiv2 try it's best. For non ILCE/NEX cameras which
608-
// likely don't have LensType2, we use Exif.Sony2.LensID because
609-
// Exif.Photo.LensModel may be incorrect (see
610-
// https://discuss.pixls.us/t/call-for-testing-rawtherapee-metadata-handling-with-exiv2-includes-cr3-support/36240/36).
635+
// so we let Exiv2 try it's best. If the LensSpec is unknown, the
636+
// lens information may be incorrect, so we use Exif.Sony2.LensID
637+
// which lists all possible lenses.
611638
if (
612-
// Camera model is neither a ILCE, ILME, nor NEX.
613-
(!find_exif_tag("Exif.Image.Model") ||
614-
(pos->toString().compare(0, 4, "ILCE") && pos->toString().compare(0, 4, "ILME") && pos->toString().compare(0, 3, "NEX"))) &&
639+
// LensSpec is unknown.
640+
(find_exif_tag("Exif.Sony2.LensSpec") &&
641+
tag_values_equal<decltype(pos), long>(
642+
pos,
643+
{0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L},
644+
[](const decltype(pos) &iter, std::size_t n) {
645+
return to_long(iter, n);
646+
})) &&
615647
// LensID exists. 0xFFFF could be one of many lenses.
616648
find_exif_tag("Exif.Sony2.LensID") && to_long(pos) && to_long(pos) != 0xFFFF) {
617649
lens = pos->print(&exif);

0 commit comments

Comments
 (0)