Exemplo n.º 1
0
        internal static GifExtension ReadExtension(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            // Note: at this point, the Extension Introducer (0x21) has already been read

            int label = stream.ReadByte();

            if (label < 0)
            {
                throw GifHelpers.UnexpectedEndOfStreamException();
            }
            switch (label)
            {
            case GifGraphicControlExtension.ExtensionLabel:
                return(GifGraphicControlExtension.ReadGraphicsControl(stream));

            case GifCommentExtension.ExtensionLabel:
                return(GifCommentExtension.ReadComment(stream));

            case GifPlainTextExtension.ExtensionLabel:
                return(GifPlainTextExtension.ReadPlainText(stream, controlExtensions, metadataOnly));

            case GifApplicationExtension.ExtensionLabel:
                return(GifApplicationExtension.ReadApplication(stream));

            default:
                throw GifHelpers.UnknownExtensionTypeException(label);
            }
        }
Exemplo n.º 2
0
        internal static GifExtension ReadExtension(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            int extensionLabel = stream.ReadByte();

            if (extensionLabel < 0)
            {
                throw GifHelpers.UnexpectedEndOfStreamException();
            }
            int num2 = extensionLabel;

            if (num2 == 1)
            {
                return(GifPlainTextExtension.ReadPlainText(stream, controlExtensions, metadataOnly));
            }
            if (num2 == 0xf9)
            {
                return(GifGraphicControlExtension.ReadGraphicsControl(stream));
            }
            switch (num2)
            {
            case 0xfe:
                return(GifCommentExtension.ReadComment(stream));

            case 0xff:
                return(GifApplicationExtension.ReadApplication(stream));
            }
            throw GifHelpers.UnknownExtensionTypeException(extensionLabel);
        }
Exemplo n.º 3
0
        private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            // Note: at this point, the label (0x01) has already been read

            byte[] bytes = new byte[13];
            stream.ReadAll(bytes, 0, bytes.Length);

            BlockSize = bytes[0];
            if (BlockSize != 12)
            {
                throw GifHelpers.InvalidBlockSizeException("Plain Text Extension", 12, BlockSize);
            }

            Left                 = BitConverter.ToUInt16(bytes, 1);
            Top                  = BitConverter.ToUInt16(bytes, 3);
            Width                = BitConverter.ToUInt16(bytes, 5);
            Height               = BitConverter.ToUInt16(bytes, 7);
            CellWidth            = bytes[9];
            CellHeight           = bytes[10];
            ForegroundColorIndex = bytes[11];
            BackgroundColorIndex = bytes[12];

            var dataBytes = GifHelpers.ReadDataBlocks(stream, metadataOnly);

            Text       = Encoding.ASCII.GetString(dataBytes);
            Extensions = controlExtensions.ToList().AsReadOnly();
        }
Exemplo n.º 4
0
 private void Read(Stream stream)
 {
     byte[] bytes = GifHelpers.ReadDataBlocks(stream, false);
     if (bytes != null)
     {
         this.Text = Encoding.ASCII.GetString(bytes);
     }
 }
Exemplo n.º 5
0
 private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
 {
     this.Descriptor = GifImageDescriptor.ReadImageDescriptor(stream);
     if (this.Descriptor.HasLocalColorTable)
     {
         this.LocalColorTable = GifHelpers.ReadColorTable(stream, this.Descriptor.LocalColorTableSize);
     }
     this.ImageData  = GifImageData.ReadImageData(stream, metadataOnly);
     this.Extensions = controlExtensions.ToList <GifExtension>().AsReadOnly();
 }
Exemplo n.º 6
0
        private void Read(Stream stream)
        {
            // Note: at this point, the label (0xFE) has already been read

            var bytes = GifHelpers.ReadDataBlocks(stream, false);

            if (bytes != null)
            {
                Text = Encoding.ASCII.GetString(bytes);
            }
        }
Exemplo n.º 7
0
        private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            // Note: at this point, the Image Separator (0x2C) has already been read

            Descriptor = GifImageDescriptor.ReadImageDescriptor(stream);
            if (Descriptor.HasLocalColorTable)
            {
                LocalColorTable = GifHelpers.ReadColorTable(stream, Descriptor.LocalColorTableSize);
            }
            ImageData  = GifImageData.ReadImageData(stream, metadataOnly);
            Extensions = controlExtensions.ToList().AsReadOnly();
        }
Exemplo n.º 8
0
 private void Read(Stream stream)
 {
     this.Signature = GifHelpers.ReadString(stream, 3);
     if (this.Signature != "GIF")
     {
         throw GifHelpers.InvalidSignatureException(this.Signature);
     }
     this.Version = GifHelpers.ReadString(stream, 3);
     if ((this.Version != "87a") && (this.Version != "89a"))
     {
         throw GifHelpers.UnsupportedVersionException(this.Version);
     }
     this.LogicalScreenDescriptor = GifLogicalScreenDescriptor.ReadLogicalScreenDescriptor(stream);
 }
Exemplo n.º 9
0
 private void Read(Stream stream)
 {
     byte[] buffer = new byte[12];
     stream.ReadAll(buffer, 0, buffer.Length);
     this.BlockSize = buffer[0];
     if (this.BlockSize != 11)
     {
         throw GifHelpers.InvalidBlockSizeException("Application Extension", 11, this.BlockSize);
     }
     this.ApplicationIdentifier = Encoding.ASCII.GetString(buffer, 1, 8);
     byte[] destinationArray = new byte[3];
     Array.Copy(buffer, 9, destinationArray, 0, 3);
     this.AuthenticationCode = destinationArray;
     this.Data = GifHelpers.ReadDataBlocks(stream, false);
 }
Exemplo n.º 10
0
        private void Read(Stream stream)
        {
            byte[] buffer = new byte[6];
            stream.ReadAll(buffer, 0, buffer.Length);
            this.BlockSize = buffer[0];
            if (this.BlockSize != 4)
            {
                throw GifHelpers.InvalidBlockSizeException("Graphic Control Extension", 4, this.BlockSize);
            }
            byte num = buffer[1];

            this.DisposalMethod    = (num & 0x1c) >> 2;
            this.UserInput         = (num & 2) != 0;
            this.HasTransparency   = (num & 1) != 0;
            this.Delay             = BitConverter.ToUInt16(buffer, 2) * 10;
            this.TransparencyIndex = buffer[4];
        }
        private void Read(Stream stream)
        {
            // Note: at this point, the label (0xFF) has already been read

            byte[] bytes = new byte[12];
            stream.ReadAll(bytes, 0, bytes.Length);
            BlockSize = bytes[0]; // should always be 11
            if (BlockSize != 11)
            {
                throw GifHelpers.InvalidBlockSizeException("Application Extension", 11, BlockSize);
            }

            ApplicationIdentifier = Encoding.ASCII.GetString(bytes, 1, 8);
            byte[] authCode = new byte[3];
            Array.Copy(bytes, 9, authCode, 0, 3);
            AuthenticationCode = authCode;
            Data = GifHelpers.ReadDataBlocks(stream, false);
        }
Exemplo n.º 12
0
        private void Read(Stream stream, bool metadataOnly)
        {
            this.Header = GifHeader.ReadHeader(stream);
            if (this.Header.LogicalScreenDescriptor.HasGlobalColorTable)
            {
                this.GlobalColorTable = GifHelpers.ReadColorTable(stream, this.Header.LogicalScreenDescriptor.GlobalColorTableSize);
            }
            this.ReadFrames(stream, metadataOnly);
            GifApplicationExtension ext = this.Extensions.OfType <GifApplicationExtension>().FirstOrDefault <GifApplicationExtension>(new Func <GifApplicationExtension, bool>(GifHelpers.IsNetscapeExtension));

            if (ext != null)
            {
                this.RepeatCount = GifHelpers.GetRepeatCount(ext);
            }
            else
            {
                this.RepeatCount = 1;
            }
        }
        private void Read(Stream stream)
        {
            // Note: at this point, the label (0xF9) has already been read

            byte[] bytes = new byte[6];
            stream.ReadAll(bytes, 0, bytes.Length);
            BlockSize = bytes[0]; // should always be 4
            if (BlockSize != 4)
            {
                throw GifHelpers.InvalidBlockSizeException("Graphic Control Extension", 4, BlockSize);
            }
            byte packedFields = bytes[1];

            DisposalMethod    = (packedFields & 0x1C) >> 2;
            UserInput         = (packedFields & 0x02) != 0;
            HasTransparency   = (packedFields & 0x01) != 0;
            Delay             = BitConverter.ToUInt16(bytes, 2) * 10; // milliseconds
            TransparencyIndex = bytes[4];
        }
Exemplo n.º 14
0
        private void Read(Stream stream)
        {
            if (stream == null)
            {
                return;
            }

            Signature = GifHelpers.ReadString(stream, 3);
            if (Signature != "GIF")
            {
                throw GifHelpers.InvalidSignatureException(Signature);
            }
            Version = GifHelpers.ReadString(stream, 3);
            if (Version != "87a" && Version != "89a")
            {
                throw GifHelpers.UnsupportedVersionException(Version);
            }
            LogicalScreenDescriptor = GifLogicalScreenDescriptor.ReadLogicalScreenDescriptor(stream);
        }
Exemplo n.º 15
0
 private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
 {
     byte[] buffer = new byte[13];
     stream.ReadAll(buffer, 0, buffer.Length);
     this.BlockSize = buffer[0];
     if (this.BlockSize != 12)
     {
         throw GifHelpers.InvalidBlockSizeException("Plain Text Extension", 12, this.BlockSize);
     }
     this.Left                 = BitConverter.ToUInt16(buffer, 1);
     this.Top                  = BitConverter.ToUInt16(buffer, 3);
     this.Width                = BitConverter.ToUInt16(buffer, 5);
     this.Height               = BitConverter.ToUInt16(buffer, 7);
     this.CellWidth            = buffer[9];
     this.CellHeight           = buffer[10];
     this.ForegroundColorIndex = buffer[11];
     this.BackgroundColorIndex = buffer[12];
     byte[] bytes = GifHelpers.ReadDataBlocks(stream, metadataOnly);
     this.Text       = Encoding.ASCII.GetString(bytes);
     this.Extensions = controlExtensions.ToList <GifExtension>().AsReadOnly();
 }
Exemplo n.º 16
0
        internal static GifBlock ReadBlock(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            int blockId = stream.ReadByte();

            if (blockId < 0)
            {
                throw GifHelpers.UnexpectedEndOfStreamException();
            }
            switch (blockId)
            {
            case GifExtension.ExtensionIntroducer:
                return(GifExtension.ReadExtension(stream, controlExtensions, metadataOnly));

            case GifFrame.ImageSeparator:
                return(GifFrame.ReadFrame(stream, controlExtensions, metadataOnly));

            case GifTrailer.TrailerByte:
                return(GifTrailer.ReadTrailer());

            default:
                throw GifHelpers.UnknownBlockTypeException(blockId);
            }
        }
Exemplo n.º 17
0
        internal static GifBlock ReadBlock(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            int blockId = stream.ReadByte();

            if (blockId < 0)
            {
                throw GifHelpers.UnexpectedEndOfStreamException();
            }
            int num2 = blockId;

            if (num2 == 0x21)
            {
                return(GifExtension.ReadExtension(stream, controlExtensions, metadataOnly));
            }
            if (num2 == 0x2c)
            {
                return(GifFrame.ReadFrame(stream, controlExtensions, metadataOnly));
            }
            if (num2 != 0x3b)
            {
                throw GifHelpers.UnknownBlockTypeException(blockId);
            }
            return(GifTrailer.ReadTrailer());
        }
Exemplo n.º 18
0
        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;
            }
        }
Exemplo n.º 19
0
 private void Read(Stream stream, bool metadataOnly)
 {
     this.LzwMinimumCodeSize = (byte)stream.ReadByte();
     this.CompressedData     = GifHelpers.ReadDataBlocks(stream, metadataOnly);
 }