mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-17 18:54:46 +03:00
Added support for saving colormaps
This commit is contained in:
parent
1ad3dd7212
commit
8a772759b1
|
@ -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
|
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(330) # subifd, requires extra support for uint64 payload
|
||||||
|
|
||||||
LIBTIFF_CORE.remove(255) # We don't have support for subfiletypes
|
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(322) # We don't have support for tiled images in libtiff
|
||||||
LIBTIFF_CORE.remove(323) # Tiled images
|
LIBTIFF_CORE.remove(323) # Tiled images
|
||||||
LIBTIFF_CORE.remove(333) # Ink Names either
|
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
|
# Note to advanced users: There may be combinations of these
|
||||||
# parameters and values that when added properly, will work and
|
# parameters and values that when added properly, will work and
|
||||||
|
|
|
@ -194,6 +194,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
del(core_items[tag])
|
del(core_items[tag])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
del(core_items[320]) # colormap is special, tested below
|
||||||
|
|
||||||
# Type codes:
|
# Type codes:
|
||||||
# 2: "ascii",
|
# 2: "ascii",
|
||||||
|
@ -354,6 +355,19 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
im2 = Image.open(out)
|
im2 = Image.open(out)
|
||||||
self.assert_image_equal(im, im2)
|
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):
|
def xtest_bw_compression_w_rgb(self):
|
||||||
""" This test passes, but when running all tests causes a failure due
|
""" 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
|
to output on stderr from the error thrown by libtiff. We need to
|
||||||
|
|
20
encode.c
20
encode.c
|
@ -936,6 +936,26 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
break;
|
break;
|
||||||
case TIFFTAG_COLORMAP:
|
case TIFFTAG_COLORMAP:
|
||||||
/* 3x uint16 * arrays of r,g,b palette values, len=2^^bpp */
|
/* 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;i<len;i++) {
|
||||||
|
((uint16 *)arrav)[i] = (uint16)PyInt_AsLong(PyTuple_GetItem(value,i));
|
||||||
|
}
|
||||||
|
status = ImagingLibTiffSetField(&encoder->state,
|
||||||
|
tag,
|
||||||
|
arrav,
|
||||||
|
((uint16 *)arrav) + stride,
|
||||||
|
((uint16 *)arrav) + 2 * stride);
|
||||||
|
free(arrav);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TIFFTAG_SUBIFD:
|
case TIFFTAG_SUBIFD:
|
||||||
/* int short length, uint32* data */
|
/* int short length, uint32* data */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user