mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-23 19:44:13 +03:00
Allow libtiff to write COLORMAP tag
This commit is contained in:
parent
7d9ac36e42
commit
d728cd5875
|
@ -203,6 +203,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
del core_items[tag]
|
del core_items[tag]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
del core_items[320] # colormap is special, tested below
|
||||||
|
|
||||||
# Type codes:
|
# Type codes:
|
||||||
# 2: "ascii",
|
# 2: "ascii",
|
||||||
|
@ -479,6 +480,18 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
with Image.open(out) as im2:
|
with Image.open(out) as im2:
|
||||||
assert_image_equal(im, im2)
|
assert_image_equal(im, im2)
|
||||||
|
|
||||||
|
def test_palette_save(self, tmp_path):
|
||||||
|
im = hopper("P")
|
||||||
|
out = str(tmp_path / "temp.tif")
|
||||||
|
|
||||||
|
TiffImagePlugin.WRITE_LIBTIFF = True
|
||||||
|
im.save(out)
|
||||||
|
TiffImagePlugin.WRITE_LIBTIFF = False
|
||||||
|
|
||||||
|
with Image.open(out) as reloaded:
|
||||||
|
# colormap/palette tag
|
||||||
|
assert len(reloaded.tag_v2[320]) == 768
|
||||||
|
|
||||||
def xtest_bw_compression_w_rgb(self, tmp_path):
|
def xtest_bw_compression_w_rgb(self, tmp_path):
|
||||||
""" 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
|
||||||
|
|
|
@ -1524,7 +1524,6 @@ def _save(im, fp, filename):
|
||||||
# BITSPERSAMPLE, etc), passing arrays with a different length will result in
|
# BITSPERSAMPLE, etc), passing arrays with a different length will result in
|
||||||
# segfaults. Block these tags until we add extra validation.
|
# segfaults. Block these tags until we add extra validation.
|
||||||
blocklist = [
|
blocklist = [
|
||||||
COLORMAP,
|
|
||||||
REFERENCEBLACKWHITE,
|
REFERENCEBLACKWHITE,
|
||||||
SAMPLEFORMAT,
|
SAMPLEFORMAT,
|
||||||
STRIPBYTECOUNTS,
|
STRIPBYTECOUNTS,
|
||||||
|
|
|
@ -483,7 +483,6 @@ LIBTIFF_CORE = {
|
||||||
65537,
|
65537,
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBTIFF_CORE.remove(320) # Array of short, crashes
|
|
||||||
LIBTIFF_CORE.remove(301) # Array of short, crashes
|
LIBTIFF_CORE.remove(301) # Array of short, crashes
|
||||||
LIBTIFF_CORE.remove(532) # Array of long, crashes
|
LIBTIFF_CORE.remove(532) # Array of long, crashes
|
||||||
|
|
||||||
|
|
23
src/encode.c
23
src/encode.c
|
@ -671,7 +671,7 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
// This list also exists in TiffTags.py
|
// This list also exists in TiffTags.py
|
||||||
const int core_tags[] = {
|
const int core_tags[] = {
|
||||||
256, 257, 258, 259, 262, 263, 266, 269, 274, 277, 278, 280, 281, 340,
|
256, 257, 258, 259, 262, 263, 266, 269, 274, 277, 278, 280, 281, 340,
|
||||||
341, 282, 283, 284, 286, 287, 296, 297, 321, 338, 32995, 32998, 32996,
|
341, 282, 283, 284, 286, 287, 296, 297, 320, 321, 338, 32995, 32998, 32996,
|
||||||
339, 32997, 330, 531, 530, 65537
|
339, 32997, 330, 531, 530, 65537
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -801,7 +801,26 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
TRACE(("Setting from Tuple: %d \n", key_int));
|
TRACE(("Setting from Tuple: %d \n", key_int));
|
||||||
len = PyTuple_Size(value);
|
len = PyTuple_Size(value);
|
||||||
|
|
||||||
if (type == TIFF_SHORT) {
|
if (key_int == TIFFTAG_COLORMAP) {
|
||||||
|
int stride = 256;
|
||||||
|
if (len != 768) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "Requiring 768 items for for Colormap");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
UINT16 *av;
|
||||||
|
/* malloc check ok, calloc checks for overflow */
|
||||||
|
av = calloc(len, sizeof(UINT16));
|
||||||
|
if (av) {
|
||||||
|
for (i=0;i<len;i++) {
|
||||||
|
av[i] = (UINT16)PyLong_AsLong(PyTuple_GetItem(value,i));
|
||||||
|
}
|
||||||
|
status = ImagingLibTiffSetField(&encoder->state, (ttag_t) key_int,
|
||||||
|
av,
|
||||||
|
av + stride,
|
||||||
|
av + stride * 2);
|
||||||
|
free(av);
|
||||||
|
}
|
||||||
|
} else if (type == TIFF_SHORT) {
|
||||||
UINT16 *av;
|
UINT16 *av;
|
||||||
/* malloc check ok, calloc checks for overflow */
|
/* malloc check ok, calloc checks for overflow */
|
||||||
av = calloc(len, sizeof(UINT16));
|
av = calloc(len, sizeof(UINT16));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user