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; this.huffmanTables = HuffmanLut.TheHuffmanLut;
var unzig = ZigZag.CreateUnzigTable();
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
int prevDCR = 0, prevDCG = 0, prevDCB = 0; int prevDCR = 0, prevDCG = 0, prevDCB = 0;
@ -327,26 +325,28 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
QuantIndex.Luminance, QuantIndex.Luminance,
prevDCR, prevDCR,
ref pixelConverter.R, ref pixelConverter.R,
ref luminanceQuantTable, ref luminanceQuantTable);
ref unzig);
prevDCG = this.WriteBlock( prevDCG = this.WriteBlock(
QuantIndex.Luminance, QuantIndex.Luminance,
prevDCG, prevDCG,
ref pixelConverter.G, ref pixelConverter.G,
ref luminanceQuantTable, ref luminanceQuantTable);
ref unzig);
prevDCB = this.WriteBlock( prevDCB = this.WriteBlock(
QuantIndex.Luminance, QuantIndex.Luminance,
prevDCB, prevDCB,
ref pixelConverter.B, ref pixelConverter.B,
ref luminanceQuantTable, ref luminanceQuantTable);
ref unzig);
if (this.IsFlushNeeded)
{
this.FlushToStream();
}
} }
} }
this.FlushInternalBuffer(); this.FlushRemainingBytes();
} }
/// <summary> /// <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); short fillValue = (short)rng.Next(-2000, 2000);
// first filled chunk // first filled chunk
int lastIndex1 = rng.Next(1, Block8x8F.Size / 2); int firstChunkStart = rng.Next(0, Block8x8.Size / 2);
for (int dataIndex = 0; dataIndex <= lastIndex1; dataIndex++) 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 // second filled chunk, there might be a spot with zero(s) between first and second chunk
int lastIndex2 = rng.Next(lastIndex1 + 1, Block8x8F.Size); int secondChunkStart = rng.Next(firstChunkEnd, Block8x8.Size);
for (int dataIndex = 0; dataIndex <= lastIndex2; dataIndex++) 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(); int actual = data.GetLastNonZeroIndex();
Assert.Equal(expected, actual); Assert.True(expected == actual, $"Expected: {expected}\nActual: {actual}\nInput matrix: {data}");
} }
} }

Loading…
Cancel
Save