2
2
// Licensed under the Six Labors Split License.
3
3
4
4
using System . Runtime . InteropServices ;
5
- using SixLabors . ImageSharp . Formats . Png ;
6
5
using SixLabors . ImageSharp . Formats . Webp ;
7
6
using SixLabors . ImageSharp . Metadata ;
8
7
using SixLabors . ImageSharp . PixelFormats ;
@@ -24,22 +23,41 @@ public void Encode_AnimatedLossless<TPixel>(TestImageProvider<TPixel> provider)
24
23
where TPixel : unmanaged, IPixel < TPixel >
25
24
{
26
25
using Image < TPixel > image = provider . GetImage ( ) ;
27
- using MemoryStream memStream = new ( ) ;
28
- image . SaveAsWebp ( memStream , new ( ) { FileFormat = WebpFileFormatType . Lossless } ) ;
26
+ WebpEncoder encoder = new ( )
27
+ {
28
+ FileFormat = WebpFileFormatType . Lossless ,
29
+ Quality = 100
30
+ } ;
31
+
32
+ // Always save as we need to compare the encoded output.
33
+ provider . Utility . SaveTestOutputFile ( image , "webp" , encoder ) ;
29
34
30
- // TODO: DebugSave, VerifySimilarity
35
+ // Compare encoded result
36
+ image . VerifyEncoder ( provider , "webp" , string . Empty , encoder ) ;
31
37
}
32
38
33
39
[ Theory ]
34
40
[ WithFile ( Lossy . Animated , PixelTypes . Rgba32 ) ]
41
+ [ WithFile ( Lossy . AnimatedLandscape , PixelTypes . Rgba32 ) ]
35
42
public void Encode_AnimatedLossy < TPixel > ( TestImageProvider < TPixel > provider )
36
43
where TPixel : unmanaged, IPixel < TPixel >
37
44
{
38
45
using Image < TPixel > image = provider . GetImage ( ) ;
39
- using MemoryStream memStream = new ( ) ;
40
- image . SaveAsWebp ( memStream , new ( ) ) ;
46
+ WebpEncoder encoder = new ( )
47
+ {
48
+ FileFormat = WebpFileFormatType . Lossy ,
49
+ Quality = 100
50
+ } ;
51
+
52
+ // Always save as we need to compare the encoded output.
53
+ provider . Utility . SaveTestOutputFile ( image , "webp" , encoder ) ;
41
54
42
- // TODO: DebugSave, VerifySimilarity
55
+ // Compare encoded result
56
+ // The reference decoder seems to produce differences up to 0.1% but the input/output have been
57
+ // checked to be correct.
58
+ string path = provider . Utility . GetTestOutputFileName ( "webp" , null , true ) ;
59
+ using Image < Rgba32 > encoded = Image . Load < Rgba32 > ( path ) ;
60
+ encoded . CompareToReferenceOutput ( ImageComparer . Tolerant ( 0.01f ) , provider , null , "webp" ) ;
43
61
}
44
62
45
63
[ Theory ]
0 commit comments