ciede2000Flooding method

Future<Image> ciede2000Flooding({
  1. required Offset offset,
  2. required Color fillColor,
  3. double tolerance = 2.3,
  4. double kc = 1.0,
  5. double kh = 1.0,
  6. double kl = 1.0,
  7. bool isDispose = false,
})

Image ciede2000 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.

@kc: kc is a constant that adjusts the weight for color difference perception. The value of c depends on the color system used. When using the Lab* color space, the value of kc is usually 1. If other color spaces are used, it may be necessary to use different values of kc to obtain a more accurate assessment of color differences.

@kh: kh is a constant that adjusts the weight for brightness difference perception. kh is mainly used to adjust the effect of brightness changes on the evaluation of color differences. It measures the relationship between changes in brightness and how sensitive the human eye is to changes in color. The value of kh depends on the color system used. When using the Lab* color space, the value of kh is usually 1. If you use other color spaces, you may need to use different kh values to get a more accurate assessment of color differences.

@kl: kl is the tuning parameter of the photometric reflectance weighting function. kL is mainly used to control the influence of brightness on chromatic aberration, and the value range of kL is between 1.0 and 2.0.

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

Implementation

Future<Image> ciede2000Flooding({
  required Offset offset,
  required Color fillColor,
  double tolerance = 2.3,
  double kc = 1.0,
  double kh = 1.0,
  double kl = 1.0,
  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.ciede2000ColorDifference(
    fillColor.labColor,
    tolerance: tolerance,
    kc: kc,
    kh: kh,
    kl: kl,
  )) return this;
  final Completer<Image> completer = Completer();
  _floodingMethod(
    uint32list,
    fillColor.rgbaUInt32,
    width,
    height,
    IntOffset(dx, dy),
    (color) => collectionColor.ciede2000ColorDifference(
      color.labColor,
      tolerance: tolerance,
      kc: kc,
      kh: kh,
      kl: kl,
    ),
  );
  decodeImageFromPixels(
      uint32list.buffer.asUint8List(), width, height, PixelFormat.rgba8888,
      (result) {
    completer.complete(result);
  });
  if (isDispose) dispose();
  return completer.future;
}