diff --git a/Tests/images/fujifilm.mpo b/Tests/images/fujifilm.mpo new file mode 100644 index 000000000..ff0deb8a6 Binary files /dev/null and b/Tests/images/fujifilm.mpo differ diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 9f79d8cfa..a39c61ef8 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -55,6 +55,16 @@ class TestFileMpo(PillowTestCase): self.assertEqual(info[296], 2) self.assertEqual(info[34665], 188) + def test_parallax(self): + # Nintendo + im = Image.open("Tests/images/sugarshack.mpo") + self.assertEqual(im._getexif()["makernote"]["Parallax"], -44.798187255859375) + + # Fujifilm + im = Image.open("Tests/images/fujifilm.mpo") + im.seek(1) + self.assertEqual(im._getexif()["makernote"][0xb211], -3.125) + def test_mp(self): for test_file in test_files: im = Image.open(test_file) diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index e43bdea6b..5e9b9a9d1 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -38,8 +38,8 @@ import array import struct import io import warnings -from . import Image, ImageFile, TiffImagePlugin -from ._binary import i8, o8, i16be as i16 +from . import Image, ImageFile, TiffImagePlugin, TiffTags +from ._binary import i8, o8, i16be as i16, i32le from .JpegPresets import presets from ._util import isStringType @@ -490,6 +490,75 @@ def _getexif(self): info.load(file) exif[0x8825] = _fixup_dict(info) + if 0x927c in exif and exif[0x927c][:8] == b"FUJIFILM": + # FujiFilm MakerNote + exif_data = exif[0x927c] + ifd_offset = i32le(exif_data[8:12]) + ifd_data = exif_data[ifd_offset:] + + makernote = {} + for i in range(0, struct.unpack(" 4: + offset, = struct.unpack("H", ifd_data[:2])[0] + for i in range(0, x): + tag, typ, count, data = struct.unpack(">HHL4s", + ifd_data[i*12 + 2:(i+1)*12 + 2]) + if tag == 0x1101: + # CameraInfo + offset, = struct.unpack(">L", data) + file.seek(offset) + + makernote['ModelID'] = file.read(4) + + file.read(4) + # Seconds since 2000 + makernote['TimeStamp'] = i32le(file.read(12)) + + file.read(4) + makernote['InternalSerialNumber'] = file.read(4) + + file.read(12) + parallax = file.read(4) + handler = TiffImagePlugin.ImageFileDirectory_v2._load_dispatch[ + TiffTags.FLOAT + ][1] + makernote['Parallax'] =\ + handler(TiffImagePlugin.ImageFileDirectory_v2(), parallax, False) + + file.read(4) + makernote['Category'] = file.read(2) + exif["makernote"] = dict(_fixup_dict(makernote)) + return exif