Browse Source

Scan decoder is not a persistent state of the decoder core

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
442af2c5be
  1. 3
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  2. 35
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

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

@ -94,7 +94,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{ {
this.dctZigZag = ZigZag.CreateUnzigTable(); this.dctZigZag = ZigZag.CreateUnzigTable();
this.stream = stream; this.stream = stream;
this.scanBuffer = new HuffmanScanBuffer(stream);
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
} }
@ -105,6 +104,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{ {
this.cancellationToken.ThrowIfCancellationRequested(); this.cancellationToken.ThrowIfCancellationRequested();
this.scanBuffer = new HuffmanScanBuffer(this.stream);
if (!this.frame.Progressive) if (!this.frame.Progressive)
{ {
this.ParseBaselineData(); this.ParseBaselineData();

35
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -172,6 +172,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <inheritdoc/> /// <inheritdoc/>
public Block8x8F[] QuantizationTables { get; private set; } public Block8x8F[] QuantizationTables { get; private set; }
private HuffmanScanDecoder scanDecoder;
/// <summary> /// <summary>
/// Finds the next file marker within the byte stream. /// Finds the next file marker within the byte stream.
/// </summary> /// </summary>
@ -213,6 +215,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken) public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
this.scanDecoder = new HuffmanScanDecoder(stream, cancellationToken);
this.ParseStream(stream, cancellationToken: cancellationToken); this.ParseStream(stream, cancellationToken: cancellationToken);
this.InitExifProfile(); this.InitExifProfile();
this.InitIccProfile(); this.InitIccProfile();
@ -1049,26 +1053,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
int spectralEnd = this.temp[1]; int spectralEnd = this.temp[1];
int successiveApproximation = this.temp[2]; int successiveApproximation = this.temp[2];
var sd = new HuffmanScanDecoder( this.scanDecoder.Frame = this.Frame;
stream, this.scanDecoder.dcHuffmanTables = this.dcHuffmanTables;
cancellationToken) this.scanDecoder.acHuffmanTables = this.acHuffmanTables;
{ this.scanDecoder.ResetInterval = this.resetInterval;
Frame = this.Frame, this.scanDecoder.componentsLength = selectorsCount;
this.scanDecoder.spectralStart = spectralStart;
dcHuffmanTables = this.dcHuffmanTables, this.scanDecoder.spectralEnd = spectralEnd;
acHuffmanTables = this.acHuffmanTables, this.scanDecoder.successiveHigh = successiveApproximation >> 4;
this.scanDecoder.successiveLow = successiveApproximation & 15;
ResetInterval = this.resetInterval,
this.scanDecoder.ParseEntropyCodedData();
componentsLength = selectorsCount,
spectralStart = spectralStart,
spectralEnd = spectralEnd,
successiveHigh = successiveApproximation >> 4,
successiveLow = successiveApproximation & 15
};
sd.ParseEntropyCodedData();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save