Browse Source

Added: ability to skip unneeded chunks for optimization mode

pull/1574/head
Peter Tribe 6 years ago
parent
commit
b8bb3293cb
  1. 5
      src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
  2. 13
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  3. 6
      src/ImageSharp/Formats/Png/PngEncoderOptions.cs

5
src/ImageSharp/Formats/Png/IPngEncoderOptions.cs

@ -57,5 +57,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets a value indicating whether this instance should write an Adam7 interlaced image.
/// </summary>
PngInterlaceMode? InterlaceMethod { get; }
/// <summary>
/// Gets a value indicating whether this instance should skip certain chunks to decrease file size
/// </summary>
bool Optimized { get; }
}
}

13
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -155,10 +155,15 @@ namespace SixLabors.ImageSharp.Formats.Png
this.WriteHeaderChunk(stream);
this.WritePaletteChunk(stream, quantized);
this.WriteTransparencyChunk(stream, pngMetadata);
this.WritePhysicalChunk(stream, metadata);
this.WriteGammaChunk(stream);
this.WriteExifChunk(stream, metadata);
this.WriteTextChunks(stream, pngMetadata);
if (!this.options.Optimized)
{
this.WritePhysicalChunk(stream, metadata);
this.WriteGammaChunk(stream);
this.WriteExifChunk(stream, metadata);
this.WriteTextChunks(stream, pngMetadata);
}
this.WriteDataChunks(image.Frames.RootFrame, quantized, stream);
this.WriteEndChunk(stream);
stream.Flush();

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

@ -29,6 +29,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.Quantizer = source.Quantizer;
this.Threshold = source.Threshold;
this.InterlaceMethod = source.InterlaceMethod;
this.Optimized = source.Optimized;
}
/// <summary>
@ -78,5 +79,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.
/// </summary>
public PngInterlaceMode? InterlaceMethod { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance should skip certain chunks to decrease file size
/// </summary>
public bool Optimized { get; set; }
}
}

Loading…
Cancel
Save