diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 4ec9b8d69..edb8d457b 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -58,17 +58,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public void LoadSpectralStride(Buffer2D data, int strideIndex) { - for (int y = 0; y < data.Height; y++) + int startIndex = strideIndex * data.Height; + + int endIndex = Math.Min(this.HeightInBlocks, startIndex + data.Height); + + for (int y = startIndex; y < endIndex; y++) { - Span blockRow = data.GetRowSpan(y); - for (int x = 0; x < data.Width; x++) + Span blockRow = data.GetRowSpan(y - startIndex); + for (int x = 0; x < this.WidthInBlocks; x++) { short[] block = blockRow[x].ToArray(); // x coordinate stays the same - we load entire stride // y coordinate is tricky as we load single stride to full buffer - offset is needed - int yOffset = strideIndex * data.Height; - this.MakeBlock(block, y + yOffset, x); + this.MakeBlock(block, y, x); } } } @@ -76,10 +79,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils public void LoadSpectral(JpegComponent c) { Buffer2D data = c.SpectralBlocks; - for (int y = 0; y < c.HeightInBlocks; y++) + for (int y = 0; y < this.HeightInBlocks; y++) { Span blockRow = data.GetRowSpan(y); - for (int x = 0; x < c.WidthInBlocks; x++) + for (int x = 0; x < this.WidthInBlocks; x++) { short[] block = blockRow[x].ToArray(); this.MakeBlock(block, y, x); @@ -94,16 +97,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils c.HeightInBlocks, index); - for (int y = 0; y < result.HeightInBlocks; y++) - { - Span blockRow = c.SpectralBlocks.GetRowSpan(y); - for (int x = 0; x < result.WidthInBlocks; x++) - { - short[] data = blockRow[x].ToArray(); - result.MakeBlock(data, y, x); - } - } - + result.LoadSpectral(c); return result; }