예제 #1
0
        public void ChangeHue(double hue, double saturation, double lightness, List <IUndoRedo> undos, bool hueSet = false, int variance = 0)
        {
            var r_command = GetCommand("Color", "R");
            var g_command = GetCommand("Color", "G");
            var b_command = GetCommand("Color", "B");

            foreach (var r in r_command.Keyframes)
            {
                var g = g_command.GetValue(r.Time);
                var b = b_command.GetValue(r.Time);

                var      hslColor = new RgbColor(r.Value, g, b).ToHsl();
                RgbColor convertedColor;

                if (hueSet)
                {
                    hslColor.SetHue(hue, variance);
                }
                else
                {
                    hslColor.ChangeHue(hue);
                    hslColor.ChangeSaturation(saturation);
                    hslColor.ChangeLightness(lightness);
                }

                convertedColor = hslColor.ToRgb();

                r_command.SetValue(r.Time, (float)convertedColor.R, undos);
                g_command.SetValue(r.Time, (float)convertedColor.G, undos);
                b_command.SetValue(r.Time, (float)convertedColor.B, undos);
            }
        }
예제 #2
0
        private void ChangeHueForAnimations(double hue, double saturation, double lightness, Type0.Parameter parameter)
        {
            Type0 r = Type0.FirstOrDefault(e => e.I_01_a == ECF.Type0.Component.R && e.I_00 == parameter);
            Type0 g = Type0.FirstOrDefault(e => e.I_01_a == ECF.Type0.Component.G && e.I_00 == parameter);
            Type0 b = Type0.FirstOrDefault(e => e.I_01_a == ECF.Type0.Component.B && e.I_00 == parameter);

            if (r == null || g == null || b == null)
            {
                return;
            }

            foreach (var r_frame in r.Keyframes)
            {
                float g_frame = g.GetValue(r_frame.Index);
                float b_frame = b.GetValue(r_frame.Index);

                if (r_frame.Float != 0.0 || g_frame != 0.0 || b_frame != 0.0)
                {
                    HslColor.HslColor color = new RgbColor(r_frame.Float, g_frame, b_frame).ToHsl();
                    color.ChangeHue(hue);
                    color.ChangeSaturation(saturation);
                    color.ChangeLightness(lightness);
                    RgbColor convertedColor = color.ToRgb();

                    r_frame.Float = (float)convertedColor.R;
                    g.SetValue(r_frame.Index, (float)convertedColor.G);
                    b.SetValue(r_frame.Index, (float)convertedColor.B);
                }
            }
        }
예제 #3
0
        public void ChangeHue(double hue, double saturation, double lightness)
        {
            //Diffuse Color
            if (F_00 != 0 || F_04 != 0 || F_08 != 0)
            {
                if (F_00 != 1 || F_04 != 1 || F_08 != 1)
                {
                    HslColor.HslColor newCol1 = new RgbColor(F_00, F_04, F_08).ToHsl();
                    newCol1.ChangeHue(hue);
                    newCol1.ChangeSaturation(saturation);
                    newCol1.ChangeLightness(lightness);
                    RgbColor convertedColor = newCol1.ToRgb();
                    F_00 = (float)convertedColor.R;
                    F_04 = (float)convertedColor.G;
                    F_08 = (float)convertedColor.B;
                }
            }

            //Specular Color
            if (F_16 != 0 || F_20 != 0 || F_24 != 0)
            {
                if (F_16 != 1 || F_20 != 1 || F_24 != 1)
                {
                    HslColor.HslColor newCol1 = new RgbColor(F_16, F_20, F_24).ToHsl();
                    newCol1.ChangeHue(hue);
                    newCol1.ChangeSaturation(saturation);
                    newCol1.ChangeLightness(lightness);
                    RgbColor convertedColor = newCol1.ToRgb();
                    F_16 = (float)convertedColor.R;
                    F_20 = (float)convertedColor.G;
                    F_24 = (float)convertedColor.B;
                }
            }

            //Ambient Color
            if (F_32 != 0 || F_36 != 0 || F_40 != 0)
            {
                if (F_32 != 1 || F_36 != 1 || F_40 != 1)
                {
                    HslColor.HslColor newCol1 = new RgbColor(F_32, F_36, F_40).ToHsl();
                    newCol1.ChangeHue(hue);
                    newCol1.ChangeSaturation(saturation);
                    newCol1.ChangeLightness(lightness);
                    RgbColor convertedColor = newCol1.ToRgb();
                    F_32 = (float)convertedColor.R;
                    F_36 = (float)convertedColor.G;
                    F_40 = (float)convertedColor.B;
                }
            }

            if (Type0 != null)
            {
                ChangeHueForAnimations(hue, saturation, lightness, ECF.Type0.Parameter.DiffuseColor);
                ChangeHueForAnimations(hue, saturation, lightness, ECF.Type0.Parameter.SpecularColor);
                ChangeHueForAnimations(hue, saturation, lightness, ECF.Type0.Parameter.AmbientColor);
            }
        }
예제 #4
0
        public void RgbTo()
        {
            RgbColor rgb = new RgbColor(0, 0, 0, 0.5);

            Assert.AreEqual(0.5, rgb.ToCmy().Alpha, "To CMY");

            Assert.AreEqual(0.5, rgb.ToCmyk().Alpha, "To CMYK");

            Assert.AreEqual(0.5, rgb.ToHsl().Alpha, "To HSL");

            Assert.AreEqual(0.5, rgb.ToHsv().Alpha, "To HSV");

            Assert.AreEqual(0.5, rgb.ToRgb().Alpha, "To RGB");
        }
예제 #5
0
        public void ChangeHue(double hue, double saturation, double lightness)
        {
            //Remove color animations as we cant hue shift them without a full ETR parser.
            RemoveColorAnimations();

            if (ETR_Entries == null)
            {
                return;
            }

            foreach (var etrEntry in ETR_Entries)
            {
                //Color1
                if (etrEntry.Color1_R != 0.0 || etrEntry.Color1_G != 0.0 || etrEntry.Color1_B != 0.0)
                {
                    if (etrEntry.Color1_R != 1.0 || etrEntry.Color1_G != 1.0 || etrEntry.Color1_B != 1.0)
                    {
                        HslColor.HslColor newCol1 = new RgbColor(etrEntry.Color1_R, etrEntry.Color1_G, etrEntry.Color1_B).ToHsl();
                        newCol1.ChangeHue(hue);
                        newCol1.ChangeSaturation(saturation);
                        newCol1.ChangeLightness(lightness);
                        RgbColor convertedColor = newCol1.ToRgb();
                        etrEntry.Color1_R = (float)convertedColor.R;
                        etrEntry.Color1_G = (float)convertedColor.G;
                        etrEntry.Color1_B = (float)convertedColor.B;
                    }
                }

                //Color2
                if (etrEntry.Color2_R != 0.0 || etrEntry.Color2_G != 0.0 || etrEntry.Color2_B != 0.0)
                {
                    if (etrEntry.Color2_R != 1.0 || etrEntry.Color2_G != 1.0 || etrEntry.Color2_B != 1.0)
                    {
                        HslColor.HslColor newCol1 = new RgbColor(etrEntry.Color2_R, etrEntry.Color2_G, etrEntry.Color2_B).ToHsl();
                        newCol1.ChangeHue(hue);
                        newCol1.ChangeSaturation(saturation);
                        newCol1.ChangeLightness(lightness);
                        RgbColor convertedColor = newCol1.ToRgb();
                        etrEntry.Color2_R = (float)convertedColor.R;
                        etrEntry.Color2_G = (float)convertedColor.G;
                        etrEntry.Color2_B = (float)convertedColor.B;
                    }
                }
            }
        }
예제 #6
0
        public void ChangeHue(double hue, double saturation, double lightness)
        {
            var r_command = GetCommand("Color", "R");
            var g_command = GetCommand("Color", "G");
            var b_command = GetCommand("Color", "B");

            foreach (var r in r_command.Keyframes)
            {
                var g = g_command.GetValue(r.Time);
                var b = b_command.GetValue(r.Time);

                var hslColor = new RgbColor(r.Value, g, b).ToHsl();
                hslColor.ChangeHue(hue);
                hslColor.ChangeSaturation(saturation);
                hslColor.ChangeLightness(lightness);
                var convertedColor = hslColor.ToRgb();

                r.Value = (float)convertedColor.R;
                g_command.SetValue(r.Time, (float)convertedColor.G);
                b_command.SetValue(r.Time, (float)convertedColor.B);
            }
        }
예제 #7
0
        public void ChangeHue(double hue, double saturation, double lightness, List <IUndoRedo> undos, bool hueSet = false, int variance = 0)
        {
            //Diffuse Color
            if (F_00 != 0 || F_04 != 0 || F_08 != 0)
            {
                if (F_00 != 1 || F_04 != 1 || F_08 != 1)
                {
                    HslColor.HslColor newCol1 = new RgbColor(F_00, F_04, F_08).ToHsl();
                    RgbColor          convertedColor;

                    if (hueSet)
                    {
                        newCol1.SetHue(hue, variance);
                    }
                    else
                    {
                        newCol1.ChangeHue(hue);
                        newCol1.ChangeSaturation(saturation);
                        newCol1.ChangeLightness(lightness);
                    }

                    convertedColor = newCol1.ToRgb();

                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_00), this, F_00, (float)convertedColor.R));
                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_04), this, F_04, (float)convertedColor.G));
                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_08), this, F_08, (float)convertedColor.B));

                    F_00 = (float)convertedColor.R;
                    F_04 = (float)convertedColor.G;
                    F_08 = (float)convertedColor.B;
                }
            }

            //Specular Color
            if (F_16 != 0 || F_20 != 0 || F_24 != 0)
            {
                if (F_16 != 1 || F_20 != 1 || F_24 != 1)
                {
                    HslColor.HslColor newCol1 = new RgbColor(F_16, F_20, F_24).ToHsl();
                    RgbColor          convertedColor;

                    if (hueSet)
                    {
                        newCol1.SetHue(hue, variance);
                    }
                    else
                    {
                        newCol1.ChangeHue(hue);
                        newCol1.ChangeSaturation(saturation);
                        newCol1.ChangeLightness(lightness);
                    }

                    convertedColor = newCol1.ToRgb();

                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_16), this, F_16, (float)convertedColor.R));
                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_20), this, F_20, (float)convertedColor.G));
                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_24), this, F_24, (float)convertedColor.B));

                    F_16 = (float)convertedColor.R;
                    F_20 = (float)convertedColor.G;
                    F_24 = (float)convertedColor.B;
                }
            }

            //Ambient Color
            if (F_32 != 0 || F_36 != 0 || F_40 != 0)
            {
                if (F_32 != 1 || F_36 != 1 || F_40 != 1)
                {
                    HslColor.HslColor newCol1 = new RgbColor(F_32, F_36, F_40).ToHsl();
                    RgbColor          convertedColor;

                    if (hueSet)
                    {
                        newCol1.SetHue(hue, variance);
                    }
                    else
                    {
                        newCol1.ChangeHue(hue);
                        newCol1.ChangeSaturation(saturation);
                        newCol1.ChangeLightness(lightness);
                    }

                    convertedColor = newCol1.ToRgb();

                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_32), this, F_32, (float)convertedColor.R));
                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_36), this, F_36, (float)convertedColor.G));
                    undos.Add(new UndoableProperty <ECF_Entry>(nameof(F_40), this, F_40, (float)convertedColor.B));

                    F_32 = (float)convertedColor.R;
                    F_36 = (float)convertedColor.G;
                    F_40 = (float)convertedColor.B;
                }
            }

            if (Type0 != null)
            {
                ChangeHueForAnimations(hue, saturation, lightness, ECF.Type0.Parameter.DiffuseColor, undos, hueSet, variance);
                ChangeHueForAnimations(hue, saturation, lightness, ECF.Type0.Parameter.SpecularColor, undos, hueSet, variance);
                ChangeHueForAnimations(hue, saturation, lightness, ECF.Type0.Parameter.AmbientColor, undos, hueSet, variance);
            }
        }
예제 #8
0
        public void ChangeHue(double hue, double saturation, double lightness, List <IUndoRedo> undos = null, bool hueSet = false, int variance = 0)
        {
            if (ETR_Entries == null)
            {
                return;
            }
            if (undos == null)
            {
                undos = new List <IUndoRedo>();
            }

            //Remove color animations as we cant hue shift them without a full ETR parser.
            RemoveColorAnimations(undos);

            foreach (var etrEntry in ETR_Entries)
            {
                //Color1
                if (etrEntry.Color1_R != 0.0 || etrEntry.Color1_G != 0.0 || etrEntry.Color1_B != 0.0)
                {
                    if (etrEntry.Color1_R != 1.0 || etrEntry.Color1_G != 1.0 || etrEntry.Color1_B != 1.0)
                    {
                        HslColor.HslColor newCol1 = new RgbColor(etrEntry.Color1_R, etrEntry.Color1_G, etrEntry.Color1_B).ToHsl();

                        RgbColor convertedColor;

                        if (hueSet)
                        {
                            newCol1.SetHue(hue, variance);
                        }
                        else
                        {
                            newCol1.ChangeHue(hue);
                            newCol1.ChangeSaturation(saturation);
                            newCol1.ChangeLightness(lightness);
                        }

                        convertedColor = newCol1.ToRgb();

                        undos.Add(new UndoableProperty <ETR_MainEntry>(nameof(etrEntry.Color1_R), etrEntry, etrEntry.Color1_R, (float)convertedColor.R));
                        undos.Add(new UndoableProperty <ETR_MainEntry>(nameof(etrEntry.Color1_G), etrEntry, etrEntry.Color1_G, (float)convertedColor.G));
                        undos.Add(new UndoableProperty <ETR_MainEntry>(nameof(etrEntry.Color1_B), etrEntry, etrEntry.Color1_B, (float)convertedColor.B));

                        etrEntry.Color1_R = (float)convertedColor.R;
                        etrEntry.Color1_G = (float)convertedColor.G;
                        etrEntry.Color1_B = (float)convertedColor.B;
                    }
                }

                //Color2
                if (etrEntry.Color2_R != 0.0 || etrEntry.Color2_G != 0.0 || etrEntry.Color2_B != 0.0)
                {
                    if (etrEntry.Color2_R != 1.0 || etrEntry.Color2_G != 1.0 || etrEntry.Color2_B != 1.0)
                    {
                        HslColor.HslColor newCol1 = new RgbColor(etrEntry.Color2_R, etrEntry.Color2_G, etrEntry.Color2_B).ToHsl();
                        RgbColor          convertedColor;

                        if (hueSet)
                        {
                            newCol1.SetHue(hue, variance);
                        }
                        else
                        {
                            newCol1.ChangeHue(hue);
                            newCol1.ChangeSaturation(saturation);
                            newCol1.ChangeLightness(lightness);
                        }

                        convertedColor = newCol1.ToRgb();

                        undos.Add(new UndoableProperty <ETR_MainEntry>(nameof(etrEntry.Color2_R), etrEntry, etrEntry.Color2_R, (float)convertedColor.R));
                        undos.Add(new UndoableProperty <ETR_MainEntry>(nameof(etrEntry.Color2_G), etrEntry, etrEntry.Color2_G, (float)convertedColor.G));
                        undos.Add(new UndoableProperty <ETR_MainEntry>(nameof(etrEntry.Color2_B), etrEntry, etrEntry.Color2_B, (float)convertedColor.B));

                        etrEntry.Color2_R = (float)convertedColor.R;
                        etrEntry.Color2_G = (float)convertedColor.G;
                        etrEntry.Color2_B = (float)convertedColor.B;
                    }
                }
            }
        }
예제 #9
0
 void update(ColorModel source)
 {
     changingValues = true;
     GetBaseColor(source);
     if (source != ColorModel.Rgb)
     {
         RgbR = basecolor.R;
         RgbG = basecolor.G;
         RgbB = basecolor.B;
     }
     if (source != ColorModel.RgbPerc)
     {
         try
         {
             var c = basecolor.ToRgb(RgbType.Percent);
             RgbPercR = c.R;
             RgbPercG = c.G;
             RgbPercB = c.B;
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex);
             throw;
         }
     }
     if (source != ColorModel.RgbByte)
     {
         var c = basecolor.ToRgb(RgbType.Byte);
         RgbByteR = c.R;
         RgbByteG = c.G;
         RgbByteB = c.B;
     }
     if (source != ColorModel.Cmy)
     {
         var c = basecolor.ToCmyk();
         CmyC = c.C;
         CmyM = c.M;
         CmyY = c.Y;
     }
     if (source != ColorModel.Cmyk)
     {
         var c = basecolor.ToCmyk(CmykType.CmykNormalized);
         CmykC = c.C;
         CmykM = c.M;
         CmykY = c.Y;
         CmykK = c.K;
     }
     if (source != ColorModel.Hsv)
     {
         try
         {
             var c = basecolor.ToHsv();
             HsvH = c.H;
             HsvS = c.S;
             HsvV = c.V;
         }
         catch (Exception ex)
         {
             Debug.WriteLine(ex);
         }
     }
     if (source != ColorModel.Xyz)
     {
         var c = basecolor.ToXyz();
         XyzX = c.X;
         XyzY = c.Y;
         XyzZ = c.Z;
     }
     if (source != ColorModel.Yiq)
     {
         var c = basecolor.ToYiq();
         YiqY = c.Y;
         YiqI = c.I;
         YiqQ = c.Q;
     }
     if (source != ColorModel.hex)
     {
         var c = basecolor;
         Hex = c.Hex;
     }
     OnPropertyChanged("RectColor");
     changingValues = false;
 }