From 05348d4f8fd75b2e6727a39afdd2da729482875e Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 14 Sep 2015 03:03:24 -0700 Subject: [PATCH] Reenabling failing/crashing tests, with fixes --- PIL/TiffImagePlugin.py | 6 +++++- Tests/test_file_libtiff.py | 2 +- Tests/test_file_tiff.py | 5 +---- encode.c | 6 +++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index e3ea03ab6..fcc84607c 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1230,8 +1230,12 @@ def _save(im, fp, filename): # 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. + legacy_ifd = {} + if hasattr(im, 'tag'): + legacy_ifd = im.tag.to_v2() for k, v in itertools.chain(ifd.items(), - getattr(im, 'ifd', {}).items()): + getattr(im, 'tag_v2', {}).items(), + legacy_ifd.items()): if k not in atts and k not in blocklist: if isinstance(v, unicode if bytes is str else str): atts[k] = v.encode('ascii', 'replace') + b"\0" diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 57eeec43d..f900b97cf 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -198,7 +198,7 @@ class TestFileLibTiff(LibTiffTestCase): # UNDONE - libtiff defaults to writing in native endian, so # on big endian, we'll get back mode = 'I;16B' here. - def xtest_big_endian(self): + def test_big_endian(self): im = Image.open('Tests/images/16bit.MM.deflate.tif') self.assertEqual(im.getpixel((0, 0)), 480) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 2d787e66d..c21eba6f4 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -308,10 +308,7 @@ class TestFileTiff(PillowTestCase): self.assertEqual(im.mode, "L") self.assert_image_similar(im, original, 7.3) -### -# UNDONE -### Segfaulting - def xtest_page_number_x_0(self): + def test_page_number_x_0(self): # Issue 973 # Test TIFF with tag 297 (Page Number) having value of 0 0. # The first number is the current page number. diff --git a/encode.c b/encode.c index 244f5ca0d..c46d78426 100644 --- a/encode.c +++ b/encode.c @@ -775,7 +775,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) len, intav); free(intav); } - } else { + } else if (PyFloat_Check(PyTuple_GetItem(value,0))) { TRACE((" %d elements, setting as floats \n", len)); floatav = malloc(sizeof(float)*len); if (floatav) { @@ -787,6 +787,10 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) len, floatav); free(floatav); } + } else { + TRACE(("Unhandled type in tuple for key %d : %s \n", + (int)PyInt_AsLong(key), + PyBytes_AsString(PyObject_Str(value)))); } } } else {