Browse Source

Fixed out of range exception for baseline tests

pull/1694/head
Dmitry Pentin 5 years ago
parent
commit
39dd5bc536
  1. 28
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs

28
tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs

@ -58,17 +58,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public void LoadSpectralStride(Buffer2D<Block8x8> 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<Block8x8> blockRow = data.GetRowSpan(y);
for (int x = 0; x < data.Width; x++)
Span<Block8x8> 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<Block8x8> data = c.SpectralBlocks;
for (int y = 0; y < c.HeightInBlocks; y++)
for (int y = 0; y < this.HeightInBlocks; y++)
{
Span<Block8x8> 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<Block8x8> 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;
}

Loading…
Cancel
Save