From 7afca199b769236cb12982f0412770ea98cfbb0e Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Sun, 11 Jul 2021 10:01:12 +0300 Subject: [PATCH] Rolled back to counter enumeration for spectral converter --- .../Decoder/SpectralConverter{TPixel}.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index 3499704ae..706e4c0b7 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData); - public abstract void ConvertStride(int step, int spectralStep); + public abstract void ConvertStride(int spectralStep); public abstract void ClearStride(int spectralStep); public abstract void Dispose(); } - internal class SpectralConverter : SpectralConverter + internal sealed class SpectralConverter : SpectralConverter where TPixel : unmanaged, IPixel { private Configuration configuration; @@ -48,6 +48,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private int PixelRowsPerStep; + private int PixelRowCounter; + private bool converted; @@ -62,7 +64,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int i = 0; i < steps; i++) { this.cancellationToken.ThrowIfCancellationRequested(); - this.ConvertStride(i, i); + this.ConvertStride(i); } this.converted = true; @@ -109,11 +111,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.colorConverter = JpegColorConverter.GetConverter(jpegData.ColorSpace, frame.Precision); } - public override void ConvertStride(int step, int spectralStep) + public override void ConvertStride(int spectralStep) { - int pixelRowStart = this.PixelRowsPerStep * step; - - int maxY = Math.Min(this.pixelBuffer.Height, pixelRowStart + this.PixelRowsPerStep); + int maxY = Math.Min(this.pixelBuffer.Height, this.PixelRowCounter + this.PixelRowsPerStep); var buffers = new Buffer2D[this.componentProcessors.Length]; for (int i = 0; i < this.componentProcessors.Length; i++) @@ -122,9 +122,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder buffers[i] = this.componentProcessors[i].ColorBuffer; } - for (int yy = pixelRowStart; yy < maxY; yy++) + for (int yy = this.PixelRowCounter; yy < maxY; yy++) { - int y = yy - pixelRowStart; + int y = yy - this.PixelRowCounter; var values = new JpegColorConverter.ComponentValues(buffers, y); this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan()); @@ -134,13 +134,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // TODO: Investigate if slicing is actually necessary PixelOperations.Instance.FromVector4Destructive(this.configuration, this.rgbaBuffer.GetSpan().Slice(0, destRow.Length), destRow); } + + this.PixelRowCounter += this.PixelRowsPerStep; } public override void ClearStride(int spectralStep) { foreach (JpegComponentPostProcessor cpp in this.componentProcessors) { - cpp.ClearSpectralStride(spectralStep); + cpp.ClearSpectralBuffers(spectralStep); } }