From 33fac14e90e94d30750af6b96e2261cedc31736e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 4 Nov 2024 20:00:11 +1100 Subject: [PATCH] Treat IFDs as LONG8 --- src/PIL/TiffTags.py | 8 ++++---- src/encode.c | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/PIL/TiffTags.py b/src/PIL/TiffTags.py index 86adaa45857..154b559759e 100644 --- a/src/PIL/TiffTags.py +++ b/src/PIL/TiffTags.py @@ -207,12 +207,12 @@ def lookup(tag: int, group: int | None = None) -> TagInfo: 33723: ("IptcNaaInfo", UNDEFINED, 1), 34377: ("PhotoshopInfo", BYTE, 0), # FIXME add more tags here - 34665: ("ExifIFD", LONG, 1), + 34665: ("ExifIFD", LONG8, 1), 34675: ("ICCProfile", UNDEFINED, 1), - 34853: ("GPSInfoIFD", LONG, 1), + 34853: ("GPSInfoIFD", LONG8, 1), 36864: ("ExifVersion", UNDEFINED, 1), 37724: ("ImageSourceData", UNDEFINED, 1), - 40965: ("InteroperabilityIFD", LONG, 1), + 40965: ("InteroperabilityIFD", LONG8, 1), 41730: ("CFAPattern", UNDEFINED, 1), # MPInfo 45056: ("MPFVersion", UNDEFINED, 1), @@ -245,7 +245,7 @@ def lookup(tag: int, group: int | None = None) -> TagInfo: 34665: { 36864: ("ExifVersion", UNDEFINED, 1), 40960: ("FlashPixVersion", UNDEFINED, 1), - 40965: ("InteroperabilityIFD", LONG, 1), + 40965: ("InteroperabilityIFD", LONG8, 1), 41730: ("CFAPattern", UNDEFINED, 1), }, # GPSInfoIFD diff --git a/src/encode.c b/src/encode.c index 1a4cd489da2..09a86a7151c 100644 --- a/src/encode.c +++ b/src/encode.c @@ -736,7 +736,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { } if (tag_type) { int type_int = PyLong_AsLong(tag_type); - if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) { + if (type_int >= TIFF_BYTE && type_int <= TIFF_LONG8) { type = (TIFFDataType)type_int; } } @@ -929,7 +929,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { ); } else if (type == TIFF_LONG) { status = ImagingLibTiffSetField( - &encoder->state, (ttag_t)key_int, PyLong_AsLongLong(value) + &encoder->state, (ttag_t)key_int, (UINT32)PyLong_AsLong(value) ); } else if (type == TIFF_SSHORT) { status = ImagingLibTiffSetField( @@ -959,6 +959,10 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { status = ImagingLibTiffSetField( &encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value) ); + } else if (type == TIFF_LONG8) { + status = ImagingLibTiffSetField( + &encoder->state, (ttag_t)key_int, PyLong_AsLongLong(value) + ); } else { TRACE( ("Unhandled type for key %d : %s \n",