I wrote a classic queue floodfill:
public static void floodFill(int y, int x, byte originalvalue, byte newvalue, byte[][] arr) {
Deque queue = new ArrayDeque();
queue.add(new int[]{y, x});
while (!queue.isEmpty()) {
int[] t = (int[]) queue.poll();
y = t[0];
x = t[1];
if (arr[y][x] == originalvalue) {
arr[y][x] = newvalue;
for (int i = 0; i < 8; i++) {
if (x + dx[i] < arr[0].length && y + dy[i] < arr.length && x + dx[i] > -1 && y + dy[i] > -1 && arr[y + dy[i]][x + dx[i]] == originalvalue) {
queue.add(new int[]{y + dy[i], x + dx[i]});
}
}
}
}
}
And now I want to write scan line Flood Fill, which is much faster. I can't find any pseudocode, and I don't understand this code.
Can you help me optimize my flood fill or write scan line one?
I call this flood fill for a byte array with dimensions 1000–2000 by 1000–2000 (not necessarily square) for a large area once, and then about 1000 to 1,000,000 times for smaller areas.