Algorithm, Flood Fill ( Depth First Search )
<p>I'm working with Java.<br>
I'm developing a paint program, the "Paint Can" tool is using a Flood Fill algorithm, but it is too expensive.</p>

<p>Here is the code:</p>

<pre><code>private int[] dx = { -1, 0, 1, 0 };
private int[] dy = { 0, 1, 0, -1 };

public void floodFill(int x, int y, Color target_color, Color replacement_color) {
    Stack&lt;Integer[]&gt; stack = new Stack&lt;Integer[]&gt;();
    if (imageBuffer.getRGB(x, y) == replacement_color.getRGB())
         return;
    stack.push(new Integer[] { x, y });
    while (!stack.isEmpty()) {
        Integer[] aux = stack.peek();
        imageBuffer.setRGB(aux[0], aux[1], replacement_color.getRGB());
        stack.pop();
        for (int i = 0; i &lt; 4; i++) {
            if (imageBuffer.getRGB(aux[0] + dx[i], aux[1] + dy[i]) == target_color.getRGB())
                stack.push(new Integer[] { aux[0] + dx[i], aux[1] + dy[i] });
        }

    }
}
</code></pre>

<p>Can someone help me make this more efficient?</p>

<p>It takes (for 1020x700 pixel image) about 1200ms to execute.</p>
