Exemplo n.º 1
0
        /// <summary>
        /// Set the saturation of the matrix. Saturation of 0.0f yields B&W, 1.0f is neutral.
        /// </summary>
        public void SetSaturation(float saturation, MatrixOrder2 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 }
            };

            //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);
        }
Exemplo n.º 2
0
        private void ShearColor(int x, int y1, float d1, int y2, float d2, MatrixOrder2 order)
        {
            QColorMatrix qm = new QColorMatrix();

            qm.m[y1, x] = d1;
            qm.m[y2, x] = d2;
            Multiply(qm, order);
        }
Exemplo n.º 3
0
        public void Translate(float offsetRed, float offsetGreen, float offsetBlue,
                              float offsetOpacity, MatrixOrder2 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);
        }
Exemplo n.º 4
0
        public void Scale(float scaleRed, float scaleGreen, float scaleBlue,
                          float scaleOpacity, MatrixOrder2 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);
        }
Exemplo n.º 5
0
        /// <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, MatrixOrder2 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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Unlike the original C++ code we multiply all value here.
        /// </summary>
        public void Multiply(QColorMatrix matrix, MatrixOrder2 order)
        {
            if (matrix == null)
            {
                throw new ArgumentException("Multiply");
            }
            float[,] a;
            float[,] b;

            if (order == MatrixOrder2.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];
                }
            }
        }
Exemplo n.º 7
0
 public void ShearBlue(float red, float green, MatrixOrder2 order)
 {
     ShearColor(2, 0, red, 1, green, order);
 }
Exemplo n.º 8
0
 public void ShearGreen(float red, float blue, MatrixOrder2 order)
 {
     ShearColor(1, 0, red, 2, blue, order);
 }
Exemplo n.º 9
0
 public void ShearRed(float green, float blue, MatrixOrder2 order)
 {
     ShearColor(0, 1, green, 2, blue, order);
 }
Exemplo n.º 10
0
 public void RotateBlue(float phi, MatrixOrder2 order)
 {
     RotateColor(phi, 1, 0, order);
 }
Exemplo n.º 11
0
 public void RotateGreen(float phi, MatrixOrder2 order)
 {
     RotateColor(phi, 0, 2, order);
 }
Exemplo n.º 12
0
 public void RotateRed(float phi, MatrixOrder2 order)
 {
     RotateColor(phi, 2, 1, order);
 }
Exemplo n.º 13
0
 public void TranslateOpacity(float offsetOpacity, MatrixOrder2 order)
 {
     Translate(0.0f, 0.0f, 0.0f, offsetOpacity, order);
 }
Exemplo n.º 14
0
 public void TranslateColors(float offset, MatrixOrder2 order)
 {
     Translate(offset, offset, offset, 0.0f, order);
 }
Exemplo n.º 15
0
 public void ScaleOpacity(float scaleOpacity, MatrixOrder2 order)
 {
     Scale(1.0f, 1.0f, 1.0f, scaleOpacity, order);
 }
Exemplo n.º 16
0
 public void ScaleColors(float scale, MatrixOrder2 order)
 {
     Scale(scale, scale, scale, 1.0f, order);
 }