From 16c95fc295683f1eb24cf327565f71a1ec6b222d Mon Sep 17 00:00:00 2001 From: wiredfool Date: Thu, 21 Nov 2013 20:33:16 -0800 Subject: [PATCH] Flags to force libtiff read/write --- PIL/TiffImagePlugin.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 757cbebcf..63d4212d8 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -54,6 +54,9 @@ import collections import itertools import os +READ_LIBTIFF = False +WRITE_LIBTIFF= False + II = b"II" # little-endian (intel-style) MM = b"MM" # big-endian (motorola-style) @@ -760,11 +763,11 @@ class TiffImageFile(ImageFile.ImageFile): offsets = self.tag[STRIPOFFSETS] h = getscalar(ROWSPERSTRIP, ysize) w = self.size[0] - if self._compression in ["tiff_ccitt", "group3", "group4", - "tiff_jpeg", "tiff_adobe_deflate", - "tiff_thunderscan", "tiff_deflate", - "tiff_sgilog", "tiff_sgilog24", - "tiff_raw_16"]: + if READ_LIBTIFF or self._compression in ["tiff_ccitt", "group3", "group4", + "tiff_jpeg", "tiff_adobe_deflate", + "tiff_thunderscan", "tiff_deflate", + "tiff_sgilog", "tiff_sgilog24", + "tiff_raw_16"]: ## if Image.DEBUG: ## print "Activating g4 compression for whole file" @@ -918,12 +921,12 @@ def _save(im, fp, filename): ifd = ImageFileDirectory(prefix) compression = im.encoderinfo.get('compression',im.info.get('compression','raw')) - libtiff = compression in ["tiff_ccitt", "group3", "group4", - "tiff_jpeg", "tiff_adobe_deflate", - "tiff_thunderscan", "tiff_deflate", - "tiff_sgilog", "tiff_sgilog24", - "tiff_raw_16"] - + libtiff = WRITE_LIBTIFF or compression in ["tiff_ccitt", "group3", "group4", + "tiff_jpeg", "tiff_adobe_deflate", + "tiff_thunderscan", "tiff_deflate", + "tiff_sgilog", "tiff_sgilog24", + "tiff_raw_16"] + # -- multi-page -- skip TIFF header on subsequent pages if not libtiff and fp.tell() == 0: # tiff header (write via IFD to get everything right)