From 9c9449af346e6bfcbf2fa6573b7ec96a14ddc8c8 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 2 Jul 2025 00:00:16 +1000 Subject: [PATCH] Removed support for LibTIFF < 4 --- Tests/test_file_libtiff.py | 31 +++---------------------------- docs/deprecations.rst | 17 +++++++++-------- src/PIL/TiffImagePlugin.py | 7 ------- src/_imaging.c | 10 ---------- src/libImaging/TiffDecode.c | 10 +--------- 5 files changed, 13 insertions(+), 62 deletions(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 1ec39eba5..c245a5a9b 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -256,19 +256,7 @@ class TestFileLibTiff(LibTiffTestCase): im.save(out, tiffinfo=new_ifd) - @pytest.mark.parametrize( - "libtiff", - ( - pytest.param( - True, - marks=pytest.mark.skipif( - not getattr(Image.core, "libtiff_support_custom_tags", False), - reason="Custom tags not supported by older libtiff", - ), - ), - False, - ), - ) + @pytest.mark.parametrize("libtiff", (True, False)) def test_custom_metadata( self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool ) -> None: @@ -724,8 +712,7 @@ class TestFileLibTiff(LibTiffTestCase): with Image.open(out) as reloaded: assert isinstance(reloaded, TiffImagePlugin.TiffImageFile) - if Image.core.libtiff_support_custom_tags: - assert reloaded.tag_v2[34665] == 125456 + assert reloaded.tag_v2[34665] == 125456 def test_crashing_metadata( self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path @@ -777,19 +764,7 @@ class TestFileLibTiff(LibTiffTestCase): assert icc_libtiff is not None assert icc == icc_libtiff - @pytest.mark.parametrize( - "libtiff", - ( - pytest.param( - True, - marks=pytest.mark.skipif( - not getattr(Image.core, "libtiff_support_custom_tags", False), - reason="Custom tags not supported by older libtiff", - ), - ), - False, - ), - ) + @pytest.mark.parametrize("libtiff", (True, False)) def test_write_icc( self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool ) -> None: diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 82530f93c..5973038e3 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -77,14 +77,6 @@ The use in :py:mod:`.ImageCms` of input modes and output modes that are not Pill image modes has been deprecated. Defaulting to "L" or "1" if the mode cannot be mapped is also deprecated. -Support for LibTIFF earlier than 4 -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. deprecated:: 10.4.0 - -Support for LibTIFF earlier than version 4 has been deprecated. -Upgrade to a newer version of LibTIFF instead. - ImageDraw.getdraw hints parameter ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -194,6 +186,15 @@ BGR;15, BGR 16 and BGR;24 The experimental BGR;15, BGR;16 and BGR;24 modes have been removed. +Support for LibTIFF earlier than 4 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 10.4.0 +.. versionremoved:: 12.0.0 + +Support for LibTIFF earlier than version 4 has been removed. +Upgrade to a newer version of LibTIFF instead. + Image isImageType() ^^^^^^^^^^^^^^^^^^^ diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index daf20f2e8..c1850f084 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -56,7 +56,6 @@ from . import ExifTags, Image, ImageFile, ImageOps, ImagePalette, TiffTags from ._binary import i16be as i16 from ._binary import i32be as i32 from ._binary import o8 -from ._deprecate import deprecate from ._typing import StrOrBytesPath from ._util import DeferredError, is_path from .TiffTags import TYPES @@ -284,9 +283,6 @@ PREFIXES = [ b"II\x2b\x00", # BigTIFF with little-endian byte order ] -if not getattr(Image.core, "libtiff_support_custom_tags", True): - deprecate("Support for LibTIFF earlier than version 4", 12) - def _accept(prefix: bytes) -> bool: return prefix.startswith(tuple(PREFIXES)) @@ -1934,9 +1930,6 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: # Custom items are supported for int, float, unicode, string and byte # values. Other types and tuples require a tagtype. if tag not in TiffTags.LIBTIFF_CORE: - if not getattr(Image.core, "libtiff_support_custom_tags", False): - continue - if tag in TiffTags.TAGS_V2_GROUPS: types[tag] = TiffTags.LONG8 elif tag in ifd.tagtype: diff --git a/src/_imaging.c b/src/_imaging.c index 8ba2a2908..fbfc0e41a 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -4352,16 +4352,6 @@ setup_module(PyObject *m) { PyObject *v = PyUnicode_FromString(ImagingTiffVersion()); PyDict_SetItemString(d, "libtiff_version", v ? v : Py_None); Py_XDECREF(v); - - // Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7 - PyObject *support_custom_tags; -#if TIFFLIB_VERSION >= 20111221 && TIFFLIB_VERSION != 20120218 && \ - TIFFLIB_VERSION != 20120922 - support_custom_tags = Py_True; -#else - support_custom_tags = Py_False; -#endif - PyDict_SetItemString(d, "libtiff_support_custom_tags", support_custom_tags); } #endif diff --git a/src/libImaging/TiffDecode.c b/src/libImaging/TiffDecode.c index e289ce405..71516fd1b 100644 --- a/src/libImaging/TiffDecode.c +++ b/src/libImaging/TiffDecode.c @@ -884,7 +884,6 @@ ImagingLibTiffMergeFieldInfo( // Refer to libtiff docs (http://www.simplesystems.org/libtiff/addingtags.html) TIFFSTATE *clientstate = (TIFFSTATE *)state->context; uint32_t n; - int status = 0; // custom fields added with ImagingLibTiffMergeFieldInfo are only used for // decoding, ignore readcount; @@ -907,14 +906,7 @@ ImagingLibTiffMergeFieldInfo( n = sizeof(info) / sizeof(info[0]); - // Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7 -#if TIFFLIB_VERSION >= 20111221 && TIFFLIB_VERSION != 20120218 && \ - TIFFLIB_VERSION != 20120922 - status = TIFFMergeFieldInfo(clientstate->tiff, info, n); -#else - TIFFMergeFieldInfo(clientstate->tiff, info, n); -#endif - return status; + return TIFFMergeFieldInfo(clientstate->tiff, info, n); } int