From fae763edd3701de39953f4b31e66719e8a65c490 Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Sun, 11 Jul 2021 11:07:59 +0300 Subject: [PATCH] Final refactor of the converter --- .../Components/Decoder/HuffmanScanDecoder.cs | 3 --- .../Decoder/SpectralConverter{TPixel}.cs | 25 ++++++------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs index 6096722717..34afa72b43 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs @@ -133,9 +133,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder else { this.ParseBaselineDataInterleaved(); - - // this is the only path where conversion is done right after the scan - this.spectralConverter.CommitConversion(); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index c0e6151373..71e37ba8a9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -14,9 +14,7 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { internal abstract class SpectralConverter : IDisposable - { - public abstract void CommitConversion(); - + { public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData); public abstract void ConvertStrideBaseline(); @@ -40,22 +38,25 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private Buffer2D pixelBuffer; - - public int BlockRowsPerStep; private int PixelRowsPerStep; 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 PixelBuffer { get { - if (!this.converted) + if (!this.Converted) { 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.ConvertNextStride(step); } - - this.converted = true; } 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) { MemoryAllocator allocator = this.configuration.MemoryAllocator;