Skip to content

Commit b0d9cb8

Browse files
committed
Add BundleColorMap tests
1 parent 4043429 commit b0d9cb8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,62 @@ private static void RunPredictor13Test()
214214
Assert.Equal(expectedResult1, actual1);
215215
}
216216

217+
[Fact]
218+
public void BundleColorMap_WithXbitsZero_Works()
219+
{
220+
// arrange
221+
byte[] row = { 238, 238, 238, 238, 238, 238, 240, 237, 240, 235, 223, 223, 218, 220, 226, 219, 220, 204, 218, 211, 218, 221, 254, 255 };
222+
int xBits = 0;
223+
uint[] actual = new uint[row.Length];
224+
uint[] expected =
225+
{
226+
4278251008, 4278251008, 4278251008, 4278251008, 4278251008,
227+
4278251008, 4278251520, 4278250752, 4278251520, 4278250240,
228+
4278247168, 4278247168, 4278245888, 4278246400, 4278247936,
229+
4278246144, 4278246400, 4278242304, 4278245888, 4278244096,
230+
4278245888, 4278246656, 4278255104, 4278255360
231+
};
232+
233+
// act
234+
LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual);
235+
236+
// assert
237+
Assert.True(actual.SequenceEqual(expected));
238+
}
239+
240+
[Fact]
241+
public void BundleColorMap_WithXbitsNoneZero_Works()
242+
{
243+
// arrange
244+
byte[] row =
245+
{
246+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
247+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
248+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
249+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
250+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
251+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
252+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
253+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
254+
};
255+
int xBits = 2;
256+
uint[] actual = new uint[row.Length];
257+
uint[] expected =
258+
{
259+
4278233600, 4278233600, 4278233600, 4278233600, 4278255360, 4278255360, 4278255360, 4278255360, 4278233600, 4278233600, 4278233600, 4278233600,
260+
4278255360, 4278255360, 4278255360, 4278255360, 4278211840, 4278211840, 4278211840, 4278211840, 4278255360, 4278255360, 4278255360, 4278255360,
261+
4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278206208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
262+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
263+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
264+
};
265+
266+
// act
267+
LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual);
268+
269+
// assert
270+
Assert.True(actual.SequenceEqual(expected));
271+
}
272+
217273
[Fact]
218274
public void CombinedShannonEntropy_Works() => RunCombinedShannonEntropyTest();
219275

0 commit comments

Comments
 (0)