11// Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
33
4- using System . Runtime . Intrinsics . X86 ;
4+ using System . Runtime . Serialization . Formatters . Binary ;
55using SixLabors . ImageSharp . Formats . Webp ;
66using SixLabors . ImageSharp . Formats . Webp . Lossy ;
77using SixLabors . ImageSharp . Tests . TestUtilities ;
8- using JsonSerializer = System . Text . Json . JsonSerializer ;
98
109namespace SixLabors . ImageSharp . Tests . Formats . Webp ;
1110
@@ -15,12 +14,6 @@ public class Vp8ResidualTests
1514 [ Fact ]
1615 public void Vp8Residual_Serialization_Works ( )
1716 {
18- if ( ! Sse2 . IsSupported )
19- {
20- // JsonSerializer without SSE2 does not seem to work, skip test then.
21- return ;
22- }
23-
2417 // arrange
2518 Vp8Residual expected = new ( ) ;
2619 Vp8EncProba encProb = new ( ) ;
@@ -34,8 +27,12 @@ public void Vp8Residual_Serialization_Works()
3427 }
3528
3629 // act
37- string jsonString = JsonSerializer . Serialize ( expected ) ;
38- Vp8Residual actual = JsonSerializer . Deserialize < Vp8Residual > ( jsonString ) ;
30+ BinaryFormatter formatter = new ( ) ;
31+ using MemoryStream ms = new ( ) ;
32+ formatter . Serialize ( ms , expected ) ;
33+ ms . Position = 0 ;
34+ object obj = formatter . Deserialize ( ms ) ;
35+ Vp8Residual actual = ( Vp8Residual ) obj ;
3936
4037 // assert
4138 Assert . Equal ( expected . CoeffType , actual . CoeffType ) ;
@@ -82,17 +79,14 @@ public void Vp8Residual_Serialization_Works()
8279 [ Fact ]
8380 public void GetResidualCost_Works ( )
8481 {
85- if ( ! Sse2 . IsSupported )
86- {
87- // JsonSerializer without SSE2 does not seem to work, skip test then.
88- return ;
89- }
90-
9182 // arrange
9283 int ctx0 = 0 ;
9384 int expected = 20911 ;
94- string jsonString = File . ReadAllText ( Path . Combine ( "TestDataWebp" , "Vp8Residual.json" ) ) ;
95- Vp8Residual residual = JsonSerializer . Deserialize < Vp8Residual > ( jsonString ) ;
85+ byte [ ] data = File . ReadAllBytes ( Path . Combine ( "TestDataWebp" , "Vp8Residual.bin" ) ) ;
86+ BinaryFormatter formatter = new ( ) ;
87+ using Stream stream = new MemoryStream ( data ) ;
88+ object obj = formatter . Deserialize ( stream ) ;
89+ Vp8Residual residual = ( Vp8Residual ) obj ;
9690
9791 // act
9892 int actual = residual . GetResidualCost ( ctx0 ) ;
@@ -101,8 +95,6 @@ public void GetResidualCost_Works()
10195 Assert . Equal ( expected , actual ) ;
10296 }
10397
104-
105-
10698 private static void CreateRandomProbas ( Vp8EncProba probas , Random rand )
10799 {
108100 for ( int t = 0 ; t < WebpConstants . NumTypes ; ++ t )
0 commit comments