diff --git a/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs b/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
index 075f8f53ea..66d3c86e46 100644
--- a/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
+++ b/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
@@ -4,7 +4,7 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
-
+using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless;
using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy;
using SixLabors.ImageSharp.Memory;
@@ -48,6 +48,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
///
private readonly int entropyPasses;
+ ///
+ /// The global configuration.
+ ///
+ private Configuration configuration;
+
///
/// Initializes a new instance of the class.
///
@@ -76,6 +81,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream));
+ this.configuration = image.GetConfiguration();
+
if (this.lossy)
{
var enc = new Vp8Encoder(this.memoryAllocator, image.Width, image.Height, this.quality, this.method, this.entropyPasses);
@@ -98,6 +105,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
public async Task EncodeAsync(Image image, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel
{
+ this.configuration = image.GetConfiguration();
+
if (stream.CanSeek)
{
this.Encode(image, stream, cancellationToken);
@@ -106,9 +115,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
{
using (var ms = new MemoryStream())
{
- this.Encode(image, ms);
+ this.Encode(image, ms, cancellationToken);
ms.Position = 0;
- await ms.CopyToAsync(stream, cancellationToken).ConfigureAwait(false);
+ await ms.CopyToAsync(stream, this.configuration.StreamProcessingBufferSize, cancellationToken).ConfigureAwait(false);
}
}
}
diff --git a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs
index f4a704de6d..dea8c62e19 100644
--- a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs
+++ b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs
@@ -7,7 +7,6 @@ using System.Linq;
using Moq;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
-using SixLabors.ImageSharp.Formats.Experimental.Webp;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
diff --git a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs
index 723efdb7d0..93768f7db1 100644
--- a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs
+++ b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[Trait("Format", "Webp")]
public class LosslessUtilsTests
{
- private static void RunSubstractGreenTest()
+ private static void RunSubtractGreenTest()
{
uint[] pixelData =
{
@@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
}
[Fact]
- public void SubtractGreen_Works() => RunSubstractGreenTest();
+ public void SubtractGreen_Works() => RunSubtractGreenTest();
[Fact]
public void AddGreenToBlueAndRed_Works() => RunAddGreenToBlueAndRedTest();
@@ -146,13 +146,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
#if SUPPORTS_RUNTIME_INTRINSICS
[Fact]
- public void SubtractGreen_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubstractGreenTest, HwIntrinsics.AllowAll);
+ public void SubtractGreen_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.AllowAll);
[Fact]
- public void SubtractGreen_WithoutAvx_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubstractGreenTest, HwIntrinsics.DisableAVX);
+ public void SubtractGreen_WithoutAvx_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableAVX);
[Fact]
- public void SubtractGreen_WithoutAvxOrSSSE3_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubstractGreenTest, HwIntrinsics.DisableAVX | HwIntrinsics.DisableSSSE3);
+ public void SubtractGreen_WithoutAvxOrSSSE3_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSubtractGreenTest, HwIntrinsics.DisableAVX | HwIntrinsics.DisableSSSE3);
[Fact]
public void AddGreenToBlueAndRed_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunAddGreenToBlueAndRedTest, HwIntrinsics.AllowAll);
diff --git a/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs
index 58d91951c4..a0bb82e807 100644
--- a/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs
@@ -27,27 +27,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
#if SUPPORTS_RUNTIME_INTRINSICS
[Fact]
public void ColorSpaceTransform_WithPeakImage_WithHardwareIntrinsics_Works()
- {
- FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithPeakImage_ProducesExpectedData, HwIntrinsics.AllowAll);
- }
+ => FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithPeakImage_ProducesExpectedData, HwIntrinsics.AllowAll);
[Fact]
public void ColorSpaceTransform_WithPeakImage_WithoutSSE41_Works()
- {
- FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithPeakImage_ProducesExpectedData, HwIntrinsics.DisableSSE41);
- }
+ => FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithPeakImage_ProducesExpectedData, HwIntrinsics.DisableSSE41);
[Fact]
public void ColorSpaceTransform_WithBikeImage_WithHardwareIntrinsics_Works()
- {
- FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.AllowAll);
- }
+ => FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.AllowAll);
[Fact]
public void ColorSpaceTransform_WithBikeImage_WithoutSSE41_Works()
- {
- FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.DisableSSE41);
- }
+ => FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.DisableSSE41);
#endif
private static void RunColorSpaceTransformTestWithPeakImage()
@@ -91,7 +83,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
// Convert image pixels to bgra array.
var imgBytes = File.ReadAllBytes(TestImageFullPath(TestImages.WebP.Peak));
- using var image = Image.Load(imgBytes);
+ using var image = Image.Load(imgBytes);
uint[] bgra = ToBgra(image);
int colorTransformBits = 3;