rgbToHSV function

  1. @override
({double h, double s, double v}) rgbToHSV(
  1. int r,
  2. int g,
  3. int b
)

Implementation

@override
({double h, double s, double v}) rgbToHSV(int r, int g, int b) {
  final red = r / 255;
  final green = g / 255;
  final blue = b / 255;

  final max = max3(red, green, blue);
  final min = min3(red, green, blue);
  final delta = max - min;

  final value = max;
  final saturation = max == 0 ? 0.0 : (delta / max);

  var hue = 0.0;
  {
    if (delta != 0) {
      if (max == red) {
        hue = ((green - blue) / delta) % 6;
      } else if (max == green) {
        hue = ((blue - red) / delta) + 2;
      } else {
        hue = ((red - green) / delta) + 4;
      }
    }

    hue *= 60;

    if (hue < 0) {
      hue += 360;
    }
  }

  return (h: hue, s: saturation, v: value);
}