Exemple #1
0
        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;

                    default:
                        // Just ignore plain text extensions, as most software don't support them.
                        break;
                    }
                }
                else if (block is GifTrailer)
                {
                    break;
                }
            }

            this.Frames     = frames.AsReadOnly();
            this.Extensions = specialExtensions.AsReadOnly();
        }
Exemple #2
0
        private void ReadFrames(Stream stream, bool metadataOnly)
        {
            List <GifFrame>     list = new List <GifFrame>();
            List <GifExtension> controlExtensions = new List <GifExtension>();
            List <GifExtension> list3             = new List <GifExtension>();

            while (true)
            {
                GifBlock block = GifBlock.ReadBlock(stream, controlExtensions, metadataOnly);
                if (block.Kind == GifBlockKind.GraphicRendering)
                {
                    controlExtensions = new List <GifExtension>();
                }
                if (block is GifFrame)
                {
                    list.Add((GifFrame)block);
                }
                else if (!(block is GifExtension))
                {
                    if (block is GifTrailer)
                    {
                        this.Frames     = list.AsReadOnly();
                        this.Extensions = list3.AsReadOnly();
                        return;
                    }
                }
                else
                {
                    GifExtension item = (GifExtension)block;
                    switch (item.Kind)
                    {
                    case GifBlockKind.Control:
                        controlExtensions.Add(item);
                        break;

                    case GifBlockKind.SpecialPurpose:
                        list3.Add(item);
                        break;

                    default:
                        break;
                    }
                }
            }
        }