Skip to content

Commit 82cdaa4

Browse files
committed
Support writing SIGNED_RATIONAL tag types
1 parent ddd4f00 commit 82cdaa4

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Tests/test_file_libtiff.py

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

358-
def test_ifd(self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
358+
@pytest.mark.parametrize("tagtype", (TiffTags.SIGNED_RATIONAL, TiffTags.IFD))
359+
def test_tag_type(
360+
self, tagtype: int, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
361+
) -> None:
359362
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", True)
360363

361364
ifd = TiffImagePlugin.ImageFileDirectory_v2()
362365
ifd[37000] = 100
363-
ifd.tagtype[37000] = TiffTags.IFD
366+
ifd.tagtype[37000] = tagtype
364367

365368
out = tmp_path / "temp.tif"
366369
im = Image.new("L", (1, 1))

src/encode.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,6 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
990990
status = ImagingLibTiffSetField(
991991
&encoder->state, (ttag_t)key_int, (FLOAT32)PyFloat_AsDouble(value)
992992
);
993-
} else if (type == TIFF_DOUBLE) {
994-
status = ImagingLibTiffSetField(
995-
&encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value)
996-
);
997993
} else if (type == TIFF_SBYTE) {
998994
status = ImagingLibTiffSetField(
999995
&encoder->state, (ttag_t)key_int, (INT8)PyLong_AsLong(value)
@@ -1002,7 +998,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
1002998
status = ImagingLibTiffSetField(
1003999
&encoder->state, (ttag_t)key_int, PyBytes_AsString(value)
10041000
);
1005-
} else if (type == TIFF_RATIONAL) {
1001+
} else if (type == TIFF_DOUBLE || type == TIFF_SRATIONAL ||
1002+
type == TIFF_RATIONAL) {
10061003
status = ImagingLibTiffSetField(
10071004
&encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value)
10081005
);

0 commit comments

Comments
 (0)