diff --git a/rtengine/imagedata.cc b/rtengine/imagedata.cc index 9008d21836..73f3b0fa65 100644 --- a/rtengine/imagedata.cc +++ b/rtengine/imagedata.cc @@ -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 +bool tag_values_equal( + const Iterator &iter, + const std::initializer_list 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. * @@ -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);