Browse Source

Fixed failing tests

pull/1761/head
Dmitry Pentin 5 years ago
parent
commit
7a21a88944
  1. 18
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
  2. 18
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs

18
src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs

@ -303,8 +303,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
this.huffmanTables = HuffmanLut.TheHuffmanLut;
var unzig = ZigZag.CreateUnzigTable();
// ReSharper disable once InconsistentNaming
int prevDCR = 0, prevDCG = 0, prevDCB = 0;
@ -327,26 +325,28 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
QuantIndex.Luminance,
prevDCR,
ref pixelConverter.R,
ref luminanceQuantTable,
ref unzig);
ref luminanceQuantTable);
prevDCG = this.WriteBlock(
QuantIndex.Luminance,
prevDCG,
ref pixelConverter.G,
ref luminanceQuantTable,
ref unzig);
ref luminanceQuantTable);
prevDCB = this.WriteBlock(
QuantIndex.Luminance,
prevDCB,
ref pixelConverter.B,
ref luminanceQuantTable,
ref unzig);
ref luminanceQuantTable);
if (this.IsFlushNeeded)
{
this.FlushToStream();
}
}
}
this.FlushInternalBuffer();
this.FlushRemainingBytes();
}
/// <summary>

18
tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs

@ -248,24 +248,26 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
short fillValue = (short)rng.Next(-2000, 2000);
// first filled chunk
int lastIndex1 = rng.Next(1, Block8x8F.Size / 2);
for (int dataIndex = 0; dataIndex <= lastIndex1; dataIndex++)
int firstChunkStart = rng.Next(0, Block8x8.Size / 2);
int firstChunkEnd = rng.Next(firstChunkStart, Block8x8.Size / 2);
for (int dataIdx = firstChunkStart; dataIdx <= firstChunkEnd; dataIdx++)
{
data[dataIndex] = fillValue;
data[dataIdx] = fillValue;
}
// second filled chunk, there might be a spot with zero(s) between first and second chunk
int lastIndex2 = rng.Next(lastIndex1 + 1, Block8x8F.Size);
for (int dataIndex = 0; dataIndex <= lastIndex2; dataIndex++)
int secondChunkStart = rng.Next(firstChunkEnd, Block8x8.Size);
int secondChunkEnd = rng.Next(secondChunkStart, Block8x8.Size);
for (int dataIdx = secondChunkStart; dataIdx <= secondChunkEnd; dataIdx++)
{
data[dataIndex] = fillValue;
data[dataIdx] = fillValue;
}
int expected = lastIndex2;
int expected = secondChunkEnd;
int actual = data.GetLastNonZeroIndex();
Assert.Equal(expected, actual);
Assert.True(expected == actual, $"Expected: {expected}\nActual: {actual}\nInput matrix: {data}");
}
}

Loading…
Cancel
Save