Browse Source

Fix issue #1594

pull/1552/head
Brian Popow 5 years ago
parent
commit
d6520d2574
  1. 9
      src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
  2. 15
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
  3. 3
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/WebP/issues/Issue1594.webp

9
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<TPixel>(Vp8LDecoder decoder, Buffer2D<TPixel> pixels)
private void DecodePixelValues<TPixel>(Vp8LDecoder decoder, Buffer2D<TPixel> pixels, int width, int height)
where TPixel : unmanaged, IPixel<TPixel>
{
Span<uint> pixelData = decoder.Pixels.GetSpan();
int width = decoder.Width;
// Apply reverse transformations, if any are present.
ApplyInverseTransforms(decoder, pixelData, this.memoryAllocator);
Span<byte> pixelDataAsBytes = MemoryMarshal.Cast<uint, byte>(pixelData);
int bytesPerRow = width * 4;
for (int y = 0; y < decoder.Height; y++)
for (int y = 0; y < height; y++)
{
Span<byte> rowAsBytes = pixelDataAsBytes.Slice(y * bytesPerRow, bytesPerRow);
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
@ -859,7 +858,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
/// <summary>
/// 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.
/// </summary>
private uint ReadSymbol(Span<HuffmanCode> table)
{

15
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<TPixel>(TestImageProvider<TPixel> provider)
public void WebpDecoder_CanDecode_Lossless_WithIssues<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
// 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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(WebpDecoder))
{
image.DebugSave(provider);
image.CompareToOriginal(provider, ReferenceDecoder);
}
}
[Theory]
[WithFile(Lossless.LossLessCorruptImage3, PixelTypes.Rgba32)]
public void WebpDecoder_ThrowImageFormatException_OnInvalidImages<TPixel>(TestImageProvider<TPixel> provider)

3
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";
}
}
}

3
tests/Images/Input/WebP/issues/Issue1594.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:37413b1a89ba7d42cdfe98196775c2ddc2f8f4d143f6fc65218dc288423b7177
size 62
Loading…
Cancel
Save