static HueMatricies() { // Rotating the hue of an image is a rather convoluted task, involving several matrix // multiplications. For efficiency, we prepare two static matrices. // This is by far the most complicated part of this class. For the background // theory, refer to the sgi-sites mentioned at the top of this file. // Prepare the preHue matrix. // Rotate the grey vector in the green plane. PreHue.RotateRed(45.0f); // Next, rotate it again in the green plane, so it coincides with the blue axis. PreHue.RotateGreen(-greenRotation, MatrixOrder.Append); // Hue rotations keep the color luminations constant, so that only the hues change // visible. To accomplish that, we shear the blue plane. var lum = PreHue.TransformVector(LuminanceRed, LuminanceGreen, LuminanceBlue, 1.0f); // Transform the luminance vector. // Calculate the shear factors for red and green. float red = lum[0] / lum[2]; float green = lum[1] / lum[2]; // Shear the blue plane. PreHue.ShearBlue(red, green, MatrixOrder.Append); // Prepare the postHue matrix. This holds the opposite transformations of the // preHue matrix. In fact, postHue is the inversion of preHue. PostHue.ShearBlue(-red, -green); PostHue.RotateGreen(greenRotation, MatrixOrder.Append); PostHue.RotateRed(-45.0f, MatrixOrder.Append); }