From c46b3fe25663cadbb00c6328584a526dda560a2f Mon Sep 17 00:00:00 2001 From: Christoph Gohlke Date: Sun, 29 Sep 2013 09:17:37 -0700 Subject: [PATCH 1/3] Make _getexif a function --- PIL/JpegImagePlugin.py | 86 ++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index a8eb1b805..90d3b5194 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -359,51 +359,55 @@ class JpegImageFile(ImageFile.ImageFile): self.tile = [] def _getexif(self): - # Extract EXIF information. This method is highly experimental, - # and is likely to be replaced with something better in a future - # version. - from PIL import TiffImagePlugin - import io - def fixup(value): - if len(value) == 1: - return value[0] - return value - # The EXIF record consists of a TIFF file embedded in a JPEG - # application marker (!). - try: - data = self.info["exif"] - except KeyError: - return None - file = io.BytesIO(data[6:]) - head = file.read(8) - exif = {} - # process dictionary + return _getexif(self) + + +def _getexif(self): + # Extract EXIF information. This method is highly experimental, + # and is likely to be replaced with something better in a future + # version. + from PIL import TiffImagePlugin + import io + def fixup(value): + if len(value) == 1: + return value[0] + return value + # The EXIF record consists of a TIFF file embedded in a JPEG + # application marker (!). + try: + data = self.info["exif"] + except KeyError: + return None + file = io.BytesIO(data[6:]) + head = file.read(8) + exif = {} + # process dictionary + info = TiffImagePlugin.ImageFileDirectory(head) + info.load(file) + for key, value in info.items(): + exif[key] = fixup(value) + # get exif extension + try: + file.seek(exif[0x8769]) + except KeyError: + pass + else: info = TiffImagePlugin.ImageFileDirectory(head) info.load(file) for key, value in info.items(): exif[key] = fixup(value) - # get exif extension - try: - file.seek(exif[0x8769]) - except KeyError: - pass - else: - info = TiffImagePlugin.ImageFileDirectory(head) - info.load(file) - for key, value in info.items(): - exif[key] = fixup(value) - # get gpsinfo extension - try: - file.seek(exif[0x8825]) - except KeyError: - pass - else: - info = TiffImagePlugin.ImageFileDirectory(head) - info.load(file) - exif[0x8825] = gps = {} - for key, value in info.items(): - gps[key] = fixup(value) - return exif + # get gpsinfo extension + try: + file.seek(exif[0x8825]) + except KeyError: + pass + else: + info = TiffImagePlugin.ImageFileDirectory(head) + info.load(file) + exif[0x8825] = gps = {} + for key, value in info.items(): + gps[key] = fixup(value) + return exif # -------------------------------------------------------------------- # stuff to save JPEG files From 2fc724d34657899803f16de0771fe3fe14e05aa8 Mon Sep 17 00:00:00 2001 From: Christoph Gohlke Date: Sun, 29 Sep 2013 09:20:00 -0700 Subject: [PATCH 2/3] Call _getexif function instead of class method --- PIL/WebPImagePlugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PIL/WebPImagePlugin.py b/PIL/WebPImagePlugin.py index d5d75391c..ef37e301c 100644 --- a/PIL/WebPImagePlugin.py +++ b/PIL/WebPImagePlugin.py @@ -39,8 +39,8 @@ class WebPImageFile(ImageFile.ImageFile): self.tile = [("raw", (0, 0) + self.size, 0, self.mode)] def _getexif(self): - from PIL.JpegImagePlugin import JpegImageFile - return JpegImageFile._getexif.im_func(self) + from PIL.JpegImagePlugin import _getexif + return _getexif(self) def _save(im, fp, filename): From 9bff0b14e0b4e3b6f53d2251c186f208125bd7d9 Mon Sep 17 00:00:00 2001 From: Christoph Gohlke Date: Sun, 29 Sep 2013 19:30:43 -0700 Subject: [PATCH 3/3] Add numpy array interface support for 16 and 32 bit integer modes --- PIL/Image.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index 2e120e500..56a4b7093 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -224,6 +224,18 @@ _MODE_CONV = { "RGBA": ('|u1', 4), "CMYK": ('|u1', 4), "YCbCr": ('|u1', 3), + "I;16": ('=u2', None), + "I;16B": ('>u2', None), + "I;16L": ('i2', None), + "I;16LS": ('u4', None), + "I;32L": ('i4', None), + "I;32LS": ('