From 49191c78fb344f4ff627c9ca35a047eec0f75c9d Mon Sep 17 00:00:00 2001 From: wiredfool Date: Thu, 7 Nov 2013 16:23:20 -0800 Subject: [PATCH] CHECK: support for int arrays as ifd entries --- PIL/TiffImagePlugin.py | 4 ++-- encode.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index fcbcf42ff..f1976c182 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1036,8 +1036,8 @@ def _save(im, fp, filename): continue if type(v) == tuple and len(v) > 2: # List of ints? - # BitsPerSample is one example, I get (8,8,8) - # UNDONE + if type(v[0]) in (int, float): + atts[k] = list(v) continue if type(v) == tuple and len(v) == 2: # one rational tuple diff --git a/encode.c b/encode.c index 10ed90d12..2c9145c71 100644 --- a/encode.c +++ b/encode.c @@ -780,18 +780,35 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) } else if(PyList_Check(value)) { int len,i; float *floatav; + int *intav; TRACE(("Setting from List: %d \n", (int)PyInt_AsLong(key))); len = (int)PyList_Size(value); - TRACE((" %d elements, setting as floats \n", len)); - floatav = malloc(sizeof(float)*len); - if (floatav) { - for (i=0;istate, + (ttag_t) PyInt_AsLong(key), + intav); + free(intav); + } + } else { + TRACE((" %d elements, setting as floats \n", len)); + floatav = malloc(sizeof(float)*len); + if (floatav) { + for (i=0;istate, + (ttag_t) PyInt_AsLong(key), + floatav); + free(floatav); + } } - status = ImagingLibTiffSetField(&encoder->state, - (ttag_t) PyInt_AsLong(key), - floatav); - free(floatav); } } else if (PyFloat_Check(value)) { TRACE(("Setting from Float: %d, %f \n", (int)PyInt_AsLong(key),PyFloat_AsDouble(value)));