Skip to content

Commit

Permalink
deprecate old rawmodes for 16-bit RGB data
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed May 8, 2024
1 parent e7f28e5 commit caea7e9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
15 changes: 15 additions & 0 deletions docs/releasenotes/10.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
17 changes: 17 additions & 0 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ 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:
"""
Expand Down Expand Up @@ -396,6 +408,9 @@ 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:
Expand Down Expand Up @@ -1556,6 +1571,8 @@ 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))
Expand Down

0 comments on commit caea7e9

Please sign in to comment.