Browse Source

Default RepeatCount to 1. Fix #1098

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
62feaf33e1
  1. 5
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 4
      src/ImageSharp/Formats/Gif/GifMetadata.cs
  3. 38
      tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs
  4. 1
      tests/ImageSharp.Tests/TestImages.cs
  5. 3
      tests/Images/Input/Gif/receipt.gif

5
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -274,9 +274,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
// Could be XMP or something else not supported yet.
// Back up and skip.
this.stream.Position -= appLength + 1;
this.SkipBlock(appLength);
// Skip the subblock and terminator.
this.SkipBlock(subBlockSize);
return;
}

4
src/ImageSharp/Formats/Gif/GifMetadata.cs

@ -36,10 +36,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// Gets or sets the number of times any animation is repeated.
/// <remarks>
/// 0 means to repeat indefinitely, count is set as play n + 1 times
/// 0 means to repeat indefinitely, count is set as repeat n-1 times
/// </remarks>
/// </summary>
public ushort RepeatCount { get; set; }
public ushort RepeatCount { get; set; } = 1;
/// <summary>
/// Gets or sets the color table mode.

38
tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs

@ -23,6 +23,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
{ TestImages.Gif.Ratio4x1, 4, 1, PixelResolutionUnit.AspectRatio }
};
public static readonly TheoryData<string, uint> RepeatFiles =
new TheoryData<string, uint>
{
{ TestImages.Gif.Cheers, 0 },
{ TestImages.Gif.Receipt, 1 },
{ TestImages.Gif.Rings, 1 }
};
[Fact]
public void CloneIsDeep()
{
@ -152,5 +160,35 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
}
}
}
[Theory]
[MemberData(nameof(RepeatFiles))]
public void Identify_VerifyRepeatCount(string imagePath, uint repeatCount)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
var decoder = new GifDecoder();
IImageInfo image = decoder.Identify(Configuration.Default, stream);
GifMetadata meta = image.Metadata.GetGifMetadata();
Assert.Equal(repeatCount, meta.RepeatCount);
}
}
[Theory]
[MemberData(nameof(RepeatFiles))]
public void Decode_VerifyRepeatCount(string imagePath, uint repeatCount)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
var decoder = new GifDecoder();
using (Image<Rgba32> image = decoder.Decode<Rgba32>(Configuration.Default, stream))
{
GifMetadata meta = image.Metadata.GetGifMetadata();
Assert.Equal(repeatCount, meta.RepeatCount);
}
}
}
}
}

1
tests/ImageSharp.Tests/TestImages.cs

@ -353,6 +353,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Rings = "Gif/rings.gif";
public const string Giphy = "Gif/giphy.gif";
public const string Cheers = "Gif/cheers.gif";
public const string Receipt = "Gif/receipt.gif";
public const string Trans = "Gif/trans.gif";
public const string Kumin = "Gif/kumin.gif";
public const string Leo = "Gif/leo.gif";

3
tests/Images/Input/Gif/receipt.gif

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