hslToRgb function

Color hslToRgb(
  1. HSLColor hsl
)

Implementation

Color hslToRgb(HSLColor hsl) {
  double r;
  double g;
  double b;
  final double h = bound01(hsl.hue, 360.0);
  final double s = bound01(hsl.saturation * 100, 100.0);
  final double l = bound01(hsl.lightness * 100, 100.0);

  if (s == 0.0) {
    r = g = b = l;
  } else {
    final q = l < 0.5 ? l * (1.0 + s) : l + s - l * s;
    final p = 2 * l - q;
    r = _hue2rgb(p, q, h + 1 / 3);
    g = _hue2rgb(p, q, h);
    b = _hue2rgb(p, q, h - 1 / 3);
  }
  return Color.fromARGB(
    hsl.alpha.round(),
    (r * 255).round(),
    (g * 255).round(),
    (b * 255).round(),
  );
}