aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-07-11 12:37:11 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-07-11 12:37:11 +0300
commitbd49bdcb109a227130d7db6856e659b435d16530 (patch)
treedb55cfdc5dae423ccdba5c7efb1162d33bdcdc48 /Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs
parentd65e5f1a23374de2872a73034e430e4a70ee4269 (diff)
downloadTango-bd49bdcb109a227130d7db6856e659b435d16530.tar.gz
Tango-bd49bdcb109a227130d7db6856e659b435d16530.zip
Embedded Tango.AnimatedGif !
Diffstat (limited to 'Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs')
-rw-r--r--Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs b/Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs
new file mode 100644
index 000000000..500ce12a8
--- /dev/null
+++ b/Software/Visual_Studio/Tango.AnimatedGif/Decoding/GifFile.cs
@@ -0,0 +1,86 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace Tango.AnimatedGif.Decoding
+{
+ internal class GifFile
+ {
+ public GifHeader Header { get; private set; }
+ public GifColor[] GlobalColorTable { get; set; }
+ public IList<GifFrame> Frames { get; set; }
+ public IList<GifExtension> Extensions { get; set; }
+ public ushort RepeatCount { get; set; }
+
+ private GifFile()
+ {
+ }
+
+ internal static GifFile ReadGifFile(Stream stream, bool metadataOnly)
+ {
+ var file = new GifFile();
+ file.Read(stream, metadataOnly);
+ return file;
+ }
+
+ private void Read(Stream stream, bool metadataOnly)
+ {
+ Header = GifHeader.ReadHeader(stream);
+
+ if (Header.LogicalScreenDescriptor.HasGlobalColorTable)
+ {
+ GlobalColorTable = GifHelpers.ReadColorTable(stream, Header.LogicalScreenDescriptor.GlobalColorTableSize);
+ }
+ ReadFrames(stream, metadataOnly);
+
+ var netscapeExtension =
+ Extensions
+ .OfType<GifApplicationExtension>()
+ .FirstOrDefault(GifHelpers.IsNetscapeExtension);
+
+ if (netscapeExtension != null)
+ RepeatCount = GifHelpers.GetRepeatCount(netscapeExtension);
+ else
+ RepeatCount = 1;
+ }
+
+ private void ReadFrames(Stream stream, bool metadataOnly)
+ {
+ List<GifFrame> frames = new List<GifFrame>();
+ List<GifExtension> controlExtensions = new List<GifExtension>();
+ List<GifExtension> specialExtensions = new List<GifExtension>();
+ while (true)
+ {
+ var block = GifBlock.ReadBlock(stream, controlExtensions, metadataOnly);
+
+ if (block.Kind == GifBlockKind.GraphicRendering)
+ controlExtensions = new List<GifExtension>();
+
+ if (block is GifFrame)
+ {
+ frames.Add((GifFrame)block);
+ }
+ else if (block is GifExtension)
+ {
+ var extension = (GifExtension)block;
+ switch (extension.Kind)
+ {
+ case GifBlockKind.Control:
+ controlExtensions.Add(extension);
+ break;
+ case GifBlockKind.SpecialPurpose:
+ specialExtensions.Add(extension);
+ break;
+ }
+ }
+ else if (block is GifTrailer)
+ {
+ break;
+ }
+ }
+
+ this.Frames = frames.AsReadOnly();
+ this.Extensions = specialExtensions.AsReadOnly();
+ }
+ }
+}