Skip to content

Commit 2f83b7e

Browse files
authored
Merge pull request #1692 from Exiv2/hassec_canon_lens_test
New Canon Lens Identification + Automatic Test of all Lenses
2 parents cfeceee + efb0af8 commit 2f83b7e

File tree

12 files changed

+599
-488
lines changed

12 files changed

+599
-488
lines changed

src/canonmn_int.cpp

Lines changed: 329 additions & 456 deletions
Large diffs are not rendered by default.

src/tags_int.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,11 @@ namespace Exiv2 {
25772577

25782578
float fnumber(float apertureValue)
25792579
{
2580-
return std::exp(std::log(2.0F) * apertureValue / 2.F);
2580+
float result = std::exp(std::log(2.0F) * apertureValue / 2.F);
2581+
if (std::abs(result - 3.5) < 0.1) {
2582+
result = 3.5;
2583+
}
2584+
return result;
25812585
}
25822586

25832587
URational exposureTime(float shutterSpeedValue)

test/data/exiv2-test.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ File 6/16: 20030925_201850.jpg
10931093
20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
10941094
20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
10951095
20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
1096-
20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
1096+
20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
10971097
20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
10981098
20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
10991099
20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
@@ -1906,7 +1906,7 @@ File 14/16: 20001004_015404.jpg
19061906
20001004_015404.jpg Exif.CanonCs.AFPoint Short 1 Auto-selected
19071907
20001004_015404.jpg Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
19081908
20001004_015404.jpg Exif.CanonCs.0x0015 Short 1 0
1909-
20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
1909+
20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
19101910
20001004_015404.jpg Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
19111911
20001004_015404.jpg Exif.CanonCs.MaxAperture Short 1 F2.8
19121912
20001004_015404.jpg Exif.CanonCs.MinAperture Short 1 F22
@@ -2734,7 +2734,7 @@ Compare image data and extracted data ------------------------------------
27342734
< 20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
27352735
< 20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
27362736
< 20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
2737-
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
2737+
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
27382738
< 20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
27392739
< 20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
27402740
< 20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
@@ -3546,7 +3546,7 @@ Compare image data and extracted data ------------------------------------
35463546
< 20001004_015404.jpg Exif.CanonCs.AFPoint Short 1 Auto-selected
35473547
< 20001004_015404.jpg Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
35483548
< 20001004_015404.jpg Exif.CanonCs.0x0015 Short 1 0
3549-
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
3549+
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
35503550
< 20001004_015404.jpg Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
35513551
< 20001004_015404.jpg Exif.CanonCs.MaxAperture Short 1 F2.8
35523552
< 20001004_015404.jpg Exif.CanonCs.MinAperture Short 1 F22
@@ -4297,7 +4297,7 @@ Compare image data and extracted data ------------------------------------
42974297
> 20030925_201850.exv Exif.CanonCs.0x0015 Short 1 32767
42984298
> 20030925_201850.exv Exif.CanonCs.LensType Short 1 n/a
42994299
> 20030925_201850.exv Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
4300-
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.6
4300+
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.5
43014301
> 20030925_201850.exv Exif.CanonCs.MinAperture Short 1 F22
43024302
> 20030925_201850.exv Exif.CanonCs.FlashActivity Short 1 Did not fire
43034303
> 20030925_201850.exv Exif.CanonCs.FlashDetails Short 1
@@ -5109,7 +5109,7 @@ Compare image data and extracted data ------------------------------------
51095109
> 20001004_015404.exv Exif.CanonCs.AFPoint Short 1 Auto-selected
51105110
> 20001004_015404.exv Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
51115111
> 20001004_015404.exv Exif.CanonCs.0x0015 Short 1 0
5112-
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
5112+
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
51135113
> 20001004_015404.exv Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
51145114
> 20001004_015404.exv Exif.CanonCs.MaxAperture Short 1 F2.8
51155115
> 20001004_015404.exv Exif.CanonCs.MinAperture Short 1 F22
@@ -6098,7 +6098,7 @@ Compare original and inserted image data ---------------------------------
60986098
< 20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
60996099
< 20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
61006100
< 20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
6101-
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
6101+
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
61026102
< 20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
61036103
< 20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
61046104
< 20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
@@ -6910,7 +6910,7 @@ Compare original and inserted image data ---------------------------------
69106910
< 20001004_015404.jpg Exif.CanonCs.AFPoint Short 1 Auto-selected
69116911
< 20001004_015404.jpg Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
69126912
< 20001004_015404.jpg Exif.CanonCs.0x0015 Short 1 0
6913-
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
6913+
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
69146914
< 20001004_015404.jpg Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
69156915
< 20001004_015404.jpg Exif.CanonCs.MaxAperture Short 1 F2.8
69166916
< 20001004_015404.jpg Exif.CanonCs.MinAperture Short 1 F22
@@ -7661,7 +7661,7 @@ Compare original and inserted image data ---------------------------------
76617661
> 20030925_201850.exv Exif.CanonCs.0x0015 Short 1 32767
76627662
> 20030925_201850.exv Exif.CanonCs.LensType Short 1 n/a
76637663
> 20030925_201850.exv Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
7664-
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.6
7664+
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.5
76657665
> 20030925_201850.exv Exif.CanonCs.MinAperture Short 1 F22
76667666
> 20030925_201850.exv Exif.CanonCs.FlashActivity Short 1 Did not fire
76677667
> 20030925_201850.exv Exif.CanonCs.FlashDetails Short 1
@@ -8473,7 +8473,7 @@ Compare original and inserted image data ---------------------------------
84738473
> 20001004_015404.exv Exif.CanonCs.AFPoint Short 1 Auto-selected
84748474
> 20001004_015404.exv Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
84758475
> 20001004_015404.exv Exif.CanonCs.0x0015 Short 1 0
8476-
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
8476+
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
84778477
> 20001004_015404.exv Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
84788478
> 20001004_015404.exv Exif.CanonCs.MaxAperture Short 1 F2.8
84798479
> 20001004_015404.exv Exif.CanonCs.MinAperture Short 1 F22

test/data/template.exv

11.7 KB
Binary file not shown.

tests/bugfixes/github/test_issue_45.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Sigma24_105mmRecognization(metaclass=system_tests.CaseMeta):
99

1010
filename = "$data_path/exiv2-g45.exv"
1111
commands = ["$exiv2 -pa --grep lens/i " + filename]
12-
stdout = ["""Exif.CanonCs.LensType Short 1 Sigma 24-105mm F4 DG OS HSM | A
12+
stdout = ["""Exif.CanonCs.LensType Short 1 Sigma 24-105mm f/4 DG OS HSM | A
1313
Exif.CanonCs.Lens Short 3 24.0 - 105.0 mm
1414
Exif.CanonCf.LensAFStopButton Short 1 0
1515
Exif.Canon.LensModel Ascii 74 24-105mm F4 DG OS HSM | Art 013

tests/bugfixes/redmine/test_issue_1166.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CheckTokina11_20mm(metaclass=system_tests.CaseMeta):
1010

1111
commands = [ "$exiv2 -pa --grep lens/i $filename" ]
1212

13-
stdout = [ """Exif.CanonCs.LensType Short 1 Tokina AT-X 11-20 F2.8 PRO DX Aspherical 11-20mm f/2.8
13+
stdout = [ """Exif.CanonCs.LensType Short 1 Tokina AT-X 11-20 f/2.8 PRO DX Aspherical 11-20mm f/2.8
1414
Exif.CanonCs.Lens Short 3 11.0 - 20.0 mm
1515
Exif.Canon.LensModel Ascii 74 11-20mm
1616
Exif.Photo.LensSpecification Rational 4 11/1 20/1 0/1 0/1

tests/bugfixes/redmine/test_issue_1170.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CheckSigma35mm(metaclass=system_tests.CaseMeta):
1010

1111
commands = [ "$exiv2 -pa --grep lens/i $filename" ]
1212

13-
stdout = [ """Exif.CanonCs.LensType Short 1 Sigma 35mm f/1.4 DG HSM
13+
stdout = [ """Exif.CanonCs.LensType Short 1 Sigma 35mm f/1.4 DG HSM *OR* Sigma 35mm f/1.5 FF High-Speed Prime | 017
1414
Exif.CanonCs.Lens Short 3 35.0 mm
1515
Exif.Canon.LensModel Ascii 74 35mm
1616
Exif.Photo.LensSpecification Rational 4 35/1 35/1 0/1 0/1

tests/bugfixes/redmine/test_issue_1252.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CanonLenses(metaclass=system_tests.CaseMeta):
1616
"$exiv2 -pa --grep lens/i " + filenames[1],
1717
]
1818

19-
stdout = ["""Exif.CanonCs.LensType Short 1 Sigma APO 120-300mm f/2.8 EX DG OS HSM
19+
stdout = ["""Exif.CanonCs.LensType Short 1 Sigma APO 120-300mm f/2.8 EX DG OS HSM *OR* Sigma 120-300mm f/2.8 DG OS HSM S013
2020
Exif.CanonCs.Lens Short 3 120.0 - 300.0 mm
2121
Exif.Canon.LensModel Ascii 74 120-300mm
2222
Exif.Photo.LensSpecification Rational 4 120/1 300/1 0/1 0/1

tests/lens_tests/__init__.py

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
import re
3+
import os
4+
import system_tests
5+
from lens_tests.utils import extract_lenses_from_cpp, make_test_cases, aperture_to_raw_exif
6+
7+
# NOTE
8+
# Normally the canon maker note holds the max aperture of the lens at the focal length
9+
# the picture was taken at. Thus for a f/4-6.3 lens, this value could be anywhere in that range.
10+
# For the below tests we only test the scenario where the lens was used at it's shortest focal length.
11+
# Thus we always pick the 'aperture_max_short' of a lens as the value to write into the
12+
# Exif.CanonCs.MaxAperture field.
13+
14+
# get directory of the current file
15+
file_dir = os.path.dirname(os.path.realpath(__file__))
16+
# to get the canon maker note cpp file that contains list of all supported lenses
17+
canon_lens_file = os.path.abspath(os.path.join(file_dir, "./../../src/canonmn_int.cpp"))
18+
# tell the below function what the start of the lens array looks like
19+
startpattern = "constexpr TagDetails canonCsLensType[] = {"
20+
# use utils function to extract all lenses
21+
lenses = extract_lenses_from_cpp(canon_lens_file, startpattern)
22+
# use utils function to define test case data
23+
test_cases = make_test_cases(lenses)
24+
25+
for lens_tc in test_cases:
26+
27+
testname = lens_tc["id"] + "_" + lens_tc["desc"]
28+
29+
globals()[testname] = system_tests.CaseMeta(
30+
"canon_lenses." + testname,
31+
tuple(),
32+
{
33+
"filename": "$data_path/template.exv",
34+
"commands": [
35+
'$exiv2 -M"set Exif.CanonCs.LensType $lens_id" -M"set Exif.CanonCs.Lens $focal_length_max $focal_length_min 1" -M"set Exif.CanonCs.MaxAperture $aperture_max" $filename && $exiv2 -pa -K Exif.CanonCs.LensType $filename'
36+
],
37+
"stderr": [""],
38+
"stdout": ["Exif.CanonCs.LensType Short 1 $lens_description\n"],
39+
"retval": [0],
40+
"lens_id": lens_tc["id"],
41+
"lens_description": lens_tc["target"],
42+
"aperture_max": aperture_to_raw_exif(lens_tc["aperture_max_short"] * lens_tc["tc"]),
43+
"focal_length_min": int(lens_tc["focal_length_min"] * lens_tc["tc"]),
44+
"focal_length_max": int(lens_tc["focal_length_max"] * lens_tc["tc"]),
45+
},
46+
)

0 commit comments

Comments
 (0)