maskFlood function
Create a mask describing the 4-connected shape containing x
,y
in the
image src
.
Implementation
Uint8List maskFlood(Image src, int x, int y,
{num threshold = 0.0, bool compareAlpha = false, int fillValue = 255}) {
final visited = Uint8List(src.width * src.height);
Color srcColor = src.getPixel(x, y);
if (!compareAlpha) {
srcColor = _setAlpha(srcColor, 0);
}
final ret = Uint8List(src.width * src.height);
_TestPixel array;
if (threshold > 0) {
final lab = rgbToLab(srcColor.r, srcColor.g, srcColor.b);
if (compareAlpha) {
lab.add(srcColor.a.toDouble());
}
array = (int y, int x) =>
visited[y * src.width + x] == 0 &&
(ret[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 &&
(ret[y * src.width + x] != 0 ||
_setAlpha(src.getPixel(x, y), 0) != srcColor);
} else {
array = (int y, int x) =>
visited[y * src.width + x] == 0 &&
(ret[y * src.width + x] != 0 || src.getPixel(x, y) != srcColor);
}
void mark(int y, int x) {
ret[y * src.width + x] = fillValue;
visited[y * src.width + x] = 1;
}
_fill4(src, x, y, array, mark, visited);
return ret;
}