Browse Source

Additional gif test cases

pull/1191/head
Brian Popow 6 years ago
parent
commit
210c4817e4
  1. 8
      src/ImageSharp/Formats/Gif/README.md
  2. 82
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  3. 7
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Gif/image-zero-height.gif
  5. BIN
      tests/Images/Input/Gif/image-zero-size.gif
  6. BIN
      tests/Images/Input/Gif/image-zero-width.gif
  7. BIN
      tests/Images/Input/Gif/max-height.gif
  8. BIN
      tests/Images/Input/Gif/max-width.gif

8
src/ImageSharp/Formats/Gif/README.md

@ -1,4 +1,6 @@
Encoder/Decoder adapted and extended from:
Encoder/Decoder adapted and extended from:
https://github.com/yufeih/Nine.Imaging/
https://imagetools.codeplex.com/
- [Nine.Imaging](https://github.com/yufeih/Nine.Imaging/)
- [imagetools.codeplex](https://imagetools.codeplex.com/)
A useful set of gif test images can be found at [pygif](https://github.com/robert-ancell/pygif/tree/master/test-suite)

82
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -2,11 +2,9 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.DotNet.RemoteExecutor;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
@ -30,32 +28,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
TestImages.Gif.Giphy, TestImages.Gif.Kumin
};
public static readonly string[] BasicVerificationFiles =
{
TestImages.Gif.Cheers,
TestImages.Gif.Rings,
// previously DecodeBadApplicationExtensionLength:
TestImages.Gif.Issues.BadAppExtLength,
TestImages.Gif.Issues.BadAppExtLength_2,
// previously DecodeBadDescriptorDimensionsLength:
TestImages.Gif.Issues.BadDescriptorWidth
};
private static readonly Dictionary<string, int> BasicVerificationFrameCount =
new Dictionary<string, int>
{
[TestImages.Gif.Cheers] = 93,
[TestImages.Gif.Issues.BadDescriptorWidth] = 36,
};
public static readonly string[] BadAppExtFiles =
{
TestImages.Gif.Issues.BadAppExtLength,
TestImages.Gif.Issues.BadAppExtLength_2
};
[Theory]
[WithFileCollection(nameof(MultiFrameTestFiles), PixelTypes.Rgba32)]
public void Decode_VerifyAllFrames<TPixel>(TestImageProvider<TPixel> provider)
@ -100,15 +72,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
}
[Theory]
[WithFileCollection(nameof(BasicVerificationFiles), PixelTypes.Rgba32)]
public void Decode_VerifyRootFrameAndFrameCount<TPixel>(TestImageProvider<TPixel> provider)
[WithFile(TestImages.Gif.Cheers, PixelTypes.Rgba32, 93)]
[WithFile(TestImages.Gif.Rings, PixelTypes.Rgba32, 1)]
[WithFile(TestImages.Gif.Issues.BadDescriptorWidth, PixelTypes.Rgba32, 36)]
public void Decode_VerifyRootFrameAndFrameCount<TPixel>(TestImageProvider<TPixel> provider, int expectedFrameCount)
where TPixel : unmanaged, IPixel<TPixel>
{
if (!BasicVerificationFrameCount.TryGetValue(provider.SourceFileOrDescription, out int expectedFrameCount))
{
expectedFrameCount = 1;
}
using (Image<TPixel> image = provider.GetImage())
{
Assert.Equal(expectedFrameCount, image.Frames.Count);
@ -153,6 +122,35 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
}
}
[Theory]
[WithFile(TestImages.Gif.ZeroSize, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.ZeroWidth, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.ZeroHeight, PixelTypes.Rgba32)]
public void Decode_WithInvalidDimensions_DoesThrowException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
System.Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(GifDecoder);
});
Assert.NotNull(ex);
Assert.Contains("Width or height should not be 0", ex.Message);
}
[Theory]
[WithFile(TestImages.Gif.MaxWidth, PixelTypes.Rgba32, 65535, 1)]
[WithFile(TestImages.Gif.MaxHeight, PixelTypes.Rgba32, 1, 65535)]
public void Decode_WithMaxDimensions_Works<TPixel>(TestImageProvider<TPixel> provider, int expectedWidth, int expectedHeight)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(GifDecoder))
{
Assert.Equal(expectedWidth, image.Width);
Assert.Equal(expectedHeight, image.Height);
}
}
[Fact]
public void CanDecodeIntermingledImages()
{
@ -172,6 +170,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
}
}
// https://github.com/SixLabors/ImageSharp/issues/405
[Theory]
[WithFile(TestImages.Gif.Issues.BadAppExtLength, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.Issues.BadAppExtLength_2, PixelTypes.Rgba32)]
public void Issue405_BadApplicationExtensionBlockLength<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.DebugSave(provider);
image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider);
}
}
[Theory]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32)]
[WithFile(TestImages.Gif.Kumin, PixelTypes.Rgba32)]

7
tests/ImageSharp.Tests/TestImages.cs

@ -397,6 +397,13 @@ namespace SixLabors.ImageSharp.Tests
public const string Ratio1x4 = "Gif/base_1x4.gif";
public const string LargeComment = "Gif/large_comment.gif";
// Test images from https://github.com/robert-ancell/pygif/tree/master/test-suite
public const string ZeroSize = "Gif/image-zero-size.gif";
public const string ZeroHeight = "Gif/image-zero-height.gif";
public const string ZeroWidth = "Gif/image-zero-width.gif";
public const string MaxWidth = "Gif/max-width.gif";
public const string MaxHeight = "Gif/max-height.gif";
public static class Issues
{
public const string BadAppExtLength = "Gif/issues/issue405_badappextlength252.gif";

BIN
tests/Images/Input/Gif/image-zero-height.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 B

BIN
tests/Images/Input/Gif/image-zero-size.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 B

BIN
tests/Images/Input/Gif/image-zero-width.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 B

BIN
tests/Images/Input/Gif/max-height.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

BIN
tests/Images/Input/Gif/max-width.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

Loading…
Cancel
Save