Browse Source

Final refactor of the converter

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
fae763edd3
  1. 3
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  2. 25
      src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

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

@ -133,9 +133,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
else else
{ {
this.ParseBaselineDataInterleaved(); this.ParseBaselineDataInterleaved();
// this is the only path where conversion is done right after the scan
this.spectralConverter.CommitConversion();
} }
} }

25
src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

@ -14,9 +14,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{ {
internal abstract class SpectralConverter : IDisposable internal abstract class SpectralConverter : IDisposable
{ {
public abstract void CommitConversion();
public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData); public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData);
public abstract void ConvertStrideBaseline(); public abstract void ConvertStrideBaseline();
@ -40,22 +38,25 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
private Buffer2D<TPixel> pixelBuffer; private Buffer2D<TPixel> pixelBuffer;
public int BlockRowsPerStep; public int BlockRowsPerStep;
private int PixelRowsPerStep; private int PixelRowsPerStep;
private int PixelRowCounter; private int PixelRowCounter;
public SpectralConverter(Configuration configuration, CancellationToken ct)
{
this.configuration = configuration;
this.cancellationToken = ct;
}
private bool converted; private bool Converted => this.PixelRowCounter >= this.pixelBuffer.Height;
public Buffer2D<TPixel> PixelBuffer public Buffer2D<TPixel> PixelBuffer
{ {
get get
{ {
if (!this.converted) if (!this.Converted)
{ {
int steps = (int)Math.Ceiling(this.pixelBuffer.Height / (float)this.PixelRowsPerStep); int steps = (int)Math.Ceiling(this.pixelBuffer.Height / (float)this.PixelRowsPerStep);
@ -64,22 +65,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.cancellationToken.ThrowIfCancellationRequested(); this.cancellationToken.ThrowIfCancellationRequested();
this.ConvertNextStride(step); this.ConvertNextStride(step);
} }
this.converted = true;
} }
return this.pixelBuffer; return this.pixelBuffer;
} }
} }
public SpectralConverter(Configuration configuration, CancellationToken ct)
{
this.configuration = configuration;
this.cancellationToken = ct;
}
public override void CommitConversion() => this.converted = true;
public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData) public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
{ {
MemoryAllocator allocator = this.configuration.MemoryAllocator; MemoryAllocator allocator = this.configuration.MemoryAllocator;

Loading…
Cancel
Save