Skip to content

Commit

Permalink
Calculate focus distance for Nikon Z cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawrence37 committed Nov 11, 2023
1 parent e5d389e commit f256593
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion rtengine/imagedata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,29 @@ FramesData::FramesData(const Glib::ustring &fname, time_t ts) :
/*
* Get the focus distance in meters.
*/
if (find_exif_tag("Exif.NikonLd2.FocusDistance")
if (Exiv2::testVersion(0, 27, 4) && find_exif_tag("Exif.NikonLd4.LensID") && to_long(pos) != 0) {
// Z lens, need to specifically look for the second instance of
// Exif.NikonLd4.FocusDistance unless using Exiv2 0.28.x and later
// (also expanded to 2 bytes of precision since 0.28.1).
#if EXIV2_TEST_VERSION(0, 28, 0)
if (find_exif_tag("Exif.NikonLd4.FocusDistance2")) {
float value = pos->toFloat();
if (Exiv2::testVersion(0, 28, 1)) {
value /= 256.f;
}
#else
pos = exif.end();
for (auto it = exif.begin(); it != exif.end(); it++) {
if (it->key() == "Exif.NikonLd4.FocusDistance") {
pos = it;
}
}
if (pos != exif.end() && pos->size()) {
float value = pos->toFloat();
#endif
focus_dist = 0.01 * std::pow(10, value / 40);
}
} else if (find_exif_tag("Exif.NikonLd2.FocusDistance")
|| find_exif_tag("Exif.NikonLd3.FocusDistance")
|| (Exiv2::testVersion(0, 27, 4)
&& find_exif_tag("Exif.NikonLd4.FocusDistance"))) {
Expand Down

0 comments on commit f256593

Please sign in to comment.