diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
index adabd0ac3..7769a0a6c 100644
--- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
+++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
@@ -192,7 +192,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
public bool UseCrossColorTransform { get; set; }
///
- /// Gets or sets a value indicating whether to use the substract green transform.
+ /// Gets or sets a value indicating whether to use the subtract green transform.
///
public bool UseSubtractGreenTransform { get; set; }
@@ -1049,7 +1049,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
return EntropyIx.Palette;
}
- using IMemoryOwner histoBuffer = this.memoryAllocator.Allocate((int)HistoIx.HistoTotal * 256);
+ using IMemoryOwner histoBuffer = this.memoryAllocator.Allocate((int)HistoIx.HistoTotal * 256, AllocationOptions.Clean);
Span histo = histoBuffer.Memory.Span;
uint pixPrev = bgra[0]; // Skip the first pixel.
ReadOnlySpan prevRow = null;
diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
index 70cc487bf..ec0040a46 100644
--- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
@@ -101,6 +101,24 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
+ [Theory]
+ [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 15114)]
+ public void Encode_Lossless_WithBestQuality_HasExpectedSize(TestImageProvider provider, int expectedBytes)
+ where TPixel : unmanaged, IPixel
+ {
+ var encoder = new WebpEncoder()
+ {
+ FileFormat = WebpFileFormatType.Lossless,
+ Method = WebpEncodingMethod.BestQuality
+ };
+
+ using Image image = provider.GetImage();
+ using var memoryStream = new MemoryStream();
+ image.Save(memoryStream, encoder);
+
+ Assert.Equal(memoryStream.Length, expectedBytes);
+ }
+
[Theory]
[WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 85)]
[WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 60)]