Skip to content

Commit b04d879

Browse files
committed
Support writing InkNames
1 parent 76f04b4 commit b04d879

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Tests/test_file_libtiff.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ def test_subifd(self, tmp_path: Path) -> None:
355355
# Should not segfault
356356
im.save(outfile)
357357

358+
def test_inknames_tag(
359+
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
360+
) -> None:
361+
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", True)
362+
363+
out = tmp_path / "temp.tif"
364+
hopper("L").save(out, tiffinfo={333: "name\x00"})
365+
366+
with Image.open(out) as reloaded:
367+
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
368+
assert reloaded.tag_v2[333] in ("name", "name\x00")
369+
358370
def test_whitepoint_tag(
359371
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
360372
) -> None:

src/PIL/TiffTags.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ def _populate() -> None:
558558
LIBTIFF_CORE.remove(255) # We don't have support for subfiletypes
559559
LIBTIFF_CORE.remove(322) # We don't have support for writing tiled images with libtiff
560560
LIBTIFF_CORE.remove(323) # Tiled images
561-
LIBTIFF_CORE.remove(333) # Ink Names either
562561

563562
# Note to advanced users: There may be combinations of these
564563
# parameters and values that when added properly, will work and

src/encode.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
668668
int key_int, status, is_core_tag, is_var_length, num_core_tags, i;
669669
TIFFDataType type = TIFF_NOTYPE;
670670
// This list also exists in TiffTags.py
671-
const int core_tags[] = {256, 257, 258, 259, 262, 263, 266, 269, 274,
672-
277, 278, 280, 281, 340, 341, 282, 283, 284,
673-
286, 287, 296, 297, 320, 321, 338, 32995, 32998,
674-
32996, 339, 32997, 330, 531, 530, 65537, 301, 532};
671+
const int core_tags[] = {256, 257, 258, 259, 262, 263, 266, 269, 274, 277,
672+
278, 280, 281, 282, 283, 284, 286, 287, 296, 297,
673+
301, 320, 321, 330, 333, 338, 339, 340, 341, 530,
674+
531, 532, 32995, 32996, 32997, 32998, 65537};
675675

676676
Py_ssize_t tags_size;
677677
PyObject *item;
@@ -821,7 +821,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
821821
}
822822
}
823823

824-
if (type == TIFF_BYTE || type == TIFF_UNDEFINED) {
824+
if (type == TIFF_BYTE || type == TIFF_UNDEFINED ||
825+
key_int == TIFFTAG_INKNAMES) {
825826
status = ImagingLibTiffSetField(
826827
&encoder->state,
827828
(ttag_t)key_int,

0 commit comments

Comments
 (0)