diff --git a/PIL/TiffTags.py b/PIL/TiffTags.py index 76f00d6dd..3bcf9b383 100644 --- a/PIL/TiffTags.py +++ b/PIL/TiffTags.py @@ -434,16 +434,13 @@ LIBTIFF_CORE = {255, 256, 257, 258, 259, 262, 263, 266, 274, 277, 269 # this has been in our tests forever, and works } -LIBTIFF_CORE.remove(320) # Array of short, crashes -LIBTIFF_CORE.remove(301) # Array of short, crashes -#LIBTIFF_CORE.remove(532) # Array of long, crashes - LIBTIFF_CORE.remove(330) # subifd, requires extra support for uint64 payload LIBTIFF_CORE.remove(255) # We don't have support for subfiletypes LIBTIFF_CORE.remove(322) # We don't have support for tiled images in libtiff LIBTIFF_CORE.remove(323) # Tiled images LIBTIFF_CORE.remove(333) # Ink Names either +LIBTIFF_CORE.remove(301) # Transfer Function. No support as of yet. # Note to advanced users: There may be combinations of these # parameters and values that when added properly, will work and diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index a0b43f8eb..4d58a1d3f 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -194,6 +194,7 @@ class TestFileLibTiff(LibTiffTestCase): del(core_items[tag]) except: pass + del(core_items[320]) # colormap is special, tested below # Type codes: # 2: "ascii", @@ -354,6 +355,19 @@ class TestFileLibTiff(LibTiffTestCase): im2 = Image.open(out) self.assert_image_equal(im, im2) + def test_palette_save(self): + im = hopper('P') + out = self.tempfile('temp.tif') + TiffImagePlugin.WRITE_LIBTIFF = True + im.save(out) + TiffImagePlugin.WRITE_LIBTIFF = False + + reloaded = Image.open(out) + # colormap/palette tag + self.assertTrue(len(reloaded.tag_v2[320]), 768) + self.assert_image_equal(im, reloaded) + + def xtest_bw_compression_w_rgb(self): """ This test passes, but when running all tests causes a failure due to output on stderr from the error thrown by libtiff. We need to diff --git a/encode.c b/encode.c index 370f94a0c..8baa002bf 100644 --- a/encode.c +++ b/encode.c @@ -936,6 +936,26 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) break; case TIFFTAG_COLORMAP: /* 3x uint16 * arrays of r,g,b palette values, len=2^^bpp */ + { + int stride = 256; + TRACE(("Setting ColorMap\n")); + if (len != 768) { + PyErr_SetString(PyExc_ValueError, "Requiring 768 items for for Colormap"); + return NULL; + } + arrav = calloc(len, sizeof(uint16)); + if (arrav) { + for (i=0;istate, + tag, + arrav, + ((uint16 *)arrav) + stride, + ((uint16 *)arrav) + 2 * stride); + free(arrav); + } + } break; case TIFFTAG_SUBIFD: /* int short length, uint32* data */