luminance property

double get luminance

Returns the WCAG relative luminance of this color (0..1).

Implementation

double get luminance {
  double linearize(double c) {
    return c <= 0.03928
        ? c / 12.92
        : ((c + 0.055) / 1.055) * ((c + 0.055) / 1.055);
  }

  final r = linearize((this.r * 255.0).round().clamp(0, 255) / 255);
  final g = linearize((this.g * 255.0).round().clamp(0, 255) / 255);
  final b = linearize((this.b * 255.0).round().clamp(0, 255) / 255);
  return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}