Browse Source

Baseline jpegs now clear allocated buffers in the decoding loop

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
519c6b227a
  1. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  2. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs
  3. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs

8
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs

@ -96,6 +96,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.scanBuffer = new HuffmanScanBuffer(this.stream);
bool fullScan = this.frame.Progressive || this.frame.MultiScan;
this.frame.AllocateComponents(fullScan);
if (!this.frame.Progressive)
{
this.ParseBaselineData();
@ -123,14 +126,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
if (this.ComponentsLength == this.frame.ComponentCount)
{
// interleaved - we can convert spectral data stride by stride
this.frame.AllocateComponents(fullScan: false);
this.ParseBaselineDataInterleaved();
}
else
{
// non-interleaved - each scan contains
this.frame.AllocateComponents(fullScan: true);
this.ParseBaselineDataNonInterleaved();
}
}
@ -303,7 +302,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{
this.CheckProgressiveData();
this.frame.AllocateComponents(fullScan: true);
if (this.ComponentsLength == 1)
{
this.ParseProgressiveDataNonInterleaved();

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs

@ -138,7 +138,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
int spectralAllocWidth = this.SizeInBlocks.Width;
int spectralAllocHeight = fullScan ? this.SizeInBlocks.Height : this.VerticalSamplingFactor;
this.SpectralBlocks = this.memoryAllocator.Allocate2D<Block8x8>(spectralAllocWidth, spectralAllocHeight, AllocationOptions.Clean);
// We don't need to clear buffer for stride-by-stride approach
AllocationOptions allocOptions = fullScan ? AllocationOptions.Clean : AllocationOptions.None;
this.SpectralBlocks = this.memoryAllocator.Allocate2D<Block8x8>(spectralAllocWidth, spectralAllocHeight, allocOptions);
}
}
}

8
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs

@ -20,6 +20,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
/// </summary>
public bool Progressive { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the frame is encoded using multiple scans (SOS markers).
/// </summary>
/// <remarks>
/// This is true for progressive and baseline non-interleaved images.
/// </remarks>
public bool MultiScan { get; set; }
/// <summary>
/// Gets or sets the precision.
/// </summary>

Loading…
Cancel
Save