Self-Starting Fast Flood-Fill Algorithm
The follow implementation self-starts, and is also somewhat faster.
public void fillFast(int x, int y, int fill)
{
if ((x < 0) || (x >= raster.width)) return;
if ((y < 0) || (y >= raster.height)) return;
int old = raster.getPixel(x, y);
if (old == fill) return;
raster.setPixel(fill, x, y);
fillEast(x+1, y, fill, old);
fillSouth(x, y+1, fill, old);
fillWest(x-1, y, fill, old);
fillNorth(x, y-1, fill, old);
}
|