From dbe4c4e870f645d5706001eaa8eb368458a633ca Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Fri, 9 Jul 2021 18:11:36 +0300 Subject: [PATCH] Fixed iteration variables --- .../Decoder/SpectralConverter{TPixel}.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index 578a05e32..3db47aa66 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -30,6 +30,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private Buffer2D pixelBuffer; + + public int BlockRowsPerStep; + + private int PixelRowsPerStep; + + private int PixelRowCounter; + + public JpegFrame Frame { set => this.InjectFrame(value); @@ -59,11 +67,18 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder // color converter from Rgba32 to TPixel this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace, frame.Precision); + + // iteration data + IJpegComponent c0 = frame.Components[0]; + + const int blockPixelHeight = 8; + this.BlockRowsPerStep = c0.SamplingFactors.Height; + this.PixelRowsPerStep = this.BlockRowsPerStep * blockPixelHeight; } public override void ConvertStride() { - int maxY = Math.Min(this.pixelBuffer.Height, this.PixelRowCounter + 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++) @@ -79,13 +94,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder var values = new JpegColorConverter.ComponentValues(buffers, y); this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan()); - Span destRow = destination.GetPixelRowSpan(yy); + Span destRow = this.pixelBuffer.GetRowSpan(yy); // TODO: Investigate if slicing is actually necessary PixelOperations.Instance.FromVector4Destructive(this.configuration, this.rgbaBuffer.GetSpan().Slice(0, destRow.Length), destRow); } - this.PixelRowCounter += PixelRowsPerStep; + this.PixelRowCounter += this.PixelRowsPerStep; } } }