From 2c260b27bf273f7154a93a43bf1e5149776fbe5d Mon Sep 17 00:00:00 2001 From: Poker Date: Tue, 24 Oct 2023 00:09:10 +0800 Subject: [PATCH] add unit test and format --- .../Formats/Webp/BitWriter/Vp8LBitWriter.cs | 6 ++-- .../Formats/WebP/WebpEncoderTests.cs | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs b/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs index bce77c9e5c..0b71a3ed0c 100644 --- a/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs +++ b/src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs @@ -44,9 +44,6 @@ internal class Vp8LBitWriter : BitWriterBase { } - /// - public override int NumBytes => this.cur + ((this.used + 7) >> 3); - /// /// Initializes a new instance of the class. /// Used internally for cloning. @@ -59,6 +56,9 @@ internal class Vp8LBitWriter : BitWriterBase this.cur = cur; } + /// + public override int NumBytes => this.cur + ((this.used + 7) >> 3); + /// /// This function writes bits into bytes in increasing addresses (little endian), /// and within a byte least-significant-bit first. This function can write up to 32 bits in one go. diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index 1721cd938b..d81c9eb93a 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; @@ -17,14 +18,28 @@ public class WebpEncoderTests { private static string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, Lossy.NoFilter06); - [Fact] - public void Encode_AnimatedLossy() + [Theory] + [WithFile(Lossless.Animated, PixelTypes.Rgba32)] + public void Encode_AnimatedLossless(TestImageProvider provider) + where TPixel : unmanaged, IPixel { - Image image = Image.Load(@"C:\WorkSpace\ImageSharp\tests\Images\Input\Webp\leo_animated_lossless.webp"); - image.SaveAsWebp(@"C:\Users\poker\Desktop\3.webp", new WebpEncoder() - { - FileFormat = WebpFileFormatType.Lossless - }); + using Image image = provider.GetImage(); + using MemoryStream memStream = new(); + image.SaveAsWebp(memStream, new() { FileFormat = WebpFileFormatType.Lossless }); + + // TODO: DebugSave, VerifySimilarity + } + + [Theory] + [WithFile(Lossy.Animated, PixelTypes.Rgba32)] + public void Encode_AnimatedLossy(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + using MemoryStream memStream = new(); + image.SaveAsWebp(memStream, new()); + + // TODO: DebugSave, VerifySimilarity } [Theory]