QColorMatrix ShearColor(int x, int y1, float d1, int y2, float d2, MatrixOrder order) { var multiplier = new QColorMatrix(); multiplier[x, y1] = d1; multiplier[x, y2] = d2; return(MultiplyBy(multiplier, order)); }
///<summary>Scales colors.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix Scale(float red, float green, float blue, float alpha, MatrixOrder order) { var multiplier = new QColorMatrix(); multiplier[0, 0] = red; multiplier[1, 1] = green; multiplier[2, 2] = blue; multiplier[3, 3] = alpha; return(MultiplyBy(multiplier, order)); }
///<summary>Translates colors.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix Translate(float red, float green, float blue, float alpha, MatrixOrder order) { var multiplier = new QColorMatrix(); multiplier[4, 0] = red; multiplier[4, 1] = green; multiplier[4, 2] = blue; multiplier[4, 3] = alpha; return(MultiplyBy(multiplier, order)); }
///<summary>Multiplies this matrix by another matrix in the specified order.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix MultiplyBy(QColorMatrix other, MatrixOrder order) { if (order == MatrixOrder.Append) { values = (this * other).values; } else { values = (other * this).values; } return(this); }
///<summary>Rotates colors by the given angle.</summary> ///<param name="phi">The angle to rotate by in degrees.</param> ///<param name="x">The X coordinate that receives the sin.</param> ///<param name="y">The Y coordinate that receives the sin.</param> ///<param name="order">The order to apply the rotation.</param> ///<returns>The original (modified) QColorMatrix.</returns> QColorMatrix RotateColor(float phi, int x, int y, MatrixOrder order) { phi *= (float)(Math.PI / 180); var multiplier = new QColorMatrix(); multiplier[x, x] = multiplier[y, y] = (float)Math.Cos(phi); var sin = (float)Math.Sin(phi); multiplier[x, y] = sin; multiplier[y, x] = -sin; return(MultiplyBy(multiplier, order)); }
///<summary>Sets the saturation.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix SetSaturation(float saturation, MatrixOrder order) { //if (saturation < 0 || saturation > 1) throw new ArgumentOutOfRangeException("saturation", "Saturation must be between zero and one"); // For the theory behind this, see the web sites at the top of this file. // In short: if saturation is 1.0f, m becomes the identity matrix, and this matrix is // unchanged. If saturation is 0.0f, each color is scaled by it's luminance weight. float satComplement = 1.0f - saturation; float satComplR = satComplement * LuminanceRed; float satComplG = satComplement * LuminanceGreen; float satComplB = satComplement * LuminanceBlue; var multiplier = new QColorMatrix(new[] { new [] { satComplR + saturation, satComplR, satComplR, 0.0f, 0.0f }, new [] { satComplG, satComplG + saturation, satComplG, 0.0f, 0.0f }, new [] { satComplB, satComplB, satComplB + saturation, 0.0f, 0.0f }, new [] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, new [] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }); return(MultiplyBy(multiplier, order)); }
public static QColorMatrix operator *(QColorMatrix left, QColorMatrix right) { if (left == null || right == null) { return(null); } var retVal = new QColorMatrix(); for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { retVal[x, y] = 0; for (int i = 0; i < 5; i++) { retVal[x, y] += left[i, y] * right[x, i]; } } } return(retVal); }
QColorMatrix ShearColor(int x, int y1, float d1, int y2, float d2, MatrixOrder order) { var multiplier = new QColorMatrix(); multiplier[x, y1] = d1; multiplier[x, y2] = d2; return MultiplyBy(multiplier, order); }
///<summary>Multiplies this matrix by another matrix by prepending the other matrix.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix MultiplyBy(QColorMatrix other) { return(MultiplyBy(other, MatrixOrder.Prepend)); }
///<summary>Translates colors.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix Translate(float red, float green, float blue, float alpha, MatrixOrder order) { var multiplier = new QColorMatrix(); multiplier[4, 0] = red; multiplier[4, 1] = green; multiplier[4, 2] = blue; multiplier[4, 3] = alpha; return MultiplyBy(multiplier, order); }
///<summary>Rotates colors by the given angle.</summary> ///<param name="phi">The angle to rotate by in degrees.</param> ///<param name="x">The X coordinate that receives the sin.</param> ///<param name="y">The Y coordinate that receives the sin.</param> ///<param name="order">The order to apply the rotation.</param> ///<returns>The original (modified) QColorMatrix.</returns> QColorMatrix RotateColor(float phi, int x, int y, MatrixOrder order) { phi *= (float)(Math.PI / 180); var multiplier = new QColorMatrix(); multiplier[x, x] = multiplier[y, y] = (float)Math.Cos(phi); var sin = (float)Math.Sin(phi); multiplier[x, y] = sin; multiplier[y, x] = -sin; return MultiplyBy(multiplier, order); }
///<summary>Sets the saturation.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix SetSaturation(float saturation, MatrixOrder order) { //if (saturation < 0 || saturation > 1) throw new ArgumentOutOfRangeException("saturation", "Saturation must be between zero and one"); // For the theory behind this, see the web sites at the top of this file. // In short: if saturation is 1.0f, m becomes the identity matrix, and this matrix is // unchanged. If saturation is 0.0f, each color is scaled by it's luminance weight. float satComplement = 1.0f - saturation; float satComplR = satComplement * LuminanceRed; float satComplG = satComplement * LuminanceGreen; float satComplB = satComplement * LuminanceBlue; var multiplier = new QColorMatrix(new[] { new [] { satComplR + saturation, satComplR, satComplR, 0.0f, 0.0f }, new [] { satComplG, satComplG + saturation, satComplG, 0.0f, 0.0f }, new [] { satComplB, satComplB, satComplB + saturation, 0.0f, 0.0f }, new [] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, new [] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }); return MultiplyBy(multiplier, order); }
///<summary>Scales colors.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix Scale(float red, float green, float blue, float alpha, MatrixOrder order) { var multiplier = new QColorMatrix(); multiplier[0, 0] = red; multiplier[1, 1] = green; multiplier[2, 2] = blue; multiplier[3, 3] = alpha; return MultiplyBy(multiplier, order); }
///<summary>Multiplies this matrix by another matrix in the specified order.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix MultiplyBy(QColorMatrix other, MatrixOrder order) { if (order == MatrixOrder.Append) values = (this * other).values; else values = (other * this).values; return this; }
///<summary>Multiplies this matrix by another matrix by prepending the other matrix.</summary> ///<returns>The original (modified) QColorMatrix.</returns> public QColorMatrix MultiplyBy(QColorMatrix other) { return MultiplyBy(other, MatrixOrder.Prepend); }
public static QColorMatrix operator *(QColorMatrix left, QColorMatrix right) { if (left == null || right == null) return null; var retVal = new QColorMatrix(); for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { retVal[x, y] = 0; for (int i = 0; i < 5; i++) retVal[x, y] += left[i, y] * right[x, i]; } } return retVal; }