Optimized flood fill routine.