/// <summary> /// Reads the application extension block parsing any animation information /// if present. /// </summary> private void ReadApplicationExtension() { int appLength = this.stream.ReadByte(); // If the length is 11 then it's a valid extension and most likely // a NETSCAPE or ANIMEXTS extension. We want the loop count from this. if (appLength == GifConstants.ApplicationBlockSize) { this.stream.Skip(appLength); int subBlockSize = this.stream.ReadByte(); // TODO: There's also a NETSCAPE buffer extension. // http://www.vurdalakov.net/misc/gif/netscape-buffering-application-extension if (subBlockSize == GifConstants.NetscapeLoopingSubBlockSize) { this.stream.Read(this.buffer, 0, GifConstants.NetscapeLoopingSubBlockSize); this.gifMetadata.RepeatCount = GifNetscapeLoopingApplicationExtension.Parse(this.buffer.AsSpan(1)).RepeatCount; this.stream.Skip(1); // Skip the terminator. return; } // Could be XMP or something else not supported yet. // Skip the subblock and terminator. this.SkipBlock(subBlockSize); return; } this.SkipBlock(appLength); // Not supported by any known decoder. }
/// <summary> /// Reads the application extension block parsing any animation or XMP information /// if present. /// </summary> private void ReadApplicationExtension() { int appLength = this.stream.ReadByte(); // If the length is 11 then it's a valid extension and most likely // a NETSCAPE, XMP or ANIMEXTS extension. We want the loop count from this. if (appLength == GifConstants.ApplicationBlockSize) { this.stream.Read(this.buffer, 0, GifConstants.ApplicationBlockSize); bool isXmp = this.buffer.AsSpan().StartsWith(GifConstants.XmpApplicationIdentificationBytes); if (isXmp && !this.IgnoreMetadata) { var extension = GifXmpApplicationExtension.Read(this.stream, this.MemoryAllocator); if (extension.Data.Length > 0) { this.metadata.XmpProfile = new XmpProfile(extension.Data); } return; } else { int subBlockSize = this.stream.ReadByte(); // TODO: There's also a NETSCAPE buffer extension. // http://www.vurdalakov.net/misc/gif/netscape-buffering-application-extension if (subBlockSize == GifConstants.NetscapeLoopingSubBlockSize) { this.stream.Read(this.buffer, 0, GifConstants.NetscapeLoopingSubBlockSize); this.gifMetadata.RepeatCount = GifNetscapeLoopingApplicationExtension.Parse(this.buffer.AsSpan(1)).RepeatCount; this.stream.Skip(1); // Skip the terminator. return; } // Could be something else not supported yet. // Skip the subblock and terminator. this.SkipBlock(subBlockSize); } return; } this.SkipBlock(appLength); // Not supported by any known decoder. }