mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
improved comments and one logic according to PR 3294 discussion
This commit is contained in:
parent
5e2d6c951a
commit
3cf1a4ea87
|
@ -352,7 +352,7 @@ def floodfill(image, xy, value, border=None, thresh=0):
|
|||
except (ValueError, IndexError):
|
||||
return # seed point outside image
|
||||
edge = {(x, y)}
|
||||
full_edge = set() # use a set to record each unique pixel processed
|
||||
full_edge = set() # use a set to keep record of current and previous edge pixels to reduce memory consumption
|
||||
while edge:
|
||||
new_edge = set()
|
||||
for (x, y) in edge: # 4 adjacent method
|
||||
|
@ -364,6 +364,7 @@ def floodfill(image, xy, value, border=None, thresh=0):
|
|||
except (ValueError, IndexError):
|
||||
pass
|
||||
else:
|
||||
full_edge.add((s, t))
|
||||
if border is None:
|
||||
fill = _color_diff(p, background) <= thresh
|
||||
else:
|
||||
|
@ -371,8 +372,7 @@ def floodfill(image, xy, value, border=None, thresh=0):
|
|||
if fill:
|
||||
pixel[s, t] = value
|
||||
new_edge.add((s, t))
|
||||
full_edge.add((s, t))
|
||||
full_edge = edge # do not record useless pixels to reduce memory consumption
|
||||
full_edge = edge # discard pixels proceeded
|
||||
edge = new_edge
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user