mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 02:46:18 +03:00
Merge pull request #3325 from radarhere/imagedraw
Removed duplicate code
This commit is contained in:
commit
9dd09fa4bf
|
@ -351,34 +351,23 @@ def floodfill(image, xy, value, border=None, thresh=0):
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
return # seed point outside image
|
return # seed point outside image
|
||||||
edge = [(x, y)]
|
edge = [(x, y)]
|
||||||
if border is None:
|
while edge:
|
||||||
while edge:
|
newedge = []
|
||||||
newedge = []
|
for (x, y) in edge:
|
||||||
for (x, y) in edge:
|
for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
|
||||||
for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
|
try:
|
||||||
try:
|
p = pixel[s, t]
|
||||||
p = pixel[s, t]
|
except (ValueError, IndexError):
|
||||||
except (ValueError, IndexError):
|
pass
|
||||||
pass
|
else:
|
||||||
|
if border is None:
|
||||||
|
fill = _color_diff(p, background) <= thresh
|
||||||
else:
|
else:
|
||||||
if _color_diff(p, background) <= thresh:
|
fill = p != value and p != border
|
||||||
pixel[s, t] = value
|
if fill:
|
||||||
newedge.append((s, t))
|
pixel[s, t] = value
|
||||||
edge = newedge
|
newedge.append((s, t))
|
||||||
else:
|
edge = newedge
|
||||||
while edge:
|
|
||||||
newedge = []
|
|
||||||
for (x, y) in edge:
|
|
||||||
for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
|
|
||||||
try:
|
|
||||||
p = pixel[s, t]
|
|
||||||
except (ValueError, IndexError):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if p != value and p != border:
|
|
||||||
pixel[s, t] = value
|
|
||||||
newedge.append((s, t))
|
|
||||||
edge = newedge
|
|
||||||
|
|
||||||
|
|
||||||
def _color_diff(rgb1, rgb2):
|
def _color_diff(rgb1, rgb2):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user