File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -434,16 +434,13 @@ def _populate():
434434 269 # this has been in our tests forever, and works
435435 }
436436
437- LIBTIFF_CORE .remove (320 ) # Array of short, crashes
438- LIBTIFF_CORE .remove (301 ) # Array of short, crashes
439- #LIBTIFF_CORE.remove(532) # Array of long, crashes
440-
441437LIBTIFF_CORE .remove (330 ) # subifd, requires extra support for uint64 payload
442438
443439LIBTIFF_CORE .remove (255 ) # We don't have support for subfiletypes
444440LIBTIFF_CORE .remove (322 ) # We don't have support for tiled images in libtiff
445441LIBTIFF_CORE .remove (323 ) # Tiled images
446442LIBTIFF_CORE .remove (333 ) # Ink Names either
443+ LIBTIFF_CORE .remove (301 ) # Transfer Function. No support as of yet.
447444
448445# Note to advanced users: There may be combinations of these
449446# parameters and values that when added properly, will work and
Original file line number Diff line number Diff line change @@ -194,6 +194,7 @@ def test_additional_metadata(self):
194194 del (core_items [tag ])
195195 except :
196196 pass
197+ del (core_items [320 ]) # colormap is special, tested below
197198
198199 # Type codes:
199200 # 2: "ascii",
@@ -354,6 +355,19 @@ def test_cmyk_save(self):
354355 im2 = Image .open (out )
355356 self .assert_image_equal (im , im2 )
356357
358+ def test_palette_save (self ):
359+ im = hopper ('P' )
360+ out = self .tempfile ('temp.tif' )
361+ TiffImagePlugin .WRITE_LIBTIFF = True
362+ im .save (out )
363+ TiffImagePlugin .WRITE_LIBTIFF = False
364+
365+ reloaded = Image .open (out )
366+ # colormap/palette tag
367+ self .assertTrue (len (reloaded .tag_v2 [320 ]), 768 )
368+ self .assert_image_equal (im , reloaded )
369+
370+
357371 def xtest_bw_compression_w_rgb (self ):
358372 """ This test passes, but when running all tests causes a failure due
359373 to output on stderr from the error thrown by libtiff. We need to
Original file line number Diff line number Diff line change @@ -936,6 +936,26 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
936936 break ;
937937 case TIFFTAG_COLORMAP :
938938 /* 3x uint16 * arrays of r,g,b palette values, len=2^^bpp */
939+ {
940+ int stride = 256 ;
941+ TRACE (("Setting ColorMap\n" ));
942+ if (len != 768 ) {
943+ PyErr_SetString (PyExc_ValueError , "Requiring 768 items for for Colormap" );
944+ return NULL ;
945+ }
946+ arrav = calloc (len , sizeof (uint16 ));
947+ if (arrav ) {
948+ for (i = 0 ;i < len ;i ++ ) {
949+ ((uint16 * )arrav )[i ] = (uint16 )PyInt_AsLong (PyTuple_GetItem (value ,i ));
950+ }
951+ status = ImagingLibTiffSetField (& encoder -> state ,
952+ tag ,
953+ arrav ,
954+ ((uint16 * )arrav ) + stride ,
955+ ((uint16 * )arrav ) + 2 * stride );
956+ free (arrav );
957+ }
958+ }
939959 break ;
940960 case TIFFTAG_SUBIFD :
941961 /* int short length, uint32* data */
You can’t perform that action at this time.
0 commit comments