Efficient Boundary Fill








Seed Value x, y:

  1. scanRight( y, x )

  2. scanLeft( y, x – 1 )


ScanUp:




  1. if y > 0 {

  2. scan (y, x1, x2, ups)

  3. if ( L blank) scanLeft ( y, x1 – 1 )

  4. if ( R blank) scanRight ( y, x2 + 1 )

  5. }



ScanDown:



  1. if y <= maxy {

  2. scan (y, x1, x2, downs)

  3. if ( L blank) scanLeft ( y, x1 – 1 )

  4. if ( R blank) scanRight ( y, x2 + 1 )

  5. }


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