saturation function

RGBA saturation (RGBA color, num saturation)

Implementation

RGBA saturation(RGBA color, num saturation) {
  saturation = (saturation < -1) ? -1 : saturation;
  num gray = 0.2989 * color.red +
      0.5870 * color.green +
      0.1140 * color.blue; //weights from CCIR 601 spec
  return new RGBA(
    red:
        clampPixel((-gray * saturation + color.red * (1 + saturation)).round()),
    green: clampPixel(
        (-gray * saturation + color.green * (1 + saturation)).round()),
    blue: clampPixel(
        (-gray * saturation + color.blue * (1 + saturation)).round()),
    alpha: color.alpha,
  );
}