Browse Source

Move filtering setup to the correct place.

pull/1781/head
James Jackson-South 5 years ago
parent
commit
b233771cb0
  1. 8
      src/ImageSharp/Formats/Png/PngEncoderOptions.cs
  2. 12
      src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs

8
src/ImageSharp/Formats/Png/PngEncoderOptions.cs

@ -18,11 +18,7 @@ namespace SixLabors.ImageSharp.Formats.Png
{
this.BitDepth = source.BitDepth;
this.ColorType = source.ColorType;
// Specification recommends default filter method None for paletted images and Paeth for others.
this.FilterMethod = source.FilterMethod ?? (source.ColorType == PngColorType.Palette
? PngFilterMethod.None
: PngFilterMethod.Paeth);
this.FilterMethod = source.FilterMethod;
this.CompressionLevel = source.CompressionLevel;
this.TextCompressionThreshold = source.TextCompressionThreshold;
this.Gamma = source.Gamma;
@ -41,7 +37,7 @@ namespace SixLabors.ImageSharp.Formats.Png
public PngColorType? ColorType { get; set; }
/// <inheritdoc/>
public PngFilterMethod? FilterMethod { get; }
public PngFilterMethod? FilterMethod { get; set; }
/// <inheritdoc/>
public PngCompressionLevel CompressionLevel { get; } = PngCompressionLevel.DefaultCompression;

12
src/ImageSharp/Formats/Png/PngEncoderOptionsHelpers.cs

@ -34,6 +34,18 @@ namespace SixLabors.ImageSharp.Formats.Png
// a sensible default based upon the pixel format.
options.ColorType ??= pngMetadata.ColorType ?? SuggestColorType<TPixel>();
options.BitDepth ??= pngMetadata.BitDepth ?? SuggestBitDepth<TPixel>();
if (!options.FilterMethod.HasValue)
{
// Specification recommends default filter method None for paletted images and Paeth for others.
if (options.ColorType == PngColorType.Palette)
{
options.FilterMethod = PngFilterMethod.None;
}
else
{
options.FilterMethod = PngFilterMethod.Paeth;
}
}
// Ensure bit depth and color type are a supported combination.
// Bit8 is the only bit depth supported by all color types.

Loading…
Cancel
Save