Exemple #1
0
        public void TestApplyBlueFilter()
        {
            var         filename   = "test5.png";
            ImageFilter filter     = new ImageFilter();
            var         testBitmap = GetTestBitmap();

            SaveBitmap(testBitmap, filename);
            filter.Load(filename);
            try
            {
                TestLoadHelper(filter, testBitmap);
                AttachDummyEventHandler(filter);
                filter.ApplyFilter(Filter.Blue);
                var filteredBitmap = filter.FilteredImage;
                Assert.IsNotNull(filteredBitmap, $"ImageFilter - upon calling \'ApplyFilter\', property \'FilteredImage\' is null.");
                var originalBitmap = filter.OriginalImage;
                Assert.IsTrue(((originalBitmap.Width == filteredBitmap.Width) && (originalBitmap.Height == filteredBitmap.Height)),
                              $"ImageFilter - upon calling \'ApplyFilter\', property \'filteredImage\' has wrong size.");
                for (int x = 0; x < filteredBitmap.Width; x++)
                {
                    for (int y = 0; y < filteredBitmap.Height; y++)
                    {
                        var c = filteredBitmap.GetPixel(x, y);
                        Assert.IsTrue(
                            ((c.R == 0) && (c.G == 0)),
                            $"ImageFilter - upon calling \'ApplyFilter(Filter.Blue)\', property \'FilteredImage\' contains wrong bitmap.");
                    }
                }
            }
            finally
            {
                filter.OriginalImage.Dispose();
                filter.FilteredImage.Dispose();
            }
        }
        public byte[] Encode()
        {
            byte[] data = codec.EncodeColors(image.GetColorArray());

            if (filter != null)
            {
                data = filter.ApplyFilter(data);
            }

            return(data);
        }
        private byte[] EncodeFromReference()
        {
            int[] indexes = referenceImage.GetColorArray().Select((c) => (c.R >> (8 - codec.BitDepth))).ToArray();

            if (colorEncoder != null)
            {
                EncodedPalettes = new List <byte[]>(Palettes.Count);
                foreach (Color[] pal in Palettes)
                {
                    EncodedPalettes.Add(colorEncoder.EncodeColors(paletteFilter == null ? pal : paletteFilter.ApplyFilter(pal)));
                }
            }
            return(imageFilter == null?codec.PackIndexes(indexes) : imageFilter.ApplyFilter(codec.PackIndexes(indexes)));
        }