diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs
index 86304d4bd..5db842ba3 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8BandProbas.cs
@@ -8,6 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
///
/// All the probabilities associated to one band.
///
+[Serializable]
internal class Vp8BandProbas
{
///
@@ -22,13 +23,6 @@ internal class Vp8BandProbas
}
}
- ///
- /// Initializes a new instance of the class.
- /// Only used for unit tests.
- ///
- [JsonConstructor]
- public Vp8BandProbas(Vp8ProbaArray[] probabilities) => this.Probabilities = probabilities;
-
///
/// Gets the Probabilities.
///
diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs
index 8268e1c02..ba1b49881 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8CostArray.cs
@@ -1,10 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
-using System.Text.Json.Serialization;
-
namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
+[Serializable]
internal class Vp8CostArray
{
///
@@ -12,12 +11,5 @@ internal class Vp8CostArray
///
public Vp8CostArray() => this.Costs = new ushort[67 + 1];
- ///
- /// Initializes a new instance of the class.
- /// Only used for unit tests.
- ///
- [JsonConstructor]
- public Vp8CostArray(ushort[] costs) => this.Costs = costs;
-
public ushort[] Costs { get; }
}
diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs
index 2441436fb..676874820 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Costs.cs
@@ -1,10 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
-using System.Text.Json.Serialization;
-
namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
+[Serializable]
internal class Vp8Costs
{
///
@@ -19,13 +18,6 @@ internal class Vp8Costs
}
}
- ///
- /// Initializes a new instance of the class.
- /// Only used for unit tests.
- ///
- [JsonConstructor]
- public Vp8Costs(Vp8CostArray[] costs) => this.Costs = costs;
-
///
/// Gets the Costs.
///
diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs
index a19f9742f..ddc1c9d61 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8ProbaArray.cs
@@ -1,13 +1,12 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
-using System.Text.Json.Serialization;
-
namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
///
/// Probabilities associated to one of the contexts.
///
+[Serializable]
internal class Vp8ProbaArray
{
///
@@ -15,13 +14,6 @@ internal class Vp8ProbaArray
///
public Vp8ProbaArray() => this.Probabilities = new byte[WebpConstants.NumProbas];
- ///
- /// Initializes a new instance of the class.
- /// Only used for unit tests.
- ///
- [JsonConstructor]
- public Vp8ProbaArray(byte[] probabilities) => this.Probabilities = probabilities;
-
///
/// Gets the probabilities.
///
diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs
index 6e0937d86..58fba10a7 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs
@@ -14,24 +14,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
///
/// On-the-fly info about the current set of residuals.
///
+[Serializable]
internal class Vp8Residual
{
public Vp8Residual()
{
}
- [JsonConstructor]
- public Vp8Residual(int first, int last, int coeffType, short[] coeffs, Vp8BandProbas[] prob, Vp8Stats[] stats, Vp8Costs[] costs)
- {
- this.First = first;
- this.Last = last;
- this.CoeffType = coeffType;
- this.Coeffs = coeffs;
- this.Prob = prob;
- this.Stats = stats;
- this.Costs = costs;
- }
-
public int First { get; set; }
public int Last { get; set; }
diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs
index b6c05f2d4..23d63f322 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Stats.cs
@@ -1,10 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
-using System.Text.Json.Serialization;
-
namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
+[Serializable]
internal class Vp8Stats
{
///
@@ -19,12 +18,5 @@ internal class Vp8Stats
}
}
- ///
- /// Initializes a new instance of the class.
- /// Only used for unit tests.
- ///
- [JsonConstructor]
- public Vp8Stats(Vp8StatsArray[] stats) => this.Stats = stats;
-
public Vp8StatsArray[] Stats { get; }
}
diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs
index 864248dd8..2ab0702eb 100644
--- a/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs
+++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8StatsArray.cs
@@ -1,10 +1,9 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
-using System.Text.Json.Serialization;
-
namespace SixLabors.ImageSharp.Formats.Webp.Lossy;
+[Serializable]
internal class Vp8StatsArray
{
///
@@ -12,12 +11,5 @@ internal class Vp8StatsArray
///
public Vp8StatsArray() => this.Stats = new uint[WebpConstants.NumProbas];
- ///
- /// Initializes a new instance of the class.
- /// Only used for unit tests.
- ///
- [JsonConstructor]
- public Vp8StatsArray(uint[] stats) => this.Stats = stats;
-
public uint[] Stats { get; }
}
diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs
index 20a161371..2371a179e 100644
--- a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs
+++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs
@@ -1,11 +1,10 @@
// Copyright (c) Six Labors.
// 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.Lossy;
using SixLabors.ImageSharp.Tests.TestUtilities;
-using JsonSerializer = System.Text.Json.JsonSerializer;
namespace SixLabors.ImageSharp.Tests.Formats.Webp;
@@ -15,12 +14,6 @@ public class Vp8ResidualTests
[Fact]
public void Vp8Residual_Serialization_Works()
{
- if (!Sse2.IsSupported)
- {
- // JsonSerializer without SSE2 does not seem to work, skip test then.
- return;
- }
-
// arrange
Vp8Residual expected = new();
Vp8EncProba encProb = new();
@@ -34,8 +27,12 @@ public class Vp8ResidualTests
}
// act
- string jsonString = JsonSerializer.Serialize(expected);
- Vp8Residual actual = JsonSerializer.Deserialize(jsonString);
+ BinaryFormatter formatter = new();
+ using MemoryStream ms = new();
+ formatter.Serialize(ms, expected);
+ ms.Position = 0;
+ object obj = formatter.Deserialize(ms);
+ Vp8Residual actual = (Vp8Residual)obj;
// assert
Assert.Equal(expected.CoeffType, actual.CoeffType);
@@ -82,17 +79,14 @@ public class Vp8ResidualTests
[Fact]
public void GetResidualCost_Works()
{
- if (!Sse2.IsSupported)
- {
- // JsonSerializer without SSE2 does not seem to work, skip test then.
- return;
- }
-
// arrange
int ctx0 = 0;
int expected = 20911;
- string jsonString = File.ReadAllText(Path.Combine("TestDataWebp", "Vp8Residual.json"));
- Vp8Residual residual = JsonSerializer.Deserialize(jsonString);
+ byte[] data = File.ReadAllBytes(Path.Combine("TestDataWebp", "Vp8Residual.bin"));
+ BinaryFormatter formatter = new();
+ using Stream stream = new MemoryStream(data);
+ object obj = formatter.Deserialize(stream);
+ Vp8Residual residual = (Vp8Residual)obj;
// act
int actual = residual.GetResidualCost(ctx0);
@@ -101,8 +95,6 @@ public class Vp8ResidualTests
Assert.Equal(expected, actual);
}
-
-
private static void CreateRandomProbas(Vp8EncProba probas, Random rand)
{
for (int t = 0; t < WebpConstants.NumTypes; ++t)
diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
index 270a02c0c..d17cffc4f 100644
--- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
+++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
@@ -56,7 +56,7 @@
PreserveNewest
-
+
PreserveNewest
diff --git a/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin b/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin
new file mode 100644
index 000000000..d96a3c093
Binary files /dev/null and b/tests/ImageSharp.Tests/TestDataWebp/Vp8Residual.bin differ