cie94Flooding method

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

Image cie94 flood.

@offset The starting point for image flooding.

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

@colorImageStyle: colorImageStyle is an enumeration type of the color image style. For more detailed content, see ColorImageStyle.

@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.

@sl: sl is a constant that adjusts the influence of the L* component (luminance). The value of sl is usually 1, which is mainly used to adjust the influence of the L* component to better match the perception of the human visual system. Since the perception of brightness by human eyes is more sensitive than that of chroma, it is necessary to accurately evaluate the perception of color difference by adjusting the value of sl.

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

Implementation

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