22// Licensed under the Six Labors Split License.
33
44using System . Runtime . InteropServices ;
5- using SixLabors . ImageSharp . Formats . Png ;
65using SixLabors . ImageSharp . Formats . Webp ;
76using SixLabors . ImageSharp . Metadata ;
87using SixLabors . ImageSharp . PixelFormats ;
@@ -24,22 +23,41 @@ public void Encode_AnimatedLossless<TPixel>(TestImageProvider<TPixel> provider)
2423 where TPixel : unmanaged, IPixel < TPixel >
2524 {
2625 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 ) ;
2934
30- // TODO: DebugSave, VerifySimilarity
35+ // Compare encoded result
36+ image . VerifyEncoder ( provider , "webp" , string . Empty , encoder ) ;
3137 }
3238
3339 [ Theory ]
3440 [ WithFile ( Lossy . Animated , PixelTypes . Rgba32 ) ]
41+ [ WithFile ( Lossy . AnimatedLandscape , PixelTypes . Rgba32 ) ]
3542 public void Encode_AnimatedLossy < TPixel > ( TestImageProvider < TPixel > provider )
3643 where TPixel : unmanaged, IPixel < TPixel >
3744 {
3845 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 ) ;
4154
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" ) ;
4361 }
4462
4563 [ Theory ]
0 commit comments