Ever been looking for a really fast flood fill algorithm? Here’s the solution. The implemented algorithm supports flood fill functionality for common images.
// Load image to fill.
Image image = loadImage(...);
// Create flood fill instance with image.
FloodFill floodFill = new FloodFill(image);
// Do some filling.
floodFill.fill(100, 100, Color.BLUE);
...
// Get the filled image.
image = floodFill.getImage();
Flood fill operations are really fast and happen directly within the writable raster of an image. The getImage() method does not copy any bytes and returns directly the changed image. The algorithm allows for a fill mask to be used; the image is filled using the borders of the mask. Antialiasing is supported. Pattern-fill has partially been implemented; checkboard only.
Note: There is still stuff to add such as pattern fill. Private methods need redesign, there is some redundancy for performance reasons.
The code is available at:
http://www.aevumobscurum.com/public/
If you want to see it in action, please go and join a game:
Webstart: http://www.aevumobscurum.com/original/webstart/AevumObscurum.jnlp
Website: http://www.aevumobscurum.com/original/index.html
And that’s how it looks:
http://www.aevumobscurum.com/original/image/screenshots/screenshot32.png