From 5d08ac75ed92ab83c978cf32e5efa7dbe99cb911 Mon Sep 17 00:00:00 2001 From: James South Date: Sun, 19 Oct 2014 13:56:23 +0100 Subject: [PATCH] Repeat count now reflects Property info Former-commit-id: 7b8ef0819336be4e596145338d44cea70f79bf66 Former-commit-id: cbf23285111354ab19023ea4d94dc0a3bae93da9 --- .../Imaging/Formats/GifEncoder.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ImageProcessor/Imaging/Formats/GifEncoder.cs b/src/ImageProcessor/Imaging/Formats/GifEncoder.cs index f93cd419b..a418c951e 100644 --- a/src/ImageProcessor/Imaging/Formats/GifEncoder.cs +++ b/src/ImageProcessor/Imaging/Formats/GifEncoder.cs @@ -277,8 +277,6 @@ namespace ImageProcessor.Imaging.Formats /// private void WriteHeaderBlock(Stream sourceGif, int w, int h) { - int count = this.repeatCount.GetValueOrDefault(0); - // File Header signature and version. this.WriteString(FileType); this.WriteString(FileVersion); @@ -296,13 +294,21 @@ namespace ImageProcessor.Imaging.Formats this.WriteColorTable(sourceGif); // Application Extension Header - this.WriteShort(ApplicationExtensionBlockIdentifier); - this.WriteByte(ApplicationBlockSize); - this.WriteString(ApplicationIdentification); - this.WriteByte(3); // Application block length - this.WriteByte(1); - this.WriteShort(count); // Repeat count for images. - this.WriteByte(0); // Terminator + int count = this.repeatCount.GetValueOrDefault(0); + if (count != 1) + { + // 0 means loop indefinitely. count is set as play n + 1 times. + count = Math.Max(0, count - 1); + this.WriteShort(ApplicationExtensionBlockIdentifier); + this.WriteByte(ApplicationBlockSize); + + this.WriteString(ApplicationIdentification); + this.WriteByte(3); // Application block length + this.WriteByte(1); + this.WriteShort(count); // Repeat count for images. + + this.WriteByte(0); // Terminator + } } ///