diff --git a/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs b/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs index 7a58ccba04..ee10bdb0e0 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless { this.DecodeImageStream(decoder, width, height, true); this.DecodeImageData(decoder, decoder.Pixels.Memory.Span); - this.DecodePixelValues(decoder, pixels); + this.DecodePixelValues(decoder, pixels, width, height); } } @@ -185,18 +185,17 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless return pixelData; } - private void DecodePixelValues(Vp8LDecoder decoder, Buffer2D pixels) + private void DecodePixelValues(Vp8LDecoder decoder, Buffer2D pixels, int width, int height) where TPixel : unmanaged, IPixel { Span pixelData = decoder.Pixels.GetSpan(); - int width = decoder.Width; // Apply reverse transformations, if any are present. ApplyInverseTransforms(decoder, pixelData, this.memoryAllocator); Span pixelDataAsBytes = MemoryMarshal.Cast(pixelData); int bytesPerRow = width * 4; - for (int y = 0; y < decoder.Height; y++) + for (int y = 0; y < height; y++) { Span rowAsBytes = pixelDataAsBytes.Slice(y * bytesPerRow, bytesPerRow); Span pixelRow = pixels.GetRowSpan(y); @@ -859,7 +858,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless /// /// Decodes the next Huffman code from the bit-stream. - /// FillBitWindow(br) needs to be called at minimum every second call to ReadSymbol, in order to pre-fetch enough bits. + /// FillBitWindow() needs to be called at minimum every second call to ReadSymbol, in order to pre-fetch enough bits. /// private uint ReadSymbol(Span table) { diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs index af46e3c58b..19cb3f695a 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs @@ -323,7 +323,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp [WithFile(Lossless.LossLessCorruptImage1, PixelTypes.Rgba32)] [WithFile(Lossless.LossLessCorruptImage2, PixelTypes.Rgba32)] [WithFile(Lossless.LossLessCorruptImage4, PixelTypes.Rgba32)] - public void WebpDecoder_CanDecodeLosslessWithIssues(TestImageProvider provider) + public void WebpDecoder_CanDecode_Lossless_WithIssues(TestImageProvider provider) where TPixel : unmanaged, IPixel { // Just make sure no exception is thrown. The reference decoder fails to load the image. @@ -333,6 +333,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp } } + // https://github.com/SixLabors/ImageSharp/issues/1594 + [Theory] + [WithFile(Lossy.Issue1594, PixelTypes.Rgba32)] + public void WebpDecoder_CanDecode_Issue1594(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using (Image image = provider.GetImage(WebpDecoder)) + { + image.DebugSave(provider); + image.CompareToOriginal(provider, ReferenceDecoder); + } + } + [Theory] [WithFile(Lossless.LossLessCorruptImage3, PixelTypes.Rgba32)] public void WebpDecoder_ThrowImageFormatException_OnInvalidImages(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index df0a8e6238..a33c502afd 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -647,6 +647,9 @@ namespace SixLabors.ImageSharp.Tests public const string AlphaCompressedGradientFilter = "WebP/alpha_filter_3_method_1.webp"; public const string AlphaThinkingSmiley = "WebP/1602311202.webp"; public const string AlphaSticker = "WebP/sticker.webp"; + + // Issues + public const string Issue1594 = "Webp/issues/Issue1594.webp"; } } } diff --git a/tests/Images/Input/WebP/issues/Issue1594.webp b/tests/Images/Input/WebP/issues/Issue1594.webp new file mode 100644 index 0000000000..664db4e2f7 --- /dev/null +++ b/tests/Images/Input/WebP/issues/Issue1594.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37413b1a89ba7d42cdfe98196775c2ddc2f8f4d143f6fc65218dc288423b7177 +size 62