Пример #1
0
        public void TestColorCoeffs()
        {
            Assert.AreEqual(30, ColorDistance.CoeffRed);
            Assert.AreEqual(59, ColorDistance.CoeffGreen);
            Assert.AreEqual(11, ColorDistance.CoeffBlue);
            Assert.AreEqual(0, ColorDistance.CoeffHue);
            Assert.AreEqual(0, ColorDistance.CoeffSaturation);
            Assert.AreEqual(0, ColorDistance.CoeffBrightness);

            using (ColorDistance.UseCoeffs(1, 2, 3, 4, 5, 6))
            {
                Assert.AreEqual(1, ColorDistance.CoeffRed);
                Assert.AreEqual(2, ColorDistance.CoeffGreen);
                Assert.AreEqual(3, ColorDistance.CoeffBlue);
                Assert.AreEqual(4, ColorDistance.CoeffHue);
                Assert.AreEqual(5, ColorDistance.CoeffSaturation);
                Assert.AreEqual(6, ColorDistance.CoeffBrightness);
            }

            Assert.AreEqual(30, ColorDistance.CoeffRed);
            Assert.AreEqual(59, ColorDistance.CoeffGreen);
            Assert.AreEqual(11, ColorDistance.CoeffBlue);
            Assert.AreEqual(0, ColorDistance.CoeffHue);
            Assert.AreEqual(0, ColorDistance.CoeffSaturation);
            Assert.AreEqual(0, ColorDistance.CoeffBrightness);
        }
        public void TestSearchSubstiture()
        {
            var palette = new Palette
            {
                new Color(0),
                new Color(250, 250, 250),
                new Color(100, 0, 0),
                new Color(0, 100, 0),
                new Color(0, 0, 100),
                new Color(0, 0, 101)
            };

            var quickColorSearcher = new PaletteQuickColorSearcher(palette);

            using (ColorDistance.UseCoeffs(1, 1, 1))
            {
                Assert.AreEqual(new Color(0), quickColorSearcher.SearchSubstitute(new Color(0)));
                Assert.AreEqual(new Color(250, 250, 250), quickColorSearcher.SearchSubstitute(new Color(254, 254, 254)));
                Assert.AreEqual(new Color(0, 0, 100), quickColorSearcher.SearchSubstitute(new Color(98, 98, 99)));
                Assert.AreEqual(new Color(0, 100, 0), quickColorSearcher.SearchSubstitute(new Color(98, 99, 98)));
                Assert.AreEqual(new Color(100, 0, 0), quickColorSearcher.SearchSubstitute(new Color(99, 98, 98)));

                Assert.AreEqual(new Color(0, 0, 100), quickColorSearcher.SearchSubstitute(new Color(0, 0, 99), true));
                Assert.AreEqual(new Color(0, 0, 101), quickColorSearcher.SearchSubstitute(new Color(0, 0, 99), true));
            }
        }
Пример #3
0
        public void TestGetVisualDistance()
        {
            Assert.AreEqual(0, ColorDistance.GetVisualDistance(new Color(1, 2, 3), new Color(1, 2, 3)));
            Assert.AreEqual(30 * 9 * 9 + 59 * 18 * 18 + 11 * 27 * 27, ColorDistance.GetVisualDistance(new Color(1, 2, 3), new Color(10, 20, 30)));

            Assert.AreEqual(30 * 1 * 1 + 59 * 2 * 2 + 11 * 3 * 3, ColorDistance.GetVisualDistance(new Color(1, 2, 3), new Color(0)));
            using (ColorDistance.UseCoeffs(5, 7, 13))
            {
                Assert.AreEqual(5 * 1 * 1 + 7 * 2 * 2 + 13 * 3 * 3, ColorDistance.GetVisualDistance(new Color(1, 2, 3), new Color(0)));
            }
            Assert.AreEqual(30 * 1 * 1 + 59 * 2 * 2 + 11 * 3 * 3, ColorDistance.GetVisualDistance(new Color(1, 2, 3), new Color(0)));

            Assert.AreEqual(new Color(123).GetVisualDistance(new Color(456)), new Color(456).GetVisualDistance(new Color(123)));
        }