calculateLuminance static method

double calculateLuminance(
  1. Color color
)

Calculate the luminance of an Color object.

Implementation

static double calculateLuminance(Color color) {
  double? r = color.red / 255.0;
  double? g = color.green / 255.0;
  double? b = color.blue / 255.0;

  // Apply gamma correction
  r = (r <= 0.03928 ? r / 12.92 : pow(2.4, (r + 0.055) / 1.055) as double?);
  g = (g <= 0.03928 ? g / 12.92 : pow((g + 0.055) / 1.055, 2.4)) as double?;
  b = (b <= 0.03928 ? b / 12.92 : pow((b + 0.055) / 1.055, 2.4)) as double?;

  return 0.2126 * r! + 0.7152 * g! + 0.0722 * b!;
}