mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Do not allow floodfill to extend into negative coordinates
This commit is contained in:
parent
6de118abd3
commit
23872c0645
BIN
Tests/images/imagedraw_floodfill_not_negative.png
Normal file
BIN
Tests/images/imagedraw_floodfill_not_negative.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 B |
|
@ -559,6 +559,24 @@ class TestImageDraw(PillowTestCase):
|
|||
# Assert
|
||||
self.assert_image_equal(im, Image.open("Tests/images/imagedraw_floodfill2.png"))
|
||||
|
||||
def test_floodfill_not_negative(self):
|
||||
# floodfill() is experimental
|
||||
# Test that floodfill does not extend into negative coordinates
|
||||
|
||||
# Arrange
|
||||
im = Image.new("RGB", (W, H))
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.line((W / 2, 0, W / 2, H / 2), fill="green")
|
||||
draw.line((0, H / 2, W / 2, H / 2), fill="green")
|
||||
|
||||
# Act
|
||||
ImageDraw.floodfill(im, (int(W / 4), int(H / 4)), ImageColor.getrgb("red"))
|
||||
|
||||
# Assert
|
||||
self.assert_image_equal(
|
||||
im, Image.open("Tests/images/imagedraw_floodfill_not_negative.png")
|
||||
)
|
||||
|
||||
def create_base_image_draw(
|
||||
self, size, mode=DEFAULT_MODE, background1=WHITE, background2=GRAY
|
||||
):
|
||||
|
|
|
@ -437,8 +437,9 @@ def floodfill(image, xy, value, border=None, thresh=0):
|
|||
new_edge = set()
|
||||
for (x, y) in edge: # 4 adjacent method
|
||||
for (s, t) in ((x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)):
|
||||
if (s, t) in full_edge:
|
||||
continue # if already processed, skip
|
||||
# If already processed, or if a coordinate is negative, skip
|
||||
if (s, t) in full_edge or s < 0 or t < 0:
|
||||
continue
|
||||
try:
|
||||
p = pixel[s, t]
|
||||
except (ValueError, IndexError):
|
||||
|
|
Loading…
Reference in New Issue
Block a user