maskFlood function
- Image src,
- int x,
- int y,
- {num threshold = 0.0,
- bool compareAlpha = false,
- int fillValue = 255}
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}) {
var visited = Uint8List(src.width * src.height);
var srcColor = src.getPixel(x, y);
if (!compareAlpha) {
srcColor = setAlpha(srcColor, 0);
}
var ret = Uint8List(src.width * src.height);
_TestPixel array;
if (threshold > 0) {
var lab = rgbToLab(getRed(srcColor), getGreen(srcColor), getBlue(srcColor));
if (compareAlpha) {
lab.add(getAlpha(srcColor).toDouble());
}
array = (int y, int x) {
return 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) {
return 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) {
return visited[y * src.width + x] == 0 &&
(ret[y * src.width + x] != 0 || src.getPixel(x, y) != srcColor);
};
}
_MarkPixel 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;
}