Skip to content

Commit 97a08ff

Browse files
committed
add tests for image modes with a different number of bytes and bands
1 parent a2a3d8e commit 97a08ff

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Tests/test_lib_image.py

+21
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,24 @@ def test_not_equal(mode):
7272
img_b = Image.frombytes(mode, (2, 2), data_b)
7373
assert img_a.tobytes() != img_b.tobytes()
7474
assert img_a.im != img_b.im
75+
76+
77+
@pytest.mark.parametrize("mode", ("RGB", "YCbCr", "HSV", "LAB"))
78+
def test_equal_three_channels_four_bytes(mode):
79+
# The "A" and "B" values in LAB images are signed values from -128 to 127,
80+
# but we store them as unsigned values from 0 to 255, so we need to use
81+
# slightly different input bytes for LAB to get the same output.
82+
img_a = Image.new(mode, (1, 1), 0x00B3B231 if mode == "LAB" else 0x00333231)
83+
img_b = Image.new(mode, (1, 1), 0xFFB3B231 if mode == "LAB" else 0xFF333231)
84+
assert img_a.tobytes() == b"123"
85+
assert img_b.tobytes() == b"123"
86+
assert img_a.im == img_b.im
87+
88+
89+
@pytest.mark.parametrize("mode", ("LA", "La", "PA"))
90+
def test_equal_two_channels_four_bytes(mode):
91+
img_a = Image.new(mode, (1, 1), 0x32000031)
92+
img_b = Image.new(mode, (1, 1), 0x32FFFF31)
93+
assert img_a.tobytes() == b"12"
94+
assert img_b.tobytes() == b"12"
95+
assert img_a.im == img_b.im

0 commit comments

Comments
 (0)