Merge pull request #3325 from radarhere/imagedraw

Removed duplicate code
This commit is contained in:
Hugo 2018-09-01 13:41:20 +03:00 committed by GitHub
commit 9dd09fa4bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -351,31 +351,20 @@ 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)]
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 border is None: if border is None:
while edge: fill = _color_diff(p, background) <= thresh
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: else:
if _color_diff(p, background) <= thresh: fill = p != value and p != border
pixel[s, t] = value if fill:
newedge.append((s, t))
edge = newedge
else:
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 pixel[s, t] = value
newedge.append((s, t)) newedge.append((s, t))
edge = newedge edge = newedge