Skip to content

Commit

Permalink
Update Canon decoder for lens detection (Exiv2#2057)
Browse files Browse the repository at this point in the history
The `Canon RF 24-105 F4-7.1 IS STM` lens is reported as using an
`Exif.CanonCs.MaxAperture` of `F7.3` instead of `F7.1`. As a result,
the translation of `Exif.CanonCs.LensType` is missing.

Fix updates the `CanonEV()` decode function to provide the correct
value.
  • Loading branch information
postscript-dev committed May 27, 2022
1 parent 315ae6d commit 8d36bcc
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,13 @@ std::ostream& printCsLensTypeByMetadata(std::ostream& os, const Value& value, co
return printCsLensFFFF(os, value, metadata);
}

// TODO: The lens identification could be improved further:
// 1. RF lenses also set Exif.CanonFi.RFLensType. If a lens cannot be found here then
// the RF mechanism could be used instead.
// 2. Exif.Photo.LensModel and Exif.Canon.LensModel provide a text description of the lens
// (e.g., "RF24-105mm F4-7.1 IS STM" - Note: no manufacturer or space after "RF").
// After parsing, the values could be used to search in the lens array.

// get the values we need from the metadata container
ExifKey lensKey("Exif.CanonCs.Lens");
auto pos = metadata->findKey(lensKey);
Expand Down Expand Up @@ -2829,6 +2836,8 @@ float canonEv(int64_t val) {
frac = 64.0F / 3;
} else if ((val == 160) && (frac == 0x08)) { // for Sigma f/6.3 lenses that report f/6.2 to camera
frac = 30.0F / 3;
} else if ((val == 160) && (frac == 0x18)) { // for Canon F4-7.1 lens that reports max aperture as f/7.3
frac = 21.0F;
}
return sign * (val + frac) / 32.0F;
}
Expand Down
Binary file added test/data/issue_2057_poc1.exv
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Exif.CanonSi.AEBBracketValue Short 1 0 0
Exif.CanonSi.ControlMode Short 1 1 1
Exif.CanonSi.SubjectDistance Short 1 0 0 m
Exif.CanonSi.ApertureValue Short 1 148 F5
Exif.CanonSi.ShutterSpeedValue Short 1 184 1/54 s
Exif.CanonSi.ShutterSpeedValue Short 1 184 1/50 s
Exif.CanonSi.MeasuredEV2 Short 1 123 9.38
Exif.CanonSi.BulbDuration Short 1 0 0
Exif.CanonSi.CameraType Short 1 248 EOS High-end
Expand Down
490 changes: 490 additions & 0 deletions test/data/test_reference_files/issue_2057_poc1.exv.out

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tests/bugfixes/github/test_issue_2057.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path

class AddLens_Canon_RF_24_105mm_F4_7_1_IS_STM(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/issues/2057
"""
url = "https://github.com/Exiv2/exiv2/issues/2057"

filename = path("$data_path/issue_2057_poc1.exv")
commands = ["$exiv2 --Print kyyvt --key Exif.CanonCs.LensType $filename"]
stderr = [""]
stdout = ["""Exif.CanonCs.LensType Short 61182 Canon RF 24-105mm F4-7.1 IS STM
"""]
retval = [0]

0 comments on commit 8d36bcc

Please sign in to comment.