コード例 #1
0
 static string OverlayColor(string color1, string color2)
 {
     Colorer.StringToARGB(color1, out byte alpha1, out byte red1, out byte green1, out byte blue1);
     Colorer.StringToARGB(color2, out byte alpha2, out byte red2, out byte green2, out byte blue2);
     red1   = (byte)((red1 * alpha1 / 255) + (red2 * alpha2 * (255 - alpha1) / (255 * 255)));
     green1 = (byte)((green1 * alpha1 / 255) + (green2 * alpha2 * (255 - alpha1) / (255 * 255)));
     blue1  = (byte)((blue1 * alpha1 / 255) + (blue2 * alpha2 * (255 - alpha1) / (255 * 255)));
     alpha1 = (byte)(alpha1 + (alpha2 * (255 - alpha1) / 255));
     return(Colorer.ARGBToString(alpha1, red1, green1, blue1));
 }
コード例 #2
0
 static string AddColor(string color1, string color2)
 {
     Colorer.StringToARGB(color1, out var alpha1, out var red1, out var green1, out var blue1);
     Colorer.StringToARGB(color2, out var alpha2, out var red2, out var green2, out var blue2);
     alpha1 = (byte)Math.Max(0, Math.Min(alpha1 + alpha2, 255));
     red1   = (byte)Math.Max(0, Math.Min(red1 + red2, 255));
     green1 = (byte)Math.Max(0, Math.Min(green1 + green2, 255));
     blue1  = (byte)Math.Max(0, Math.Min(blue1 + blue2, 255));
     return(Colorer.ARGBToString(alpha1, red1, green1, blue1));
 }
コード例 #3
0
 static string AdjustColor(string color, double multiplier, bool doAlpha, bool doRed, bool doGreen, bool doBlue)
 {
     Colorer.StringToARGB(color, out var alpha, out var red, out var green, out var blue);
     if (doAlpha)
     {
         alpha = (byte)Math.Max(0, Math.Min((int)(alpha * multiplier + 0.5), 255));
     }
     if (doRed)
     {
         red = (byte)Math.Max(0, Math.Min((int)(red * multiplier + 0.5), 255));
     }
     if (doGreen)
     {
         green = (byte)Math.Max(0, Math.Min((int)(green * multiplier + 0.5), 255));
     }
     if (doBlue)
     {
         blue = (byte)Math.Max(0, Math.Min((int)(blue * multiplier + 0.5), 255));
     }
     return(Colorer.ARGBToString(alpha, red, green, blue));
 }
コード例 #4
0
 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) => Colorer.ARGBToString((byte)values[0], (byte)values[1], (byte)values[2], (byte)values[3]);
コード例 #5
0
ファイル: ColorerTest.cs プロジェクト: TechnoLingua/NeoEdit
        public void ColorerTest()
        {
            // StringToString
            Assert.AreEqual(Colorer.StringToString("a"), "ffaaaaaa");
            Assert.AreEqual(Colorer.StringToString("AB"), "ffababab");
            Assert.AreEqual(Colorer.StringToString("cD0"), "ffccdd00");
            Assert.AreEqual(Colorer.StringToString("C0DE"), "cc00ddee");
            try { Colorer.StringToString("ad0be"); Assert.Fail(); } catch { }
            Assert.AreEqual(Colorer.StringToString("dEc0dE"), "ffdec0de");
            try { Colorer.StringToString("dec0ded"); Assert.Fail(); } catch { }
            Assert.AreEqual(Colorer.StringToString("F00dFaCe"), "f00dface");
            try { Colorer.StringToString("coder"); Assert.Fail(); } catch { }
            try { Colorer.StringToString("deadbeeff00d"); Assert.Fail(); } catch { }

            // StringToValue
            Assert.AreEqual(Colorer.StringToValue("a"), 0xffaaaaaa);
            Assert.AreEqual(Colorer.StringToValue("AB"), 0xffababab);
            Assert.AreEqual(Colorer.StringToValue("cD0"), 0xffccdd00);
            Assert.AreEqual(Colorer.StringToValue("C0DE"), 0xcc00ddee);
            try { Colorer.StringToValue("ad0be"); Assert.Fail(); } catch { }
            Assert.AreEqual(Colorer.StringToValue("dEc0dE"), 0xffdec0de);
            try { Colorer.StringToValue("dec0ded"); Assert.Fail(); } catch { }
            Assert.AreEqual(Colorer.StringToValue("F00dFaCe"), 0xf00dface);
            try { Colorer.StringToValue("coder"); Assert.Fail(); } catch { }
            try { Colorer.StringToValue("deadbeeff00d"); Assert.Fail(); } catch { }

            // ValueToString
            Assert.AreEqual(Colorer.ValueToString(0xffaaaaaa), "ffaaaaaa");
            Assert.AreEqual(Colorer.ValueToString(0xffababab), "ffababab");
            Assert.AreEqual(Colorer.ValueToString(0xffccdd00), "ffccdd00");
            Assert.AreEqual(Colorer.ValueToString(0xcc00ddee), "cc00ddee");
            Assert.AreEqual(Colorer.ValueToString(0xffdec0de), "ffdec0de");
            Assert.AreEqual(Colorer.ValueToString(0xf00dface), "f00dface");

            // ValueToARGB
            ValueToARGB(0xffaaaaaa, 0xff, 0xaa, 0xaa, 0xaa);
            ValueToARGB(0xffababab, 0xff, 0xab, 0xab, 0xab);
            ValueToARGB(0xffccdd00, 0xff, 0xcc, 0xdd, 0x00);
            ValueToARGB(0xcc00ddee, 0xcc, 0x00, 0xdd, 0xee);
            ValueToARGB(0xffdec0de, 0xff, 0xde, 0xc0, 0xde);
            ValueToARGB(0xf00dface, 0xf0, 0x0d, 0xfa, 0xce);

            // StringToARGB
            StringToARGB("a", 0xff, 0xaa, 0xaa, 0xaa);
            StringToARGB("AB", 0xff, 0xab, 0xab, 0xab);
            StringToARGB("cD0", 0xff, 0xcc, 0xdd, 0x00);
            StringToARGB("C0DE", 0xcc, 0x00, 0xdd, 0xee);
            try { StringToARGB("ad0be", 0, 0, 0, 0); Assert.Fail(); } catch { }
            StringToARGB("dEc0dE", 0xff, 0xde, 0xc0, 0xde);
            try { StringToARGB("dec0ded", 0, 0, 0, 0); Assert.Fail(); } catch { }
            StringToARGB("F00dFaCe", 0xf0, 0x0d, 0xfa, 0xce);
            try { StringToARGB("coder", 0, 0, 0, 0); Assert.Fail(); } catch { }
            try { StringToARGB("deadbeeff00d", 0, 0, 0, 0); Assert.Fail(); } catch { }

            // ARGBToString
            Assert.AreEqual(Colorer.ARGBToString(0xff, 0xaa, 0xaa, 0xaa), "ffaaaaaa");
            Assert.AreEqual(Colorer.ARGBToString(0xff, 0xab, 0xab, 0xab), "ffababab");
            Assert.AreEqual(Colorer.ARGBToString(0xff, 0xcc, 0xdd, 0x00), "ffccdd00");
            Assert.AreEqual(Colorer.ARGBToString(0xcc, 0x00, 0xdd, 0xee), "cc00ddee");
            Assert.AreEqual(Colorer.ARGBToString(0xff, 0xde, 0xc0, 0xde), "ffdec0de");
            Assert.AreEqual(Colorer.ARGBToString(0xf0, 0x0d, 0xfa, 0xce), "f00dface");

            // ARGBToValue
            Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xaa, 0xaa, 0xaa), 0xffaaaaaa);
            Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xab, 0xab, 0xab), 0xffababab);
            Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xcc, 0xdd, 0x00), 0xffccdd00);
            Assert.AreEqual(Colorer.ARGBToValue(0xcc, 0x00, 0xdd, 0xee), 0xcc00ddee);
            Assert.AreEqual(Colorer.ARGBToValue(0xff, 0xde, 0xc0, 0xde), 0xffdec0de);
            Assert.AreEqual(Colorer.ARGBToValue(0xf0, 0x0d, 0xfa, 0xce), 0xf00dface);
        }