diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index 722c9c899..98dbddb48 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/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;
}
diff --git a/src/ImageSharp/Formats/Gif/GifMetadata.cs b/src/ImageSharp/Formats/Gif/GifMetadata.cs
index b00db6752..1914875d9 100644
--- a/src/ImageSharp/Formats/Gif/GifMetadata.cs
+++ b/src/ImageSharp/Formats/Gif/GifMetadata.cs
@@ -36,10 +36,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// Gets or sets the number of times any animation is repeated.
///
- /// 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
///
///
- public ushort RepeatCount { get; set; }
+ public ushort RepeatCount { get; set; } = 1;
///
/// Gets or sets the color table mode.
diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs
index 7f1acf71e..43bd1d861 100644
--- a/tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs
+++ b/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 RepeatFiles =
+ new TheoryData
+ {
+ { 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 image = decoder.Decode(Configuration.Default, stream))
+ {
+ GifMetadata meta = image.Metadata.GetGifMetadata();
+ Assert.Equal(repeatCount, meta.RepeatCount);
+ }
+ }
+ }
}
}
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index f5cdb29b6..f6c19ba0c 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/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";
diff --git a/tests/Images/Input/Gif/receipt.gif b/tests/Images/Input/Gif/receipt.gif
new file mode 100644
index 000000000..ce800a819
--- /dev/null
+++ b/tests/Images/Input/Gif/receipt.gif
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bac212852eee73f3c29f30be0be375e5caccbe86e5f4adfaa8c0a7a3673a91ab
+size 50686