private void ShearColor(int x, int y1, float d1, int y2, float d2, MatrixOrder order)
        {
            QColorMatrix qm = new QColorMatrix();

            qm.m[y1, x] = d1;
            qm.m[y2, x] = d2;
            Multiply(qm, order);
        }
 private void Copy(QColorMatrix qm)
 {
     if (qm == null)
     {
         Reset();
         return;
     }
     Copy(qm.m);
 }
        public void Translate(float offsetRed, float offsetGreen, float offsetBlue,
                              float offsetOpacity, MatrixOrder order)
        {
            QColorMatrix qm = new QColorMatrix();

            qm.m[4, 0] = offsetRed;
            qm.m[4, 1] = offsetGreen;
            qm.m[4, 2] = offsetBlue;
            qm.m[4, 3] = offsetOpacity;
            Multiply(qm, order);
        }
        public void Scale(float scaleRed, float scaleGreen, float scaleBlue,
                          float scaleOpacity, MatrixOrder order)
        {
            QColorMatrix qm = new QColorMatrix();

            qm.m[0, 0] = scaleRed;
            qm.m[1, 1] = scaleGreen;
            qm.m[2, 2] = scaleBlue;
            qm.m[3, 3] = scaleOpacity;
            Multiply(qm, order);
        }
        /// <summary>
        /// x and y are the indices of the value to receive the sin(phi) value
        /// </summary>
        /// <param name="phi">phi is in degrees</param>
        private void RotateColor(float phi, int x, int y, MatrixOrder order)
        {
            phi *= rad;
            QColorMatrix qm = new QColorMatrix();

            qm.m[x, x] = qm.m[y, y] = (float)Math.Cos(phi);

            float s = (float)Math.Sin(phi);

            qm.m[y, x] = s;
            qm.m[x, y] = -s;

            Multiply(qm, order);
        }
        /// <summary>
        /// Unlike the original C++ code we multiply all value here.
        /// </summary>
        public void Multiply(QColorMatrix matrix, MatrixOrder order)
        {
            if (matrix == null)
            {
                throw new ArgumentException();
            }
            float[,] a = null;
            float[,] b = null;

            if (order == MatrixOrder.MatrixOrderAppend)
            {
                a = matrix.m;
                b = m;
            }
            else
            {
                a = m;
                b = matrix.m;
            }

            float[,] temp = new float[MatrixLength, MatrixLength];
            for (int y = 0; y < MatrixLength; y++)
            {
                for (int x = 0; x < MatrixLength; x++)
                {
                    float t = 0;
                    for (int i = 0; i < MatrixLength; i++)
                    {
                        t += b[y, i] * a[i, x];
                    }
                    temp[y, x] = t;
                }
            }
            for (int y = 0; y < MatrixLength; y++)
            {
                for (int x = 0; x < MatrixLength; x++)
                {
                    m[y, x] = temp[y, x];
                }
            }
        }
        /// <summary>
        /// Set the saturation of the matrix. Saturation of 0.0f yields B&W, 1.0f is neutral.
        /// </summary>
        public void SetSaturation(float saturation, MatrixOrder order)
        {
            // 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 satCompl  = 1.0f - saturation;
            float satComplR = lumR * satCompl;
            float satComplG = lumG * satCompl;
            float satComplB = lumB * satCompl;

            float[,] tm = new float[, ]
            {
                { satComplR + saturation, satComplR, satComplR, 0.0f, 0.0f },
                { satComplG, satComplG + saturation, satComplG, 0.0f, 0.0f },
                { satComplB, satComplB, satComplB + saturation, 0.0f, 0.0f },
                { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
                { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
            };

            QColorMatrix qm = new QColorMatrix(tm);

            Multiply(qm, order);
        }
 public void Multiply(QColorMatrix matrix)
 {
     Multiply(matrix, MatrixOrder.MatrixOrderPrepend);
 }
 public QColorMatrix(QColorMatrix qm)
 {
     Copy(qm);
 }