public static void adjustContrast(ColorMatrix cm, int value)
        {
            value = (int)cleanValue(value, 100);
            if (value == 0)
            {
                return;
            }
            float x;

            if (value < 0)
            {
                x = 127 + value / 100 * 127;
            }
            else
            {
                x = value % 1;
                if (x == 0)
                {
                    x = (float)DELTA_INDEX[value];
                }
                else
                {
                    x = (float)DELTA_INDEX[(value << 0)] * (1 - x)
                        + (float)DELTA_INDEX[(value << 0) + 1] * x;
                }
                x = x * 127 + 127;
            }

            float[] mat = new float[] {
                x / 127, 0, 0, 0, 0.5f * (127 - x), 0, x / 127, 0, 0, 0.5f * (127 - x), 0, 0,
                x / 127, 0, 0.5f * (127 - x), 0, 0, 0, 1, 0, 0, 0, 0, 0, 1
            };
            cm.PostConcat(new ColorMatrix(mat));
        }
        public static void adjustHue(ColorMatrix cm, float value)
        {
            value = cleanValue(value, 180f) / 180f * (float)Math.PI;
            if (value == 0)
            {
                return;
            }

            float cosVal = (float)Math.Cos(value);
            float sinVal = (float)Math.Sin(value);
            float lumR   = 0.213f;
            float lumG   = 0.715f;
            float lumB   = 0.072f;

            float[] mat = new float[] {
                lumR + cosVal * (1 - lumR) + sinVal * (-lumR),
                lumG + cosVal * (-lumG) + sinVal * (-lumG),
                lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0,
                lumR + cosVal * (-lumR) + sinVal * (0.143f),
                lumG + cosVal * (1 - lumG) + sinVal * (0.140f),
                lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0,
                lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)),
                lumG + cosVal * (-lumG) + sinVal * (lumG),
                lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f,
                0f, 1f
            };
            cm.PostConcat(new ColorMatrix(mat));
        }
        public static void adjustBrightness(ColorMatrix cm, float value)
        {
            value = cleanValue(value, 100);
            if (value == 0)
            {
                return;
            }

            float[] mat = new float[] {
                1, 0, 0, 0, value, 0, 1, 0, 0, value, 0, 0, 1, 0, value, 0, 0, 0, 1, 0, 0, 0, 0, 0,
                1
            };
            cm.PostConcat(new ColorMatrix(mat));
        }
예제 #4
0
            private int rotateColor(int color, float rad)
            {
                float deg = rad * 180 / (float)Math.PI;
                int   r   = Color.GetRedComponent(color);
                int   g   = Color.GetGreenComponent(color);
                int   b   = Color.GetBlueComponent(color);

                ColorMatrix cm  = new ColorMatrix();
                ColorMatrix tmp = new ColorMatrix();

                cm.SetRGB2YUV();
                tmp.SetRotate(0, deg);
                cm.PostConcat(tmp);
                tmp.SetYUV2RGB();
                cm.PostConcat(tmp);

                float[] a = cm.GetArray();

                int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b);
                int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b);
                int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b);

                return(Color.Argb(Color.GetAlphaComponent(color), pinToByte(ir), pinToByte(ig), pinToByte(ib)));
            }
        public static void adjustSaturation(ColorMatrix cm, float value)
        {
            value = cleanValue(value, 100);
            if (value == 0)
            {
                return;
            }

            float x    = 1 + ((value > 0) ? 3 * value / 100 : value / 100);
            float lumR = 0.3086f;
            float lumG = 0.6094f;
            float lumB = 0.0820f;

            float[] mat = new float[] {
                lumR *(1 - x) + x, lumG *(1 - x), lumB *(1 - x), 0, 0, lumR *(1 - x),
                lumG *(1 - x) + x, lumB *(1 - x), 0, 0, lumR *(1 - x), lumG *(1 - x),
                lumB *(1 - x) + x, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1
            };
            cm.PostConcat(new ColorMatrix(mat));
        }
예제 #6
0
        public ColorMatrix Create()
        {
            ColorMatrix cm = new ColorMatrix(new float[]
            {
                _contrast, 0, 0, 0, _brightness,
                0, _contrast, 0, 0, _brightness,
                0, 0, _contrast, 0, _brightness,
                0, 0, 0, _alpha, 0
            });

            AdjustHue(cm, _hue);
            //if (_saturation < 0.99f)
            {
                var cm2 = new ColorMatrix();
                cm2.SetSaturation(_saturation);
                cm.PostConcat(cm2);
                //cm.SetSaturation(_saturation);
            }

            return(cm);
        }