From aba7a340360f2a9bfc9204513f1924aa441748ad Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 28 Dec 2014 21:47:16 +0100 Subject: [PATCH] Fix setting of TIFF ExtraSamples tag. - force cast ExtraSamples to a list. - fix calls to ImagingLibTiffSetField to include array length. --- PIL/TiffImagePlugin.py | 2 ++ encode.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index b0e7c9639..f9f208af4 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1183,6 +1183,8 @@ def _save(im, fp, filename): atts = {} # bits per sample is a single short in the tiff directory, not a list. atts[BITSPERSAMPLE] = bits[0] + if EXTRASAMPLES in ifd: + atts[EXTRASAMPLES] = list(ifd[EXTRASAMPLES]) # Merge the ones that we have with (optional) more bits from # the original file, e.g x,y resolution so that we can # save(load('')) == original file. diff --git a/encode.c b/encode.c index 6bdb8c71a..0f66e230b 100644 --- a/encode.c +++ b/encode.c @@ -770,7 +770,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) } status = ImagingLibTiffSetField(&encoder->state, (ttag_t) PyInt_AsLong(key), - intav); + len, intav); free(intav); } } else { @@ -782,7 +782,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) } status = ImagingLibTiffSetField(&encoder->state, (ttag_t) PyInt_AsLong(key), - floatav); + len, floatav); free(floatav); } }