Skip to content

Commit

Permalink
Canon MakerNote: Allow callable to process tag value
Browse files Browse the repository at this point in the history
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 <djvg@djvg.net>
  • Loading branch information
TheDJVG committed Oct 22, 2023
1 parent d60f18d commit 6434332
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 4 additions & 1 deletion exifread/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 12 additions & 11 deletions exifread/tags/makernote/canon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ),
Expand Down Expand Up @@ -538,6 +549,7 @@
3: 'None'
}),
9: ('SequenceNumber', ),
12: ('CameraTemperature', convert_temp),
14: ('AFPointUsed', ),
15: ('FlashBias', {
0xFFC0: '-2 EV',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6434332

Please sign in to comment.