Skip to content

Commit c96bbf3

Browse files
committed
Use round()
1 parent 89beb8f commit c96bbf3

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

Tests/test_imagecolor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_color_hsv() -> None:
200200

201201

202202
@pytest.mark.parametrize("mode, premultiplied_mode", (("LA", "La"), ("RGBA", "RGBa")))
203-
@pytest.mark.parametrize("color", ("#f00", "#ff000080"))
203+
@pytest.mark.parametrize("color", ("#f00", "#ff000080", "#ff000050"))
204204
def test_color_premultiplied_alpha(
205205
mode: str, premultiplied_mode: str, color: str
206206
) -> None:

src/PIL/ImageColor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def getcolor(color: str, mode: str) -> int | tuple[int, ...]:
161161
else:
162162
value = rgb
163163
if mode[-1] == "a":
164-
# Rounded, to match convert()'s premultiplication.
165-
value = tuple((band * alpha + 127) // 255 for band in value)
164+
value = tuple(round(band * alpha / 255) for band in value)
166165
if mode[-1] in ("A", "a"):
167166
return value + (alpha,)
168167
return value[0] if len(value) == 1 else value

0 commit comments

Comments
 (0)