From 6434332c4d26ccb3a62b4b51dd2f4051f497411f Mon Sep 17 00:00:00 2001 From: Daan van Gorkum Date: Sun, 22 Oct 2023 12:36:36 +0800 Subject: [PATCH] Canon MakerNote: Allow callable to process tag value While working on some images I found that the library did not expose the 'CameraTemperature' tag from the ShotInfo MakerNote. To support this I added a callable and allow that callable to be called with the tag value. I might be useful for other tags too. Example output from a JPEG image taken on a Canon EOS 2000D: ``` >>> exif = exifread.process_file(fd, details=True) >>> exif["MakerNote CameraTemperature"] (0x0000) Proprietary=55 C @ 0 ``` Signed-off-by: Daan van Gorkum --- exifread/classes.py | 5 ++++- exifread/tags/makernote/canon.py | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/exifread/classes.py b/exifread/classes.py index 7b0eb97a..a5818cd9 100644 --- a/exifread/classes.py +++ b/exifread/classes.py @@ -542,7 +542,10 @@ def _canon_decode_tag(self, value, mn_tags): tag = mn_tags.get(i, ('Unknown', )) name = tag[0] if len(tag) > 1: - val = tag[1].get(value[i], 'Unknown') + if callable(tag[1]): + val = tag[1](value[i]) + else: + val = tag[1].get(value[i], 'Unknown') else: val = value[i] try: diff --git a/exifread/tags/makernote/canon.py b/exifread/tags/makernote/canon.py index f41c84c7..a84d1683 100644 --- a/exifread/tags/makernote/canon.py +++ b/exifread/tags/makernote/canon.py @@ -4,6 +4,17 @@ http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html """ +def add_one(value): + return value + 1 + + +def subtract_one(value): + return value - 1 + + +def convert_temp(value): + return '%d C' % (value - 128) + TAGS = { 0x0003: ('FlashInfo',), 0x0006: ('ImageType', ), @@ -538,6 +549,7 @@ 3: 'None' }), 9: ('SequenceNumber', ), + 12: ('CameraTemperature', convert_temp), 14: ('AFPointUsed', ), 15: ('FlashBias', { 0xFFC0: '-2 EV', @@ -659,17 +671,6 @@ } -def add_one(value): - return value + 1 - - -def subtract_one(value): - return value - 1 - - -def convert_temp(value): - return '%d C' % (value - 128) - # CameraInfo data structures have variable sized members. Each entry here is: # byte offset: (item name, data item type, decoding map). # Note that the data item type is fed directly to struct.unpack at the