예제 #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);
        }
예제 #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);
        }
예제 #3
0
 private void Copy(QColorMatrix qm)
 {
     if (qm == null)
     {
         Reset();
         return;
     }
     Copy(qm.m);
 }
예제 #4
0
 /// <summary>
 /// Sets the current color matrix using a provided color matrix
 /// </summary>
 /// <param name="dmtx">The provided color matrix</param>
 private void SetColorMatrix(QColorMatrix clrmtx)
 {
     for (int i = 0; i < 5; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             this.Matrix[i, j] = clrmtx.Matrix[i, j];
         }
     }
 }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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];
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Scale the RGB and opacity to the provided values
        /// </summary>
        /// <param name="scaleRed">Red scale value</param>
        /// <param name="scaleGreen">Green scale value</param>
        /// <param name="scaleBlue">Blue scale value</param>
        /// <param name="scaleOpacity">Opacity scale value</param>
        /// <returns>True if successfull, otherwise false</returns>
        public bool Scale2(float scaleRed, float scaleGreen, float scaleBlue, float scaleOpacity)
        {
            try
            {
                QColorMatrix qm = new QColorMatrix();

                qm.Matrix[0, 0] = scaleRed;
                qm.Matrix[1, 1] = scaleGreen;
                qm.Matrix[2, 2] = scaleBlue;
                qm.Matrix[3, 3] = scaleOpacity;

                //ORIGINAL: this.SetColorMatrix(new ColorMatrixExt(this * dcmtx));

                this.Multiply(qm);
                //this.SetColorMatrix(new QColorMatrix(qm.Matrix));
                this.SetColorMatrix(this);
            }
            catch (IndexOutOfRangeException)
            {
                return(false);
            }

            return(true);
        }
예제 #10
0
 public QColorMatrix(QColorMatrix qm)
 {
     Copy(qm);
 }
예제 #11
0
 public void Multiply(QColorMatrix matrix)
 {
     Multiply(matrix, MatrixOrder2.MatrixOrderPrepend);
 }