Skip to content

Commit 583f0a5

Browse files
committed
Removed BGR;15, BGR;16 and BGR;24 modes
1 parent 37cd041 commit 583f0a5

16 files changed

+50
-290
lines changed

Tests/helper.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,13 @@ def _cached_hopper(mode: str) -> Image.Image:
271271
im = hopper("L")
272272
else:
273273
im = hopper()
274-
if mode.startswith("BGR;"):
275-
with pytest.warns(DeprecationWarning, match="BGR;"):
276-
im = im.convert(mode)
277-
else:
278-
try:
279-
im = im.convert(mode)
280-
except ImportError:
281-
if mode == "LAB":
282-
im = Image.open("Tests/images/hopper.Lab.tif")
283-
else:
284-
raise
274+
try:
275+
im = im.convert(mode)
276+
except ImportError:
277+
if mode == "LAB":
278+
im = Image.open("Tests/images/hopper.Lab.tif")
279+
else:
280+
raise
285281
return im
286282

287283

Tests/test_image.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
assert_image_similar_tofile,
3131
assert_not_all_same,
3232
hopper,
33-
is_big_endian,
3433
is_win32,
3534
mark_if_feature_version,
3635
skip_unless_feature,
@@ -50,19 +49,10 @@
5049
PrettyPrinter = None
5150

5251

53-
# Deprecation helper
54-
def helper_image_new(mode: str, size: tuple[int, int]) -> Image.Image:
55-
if mode.startswith("BGR;"):
56-
with pytest.warns(DeprecationWarning, match="BGR;"):
57-
return Image.new(mode, size)
58-
else:
59-
return Image.new(mode, size)
60-
61-
6252
class TestImage:
63-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
53+
@pytest.mark.parametrize("mode", Image.MODES)
6454
def test_image_modes_success(self, mode: str) -> None:
65-
helper_image_new(mode, (1, 1))
55+
Image.new(mode, (1, 1))
6656

6757
@pytest.mark.parametrize("mode", ("", "bad", "very very long"))
6858
def test_image_modes_fail(self, mode: str) -> None:
@@ -1148,33 +1138,27 @@ def test_deprecation(self) -> None:
11481138

11491139

11501140
class TestImageBytes:
1151-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
1141+
@pytest.mark.parametrize("mode", Image.MODES)
11521142
def test_roundtrip_bytes_constructor(self, mode: str) -> None:
11531143
im = hopper(mode)
11541144
source_bytes = im.tobytes()
11551145

1156-
if mode.startswith("BGR;"):
1157-
with pytest.warns(DeprecationWarning, match=mode):
1158-
reloaded = Image.frombytes(mode, im.size, source_bytes)
1159-
else:
1160-
reloaded = Image.frombytes(mode, im.size, source_bytes)
1146+
reloaded = Image.frombytes(mode, im.size, source_bytes)
11611147
assert reloaded.tobytes() == source_bytes
11621148

1163-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
1149+
@pytest.mark.parametrize("mode", Image.MODES)
11641150
def test_roundtrip_bytes_method(self, mode: str) -> None:
11651151
im = hopper(mode)
11661152
source_bytes = im.tobytes()
11671153

1168-
reloaded = helper_image_new(mode, im.size)
1154+
reloaded = Image.new(mode, im.size)
11691155
reloaded.frombytes(source_bytes)
11701156
assert reloaded.tobytes() == source_bytes
11711157

1172-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
1158+
@pytest.mark.parametrize("mode", Image.MODES)
11731159
def test_getdata_putdata(self, mode: str) -> None:
1174-
if is_big_endian() and mode == "BGR;15":
1175-
pytest.xfail("Known failure of BGR;15 on big-endian")
11761160
im = hopper(mode)
1177-
reloaded = helper_image_new(mode, im.size)
1161+
reloaded = Image.new(mode, im.size)
11781162
reloaded.putdata(im.getdata())
11791163
assert_image_equal(im, reloaded)
11801164

Tests/test_image_access.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ def color(mode: str) -> int | tuple[int, ...]:
123123
bands = Image.getmodebands(mode)
124124
if bands == 1:
125125
return 1
126-
if mode in ("BGR;15", "BGR;16"):
127-
# These modes have less than 8 bits per band,
128-
# so (1, 2, 3) cannot be roundtripped.
129-
return (16, 32, 49)
130126
return tuple(range(1, bands + 1))
131127

132128
def check(self, mode: str, expected_color_int: int | None = None) -> None:
@@ -191,11 +187,6 @@ def check(self, mode: str, expected_color_int: int | None = None) -> None:
191187
def test_basic(self, mode: str) -> None:
192188
self.check(mode)
193189

194-
@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
195-
def test_deprecated(self, mode: str) -> None:
196-
with pytest.warns(DeprecationWarning, match="BGR;"):
197-
self.check(mode)
198-
199190
def test_list(self) -> None:
200191
im = hopper()
201192
assert im.getpixel([0, 0]) == (20, 20, 70)
@@ -218,7 +209,7 @@ def test_p_putpixel_rgb_rgba(self, mode: str, color: tuple[int, ...]) -> None:
218209

219210

220211
class TestImagePutPixelError:
221-
IMAGE_MODES1 = ["LA", "RGB", "RGBA", "BGR;15"]
212+
IMAGE_MODES1 = ["LA", "RGB", "RGBA"]
222213
IMAGE_MODES2 = ["L", "I", "I;16"]
223214
INVALID_TYPES = ["foo", 1.0, None]
224215

@@ -234,11 +225,6 @@ def test_putpixel_type_error1(self, mode: str) -> None:
234225
(
235226
("L", (0, 2), "color must be int or single-element tuple"),
236227
("LA", (0, 3), "color must be int, or tuple of one or two elements"),
237-
(
238-
"BGR;15",
239-
(0, 2),
240-
"color must be int, or tuple of one or three elements",
241-
),
242228
(
243229
"RGB",
244230
(0, 2, 5),

Tests/test_image_putdata.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ def test_mode_F() -> None:
7878
assert list(im.getdata()) == target
7979

8080

81-
@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
82-
def test_mode_BGR(mode: str) -> None:
83-
data = [(16, 32, 49), (32, 32, 98)]
84-
with pytest.warns(DeprecationWarning, match=mode):
85-
im = Image.new(mode, (1, 2))
86-
im.putdata(data)
87-
88-
assert list(im.getdata()) == data
89-
90-
9181
def test_array_B() -> None:
9282
# shouldn't segfault
9383
# see https://github.com/python-pillow/Pillow/issues/1008

Tests/test_image_resize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def test_default_filter_bicubic(self, mode: str) -> None:
324324
im = hopper(mode)
325325
assert im.resize((20, 20), Image.Resampling.BICUBIC) == im.resize((20, 20))
326326

327-
@pytest.mark.parametrize("mode", ("1", "P", "BGR;15", "BGR;16"))
327+
@pytest.mark.parametrize("mode", ("1", "P"))
328328
def test_default_filter_nearest(self, mode: str) -> None:
329329
im = hopper(mode)
330330
assert im.resize((20, 20), Image.Resampling.NEAREST) == im.resize((20, 20))

Tests/test_lib_pack.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,6 @@ def test_RGB(self) -> None:
361361
"RGB", "CMYK", 4, (250, 249, 248), (242, 241, 240), (234, 233, 233)
362362
)
363363

364-
def test_BGR(self) -> None:
365-
with pytest.warns(DeprecationWarning, match="BGR;15"):
366-
self.assert_unpack(
367-
"BGR;15", "BGR;15", 3, (8, 131, 0), (24, 0, 8), (41, 131, 8)
368-
)
369-
with pytest.warns(DeprecationWarning, match="BGR;16"):
370-
self.assert_unpack(
371-
"BGR;16", "BGR;16", 3, (8, 64, 0), (24, 129, 0), (41, 194, 0)
372-
)
373-
with pytest.warns(DeprecationWarning, match="BGR;24"):
374-
self.assert_unpack("BGR;24", "BGR;24", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
375-
376364
def test_RGBA(self) -> None:
377365
self.assert_unpack("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6))
378366
self.assert_unpack(

docs/deprecations.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ ImageMath eval()
7878
``ImageMath.eval()`` has been deprecated. Use :py:meth:`~PIL.ImageMath.lambda_eval` or
7979
:py:meth:`~PIL.ImageMath.unsafe_eval` instead.
8080

81-
BGR;15, BGR 16 and BGR;24
82-
^^^^^^^^^^^^^^^^^^^^^^^^^
83-
84-
.. deprecated:: 10.4.0
85-
86-
The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated.
87-
8881
Non-image modes in ImageCms
8982
^^^^^^^^^^^^^^^^^^^^^^^^^^^
9083

@@ -221,6 +214,14 @@ Removed features
221214
Deprecated features are only removed in major releases after an appropriate
222215
period of deprecation has passed.
223216

217+
BGR;15, BGR 16 and BGR;24
218+
^^^^^^^^^^^^^^^^^^^^^^^^^
219+
220+
.. deprecated:: 10.4.0
221+
.. versionremoved:: 12.0.0
222+
223+
The experimental BGR;15, BGR;16 and BGR;24 modes have been removed.
224+
224225
TiffImagePlugin IFD_LEGACY_API
225226
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226227

docs/reference/arrow_support.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ with any Arrow provider or consumer in the Python ecosystem.
2121
Data formats
2222
============
2323

24-
Pillow currently supports exporting Arrow images in all modes
25-
**except** for ``BGR;15``, ``BGR;16`` and ``BGR;24``. This is due to
26-
line-length packing in these modes making for non-continuous memory.
24+
Pillow currently supports exporting Arrow images in all modes.
2725

2826
For single-band images, the exported array is width*height elements,
2927
with each pixel corresponding to the appropriate Arrow type.

src/PIL/Image.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,6 @@ def convert(
980980
:returns: An :py:class:`~PIL.Image.Image` object.
981981
"""
982982

983-
if mode in ("BGR;15", "BGR;16", "BGR;24"):
984-
deprecate(mode, 12)
985-
986983
self.load()
987984

988985
has_transparency = "transparency" in self.info
@@ -2229,8 +2226,6 @@ def resize(
22292226
:py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`,
22302227
:py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`.
22312228
If the image has mode "1" or "P", it is always set to
2232-
:py:data:`Resampling.NEAREST`. If the image mode is "BGR;15",
2233-
"BGR;16" or "BGR;24", then the default filter is
22342229
:py:data:`Resampling.NEAREST`. Otherwise, the default filter is
22352230
:py:data:`Resampling.BICUBIC`. See: :ref:`concept-filters`.
22362231
:param box: An optional 4-tuple of floats providing
@@ -2253,8 +2248,7 @@ def resize(
22532248
"""
22542249

22552250
if resample is None:
2256-
bgr = self.mode.startswith("BGR;")
2257-
resample = Resampling.NEAREST if bgr else Resampling.BICUBIC
2251+
resample = Resampling.BICUBIC
22582252
elif resample not in (
22592253
Resampling.NEAREST,
22602254
Resampling.BILINEAR,
@@ -3085,9 +3079,6 @@ def new(
30853079
:returns: An :py:class:`~PIL.Image.Image` object.
30863080
"""
30873081

3088-
if mode in ("BGR;15", "BGR;16", "BGR;24"):
3089-
deprecate(mode, 12)
3090-
30913082
_check_size(size)
30923083

30933084
if color is None:

src/PIL/ImageMode.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
from functools import lru_cache
1919
from typing import NamedTuple
2020

21-
from ._deprecate import deprecate
22-
2321

2422
class ModeDescriptor(NamedTuple):
2523
"""Wrapper for mode strings."""
@@ -57,16 +55,11 @@ def getmode(mode: str) -> ModeDescriptor:
5755
"HSV": ("RGB", "L", ("H", "S", "V"), "|u1"),
5856
# extra experimental modes
5957
"RGBa": ("RGB", "L", ("R", "G", "B", "a"), "|u1"),
60-
"BGR;15": ("RGB", "L", ("B", "G", "R"), "|u1"),
61-
"BGR;16": ("RGB", "L", ("B", "G", "R"), "|u1"),
62-
"BGR;24": ("RGB", "L", ("B", "G", "R"), "|u1"),
6358
"LA": ("L", "L", ("L", "A"), "|u1"),
6459
"La": ("L", "L", ("L", "a"), "|u1"),
6560
"PA": ("RGB", "L", ("P", "A"), "|u1"),
6661
}
6762
if mode in modes:
68-
if mode in ("BGR;15", "BGR;16", "BGR;24"):
69-
deprecate(mode, 12)
7063
base_mode, base_type, bands, type_str = modes[mode]
7164
return ModeDescriptor(mode, bands, base_mode, base_type, type_str)
7265

0 commit comments

Comments
 (0)