Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Tests/test_imageops.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,13 @@ def autocontrast(cutoff: int | tuple[int, int]) -> list[int]:
assert autocontrast(10) != autocontrast((1, 10))


@pytest.mark.parametrize("cutoff", ((), (10,), (10, 10, 10)))
def test_autocontrast_invalid_cutoff(cutoff: tuple[int, ...]) -> None:
im = Image.new("L", (1, 1))
with pytest.raises(ValueError, match="cutoff must be either a tuple"):
ImageOps.autocontrast(im, cutoff=cutoff) # type: ignore[arg-type]


@pytest.mark.parametrize("ignore", (-1, 256, [0, -1], [0, 256]))
def test_autocontrast_invalid_ignore(ignore: int | list[int]) -> None:
im = Image.new("L", (1, 1))
Expand Down
6 changes: 6 additions & 0 deletions src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def autocontrast(

:return: An image.
"""
if isinstance(cutoff, tuple) and len(cutoff) != 2:
msg = ( # type: ignore[unreachable]
"cutoff must be either a tuple of (low, high), or a single number for both"
)
raise ValueError(msg)

if ignore is not None:
if isinstance(ignore, int):
ignore = (ignore,)
Expand Down
Loading