From 374be0c1ba9d71b106d7a00c1b76a3715ba8f31c Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 7 May 2024 19:51:16 -0500 Subject: [PATCH] deprecate old rawmodes for 16-bit RGB data --- docs/deprecations.rst | 17 +++++++++++++++++ docs/releasenotes/10.4.0.rst | 15 +++++++++++++++ src/PIL/Image.py | 26 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 627672e1f3b..a35949ccd58 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -107,6 +107,23 @@ BGR;15, BGR 16 and BGR;24 The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated. +16-Bit RGB/BGR Rawmodes +^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 10.4.0 + +The following rawmodes have been deprecated and replaced with better-named rawmodes. + +RGB;15 → XBGR;1555 +RGB;16 → BGR;565 +BGR;5 → XRGB;1555 +BGR;15 → XRGB;1555 +BGR;16 → RGB;565 +RGB;4B → XBGR;4 +RGBA;4B → ABGR;4 +RGBA;15 → ARGB;1555 +BGRA;15 → ABGR;1555 + Support for LibTIFF earlier than 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/releasenotes/10.4.0.rst b/docs/releasenotes/10.4.0.rst index 44727efd41f..2e0b79f1d33 100644 --- a/docs/releasenotes/10.4.0.rst +++ b/docs/releasenotes/10.4.0.rst @@ -28,6 +28,21 @@ BGR;15, BGR 16 and BGR;24 The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated. +16-Bit RGB/BGR Rawmodes +^^^^^^^^^^^^^^^^^^^^^^^ + +The following rawmodes have been deprecated and replaced with better-named rawmodes. + +RGB;15 → XBGR;1555 +RGB;16 → BGR;565 +BGR;5 → XRGB;1555 +BGR;15 → XRGB;1555 +BGR;16 → RGB;565 +RGB;4B → XBGR;4 +RGBA;4B → ABGR;4 +RGBA;15 → ARGB;1555 +BGRA;15 → ABGR;1555 + Support for LibTIFF earlier than 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/PIL/Image.py b/src/PIL/Image.py index bdd869ccc15..f7aad57d314 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -276,6 +276,19 @@ def _conv_type_shape(im): # may have to modify the stride calculation in map.c too! _MAPMODES = ("L", "P", "RGBX", "RGBA", "CMYK", "I;16", "I;16L", "I;16B") +# map of old deprecated rawmode to new replacement rawmode +_DEPRECATED_RAWMODES = { + "RGB;15": "XBGR;1555", + "RGB;16": "BGR;565", + "BGR;5": "XRGB;1555", + "BGR;15": "XRGB;1555", + "BGR;16": "RGB;565", + "RGB;4B": "XBGR;4", + "RGBA;4B": "ABGR;4", + "RGBA;15": "ARGB;1555", + "BGRA;15": "ABGR;1555", +} + def getmodebase(mode: str) -> str: """ @@ -417,6 +430,13 @@ def _getdecoder(mode, decoder_name, args, extra=()): elif not isinstance(args, tuple): args = (args,) + if decoder_name == "raw" and args[0] in _DEPRECATED_RAWMODES: + deprecate( + f"rawmode {args[0]}", + 12, + replacement=f"rawmode {_DEPRECATED_RAWMODES[args[0]]}", + ) + try: decoder = DECODERS[decoder_name] except KeyError: @@ -1587,6 +1607,12 @@ def getpalette(self, rawmode: str | None = "RGB") -> list[int] | None: mode = self.im.getpalettemode() except ValueError: return None # no palette + if rawmode in _DEPRECATED_RAWMODES: + deprecate( + f"rawmode {rawmode}", + 12, + replacement=f"rawmode {_DEPRECATED_RAWMODES[rawmode]}", + ) if rawmode is None: rawmode = mode return list(self.im.getpalette(mode, rawmode))