diff --git a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizer.cs b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizer.cs index 55ff95312..382e8d6f0 100644 --- a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizer.cs +++ b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizer.cs @@ -109,7 +109,7 @@ private static IEnumerable IndexedPixels(ImageBuffer image, Color32[] lo { Color32 pixel = pixelLine[i]; byte bestMatch = fallback; - if (pixel.A > alphaThreshold) + if (pixel.A >= alphaThreshold) { bestMatch = lookup.GetPaletteIndex(pixel); paletteHistogram[bestMatch].AddPixel(pixel); diff --git a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs index 40d0e2fc7..09c8f7c24 100644 --- a/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs +++ b/src/ImageProcessor/Imaging/Quantizers/WuQuantizer/WuQuantizerBase.cs @@ -68,6 +68,48 @@ public abstract class WuQuantizerBase : IWuQuantizer /// private const int MaxSideIndex = 32; + /// + /// The transparency threshold. + /// + private byte threshold = 0; + + /// + /// The transparency fade. + /// + private byte fade = 1; + + /// + /// Gets or sets the transparency threshold (0 - 255) + /// + public byte Threshold + { + get + { + return this.threshold; + } + + set + { + this.threshold = value; + } + } + + /// + /// Gets or sets the alpha fade (0 - 255) + /// + public byte Fade + { + get + { + return this.fade; + } + + set + { + this.fade = value; + } + } + /// /// Quantize an image and return the resulting output bitmap /// @@ -79,7 +121,7 @@ public abstract class WuQuantizerBase : IWuQuantizer /// public Bitmap Quantize(Image source) { - return this.Quantize(source, 0, 1); + return this.Quantize(source, this.Threshold, this.Fade); } /// @@ -209,7 +251,7 @@ public Bitmap Quantize(Image source, int alphaThreshold, int alphaFader, Histogr [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] private static void BuildHistogram(Histogram histogram, ImageBuffer imageBuffer, int alphaThreshold, int alphaFader) { - ColorMoment[, , ,] moments = histogram.Moments; + ColorMoment[,,,] moments = histogram.Moments; foreach (Color32[] pixelLine in imageBuffer.PixelLines) { @@ -248,7 +290,7 @@ private static void BuildHistogram(Histogram histogram, ImageBuffer imageBuffer, /// The three dimensional array of to process. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static void CalculateMoments(ColorMoment[, , ,] moments) + private static void CalculateMoments(ColorMoment[,,,] moments) { ColorMoment[,] areaSquared = new ColorMoment[SideSize, SideSize]; ColorMoment[] area = new ColorMoment[SideSize]; @@ -294,7 +336,7 @@ private static void CalculateMoments(ColorMoment[, , ,] moments) /// The representing the top of the cube. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static ColorMoment Top(Box cube, int direction, int position, ColorMoment[, , ,] moment) + private static ColorMoment Top(Box cube, int direction, int position, ColorMoment[,,,] moment) { switch (direction) { @@ -359,7 +401,7 @@ private static ColorMoment Top(Box cube, int direction, int position, ColorMomen /// The representing the bottom of the cube. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static ColorMoment Bottom(Box cube, int direction, ColorMoment[, , ,] moment) + private static ColorMoment Bottom(Box cube, int direction, ColorMoment[,,,] moment) { switch (direction) { @@ -433,7 +475,7 @@ private static ColorMoment Bottom(Box cube, int direction, ColorMoment[, , ,] mo /// The representing the sum. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static CubeCut Maximize(ColorMoment[, , ,] moments, Box cube, int direction, byte first, byte last, ColorMoment whole) + private static CubeCut Maximize(ColorMoment[,,,] moments, Box cube, int direction, byte first, byte last, ColorMoment whole) { ColorMoment bottom = Bottom(cube, direction, moments); float result = 0.0f; @@ -481,7 +523,7 @@ private static CubeCut Maximize(ColorMoment[, , ,] moments, Box cube, int direct /// The indicating the result. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static bool Cut(ColorMoment[, , ,] moments, ref Box first, ref Box second) + private static bool Cut(ColorMoment[,,,] moments, ref Box first, ref Box second) { int direction; ColorMoment whole = Volume(moments, first); @@ -591,7 +633,7 @@ private static bool Cut(ColorMoment[, , ,] moments, ref Box first, ref Box secon /// The representing the variance. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static float CalculateVariance(ColorMoment[, , ,] moments, Box cube) + private static float CalculateVariance(ColorMoment[,,,] moments, Box cube) { ColorMoment volume = Volume(moments, cube); return volume.Variance(); @@ -610,7 +652,7 @@ private static float CalculateVariance(ColorMoment[, , ,] moments, Box cube) /// The representing the volume. /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static ColorMoment Volume(ColorMoment[, , ,] moments, Box cube) + private static ColorMoment Volume(ColorMoment[,,,] moments, Box cube) { return (moments[cube.AlphaMaximum, cube.RedMaximum, cube.GreenMaximum, cube.BlueMaximum] - moments[cube.AlphaMaximum, cube.RedMaximum, cube.GreenMinimum, cube.BlueMaximum] - @@ -644,7 +686,7 @@ private static ColorMoment Volume(ColorMoment[, , ,] moments, Box cube) /// The array . /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static Box[] SplitData(ref int colorCount, ColorMoment[, , ,] moments) + private static Box[] SplitData(ref int colorCount, ColorMoment[,,,] moments) { --colorCount; int next = 0; @@ -706,7 +748,7 @@ private static Box[] SplitData(ref int colorCount, ColorMoment[, , ,] moments) /// The array of . /// [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1001:CommasMustBeSpacedCorrectly", Justification = "Reviewed. Suppression is OK here.")] - private static Color32[] BuildLookups(Box[] cubes, ColorMoment[, , ,] moments) + private static Color32[] BuildLookups(Box[] cubes, ColorMoment[,,,] moments) { Color32[] lookups = new Color32[cubes.Length];