hueRotation function

void hueRotation(
  1. Uint8List bytes,
  2. int degrees
)

Implementation

void hueRotation(Uint8List bytes, int degrees) {
  double U = cos(degrees * pi / 180);
  double W = sin(degrees * pi / 180);

  for (int i = 0; i < bytes.length; i += 4) {
    num r = bytes[i], g = bytes[i + 1], b = bytes[i + 2];
    bytes[i] = clampPixel(((.299 + .701 * U + .168 * W) * r +
            (.587 - .587 * U + .330 * W) * g +
            (.114 - .114 * U - .497 * W) * b)
        .round());
    bytes[i + 1] = clampPixel(((.299 - .299 * U - .328 * W) * r +
            (.587 + .413 * U + .035 * W) * g +
            (.114 - .114 * U + .292 * W) * b)
        .round());
    bytes[i + 2] = clampPixel(((.299 - .3 * U + 1.25 * W) * r +
            (.587 - .588 * U - 1.05 * W) * g +
            (.114 + .886 * U - .203 * W) * b)
        .round());
  }
}