Browse Source

Slight improvement to indexed png

Premultiply partial alpha colors above threshold


Former-commit-id: e3180b0889327530c971611680ae34e71d24db79
Former-commit-id: 135d6264188a87e221d38e68e9c905782c4a5d7e
Former-commit-id: 546f847865693d9b0a72f73438cd9a1d83c3a669
pull/1/head
James Jackson-South 10 years ago
parent
commit
5d03d0b106
  1. 10
      src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs
  2. 11
      src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs
  3. 2
      src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs

10
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);
}

11
src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs

@ -91,17 +91,6 @@ namespace ImageProcessorCore.Quantizers
protected override List<TColor> GetPalette()
{
return this.octree.Palletize(Math.Max(this.colors, 1));
// First off convert the Octree to maxColors colors
//List<TColor> 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;
}
/// <summary>

2
src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs

@ -95,7 +95,7 @@ namespace ImageProcessorCore.Quantizers
/// <param name="output">The output pixel array</param>
/// <param name="width">The width in pixels of the image</param>
/// <param name="height">The height in pixels of the image</param>
protected virtual void SecondPass(PixelAccessor<TColor,TPacked> source, byte[] output, int width, int height)
protected virtual void SecondPass(PixelAccessor<TColor, TPacked> source, byte[] output, int width, int height)
{
Parallel.For(
0,

Loading…
Cancel
Save