Skip to content
Closed
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
8 changes: 8 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,14 @@ def test_floodfill(bbox: Coords) -> None:
assert_image_equal(im, Image.new("RGB", (1, 1), red))


@pytest.mark.parametrize("xy", ((-1, 1), (1, -1), (-1, -1), (-3, 0), (0, -3)))
def test_floodfill_negative_seed(xy: tuple[int, int]) -> None:
im = Image.new("RGB", (3, 3))
original = im.copy()
ImageDraw.floodfill(im, xy, (255, 0, 0))
assert_image_equal(im, original)


@pytest.mark.parametrize("bbox", BBOX)
def test_floodfill_border(bbox: Coords) -> None:
# floodfill() is experimental
Expand Down
6 changes: 6 additions & 0 deletions docs/releasenotes/13.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ TODO
Other changes
=============

Negative seed coordinates in ImageDraw.floodfill
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:py:func:`~PIL.ImageDraw.floodfill` now leaves the image unchanged when either
seed coordinate is negative, instead of wrapping around to the opposite edge.

Resizing I;16B and I;16N images
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ def floodfill(
pixel = image.load()
assert pixel is not None
x, y = xy
if x < 0 or y < 0:
return
try:
background = pixel[x, y]
if _color_diff(value, background) <= thresh:
Expand Down
Loading