From 0ec76d5d3afcf9d938156308f2ed0f98e93cce3a Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 11 Jul 2023 20:33:19 +1000 Subject: [PATCH] add tests for image modes with a different number of bytes and bands --- Tests/test_lib_image.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Tests/test_lib_image.py b/Tests/test_lib_image.py index 445f806ef..438ecd5ca 100644 --- a/Tests/test_lib_image.py +++ b/Tests/test_lib_image.py @@ -72,3 +72,24 @@ def test_not_equal(mode): img_b = Image.frombytes(mode, (2, 2), data_b) assert img_a.tobytes() != img_b.tobytes() assert img_a.im != img_b.im + + +@pytest.mark.parametrize("mode", ("RGB", "YCbCr", "HSV", "LAB")) +def test_equal_three_channels_four_bytes(mode): + # The "A" and "B" values in LAB images are signed values from -128 to 127, + # but we store them as unsigned values from 0 to 255, so we need to use + # slightly different input bytes for LAB to get the same output. + img_a = Image.new(mode, (1, 1), 0x00B3B231 if mode == "LAB" else 0x00333231) + img_b = Image.new(mode, (1, 1), 0xFFB3B231 if mode == "LAB" else 0xFF333231) + assert img_a.tobytes() == b"123" + assert img_b.tobytes() == b"123" + assert img_a.im == img_b.im + + +@pytest.mark.parametrize("mode", ("LA", "La", "PA")) +def test_equal_two_channels_four_bytes(mode): + img_a = Image.new(mode, (1, 1), 0x32000031) + img_b = Image.new(mode, (1, 1), 0x32FFFF31) + assert img_a.tobytes() == b"12" + assert img_b.tobytes() == b"12" + assert img_a.im == img_b.im