mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-15 09:44:46 +03:00
Support saving variable length rational TIFF tags
This commit is contained in:
parent
ec6d5efe4d
commit
7afbafd1e2
|
@ -355,6 +355,18 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
# Should not segfault
|
||||
im.save(outfile)
|
||||
|
||||
def test_whitepoint_tag(
|
||||
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", True)
|
||||
|
||||
out = tmp_path / "temp.tif"
|
||||
hopper().save(out, tiffinfo={318: (0.3127, 0.3289)})
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
|
||||
assert reloaded.tag_v2[318] == pytest.approx((0.3127, 0.3289))
|
||||
|
||||
def test_xmlpacket_tag(
|
||||
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
|
|
12
src/encode.c
12
src/encode.c
|
@ -922,6 +922,18 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
|||
);
|
||||
free(av);
|
||||
}
|
||||
} else if (type == TIFF_RATIONAL) {
|
||||
FLOAT32 *av;
|
||||
/* malloc check ok, calloc checks for overflow */
|
||||
av = calloc(len, sizeof(FLOAT32));
|
||||
if (av) {
|
||||
for (i = 0; i < len; i++) {
|
||||
av[i] = (FLOAT32)PyFloat_AsDouble(PyTuple_GetItem(value, i));
|
||||
}
|
||||
status =
|
||||
ImagingLibTiffSetField(&encoder->state, (ttag_t)key_int, av);
|
||||
free(av);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (type == TIFF_SHORT) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user