Skip to content

Commit 2c260b2

Browse files
committed
add unit test and format
1 parent 87de521 commit 2c260b2

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/ImageSharp/Formats/Webp/BitWriter/Vp8LBitWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public Vp8LBitWriter(int expectedSize)
4444
{
4545
}
4646

47-
/// <inheritdoc/>
48-
public override int NumBytes => this.cur + ((this.used + 7) >> 3);
49-
5047
/// <summary>
5148
/// Initializes a new instance of the <see cref="Vp8LBitWriter"/> class.
5249
/// Used internally for cloning.
@@ -59,6 +56,9 @@ private Vp8LBitWriter(byte[] buffer, ulong bits, int used, int cur)
5956
this.cur = cur;
6057
}
6158

59+
/// <inheritdoc/>
60+
public override int NumBytes => this.cur + ((this.used + 7) >> 3);
61+
6262
/// <summary>
6363
/// This function writes bits into bytes in increasing addresses (little endian),
6464
/// and within a byte least-significant-bit first. This function can write up to 32 bits in one go.

tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Six Labors Split License.
33

44
using System.Runtime.InteropServices;
5+
using SixLabors.ImageSharp.Formats.Png;
56
using SixLabors.ImageSharp.Formats.Webp;
67
using SixLabors.ImageSharp.Metadata;
78
using SixLabors.ImageSharp.PixelFormats;
@@ -17,14 +18,28 @@ public class WebpEncoderTests
1718
{
1819
private static string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, Lossy.NoFilter06);
1920

20-
[Fact]
21-
public void Encode_AnimatedLossy()
21+
[Theory]
22+
[WithFile(Lossless.Animated, PixelTypes.Rgba32)]
23+
public void Encode_AnimatedLossless<TPixel>(TestImageProvider<TPixel> provider)
24+
where TPixel : unmanaged, IPixel<TPixel>
2225
{
23-
Image<Rgba32> image = Image.Load<Rgba32>(@"C:\WorkSpace\ImageSharp\tests\Images\Input\Webp\leo_animated_lossless.webp");
24-
image.SaveAsWebp(@"C:\Users\poker\Desktop\3.webp", new WebpEncoder()
25-
{
26-
FileFormat = WebpFileFormatType.Lossless
27-
});
26+
using Image<TPixel> image = provider.GetImage();
27+
using MemoryStream memStream = new();
28+
image.SaveAsWebp(memStream, new() { FileFormat = WebpFileFormatType.Lossless });
29+
30+
// TODO: DebugSave, VerifySimilarity
31+
}
32+
33+
[Theory]
34+
[WithFile(Lossy.Animated, PixelTypes.Rgba32)]
35+
public void Encode_AnimatedLossy<TPixel>(TestImageProvider<TPixel> provider)
36+
where TPixel : unmanaged, IPixel<TPixel>
37+
{
38+
using Image<TPixel> image = provider.GetImage();
39+
using MemoryStream memStream = new();
40+
image.SaveAsWebp(memStream, new());
41+
42+
// TODO: DebugSave, VerifySimilarity
2843
}
2944

3045
[Theory]

0 commit comments

Comments
 (0)