diff --git a/src/ImageProcessor/Formats/Gif/GifEncoder.cs b/src/ImageProcessor/Formats/Gif/GifEncoder.cs index 735d26c39..5d2700511 100644 --- a/src/ImageProcessor/Formats/Gif/GifEncoder.cs +++ b/src/ImageProcessor/Formats/Gif/GifEncoder.cs @@ -57,7 +57,7 @@ namespace ImageProcessor.Formats // Write the LSD and check to see if we need a global color table. // Always true just now. - bool globalColor = this.WriteGlobalLogicalScreenDescriptor(image, stream, bitDepth); + this.WriteGlobalLogicalScreenDescriptor(image, stream, bitDepth); QuantizedImage quantized = this.WriteColorTable(imageBase, stream, quality, bitDepth); this.WriteGraphicalControlExtension(imageBase, stream); diff --git a/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs b/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs index 6f6f375e9..3d82fb71f 100644 --- a/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs +++ b/src/ImageProcessor/Formats/Gif/Quantizer/OctreeQuantizer.cs @@ -8,6 +8,8 @@ namespace ImageProcessor.Formats using System; using System.Collections.Generic; + using ImageProcessor.Common.Extensions; + /// /// Encapsulates methods to calculate the colour palette if an image using an Octree pattern. /// @@ -60,6 +62,11 @@ namespace ImageProcessor.Formats this.maxColors = maxColors; } + /// + /// Gets or sets the transparency threshold. + /// + public byte Threshold { get; set; } = 128; + /// /// Process the pixel in the first pass of the algorithm /// @@ -90,8 +97,8 @@ namespace ImageProcessor.Formats // The color at [maxColors] is set to transparent byte paletteIndex = (byte)this.maxColors; - // Get the palette index if this non-transparent - if (pixel.A > 0) + // Get the palette index if it's transparency meets criterea. + if (pixel.A >= this.Threshold) { paletteIndex = (byte)this.octree.GetPaletteIndex(pixel); } @@ -110,7 +117,6 @@ namespace ImageProcessor.Formats // First off convert the Octree to maxColors colors List palette = this.octree.Palletize(Math.Max(this.maxColors - 1, 1)); - // Add empty color for transparency palette.Add(Bgra32.Empty); return palette; @@ -175,7 +181,7 @@ namespace ImageProcessor.Formats /// /// Gets or sets the number of leaves in the tree /// - private int Leaves + public int Leaves { get { return this.leafCount; } set { this.leafCount = value; } diff --git a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs index 11221d115..c65f2381c 100644 --- a/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs +++ b/tests/ImageProcessor.Tests/Processors/Filters/FilterTests.cs @@ -13,31 +13,31 @@ namespace ImageProcessor.Tests { public static readonly TheoryData Filters = new TheoryData { - //{ "Brightness-50", new Brightness(50) }, - //{ "Brightness--50", new Brightness(-50) }, - //{ "Contrast-50", new Contrast(50) }, - //{ "Contrast--50", new Contrast(-50) }, - //{ "Blend", new Blend(new Image(File.OpenRead("../../TestImages/Formats/Bmp/Car.bmp")),15)}, - //{ "Saturation-50", new Saturation(50) }, - //{ "Saturation--50", new Saturation(-50) }, - //{ "Alpha--50", new Alpha(50) }, - //{ "Invert", new Invert() }, - //{ "Sepia", new Sepia() }, - //{ "BlackWhite", new BlackWhite() }, - //{ "Lomograph", new Lomograph() }, - //{ "Polaroid", new Polaroid() }, - //{ "Kodachrome", new Kodachrome() }, - //{ "GreyscaleBt709", new GreyscaleBt709() }, - //{ "GreyscaleBt601", new GreyscaleBt601() }, - //{ "Kayyali", new Kayyali() }, - //{ "Kirsch", new Kirsch() }, - //{ "Laplacian3X3", new Laplacian3X3() }, - //{ "Laplacian5X5", new Laplacian5X5() }, - //{ "LaplacianOfGaussian", new LaplacianOfGaussian() }, - //{ "Prewitt", new Prewitt() }, - //{ "RobertsCross", new RobertsCross() }, - //{ "Scharr", new Scharr() }, - //{ "Sobel", new Sobel() }, + { "Brightness-50", new Brightness(50) }, + { "Brightness--50", new Brightness(-50) }, + { "Contrast-50", new Contrast(50) }, + { "Contrast--50", new Contrast(-50) }, + { "Blend", new Blend(new Image(File.OpenRead("../../TestImages/Formats/Bmp/Car.bmp")),15)}, + { "Saturation-50", new Saturation(50) }, + { "Saturation--50", new Saturation(-50) }, + { "Alpha--50", new Alpha(50) }, + { "Invert", new Invert() }, + { "Sepia", new Sepia() }, + { "BlackWhite", new BlackWhite() }, + { "Lomograph", new Lomograph() }, + { "Polaroid", new Polaroid() }, + { "Kodachrome", new Kodachrome() }, + { "GreyscaleBt709", new GreyscaleBt709() }, + { "GreyscaleBt601", new GreyscaleBt601() }, + { "Kayyali", new Kayyali() }, + { "Kirsch", new Kirsch() }, + { "Laplacian3X3", new Laplacian3X3() }, + { "Laplacian5X5", new Laplacian5X5() }, + { "LaplacianOfGaussian", new LaplacianOfGaussian() }, + { "Prewitt", new Prewitt() }, + { "RobertsCross", new RobertsCross() }, + { "Scharr", new Scharr() }, + { "Sobel", new Sobel() }, { "GuassianBlur", new GuassianBlur(10) }, { "GuassianSharpen", new GuassianSharpen(10) } };