Exemplo n.º 1
0
        public void TestDefaultSettings()
        {
            var image = new CodedImage {
                Size = new Size(5, 5)
            };
            var colorer = new ImageColorsController4Test(new ImageColorsManipulator(image));

            var palette1 = new CodedPalette {
                Name = "Palette 1"
            };
            var palette2 = new CodedPalette {
                Name = "Palette 2"
            };

            palette2.Add(1);
            palette2.Add(2);
            palette2.Add(3);

            using (colorer.SuspendCallManipulations())
            {
                colorer.AddColorPalettes(new[] { palette1, palette2 });

                colorer.PaletteName               = "Palette 2";
                colorer.MaxColorsCount            = 2;
                colorer.DitherLevel               = 5;
                colorer.ColorComparisonType       = ImageColorsController.ColorComparisonTypes.Exact;
                colorer.EnsureBlackAndWhiteColors = true;
            }

            var newColorer = new ImageColorsController4Test(new ImageColorsManipulator(image), new[] { palette1, palette2 }, palette1);             // Pass different initial palette

            // Precondition checks
            Assert.AreNotEqual("Palette 2", newColorer.PaletteName);
            Assert.AreNotSame(palette2, newColorer.SelectedPalette);
            Assert.AreNotEqual(2, newColorer.MaxColorsCount);
            Assert.AreNotEqual(5, newColorer.DitherLevel);
            Assert.AreNotEqual(ImageColorsController.ColorComparisonTypes.Exact, newColorer.ColorComparisonType);
            Assert.IsFalse(newColorer.EnsureBlackAndWhiteColors);

            colorer.SaveDefaults();

            newColorer = new ImageColorsController4Test(new ImageColorsManipulator(image), new[] { palette1, palette2 }, palette1);             // Pass different initial palette

            Assert.AreEqual("Palette 2", newColorer.PaletteName);
            Assert.AreSame(palette2, newColorer.SelectedPalette);
            Assert.AreEqual(2, newColorer.MaxColorsCount);
            Assert.AreEqual(5, newColorer.DitherLevel);
            Assert.AreEqual(ImageColorsController.ColorComparisonTypes.Exact, newColorer.ColorComparisonType);
            Assert.IsTrue(newColorer.EnsureBlackAndWhiteColors);

            SAEWizardSettings.Default.Reset();             // Restore defaults
        }
Exemplo n.º 2
0
        public void TestAddColorPalettes()
        {
            var image = new CodedImage {
                Size = new Size(5, 5)
            };
            var colorer = new ImageColorsController4Test(new ImageColorsManipulator(image));

            Assert.IsNull(colorer.AvailablePalettes);
            Assert.IsNull(colorer.AvailablePalettesNames);
            Assert.IsNull(colorer.SelectedPalette);

            var palette1 = new CodedPalette {
                Name = "Palette 1"
            };
            var palette2 = new CodedPalette {
                Name = "Palette 2"
            };

            colorer.AddColorPalettes(new[] { palette1, palette2 });

            Assert.AreEqual(2, colorer.AvailablePalettes.Count());
            Assert.AreEqual(2, colorer.AvailablePalettesNames.Count());
            Assert.AreSame(palette1, colorer.SelectedPalette);
            Assert.AreEqual("Palette 1", colorer.PaletteName);

            var palette3 = new CodedPalette {
                Name = "Palette 3"
            };

            colorer.AddColorPalettes(new[] { palette3 });

            Assert.AreEqual(3, colorer.AvailablePalettes.Count());
            Assert.AreEqual(3, colorer.AvailablePalettesNames.Count());
            Assert.AreSame(palette1, colorer.SelectedPalette, "Should keep already selected palette.");
            Assert.AreEqual("Palette 1", colorer.PaletteName, "Should keep already selected palette.");
        }