You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
exiv2/tests/lens_tests/test_canon_lenses.py

68 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
import re
import os
import system_tests
import math
from lens_tests.utils import extract_lenses_from_cpp
# 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)
def aperture_to_raw_exif(aperture):
#see https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/Canon.pm#L9678
aperture = float(aperture)
# for apertures < 1 the below is negative
num = math.log(aperture)*2/math.log(2)
# temporarily make the number positive
if (num < 0):
num = -num
sign = -1
else:
sign = 1;
val = int(num)
frac = num - val
if (abs(frac - 0.33) < 0.05):
frac = 0x0c
elif (abs(frac - 0.67) < 0.05):
frac = 0x14;
else:
frac = int(frac * 0x20 + 0.5)
return sign * (val * 0x20 + frac);
for (lens_id, lens_desc, meta) in lenses:
tc = float(meta["tc"] or 1)
testname = lens_id + "_" + lens_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_id,
"lens_description": lens_desc,
"aperture_max": aperture_to_raw_exif(meta["aperture_max_short"]),
"focal_length_min": int(int(meta["focal_length_min"]) * tc),
"focal_length_max": int(int(meta["focal_length_max"]) * tc),
},
)