saturation function

void saturation(
  1. Uint8List bytes,
  2. num saturation
)

Implementation

void saturation(Uint8List bytes, num saturation) {
  saturation = (saturation < -1) ? -1 : saturation;
  for (int i = 0; i < bytes.length; i += 4) {
    num r = bytes[i], g = bytes[i + 1], b = bytes[i + 2];
    num gray =
        0.2989 * r + 0.5870 * g + 0.1140 * b; //weights from CCIR 601 spec
    bytes[i] =
        clampPixel((-gray * saturation + bytes[i] * (1 + saturation)).round());
    bytes[i + 1] = clampPixel(
        (-gray * saturation + bytes[i + 1] * (1 + saturation)).round());
    bytes[i + 2] = clampPixel(
        (-gray * saturation + bytes[i + 2] * (1 + saturation)).round());
  }
}