toRgbColor method

  1. @override
RgbColor toRgbColor()
override

Implementation

@override
RgbColor toRgbColor() {
  num x = this.x / 100;
  num y = this.y / 100;
  num z = this.z / 100;

  var rgb = <String, num>{
    'r': x * 3.2406 + y * -1.5372 + z * -0.4986,
    'g': x * -0.9689 + y * 1.8758 + z * 0.0415,
    'b': x * 0.0557 + y * -0.2040 + z * 1.0570
  };

  rgb.forEach((key, value) {
    if (value > 0.0031308) {
      rgb[key] = 1.055 * pow(value, 1 / 2.4) - 0.055;
    } else {
      rgb[key] = value * 12.92;
    }
    rgb[key] = rgb[key]! * 255;
  });

  return RgbColor(rgb['r']!, rgb['g']!, rgb['b']!);
}