
Access pattern is not cache-friendly, for the queuing variant.Not suitable for pattern filling, as it requires pixel test results to change.Tests most filled pixels a total of four times.Uses a lot of memory, particularly when using a stack.Very simple algorithm - easy to make bug-free.Use multiple threads (ideally with slightly different visiting orders, so they don't stay in the same area).
Blacksmith3d 6 flood fill not working code#
Interleave two or more copies of the code with extra stacks/queues, to allow out-of-order processors more opportunity to parallelize. Use a loop for the east/west directions, queuing pixels above/below as you go (making it similar to the span filling algorithms, below). Check and set each node's pixel color before adding it to the stack/queue, reducing stack/queue size. Set n equal to the first element of Q.Īdd the node to the west of n to the end of Q.Īdd the node to the east of n to the end of Q.Īdd the node to the north of n to the end of Q.Īdd the node to the south of n to the end of Q.ħ. Moving the recursion into a data structure Ĥ. Though easy to understand, the implementation of the algorithm used above is impractical in languages and environments where stack space is severely constrained (e.g. Perform Flood-fill one step to the east of node Perform Flood-fill one step to the west of nodeĦ. Perform Flood-fill one step to the north of nodeĥ. Perform Flood-fill one step to the south of node.Ĥ. The earliest-known, implicitly stack-based, recursive, four-way flood-fill implementation goes as follows: Flood-fill (node):ģ. Stack-based recursive implementation (four-way) Any node that has Set called on it must then no longer be Inside.ĭepending on whether we consider nodes touching at the corners connected or not, we have two variations: eight-way and four-way respectively. One called Inside which returns true for unfilled points that, by their color, would be inside the filled area, and one called Set which fills a pixel/node. In order to generalize the algorithm in the common way, the following descriptions will instead have two routines available. For a boundary-fill, in place of the target color, a border color would be supplied. The algorithm looks for all nodes in the array that are connected to the start node by a path of the target color and changes them to the replacement color.
The traditional flood-fill algorithm takes three parameters: a start node, a target color, and a replacement color.