Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests for Webp lossless utils #2424

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 80 additions & 10 deletions tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,88 @@ private static void RunPredictor12Test()
private static void RunPredictor13Test()
{
// arrange
uint[] topData = { 4278193922, 4278193666 };
const uint left = 4278193410;
const uint expectedResult = 4278193154;
uint[] topData0 = { 4278193922, 4278193666 };
const uint left0 = 4278193410;
const uint expectedResult0 = 4278193154;
uint[] topData1 = { 4294933015, 4278219803 };
const uint left1 = 4278236686;
const uint expectedResult1 = 4278231571;
uint actual0 = 0;
uint actual1 = 0;

// act
unsafe
{
fixed (uint* top = &topData[1])
fixed (uint* top = &topData0[1])
{
uint actual = LosslessUtils.Predictor13(left, top);
actual0 = LosslessUtils.Predictor13(left0, top);
}

// assert
Assert.Equal(expectedResult, actual);
fixed (uint* top = &topData1[1])
{
actual1 = LosslessUtils.Predictor13(left1, top);
}
}

// assert
Assert.Equal(expectedResult0, actual0);
Assert.Equal(expectedResult1, actual1);
}

[Fact]
public void BundleColorMap_WithXbitsZero_Works()
{
// arrange
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 };
int xBits = 0;
uint[] actual = new uint[row.Length];
uint[] expected =
{
4278251008, 4278251008, 4278251008, 4278251008, 4278251008,
4278251008, 4278251520, 4278250752, 4278251520, 4278250240,
4278247168, 4278247168, 4278245888, 4278246400, 4278247936,
4278246144, 4278246400, 4278242304, 4278245888, 4278244096,
4278245888, 4278246656, 4278255104, 4278255360
};

// act
LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual);

// assert
Assert.True(actual.SequenceEqual(expected));
}

[Fact]
public void BundleColorMap_WithXbitsNoneZero_Works()
{
// arrange
byte[] row =
{
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
int xBits = 2;
uint[] actual = new uint[row.Length];
uint[] expected =
{
4278233600, 4278233600, 4278233600, 4278233600, 4278255360, 4278255360, 4278255360, 4278255360, 4278233600, 4278233600, 4278233600, 4278233600,
4278255360, 4278255360, 4278255360, 4278255360, 4278211840, 4278211840, 4278211840, 4278211840, 4278255360, 4278255360, 4278255360, 4278255360,
4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278255360, 4278206208, 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, 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
};

// act
LosslessUtils.BundleColorMap(row, actual.Length, xBits, actual);

// assert
Assert.True(actual.SequenceEqual(expected));
}

[Fact]
Expand All @@ -215,9 +282,6 @@ private static void RunPredictor13Test()
[Fact]
public void Predictor13_Works() => RunPredictor13Test();

[Fact]
public void SubtractGreen_Works() => RunSubtractGreenTest();

[Fact]
public void AddGreenToBlueAndRed_Works() => RunAddGreenToBlueAndRedTest();

Expand Down Expand Up @@ -251,12 +315,18 @@ private static void RunPredictor13Test()
[Fact]
public void Predictor13_WithoutSSE2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunPredictor13Test, HwIntrinsics.DisableSSE2);

[Fact]
public void SubtractGreen_Works() => RunSubtractGreenTest();

[Fact]
public void SubtractGreen_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.AllowAll);

[Fact]
public void SubtractGreen_WithoutAVX2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableAVX2);

[Fact]
public void SubtractGreen_Scalar_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableHWIntrinsic);

[Fact]
public void SubtractGreen_WithoutAvxOrSSSE3_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableAVX2 | HwIntrinsics.DisableSSSE3);

Expand Down