colorLuminance function

double colorLuminance(
  1. TrueColor color
)

Function that calculates the TrueColor luminance and returns a value between 0.0 and 1.0. Being 0.0 black and 1.0 white.

Implementation

double colorLuminance(TrueColor color) {
  final rsRGB = color.r / 255.0;
  final gsRGB = color.g / 255.0;
  final bsRGB = color.b / 255.0;

  final r = (rsRGB <= 0.03928) ? rsRGB / 12.92 : math.pow((rsRGB + 0.055) / 1.055, 2.4);
  final g = (gsRGB <= 0.03928) ? gsRGB / 12.92 : math.pow((gsRGB + 0.055) / 1.055, 2.4);
  final b = (bsRGB <= 0.03928) ? bsRGB / 12.92 : math.pow((bsRGB + 0.055) / 1.055, 2.4);

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