maskFlood function Null safety

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);

  var 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(getRed(srcColor), getGreen(srcColor), getBlue(srcColor));

    if (compareAlpha) {
      lab.add(getAlpha(srcColor).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;
}