maskFlood function

Uint8List maskFlood(
  1. Image src,
  2. int x,
  3. int y,
  4. {num threshold = 0.0,
  5. bool compareAlpha = false,
  6. 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}) {
  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;
}