grayscale method

VisualEffect<ContainerLayer> grayscale(
  1. double amount
)

Implementation

VisualEffect grayscale(double amount) {
  if (amount == 0) {
    return this;
  }

  final effectiveValue = 1 - amount.clamp(0.0, 1.0);

  final a = 0.2126 + 0.7874 * effectiveValue;
  final b = 0.7152 - 0.7152 * effectiveValue;
  final c = 0.0722 - 0.0722 * effectiveValue;
  final f = 0.2126 - 0.2126 * effectiveValue;
  final g = 0.7152 + 0.2848 * effectiveValue;
  final h = c;
  final k = f;
  final l = b;
  final m = 0.0722 + 0.9278 * effectiveValue;

  // See: https://www.w3.org/TR/filter-effects-1/#grayscaleEquivalent
  final colorFilter = ColorFilter.matrix(
    [
      a, b, c, 0, 0,
      //
      f, g, h, 0, 0,
      //
      k, l, m, 0, 0,
      //
      0, 0, 0, 1, 0,
    ],
  );

  return _ColorFilterVisualEffect(
    colorFilter: colorFilter,
    childSize: childSize,
    childEffect: this,
  );
}