diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs index 9901d0cff..4607bf1c0 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs @@ -367,17 +367,17 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy this.ImportLine(v.Slice(uvStartIdx - 1), uvStride, vLeft.Slice(1), uvh, 8); } - Span yTop = this.YTop.Slice(this.yTopIdx); + Span yTop = this.YTop.Slice(this.yTopIdx, 16); if (this.Y == 0) { yTop.Fill(127); - this.UvTop.GetSpan().Fill(127); + this.UvTop.Slice(this.uvTopIdx, 16).Fill(127); } else { this.ImportLine(y.Slice(yStartIdx - yStride), 1, yTop, w, 16); - this.ImportLine(u.Slice(uvStartIdx - uvStride), 1, this.UvTop.GetSpan().Slice(8), uvw, 8); - this.ImportLine(v.Slice(uvStartIdx - uvStride), 1, this.UvTop.GetSpan().Slice(8), uvw, 8); + this.ImportLine(u.Slice(uvStartIdx - uvStride), 1, this.UvTop.Slice(this.uvTopIdx, 8), uvw, 8); + this.ImportLine(v.Slice(uvStartIdx - uvStride), 1, this.UvTop.Slice(this.uvTopIdx + 8, 8), uvw, 8); } } diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs index c224a58af..d4a21c49b 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs @@ -224,7 +224,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy var alphas = new int[WebPConstants.MaxAlpha + 1]; this.alpha = this.MacroBlockAnalysis(width, height, it, y, u, v, yStride, uvStride, alphas, out this.uvAlpha); - // Analysis is done, proceed to actual coding. + // Analysis is done, proceed to actual encoding. // TODO: EncodeAlpha(); this.segmentHeader = new Vp8EncSegmentHeader(4); diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs index 4777adb4f..90f3a3f42 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs @@ -24,11 +24,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP Quality = quality }; - using (Image image = provider.GetImage()) - { - var testOutputDetails = string.Concat("lossless", "_q", quality); - image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); - } + using Image image = provider.GetImage(); + var testOutputDetails = string.Concat("lossless", "_q", quality); + image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); } [Theory] @@ -46,14 +44,53 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP { Lossy = false, Method = method, - Quality = 100 + Quality = 75 }; - using (Image image = provider.GetImage()) + using Image image = provider.GetImage(); + var testOutputDetails = string.Concat("lossless", "_m", method); + image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); + } + + [Theory] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 100)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 75)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 20)] + public void Encode_Lossy_WithDifferentQuality_Works(TestImageProvider provider, int quality) + where TPixel : unmanaged, IPixel + { + var encoder = new WebPEncoder() { - var testOutputDetails = string.Concat("lossless", "_m", method); - image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); - } + Lossy = true, + Quality = quality + }; + + using Image image = provider.GetImage(); + var testOutputDetails = string.Concat("lossy", "_q", quality); + image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); + } + + [Theory] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 0)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 1)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 2)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 3)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 4)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 5)] + [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 6)] + public void Encode_Lossy_WithDifferentMethods_Works(TestImageProvider provider, int method) + where TPixel : unmanaged, IPixel + { + var encoder = new WebPEncoder() + { + Lossy = true, + Method = method, + Quality = 75 + }; + + using Image image = provider.GetImage(); + var testOutputDetails = string.Concat("lossy", "_m", method); + image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); } } }