|
5 | 5 | using System.Text.Json;
|
6 | 6 | using SixLabors.ImageSharp.Formats.Webp;
|
7 | 7 | using SixLabors.ImageSharp.Formats.Webp.Lossy;
|
| 8 | +using SixLabors.ImageSharp.Tests.Formats.WebP.Serialization; |
8 | 9 | using SixLabors.ImageSharp.Tests.TestUtilities;
|
| 10 | +using JsonSerializer = System.Text.Json.JsonSerializer; |
9 | 11 |
|
10 | 12 | namespace SixLabors.ImageSharp.Tests.Formats.Webp;
|
11 | 13 |
|
12 | 14 | [Trait("Format", "Webp")]
|
13 | 15 | public class Vp8ResidualTests
|
14 | 16 | {
|
15 | 17 | [Fact]
|
16 |
| - public void GetResidualCost_Works() |
| 18 | + public void Vp8CostArray_Serialization_Works() |
17 | 19 | {
|
18 |
| - if (!Sse2.IsSupported) |
| 20 | + // arrange |
| 21 | + Vp8CostArray expected = new(); |
| 22 | + for (ushort i = 0; i < expected.Costs.Length; i++) |
19 | 23 | {
|
20 |
| - // JsonSerializer without SSE2 does not seem to work, skip test then. |
21 |
| - return; |
| 24 | + expected.Costs[i] = i; |
22 | 25 | }
|
23 | 26 |
|
24 |
| - // arrange |
25 |
| - int ctx0 = 0; |
26 |
| - int expected = 20911; |
27 |
| - string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); |
28 |
| - Vp8Residual residual = JsonSerializer.Deserialize<Vp8Residual>(jsonString); |
| 27 | + JsonSerializerOptions options = new() |
| 28 | + { |
| 29 | + Converters = { new Vp8CostArrayJsonConverter() } |
| 30 | + }; |
29 | 31 |
|
30 | 32 | // act
|
31 |
| - int actual = residual.GetResidualCost(ctx0); |
| 33 | + string jsonString = JsonSerializer.Serialize(expected); |
| 34 | + Vp8CostArray actual = JsonSerializer.Deserialize<Vp8CostArray>(jsonString, options); |
32 | 35 |
|
33 | 36 | // assert
|
34 |
| - Assert.Equal(expected, actual); |
| 37 | + Assert.Equal(expected.Costs, actual.Costs); |
35 | 38 | }
|
36 | 39 |
|
37 | 40 | [Fact]
|
38 |
| - public void Serialization_Works() |
| 41 | + public void Vp8Residual_Serialization_Works() |
39 | 42 | {
|
40 | 43 | if (!Sse2.IsSupported)
|
41 | 44 | {
|
@@ -101,6 +104,30 @@ public void Serialization_Works()
|
101 | 104 | }
|
102 | 105 | }
|
103 | 106 |
|
| 107 | + [Fact] |
| 108 | + public void GetResidualCost_Works() |
| 109 | + { |
| 110 | + if (!Sse2.IsSupported) |
| 111 | + { |
| 112 | + // JsonSerializer without SSE2 does not seem to work, skip test then. |
| 113 | + return; |
| 114 | + } |
| 115 | + |
| 116 | + // arrange |
| 117 | + int ctx0 = 0; |
| 118 | + int expected = 20911; |
| 119 | + string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json")); |
| 120 | + Vp8Residual residual = JsonSerializer.Deserialize<Vp8Residual>(jsonString); |
| 121 | + |
| 122 | + // act |
| 123 | + int actual = residual.GetResidualCost(ctx0); |
| 124 | + |
| 125 | + // assert |
| 126 | + Assert.Equal(expected, actual); |
| 127 | + } |
| 128 | + |
| 129 | + |
| 130 | + |
104 | 131 | private static void CreateRandomProbas(Vp8EncProba probas, Random rand)
|
105 | 132 | {
|
106 | 133 | for (int t = 0; t < WebpConstants.NumTypes; ++t)
|
|
0 commit comments