Skip to content

Commit

Permalink
Improve lens identification for Sony ARWs
Browse files Browse the repository at this point in the history
Let Exiv2 get the lens name if the lens spec is present. Otherwise, use
the lens ID.
  • Loading branch information
Lawrence37 committed Jan 6, 2025
1 parent 98752a2 commit 69b1b57
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions rtengine/imagedata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ auto to_long(const Iterator &iter, Integer n = Integer{0}) -> decltype(
#endif
}

/**
* Returns if the values at the iterator are equal to the given values.
*
* @param iter The iterator.
* @param compare_to The values to compare to.
* @param get_value A function that accepts the iterator and an index and
* returns the value at the index.
* @return If the values are equal.
*/
template <typename Iterator, typename T>
bool tag_values_equal(
const Iterator &iter,
const std::initializer_list<T> compare_to,
T (*get_value)(const Iterator &, std::size_t))
{
const auto size = compare_to.size();
if (size != iter->count()) {
return false;
}
std::size_t i = 0;
for (const auto value : compare_to) {
if (get_value(iter, i++) != value) {
return false;
}
}
return true;
}

/**
* Convenience class for reading data from a metadata tag's bytes value.
*
Expand Down Expand Up @@ -604,14 +632,13 @@ FramesData::FramesData(const Glib::ustring &fname, time_t ts) :
} else if (!make.compare(0, 4, "SONY")) {
// ExifTool prefers LensType2 over LensType (called
// Exif.Sony2.LensID by Exiv2). Exiv2 doesn't support LensType2 yet,
// so we let Exiv2 try it's best. For non ILCE/NEX cameras which
// likely don't have LensType2, we use Exif.Sony2.LensID because
// Exif.Photo.LensModel may be incorrect (see
// https://discuss.pixls.us/t/call-for-testing-rawtherapee-metadata-handling-with-exiv2-includes-cr3-support/36240/36).
// so we let Exiv2 try it's best. If the LensSpec is unknown, the
// lens information may be incorrect, so we use Exif.Sony2.LensID
// which lists all possible lenses.
if (
// Camera model is neither a ILCE, ILME, nor NEX.
(!find_exif_tag("Exif.Image.Model") ||
(pos->toString().compare(0, 4, "ILCE") && pos->toString().compare(0, 4, "ILME") && pos->toString().compare(0, 3, "NEX"))) &&
// LensSpec is unknown.
(find_exif_tag("Exif.Sony2.LensSpec") &&
tag_values_equal(pos, {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L}, to_long)) &&
// LensID exists. 0xFFFF could be one of many lenses.
find_exif_tag("Exif.Sony2.LensID") && to_long(pos) && to_long(pos) != 0xFFFF) {
lens = pos->print(&exif);
Expand Down

0 comments on commit 69b1b57

Please sign in to comment.