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);
        }
        internal void Read(GifReader reader)
        {
            Byte size = reader.ReadByte();

            if (size != 4)
            {
                System.Diagnostics.Debug.WriteLine("Wrong size of " + ToString());
            }

            Byte flags = reader.ReadByte();

            disposalMethod    = (GifDisposalMethod)((flags & 0x1C) >> 2);
            userInputExpected = 0x02 == (flags & 0x02);
            transparency      = 0x01 == (flags & 0x01);

            delay             = reader.ReadUInt16();
            transparencyIndex = reader.ReadByte();

            Byte terminator = reader.ReadByte();

            if (terminator != 0x00)
            {
                throw new Exception("Unknown extension terminator: 0x" + terminator.ToString("X2"));
            }
        }
Exemplo n.º 3
0
        internal void Read(GifReader reader)
        {
            Byte size = reader.ReadByte();

            if (size != 11)
            {
                System.Diagnostics.Debug.WriteLine("Wrong size of " + ToString());
            }

            applicationIdentifier         = reader.ReadString(8);
            applicationAuthenticationCode = reader.ReadString(3);

            bytes = reader.ReadBinarySubBlocks();
        }
Exemplo n.º 4
0
        internal void Read(GifReader reader)
        {
            left = reader.ReadUInt16();
            top  = reader.ReadUInt16();

            width  = reader.ReadUInt16();
            height = reader.ReadUInt16();

            Byte flags = reader.ReadByte();

            localColorTableFlag   = 0x80 == (flags & 0x80);
            interlaced            = 0x40 == (flags & 0x40);
            localColorTableSorted = 0x20 == (flags & 0x20);
            localColorTableSize   = (UInt16)(2 << (flags & 0x07));
        }
        internal void Read(GifReader reader)
        {
            width  = reader.ReadUInt16();
            height = reader.ReadUInt16();

            Byte flags = reader.ReadByte();

            globalColorTableFlag   = 0x80 == (flags & 0x80);
            colorResolution        = (Byte)(((flags & 0x70) >> 4) + 1);
            globalColorTableSorted = 0x08 == (flags & 0x08);
            globalColorTableSize   = (UInt16)(2 << (flags & 0x07));

            backgroundColorIndex = reader.ReadByte();
            pixelAspectRatio     = reader.ReadByte();
        }
Exemplo n.º 6
0
        internal void Read(GifReader reader, GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock)
        {
            bytes = reader.ReadBytes(gifLogicalScreenDescriptorBlock.GlobalColorTableSize * 3);

            //byte[] globalColorTableBuffer = reader.ReadBytes(globalColorTableSize * 3);

            //globalColorTable = new Color[globalColorTableSize];

            //int baseIndex = 0;
            //for (UInt16 colorIndex = 0; colorIndex < globalColorTableSize; colorIndex++)
            //{
            //    globalColorTable[colorIndex] = Color.FromArgb(globalColorTableBuffer[baseIndex], globalColorTableBuffer[baseIndex + 1], globalColorTableBuffer[baseIndex + 2]);
            //    baseIndex += 3;
            //}
        }
Exemplo n.º 7
0
        internal void Read(GifReader reader)
        {
            String signature = reader.ReadString(3);

            if (signature != "GIF")
            {
                throw new Exception("No GIF signature");
            }

            version = reader.ReadString(3);
            if ((version != "87a") && (version != "89a"))
            {
                throw new Exception("Unsupported GIF version: " + version);
            }
        }
Exemplo n.º 8
0
        internal void Read(GifReader reader)
        {
            Byte size = reader.ReadByte();

            if (size != 12)
            {
                System.Diagnostics.Debug.WriteLine("Wrong size of " + ToString());
            }

            left   = reader.ReadUInt16();
            top    = reader.ReadUInt16();
            width  = reader.ReadUInt16();
            height = reader.ReadUInt16();

            cellWidth  = reader.ReadByte();
            cellHeight = reader.ReadByte();

            foregroundColor = reader.ReadByte();
            backgroundColor = reader.ReadByte();

            text = reader.ReadTextSubBlocks();
        }
Exemplo n.º 9
0
 internal void Read(GifReader reader)
 {
     bytes = reader.ReadBinarySubBlocks();
 }
Exemplo n.º 10
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"));
                }
            }
        }
Exemplo n.º 11
0
 internal GifExtensionBlock(Byte label, GifReader reader)
     : base(GifBlockType.Extension)
 {
     this.label = label;
     Read(reader);
 }
Exemplo n.º 12
0
 internal GifApplicationExtensionBlock(GifReader reader)
     : base(GifBlockType.ApplicationExtension)
 {
     Read(reader);
 }
 internal GifLogicalScreenDescriptorBlock(GifReader reader)
     : base(GifBlockType.LogicalScreenDescriptor)
 {
     Read(reader);
 }
Exemplo n.º 14
0
 internal GifCommentExtensionBlock(GifReader reader)
     : base(GifBlockType.CommentExtension)
 {
     Read(reader);
 }
Exemplo n.º 15
0
 internal GifImageDescriptorBlock(GifReader reader)
     : base(GifBlockType.ImageDescriptor)
 {
     Read(reader);
 }
 internal GifGraphicControExtensionBlock(GifReader reader)
     : base(GifBlockType.GraphicControlExtension)
 {
     Read(reader);
 }
Exemplo n.º 17
0
 internal void Read(GifReader reader)
 {
     comment = reader.ReadTextSubBlocks();
 }
Exemplo n.º 18
0
 internal GifLocalColorTableBlock(GifReader reader, GifImageDescriptorBlock gifImageDescriptorBlock)
     : base(GifBlockType.LocalColorTable)
 {
     Read(reader, gifImageDescriptorBlock);
 }
Exemplo n.º 19
0
 internal GifHeaderBlock(GifReader reader)
     : base(GifBlockType.Header)
 {
     Read(reader);
 }
Exemplo n.º 20
0
        internal void Read(GifReader reader)
        {
            lzwMinimumCodeSize = reader.ReadByte();

            imageData = reader.ReadBinarySubBlocks();
        }
Exemplo n.º 21
0
 internal GifTableBasedImageDataBlock(GifReader reader)
     : base(GifBlockType.TableBasedImageData)
 {
     Read(reader);
 }
Exemplo n.º 22
0
 internal void Read(GifReader reader, GifImageDescriptorBlock gifImageDescriptorBlock)
 {
     bytes = reader.ReadBytes(gifImageDescriptorBlock.LocalColorTableSize * 3);
 }
Exemplo n.º 23
0
 internal GifPlainTextExtensionBlock(GifReader reader)
     : base(GifBlockType.PlainTextExtension)
 {
     Read(reader);
 }
Exemplo n.º 24
0
 internal GifGlobalColorTableBlock(GifReader reader, GifLogicalScreenDescriptorBlock gifLogicalScreenDescriptorBlock)
     : base(GifBlockType.GlobalColorTable)
 {
     Read(reader, gifLogicalScreenDescriptorBlock);
 }