fillFlood function
Fill the 4-connected shape containing x
,y
in the image src
with the
given color
.
Implementation
Image fillFlood(Image src, int x, int y, int color,
{num threshold = 0.0, bool compareAlpha = false}) {
final visited = Uint8List(src.width * src.height);
var srcColor = src.getPixel(x, y);
if (!compareAlpha) {
srcColor = setAlpha(srcColor, 0);
}
_TestPixel array;
if (threshold > 0) {
final lab =
rgbToLab(getRed(srcColor), getGreen(srcColor), getBlue(srcColor));
if (compareAlpha) {
lab.add(getAlpha(srcColor).toDouble());
}
array = (int y, int x) =>
visited[y * src.width + x] == 0 &&
_testPixelLabColorDistance(src, x, y, lab, threshold);
} else if (!compareAlpha) {
array = (int y, int x) =>
visited[y * src.width + x] == 0 &&
setAlpha(src.getPixel(x, y), 0) != srcColor;
} else {
array = (int y, int x) =>
visited[y * src.width + x] == 0 && src.getPixel(x, y) != srcColor;
}
void mark(int y, int x) {
src.setPixel(x, y, color);
visited[y * src.width + x] = 1;
}
_fill4(src, x, y, array, mark, visited);
return src;
}