Skip to content

Commit

Permalink
Improve focus distance precision for Nikon Z
Browse files Browse the repository at this point in the history
  • Loading branch information
kmilos committed Aug 8, 2023
1 parent 6ea6e2c commit 2a02539
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,8 +1719,8 @@ constexpr TagInfo Nikon3MakerNote::tagInfoLd4_[] = {
printApertureLd4},
{60, "FocalLength2", N_("Focal Length 2"), N_("Focal length 2"), IfdId::nikonLd4Id, SectionId::makerTags,
unsignedShort, 1, printFocalLd4},
{79, "FocusDistance2", N_("Focus Distance 2"), N_("Focus distance 2"), IfdId::nikonLd4Id, SectionId::makerTags,
unsignedByte, 1, printFocusDistance},
{78, "FocusDistance2", N_("Focus Distance 2"), N_("Focus distance 2"), IfdId::nikonLd4Id, SectionId::makerTags,
unsignedShort, 1, printFocusDistanceLd4},
// End of list marker
{0xffff, "(UnknownNikonLd4Tag)", "(UnknownNikonLd4Tag)", N_("Unknown Nikon Lens Data 3 Tag"), IfdId::nikonLd4Id,
SectionId::makerTags, unsignedByte, 1, printValue},
Expand Down Expand Up @@ -3963,4 +3963,16 @@ std::ostream& Nikon3MakerNote::printFocalLd4(std::ostream& os, const Value& valu
return os;
}

std::ostream& Nikon3MakerNote::printFocusDistanceLd4(std::ostream& os, const Value& value, const ExifData*) {
if (value.count() != 1 || value.typeId() != unsignedShort) {
return os << "(" << value << ")";
}
double dist = 0.01 * pow(10.0, (value.toInt64() / 256.0) / 40.0);
std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << dist << " m";
os.copyfmt(oss);
return os;
}

} // namespace Exiv2::Internal
2 changes: 2 additions & 0 deletions src/nikonmn_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class Nikon3MakerNote {
static std::ostream& printLensId4ZMount(std::ostream& os, const Value& value, const ExifData*);
//! Print focus distance
static std::ostream& printFocusDistance(std::ostream& os, const Value& value, const ExifData*);
//! Print focus distance for new LensData as used for e.g. Nikon Z 6/7
static std::ostream& printFocusDistanceLd4(std::ostream& os, const Value& value, const ExifData*);
//! Print lens aperture value
static std::ostream& printAperture(std::ostream& os, const Value& value, const ExifData*);
//! Print lens aperture value for new LensData as used for e.g. Nikon Z 6/7
Expand Down
2 changes: 1 addition & 1 deletion test/data/test_reference_files/CH0_0174.exv.out
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Exif.NikonLd4.LensID Short 1 0 0
Exif.NikonLd4.MaxAperture Short 1 0 F0.5
Exif.NikonLd4.FNumber Short 1 0 F0.5
Exif.NikonLd4.FocalLength2 Short 1 0 0 mm
Exif.NikonLd4.FocusDistance2 Byte 1 0 0.01 m
Exif.NikonLd4.FocusDistance2 Short 1 0 0.01 m
Exif.Nikon3.RawImageCenter Short 2 2274 1515 2274 1515
Exif.Nikon3.RetouchHistory Short 10 0 0 0 0 0 0 0 0 0 0 None
Exif.Nikon3.ShutterCount Long 1 174 174
Expand Down

0 comments on commit 2a02539

Please sign in to comment.