|
|
@ -1,11 +1,10 @@ |
|
|
// Copyright (c) Six Labors.
|
|
|
// Copyright (c) Six Labors.
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
|
using System.Runtime.Intrinsics.X86; |
|
|
using System.Runtime.Serialization.Formatters.Binary; |
|
|
using SixLabors.ImageSharp.Formats.Webp; |
|
|
using SixLabors.ImageSharp.Formats.Webp; |
|
|
using SixLabors.ImageSharp.Formats.Webp.Lossy; |
|
|
using SixLabors.ImageSharp.Formats.Webp.Lossy; |
|
|
using SixLabors.ImageSharp.Tests.TestUtilities; |
|
|
using SixLabors.ImageSharp.Tests.TestUtilities; |
|
|
using JsonSerializer = System.Text.Json.JsonSerializer; |
|
|
|
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Webp; |
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Webp; |
|
|
|
|
|
|
|
|
@ -15,12 +14,6 @@ public class Vp8ResidualTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Vp8Residual_Serialization_Works() |
|
|
public void Vp8Residual_Serialization_Works() |
|
|
{ |
|
|
{ |
|
|
if (!Sse2.IsSupported) |
|
|
|
|
|
{ |
|
|
|
|
|
// JsonSerializer without SSE2 does not seem to work, skip test then.
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// arrange
|
|
|
// arrange
|
|
|
Vp8Residual expected = new(); |
|
|
Vp8Residual expected = new(); |
|
|
Vp8EncProba encProb = new(); |
|
|
Vp8EncProba encProb = new(); |
|
|
@ -34,8 +27,12 @@ public class Vp8ResidualTests |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// act
|
|
|
// act
|
|
|
string jsonString = JsonSerializer.Serialize(expected); |
|
|
BinaryFormatter formatter = new(); |
|
|
Vp8Residual actual = JsonSerializer.Deserialize<Vp8Residual>(jsonString); |
|
|
using MemoryStream ms = new(); |
|
|
|
|
|
formatter.Serialize(ms, expected); |
|
|
|
|
|
ms.Position = 0; |
|
|
|
|
|
object obj = formatter.Deserialize(ms); |
|
|
|
|
|
Vp8Residual actual = (Vp8Residual)obj; |
|
|
|
|
|
|
|
|
// assert
|
|
|
// assert
|
|
|
Assert.Equal(expected.CoeffType, actual.CoeffType); |
|
|
Assert.Equal(expected.CoeffType, actual.CoeffType); |
|
|
@ -82,17 +79,14 @@ public class Vp8ResidualTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void GetResidualCost_Works() |
|
|
public void GetResidualCost_Works() |
|
|
{ |
|
|
{ |
|
|
if (!Sse2.IsSupported) |
|
|
|
|
|
{ |
|
|
|
|
|
// JsonSerializer without SSE2 does not seem to work, skip test then.
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// arrange
|
|
|
// arrange
|
|
|
int ctx0 = 0; |
|
|
int ctx0 = 0; |
|
|
int expected = 20911; |
|
|
int expected = 20911; |
|
|
string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); |
|
|
byte[] data = File.ReadAllBytes(Path.Combine("TestDataWebp", "Vp8Residual.bin")); |
|
|
Vp8Residual residual = JsonSerializer.Deserialize<Vp8Residual>(jsonString); |
|
|
BinaryFormatter formatter = new(); |
|
|
|
|
|
using Stream stream = new MemoryStream(data); |
|
|
|
|
|
object obj = formatter.Deserialize(stream); |
|
|
|
|
|
Vp8Residual residual = (Vp8Residual)obj; |
|
|
|
|
|
|
|
|
// act
|
|
|
// act
|
|
|
int actual = residual.GetResidualCost(ctx0); |
|
|
int actual = residual.GetResidualCost(ctx0); |
|
|
@ -101,8 +95,6 @@ public class Vp8ResidualTests |
|
|
Assert.Equal(expected, actual); |
|
|
Assert.Equal(expected, actual); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void CreateRandomProbas(Vp8EncProba probas, Random rand) |
|
|
private static void CreateRandomProbas(Vp8EncProba probas, Random rand) |
|
|
{ |
|
|
{ |
|
|
for (int t = 0; t < WebpConstants.NumTypes; ++t) |
|
|
for (int t = 0; t < WebpConstants.NumTypes; ++t) |
|
|
|