Efficient Boundary Fill
Seed Value x, y:
scanRight( y, x )
scanLeft( y, x – 1 )
ScanUp:
if y > 0 {
scan (y, x1, x2, ups)
if ( L blank) scanLeft ( y, x1 – 1 )
if ( R blank) scanRight ( y, x2 + 1 )
}
ScanDown:
if y <= maxy {
scan (y, x1, x2, downs)
if ( L blank) scanLeft ( y, x1 – 1 )
if ( R blank) scanRight ( y, x2 + 1 )
}
scan:
Finds spans and pushes them on stack to scanUp or ScanDown as requested, leaving pixel x1 in L and pixel x2 in R
scanLeft:
Pushes only one interval, if there is one, to scanUp & scanDown
scanRight:
Pushes only one interval, if there is one, to scanUp & scanDown