Exemplo n.º 1
0
        internal static GifApplicationExtensionBlock Create(GifReader reader)
        {
            GifApplicationExtensionBlock gifApplicationExtensionBlock = new GifApplicationExtensionBlock(reader);

            if (gifApplicationExtensionBlock.ApplicationIdentifier.Equals("NETSCAPE") && gifApplicationExtensionBlock.ApplicationAuthenticationCode.Equals("2.0"))
            {
                if ((null != gifApplicationExtensionBlock.Bytes))
                {
                    if ((3 == gifApplicationExtensionBlock.Bytes.Length) && (1 == gifApplicationExtensionBlock.Bytes[0]))
                    {
                        gifApplicationExtensionBlock = new GifNetscapeLoopingApplicationExtensionBlock(gifApplicationExtensionBlock);
                    }
                    else if ((5 == gifApplicationExtensionBlock.Bytes.Length) && (2 == gifApplicationExtensionBlock.Bytes[0]))
                    {
                        gifApplicationExtensionBlock = new GifNetscapeBufferingApplicationExtensionBlock(gifApplicationExtensionBlock);
                    }
                }
            }
            else if (gifApplicationExtensionBlock.ApplicationIdentifier.Equals("ANIMEXTS") && gifApplicationExtensionBlock.ApplicationAuthenticationCode.Equals("1.0"))
            {
                if ((null != gifApplicationExtensionBlock.Bytes) && (3 == gifApplicationExtensionBlock.Bytes.Length) && (1 == gifApplicationExtensionBlock.Bytes[0]))
                {
                    gifApplicationExtensionBlock = new GifAnimextsLoopingApplicationExtensionBlock(gifApplicationExtensionBlock);
                }
            }

            return(gifApplicationExtensionBlock);
        }
Exemplo n.º 2
0
        internal GifAnimextsLoopingApplicationExtensionBlock(GifApplicationExtensionBlock gifApplicationExtensionBlock)
            : base(GifBlockType.AnimextsLoopingApplicationExtension)
        {
            applicationIdentifier         = gifApplicationExtensionBlock.ApplicationIdentifier;
            applicationAuthenticationCode = gifApplicationExtensionBlock.ApplicationAuthenticationCode;
            bytes = gifApplicationExtensionBlock.Bytes;

            if ((null == bytes) || (bytes.Length != 3) || (bytes[0] != 1))
            {
                System.Diagnostics.Debug.WriteLine("Wrong format of " + ToString());
            }

            loopCount = (UInt16)(((UInt16)bytes[2] << 8) | (UInt16)bytes[1]);
        }
        internal GifAnimextsLoopingApplicationExtensionBlock(GifApplicationExtensionBlock gifApplicationExtensionBlock)
            : base(GifBlockType.AnimextsLoopingApplicationExtension)
        {
            applicationIdentifier = gifApplicationExtensionBlock.ApplicationIdentifier;
            applicationAuthenticationCode = gifApplicationExtensionBlock.ApplicationAuthenticationCode;
            bytes = gifApplicationExtensionBlock.Bytes;

            if ((null == bytes) || (bytes.Length != 3) || (bytes[0] != 1))
            {
                System.Diagnostics.Debug.WriteLine("Wrong format of " + ToString());
            }

            loopCount = (UInt16)(((UInt16)bytes[2] << 8) | (UInt16)bytes[1]);
        }
        internal GifNetscapeBufferingApplicationExtensionBlock(GifApplicationExtensionBlock gifApplicationExtensionBlock)
            : base(GifBlockType.NetscapeLoopingApplicationExtension)
        {
            applicationIdentifier = gifApplicationExtensionBlock.ApplicationIdentifier;
            applicationAuthenticationCode = gifApplicationExtensionBlock.ApplicationAuthenticationCode;
            bytes = gifApplicationExtensionBlock.Bytes;

            if ((null == bytes) || (bytes.Length != 5) || (bytes[0] != 2))
            {
                System.Diagnostics.Debug.WriteLine("Wrong format of " + ToString());
            }

            bufferSize = (UInt32)(((UInt32)bytes[4] << 24) | ((UInt32)bytes[3] << 16) | ((UInt32)bytes[2] << 8) | (UInt32)bytes[1]);
        }
        internal GifNetscapeBufferingApplicationExtensionBlock(GifApplicationExtensionBlock gifApplicationExtensionBlock)
            : base(GifBlockType.NetscapeLoopingApplicationExtension)
        {
            applicationIdentifier         = gifApplicationExtensionBlock.ApplicationIdentifier;
            applicationAuthenticationCode = gifApplicationExtensionBlock.ApplicationAuthenticationCode;
            bytes = gifApplicationExtensionBlock.Bytes;

            if ((null == bytes) || (bytes.Length != 5) || (bytes[0] != 2))
            {
                System.Diagnostics.Debug.WriteLine("Wrong format of " + ToString());
            }

            bufferSize = (UInt32)(((UInt32)bytes[4] << 24) | ((UInt32)bytes[3] << 16) | ((UInt32)bytes[2] << 8) | (UInt32)bytes[1]);
        }
        internal static GifApplicationExtensionBlock Create(GifReader reader)
        {
            GifApplicationExtensionBlock gifApplicationExtensionBlock = new GifApplicationExtensionBlock(reader);

            if (gifApplicationExtensionBlock.ApplicationIdentifier.Equals("NETSCAPE") && gifApplicationExtensionBlock.ApplicationAuthenticationCode.Equals("2.0"))
            {
                if ((null != gifApplicationExtensionBlock.Bytes))
                {
                    if ((3 == gifApplicationExtensionBlock.Bytes.Length) && (1 == gifApplicationExtensionBlock.Bytes[0]))
                    {
                        gifApplicationExtensionBlock = new GifNetscapeLoopingApplicationExtensionBlock(gifApplicationExtensionBlock);
                    }
                    else if ((5 == gifApplicationExtensionBlock.Bytes.Length) && (2 == gifApplicationExtensionBlock.Bytes[0]))
                    {
                        gifApplicationExtensionBlock = new GifNetscapeBufferingApplicationExtensionBlock(gifApplicationExtensionBlock);
                    }

                }
            }
            else if (gifApplicationExtensionBlock.ApplicationIdentifier.Equals("ANIMEXTS") && gifApplicationExtensionBlock.ApplicationAuthenticationCode.Equals("1.0"))
            {
                if ((null != gifApplicationExtensionBlock.Bytes) && (3 == gifApplicationExtensionBlock.Bytes.Length) && (1 == gifApplicationExtensionBlock.Bytes[0]))
                {
                    gifApplicationExtensionBlock = new GifAnimextsLoopingApplicationExtensionBlock(gifApplicationExtensionBlock);
                }
            }

            return gifApplicationExtensionBlock;
        }
Exemplo n.º 7
0
        static private void DumpBlock(GifBlock gifBlock)
        {
            GifExtensionBlock gifUnknownBlock = gifBlock as GifExtensionBlock;

            if (gifUnknownBlock != null)
            {
                Console.WriteLine("\tLength:\t\t\t\t" + gifUnknownBlock.Bytes.Length);
            }

            GifHeaderBlock gifHeaderBlock = gifBlock as GifHeaderBlock;

            if (gifHeaderBlock != null)
            {
                Console.WriteLine("\tVersion:\t\t\t" + gifHeaderBlock.Version);
            }

            GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock = gifBlock as GifLogicalScreenDescriptorBlock;

            if (gifLogicalScreenDescriptorBlock != null)
            {
                Console.WriteLine("\tWidth:\t\t\t\t" + gifLogicalScreenDescriptorBlock.Width);
                Console.WriteLine("\tHeight:\t\t\t\t" + gifLogicalScreenDescriptorBlock.Height);

                Console.WriteLine("\tGlobalColorTableFlag:\t\t" + gifLogicalScreenDescriptorBlock.GlobalColorTableFlag);
                Console.WriteLine("\tColorResolution:\t\t" + gifLogicalScreenDescriptorBlock.ColorResolution);
                Console.WriteLine("\tGlobalColorTableSorted:\t\t" + gifLogicalScreenDescriptorBlock.GlobalColorTableSorted);
                Console.WriteLine("\tGlobalColorTableSize:\t\t" + gifLogicalScreenDescriptorBlock.GlobalColorTableSize);

                Console.WriteLine("\tBackgroundColorIndex:\t\t" + gifLogicalScreenDescriptorBlock.BackgroundColorIndex);
                Console.WriteLine("\tPixelAspectRatio:\t\t" + gifLogicalScreenDescriptorBlock.PixelAspectRatio);
            }

            GifGlobalColorTableBlock gifGlobalColorTableBlock = gifBlock as GifGlobalColorTableBlock;

            if (gifGlobalColorTableBlock != null)
            {
                Console.WriteLine("\tLength:\t\t\t\t" + gifGlobalColorTableBlock.Bytes.Length);
            }

            GifImageDescriptorBlock gifImageDescriptorBlock = gifBlock as GifImageDescriptorBlock;

            if (gifImageDescriptorBlock != null)
            {
                Console.WriteLine("\tLeft:\t\t\t\t" + gifImageDescriptorBlock.Left);
                Console.WriteLine("\tTop:\t\t\t\t" + gifImageDescriptorBlock.Top);
                Console.WriteLine("\tWidth:\t\t\t\t" + gifImageDescriptorBlock.Width);
                Console.WriteLine("\tHeight:\t\t\t\t" + gifImageDescriptorBlock.Height);
                Console.WriteLine("\tInterlaced:\t\t\t" + gifImageDescriptorBlock.Interlaced);
                Console.WriteLine("\tLocalColorTableFlag:\t\t" + gifImageDescriptorBlock.LocalColorTableFlag);
                Console.WriteLine("\tLocalColorTableSorted:\t\t" + gifImageDescriptorBlock.LocalColorTableSorted);
                Console.WriteLine("\tLocalColorTableSize:\t\t" + gifImageDescriptorBlock.LocalColorTableSize);
            }

            GifLocalColorTableBlock gifLocalColorTableBlock = gifBlock as GifLocalColorTableBlock;

            if (gifLocalColorTableBlock != null)
            {
                Console.WriteLine("\tLength:\t\t\t\t" + gifLocalColorTableBlock.Bytes.Length);
            }

            GifTableBasedImageDataBlock gifTableBasedImageDataBlock = gifBlock as GifTableBasedImageDataBlock;

            if (gifTableBasedImageDataBlock != null)
            {
                Console.WriteLine("\tLzwMinimumCodeSize:\t\t" + gifTableBasedImageDataBlock.LzwMinimumCodeSize);
                Console.WriteLine("\tLength:\t\t\t\t" + gifTableBasedImageDataBlock.ImageData.Length);
            }

            GifGraphicControExtensionBlock gifGraphicControExtensionBlock = gifBlock as GifGraphicControExtensionBlock;

            if (gifGraphicControExtensionBlock != null)
            {
                Console.WriteLine("\tDisposalMethod:\t\t\t" + gifGraphicControExtensionBlock.DisposalMethod + " (" + (int)gifGraphicControExtensionBlock.DisposalMethod + ")");
                Console.WriteLine("\tUserInputExpected:\t\t" + gifGraphicControExtensionBlock.UserInputExpected);
                Console.WriteLine("\tTransparency:\t\t\t" + gifGraphicControExtensionBlock.Transparency);
                Console.WriteLine("\tDelay:\t\t\t\t" + gifGraphicControExtensionBlock.Delay);
                Console.WriteLine("\tTransparencyIndex:\t\t" + gifGraphicControExtensionBlock.TransparencyIndex);
            }

            GifCommentExtensionBlock gifCommentExtensionBlock = gifBlock as GifCommentExtensionBlock;

            if (gifCommentExtensionBlock != null)
            {
                Console.WriteLine("\tComment:\t\t\t" + gifCommentExtensionBlock.Comment);
            }

            GifPlainTextExtensionBlock gifPlainTextExtensionBlock = gifBlock as GifPlainTextExtensionBlock;

            if (gifPlainTextExtensionBlock != null)
            {
                Console.WriteLine("\tLeft:\t\t\t\t" + gifPlainTextExtensionBlock.Left);
                Console.WriteLine("\tTop:\t\t\t\t" + gifPlainTextExtensionBlock.Top);
                Console.WriteLine("\tWidth:\t\t\t\t" + gifPlainTextExtensionBlock.Width);
                Console.WriteLine("\tHeight:\t\t\t\t" + gifPlainTextExtensionBlock.Height);
                Console.WriteLine("\tCellWidth:\t\t\t" + gifPlainTextExtensionBlock.CellWidth);
                Console.WriteLine("\tCellHeight:\t\t\t" + gifPlainTextExtensionBlock.CellHeight);
                Console.WriteLine("\tForegroundColor:\t\t" + gifPlainTextExtensionBlock.ForegroundColor);
                Console.WriteLine("\tBackgroundColor:\t\t" + gifPlainTextExtensionBlock.BackgroundColor);
                Console.WriteLine("\tText:\t\t\t" + gifPlainTextExtensionBlock.Text);
            }

            GifApplicationExtensionBlock gifApplicationExtensionBlock = gifBlock as GifApplicationExtensionBlock;

            if (gifApplicationExtensionBlock != null)
            {
                Console.WriteLine("\tApplicationIdentifier:\t\t" + gifApplicationExtensionBlock.ApplicationIdentifier);
                Console.WriteLine("\tApplicationAuthenticationCode:\t" + gifApplicationExtensionBlock.ApplicationAuthenticationCode);
            }
            GifNetscapeLoopingApplicationExtensionBlock gifNetscapeExtensionBlock = gifBlock as GifNetscapeLoopingApplicationExtensionBlock;

            if (gifNetscapeExtensionBlock != null)
            {
                Console.WriteLine("\tLoopCount:\t\t\t" + gifNetscapeExtensionBlock.LoopCount);
            }
            GifNetscapeBufferingApplicationExtensionBlock gifNetscapeBufferingExtensionBlock = gifBlock as GifNetscapeBufferingApplicationExtensionBlock;

            if (gifNetscapeBufferingExtensionBlock != null)
            {
                Console.WriteLine("\tBufferSize:\t\t\t" + gifNetscapeBufferingExtensionBlock.BufferSize);
            }
            GifAnimextsLoopingApplicationExtensionBlock gifAnimextsLoopingExtensionBlock = gifBlock as GifAnimextsLoopingApplicationExtensionBlock;

            if (gifAnimextsLoopingExtensionBlock != null)
            {
                Console.WriteLine("\tLoopCount:\t\t\t" + gifAnimextsLoopingExtensionBlock.LoopCount);
            }
        }
Exemplo n.º 8
0
        public void Read(Stream stream)
        {
            blocks.Clear();

            // reader

            GifReader reader = new GifReader(stream);

            // Header

            AddBlock(new GifHeaderBlock(reader));

            // Logical Screen Descriptor

            GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock = new GifLogicalScreenDescriptorBlock(reader);

            AddBlock(gifLogicalScreenDescriptorBlock);

            // Global Color Table

            if (gifLogicalScreenDescriptorBlock.GlobalColorTableFlag)
            {
                AddBlock(new GifGlobalColorTableBlock(reader, gifLogicalScreenDescriptorBlock));
            }

            // Segments

            while (true)
            {
                Byte identifier = reader.ReadByte();
                switch (identifier)
                {
                // Frames

                case 0x2C:
                    GifImageDescriptorBlock gifImageDescriptorBlock = new GifImageDescriptorBlock(reader);
                    AddBlock(gifImageDescriptorBlock);

                    if (gifImageDescriptorBlock.LocalColorTableFlag)
                    {
                        AddBlock(new GifLocalColorTableBlock(reader, gifImageDescriptorBlock));
                    }

                    AddBlock(new GifTableBasedImageDataBlock(reader));
                    break;

                // Extensions

                case 0x21:
                    Byte label = reader.ReadByte();

                    switch (label)
                    {
                    case 0xF9:
                        AddBlock(new GifGraphicControExtensionBlock(reader));
                        break;

                    case 0xFE:
                        AddBlock(new GifCommentExtensionBlock(reader));
                        break;

                    case 0x01:
                        AddBlock(new GifPlainTextExtensionBlock(reader));
                        break;

                    case 0xFF:
                        AddBlock(GifApplicationExtensionBlock.Create(reader));
                        break;

                    default:
                        AddBlock(new GifExtensionBlock(label, reader));
                        break;
                    }
                    break;

                // Trailer

                case 0x3B:
                    AddBlock(new GifTrailerBlock());
                    return;

                default:
                    throw new Exception("Unknown segment identifier: 0x" + identifier.ToString("X2"));
                }
            }
        }