cie76Flooding method

Future<Image> cie76Flooding({
  1. required Offset offset,
  2. required Color fillColor,
  3. double tolerance = 2.3,
  4. bool isDispose = false,
})

Image cie76 flood.

@offset The starting point for image flooding.

@fillColor The fill color of the image flood, in RGB format.

@tolerance Color tolerance for image flooding, defaults to 2.3.

@isDispose Whether to release the original image after image flooding.

Implementation

Future<Image> cie76Flooding({
  required Offset offset,
  required Color fillColor,
  double tolerance = 2.3,
  bool isDispose = false,
}) async {
  final Uint32List? uint32list = await uint32List();
  if (uint32list == null || uint32list.isEmpty) return this;
  final int dx = offset.dx.floor();
  final int dy = offset.dy.floor();
  if (dx < 0 || dx == width || dy < 0 || dy == height) return this;
  final int index = (width * dy + dx).clamp(0, uint32list.length - 1);
  final LABColor collectionColor = uint32list[index].uInt32toColor.labColor;
  if (!collectionColor.cie76ColorDifference(fillColor.labColor,
      tolerance: tolerance)) return this;
  final Completer<Image> completer = Completer();
  _floodingMethod(
      uint32list,
      fillColor.rgbaUInt32,
      width,
      height,
      IntOffset(dx, dy),
      (color) => collectionColor.cie76ColorDifference(color.labColor,
          tolerance: tolerance));
  decodeImageFromPixels(
      uint32list.buffer.asUint8List(), width, height, PixelFormat.rgba8888,
      (result) {
    completer.complete(result);
  });
  if (isDispose) dispose();
  return completer.future;
}