Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Canon Lens Identification + Automatic Test of all Lenses #1692

Merged
merged 17 commits into from Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
785 changes: 329 additions & 456 deletions src/canonmn_int.cpp

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/tags_int.cpp
Expand Up @@ -2577,7 +2577,11 @@ namespace Exiv2 {

float fnumber(float apertureValue)
{
return std::exp(std::log(2.0F) * apertureValue / 2.F);
float result = std::exp(std::log(2.0F) * apertureValue / 2.F);
if (std::abs(result - 3.5) < 0.1) {
result = 3.5;
}
return result;
}

URational exposureTime(float shutterSpeedValue)
Expand Down
20 changes: 10 additions & 10 deletions test/data/exiv2-test.out
Expand Up @@ -1093,7 +1093,7 @@ File 6/16: 20030925_201850.jpg
20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
Expand Down Expand Up @@ -1906,7 +1906,7 @@ File 14/16: 20001004_015404.jpg
20001004_015404.jpg Exif.CanonCs.AFPoint Short 1 Auto-selected
20001004_015404.jpg Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
20001004_015404.jpg Exif.CanonCs.0x0015 Short 1 0
20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
20001004_015404.jpg Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
20001004_015404.jpg Exif.CanonCs.MaxAperture Short 1 F2.8
20001004_015404.jpg Exif.CanonCs.MinAperture Short 1 F22
Expand Down Expand Up @@ -2734,7 +2734,7 @@ Compare image data and extracted data ------------------------------------
< 20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
< 20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
< 20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
< 20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
< 20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
< 20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
Expand Down Expand Up @@ -3546,7 +3546,7 @@ Compare image data and extracted data ------------------------------------
< 20001004_015404.jpg Exif.CanonCs.AFPoint Short 1 Auto-selected
< 20001004_015404.jpg Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
< 20001004_015404.jpg Exif.CanonCs.0x0015 Short 1 0
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
< 20001004_015404.jpg Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
< 20001004_015404.jpg Exif.CanonCs.MaxAperture Short 1 F2.8
< 20001004_015404.jpg Exif.CanonCs.MinAperture Short 1 F22
Expand Down Expand Up @@ -4297,7 +4297,7 @@ Compare image data and extracted data ------------------------------------
> 20030925_201850.exv Exif.CanonCs.0x0015 Short 1 32767
> 20030925_201850.exv Exif.CanonCs.LensType Short 1 n/a
> 20030925_201850.exv Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.6
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.5
> 20030925_201850.exv Exif.CanonCs.MinAperture Short 1 F22
> 20030925_201850.exv Exif.CanonCs.FlashActivity Short 1 Did not fire
> 20030925_201850.exv Exif.CanonCs.FlashDetails Short 1
Expand Down Expand Up @@ -5109,7 +5109,7 @@ Compare image data and extracted data ------------------------------------
> 20001004_015404.exv Exif.CanonCs.AFPoint Short 1 Auto-selected
> 20001004_015404.exv Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
> 20001004_015404.exv Exif.CanonCs.0x0015 Short 1 0
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
> 20001004_015404.exv Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
> 20001004_015404.exv Exif.CanonCs.MaxAperture Short 1 F2.8
> 20001004_015404.exv Exif.CanonCs.MinAperture Short 1 F22
Expand Down Expand Up @@ -6098,7 +6098,7 @@ Compare original and inserted image data ---------------------------------
< 20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
< 20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
< 20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
< 20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
< 20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
< 20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
Expand Down Expand Up @@ -6910,7 +6910,7 @@ Compare original and inserted image data ---------------------------------
< 20001004_015404.jpg Exif.CanonCs.AFPoint Short 1 Auto-selected
< 20001004_015404.jpg Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
< 20001004_015404.jpg Exif.CanonCs.0x0015 Short 1 0
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
< 20001004_015404.jpg Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
< 20001004_015404.jpg Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
< 20001004_015404.jpg Exif.CanonCs.MaxAperture Short 1 F2.8
< 20001004_015404.jpg Exif.CanonCs.MinAperture Short 1 F22
Expand Down Expand Up @@ -7661,7 +7661,7 @@ Compare original and inserted image data ---------------------------------
> 20030925_201850.exv Exif.CanonCs.0x0015 Short 1 32767
> 20030925_201850.exv Exif.CanonCs.LensType Short 1 n/a
> 20030925_201850.exv Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.6
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.5
> 20030925_201850.exv Exif.CanonCs.MinAperture Short 1 F22
> 20030925_201850.exv Exif.CanonCs.FlashActivity Short 1 Did not fire
> 20030925_201850.exv Exif.CanonCs.FlashDetails Short 1
Expand Down Expand Up @@ -8473,7 +8473,7 @@ Compare original and inserted image data ---------------------------------
> 20001004_015404.exv Exif.CanonCs.AFPoint Short 1 Auto-selected
> 20001004_015404.exv Exif.CanonCs.ExposureProgram Short 1 Aperture priority (Av)
> 20001004_015404.exv Exif.CanonCs.0x0015 Short 1 0
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM
> 20001004_015404.exv Exif.CanonCs.LensType Short 1 Canon EF 28-70mm f/2.8L USM *OR* Sigma 28-70mm f/2.8 EX
> 20001004_015404.exv Exif.CanonCs.Lens Short 3 28.0 - 70.0 mm
> 20001004_015404.exv Exif.CanonCs.MaxAperture Short 1 F2.8
> 20001004_015404.exv Exif.CanonCs.MinAperture Short 1 F22
Expand Down
Binary file added test/data/template.exv
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/bugfixes/github/test_issue_45.py
Expand Up @@ -9,7 +9,7 @@ class Sigma24_105mmRecognization(metaclass=system_tests.CaseMeta):

filename = "$data_path/exiv2-g45.exv"
commands = ["$exiv2 -pa --grep lens/i " + filename]
stdout = ["""Exif.CanonCs.LensType Short 1 Sigma 24-105mm F4 DG OS HSM | A
stdout = ["""Exif.CanonCs.LensType Short 1 Sigma 24-105mm f/4 DG OS HSM | A
Exif.CanonCs.Lens Short 3 24.0 - 105.0 mm
Exif.CanonCf.LensAFStopButton Short 1 0
Exif.Canon.LensModel Ascii 74 24-105mm F4 DG OS HSM | Art 013
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/redmine/test_issue_1166.py
Expand Up @@ -10,7 +10,7 @@ class CheckTokina11_20mm(metaclass=system_tests.CaseMeta):

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

stdout = [ """Exif.CanonCs.LensType Short 1 Tokina AT-X 11-20 F2.8 PRO DX Aspherical 11-20mm f/2.8
stdout = [ """Exif.CanonCs.LensType Short 1 Tokina AT-X 11-20 f/2.8 PRO DX Aspherical 11-20mm f/2.8
Exif.CanonCs.Lens Short 3 11.0 - 20.0 mm
Exif.Canon.LensModel Ascii 74 11-20mm
Exif.Photo.LensSpecification Rational 4 11/1 20/1 0/1 0/1
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/redmine/test_issue_1170.py
Expand Up @@ -10,7 +10,7 @@ class CheckSigma35mm(metaclass=system_tests.CaseMeta):

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

stdout = [ """Exif.CanonCs.LensType Short 1 Sigma 35mm f/1.4 DG HSM
stdout = [ """Exif.CanonCs.LensType Short 1 Sigma 35mm f/1.4 DG HSM *OR* Sigma 35mm f/1.5 FF High-Speed Prime | 017
Exif.CanonCs.Lens Short 3 35.0 mm
Exif.Canon.LensModel Ascii 74 35mm
Exif.Photo.LensSpecification Rational 4 35/1 35/1 0/1 0/1
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes/redmine/test_issue_1252.py
Expand Up @@ -16,7 +16,7 @@ class CanonLenses(metaclass=system_tests.CaseMeta):
"$exiv2 -pa --grep lens/i " + filenames[1],
]

stdout = ["""Exif.CanonCs.LensType Short 1 Sigma APO 120-300mm f/2.8 EX DG OS HSM
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
Exif.CanonCs.Lens Short 3 120.0 - 300.0 mm
Exif.Canon.LensModel Ascii 74 120-300mm
Exif.Photo.LensSpecification Rational 4 120/1 300/1 0/1 0/1
Expand Down
Empty file added tests/lens_tests/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions tests/lens_tests/test_canon_lenses.py
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
import re
import os
import system_tests
from lens_tests.utils import extract_lenses_from_cpp, make_test_cases, aperture_to_raw_exif

# NOTE
# Normally the canon maker note holds the max aperture of the lens at the focal length
# the picture was taken at. Thus for a f/4-6.3 lens, this value could be anywhere in that range.
# For the below tests we only test the scenario where the lens was used at it's shortest focal length.
# Thus we always pick the 'aperture_max_short' of a lens as the value to write into the
# Exif.CanonCs.MaxAperture field.

# get directory of the current file
file_dir = os.path.dirname(os.path.realpath(__file__))
# to get the canon maker note cpp file that contains list of all supported lenses
canon_lens_file = os.path.abspath(os.path.join(file_dir, "./../../src/canonmn_int.cpp"))
# tell the below function what the start of the lens array looks like
startpattern = "constexpr TagDetails canonCsLensType[] = {"
# use utils function to extract all lenses
lenses = extract_lenses_from_cpp(canon_lens_file, startpattern)
# use utils function to define test case data
test_cases = make_test_cases(lenses)

for lens_tc in test_cases:

testname = lens_tc["id"] + "_" + lens_tc["desc"]

globals()[testname] = system_tests.CaseMeta(
"canon_lenses." + testname,
tuple(),
{
"filename": "$data_path/template.exv",
"commands": [
'$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'
],
"stderr": [""],
"stdout": ["Exif.CanonCs.LensType Short 1 $lens_description\n"],
"retval": [0],
"lens_id": lens_tc["id"],
"lens_description": lens_tc["target"],
"aperture_max": aperture_to_raw_exif(lens_tc["aperture_max_short"] * lens_tc["tc"]),
"focal_length_min": int(lens_tc["focal_length_min"] * lens_tc["tc"]),
"focal_length_max": int(lens_tc["focal_length_max"] * lens_tc["tc"]),
},
)