Browse Source

Fix quantization altering the original image.

af/merge-core
James Jackson-South 10 years ago
parent
commit
0b4e7615ed
  1. 13
      src/ImageSharp/Quantizers/Quantizer.cs

13
src/ImageSharp/Quantizers/Quantizer.cs

@ -68,8 +68,21 @@ namespace ImageSharp.Quantizers
// Collect the palette. Required before the second pass runs. // Collect the palette. Required before the second pass runs.
colorPalette = this.GetPalette(); colorPalette = this.GetPalette();
if (this.Dither)
{
// We clone the image as we don't want to alter the original.
using (Image<TColor> clone = new Image<TColor>(image))
using (PixelAccessor<TColor> clonedPixels = clone.Lock())
{
this.SecondPass(clonedPixels, quantizedPixels, width, height);
}
}
else
{
this.SecondPass(pixels, quantizedPixels, width, height); this.SecondPass(pixels, quantizedPixels, width, height);
} }
}
return new QuantizedImage<TColor>(width, height, colorPalette, quantizedPixels); return new QuantizedImage<TColor>(width, height, colorPalette, quantizedPixels);
} }

Loading…
Cancel
Save