diff --git a/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs b/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs index 8e959155cc..fc6ad3f672 100644 --- a/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs @@ -516,11 +516,19 @@ namespace ImageProcessorCore.Formats { int offset = i * 3; Color color = new Color(palette[i].ToVector4()); + int alpha = color.A; + + // Premultiply the color. This helps prevent banding. + if (alpha < 255 && alpha > this.Threshold) + { + color = Color.Multiply(color, new Color(alpha, alpha, alpha, 255)); + } + colorTable[offset] = color.R; colorTable[offset + 1] = color.G; colorTable[offset + 2] = color.B; - if (color.A <= this.Threshold) + if (alpha <= this.Threshold) { transparentPixels.Add((byte)offset); } diff --git a/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs b/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs index 0e53cbbab9..d6eeb535ff 100644 --- a/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs @@ -91,17 +91,6 @@ namespace ImageProcessorCore.Quantizers protected override List GetPalette() { return this.octree.Palletize(Math.Max(this.colors, 1)); - - // First off convert the Octree to maxColors colors - //List palette = this.octree.Palletize(Math.Max(this.colors, 1)); - - //int diff = this.colors - palette.Count; - //if (diff > 0) - //{ - // palette.AddRange(Enumerable.Repeat(default(TColor), diff)); - //} - - //return palette; } /// diff --git a/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs b/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs index cbaa8435ed..1354808798 100644 --- a/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs @@ -95,7 +95,7 @@ namespace ImageProcessorCore.Quantizers /// The output pixel array /// The width in pixels of the image /// The height in pixels of the image - protected virtual void SecondPass(PixelAccessor source, byte[] output, int width, int height) + protected virtual void SecondPass(PixelAccessor source, byte[] output, int width, int height) { Parallel.For( 0,