private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            //Note: at this point, the label (0x01) has already been read
            var 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();
        }
        private void Read(Stream stream)
        {
            // Note: at this point, the label (0xFF) has already been read
            var 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);
            var authCode = new byte[3];

            Array.Copy(bytes, 9, authCode, 0, 3);
            AuthenticationCode = authCode;
            Data = GifHelpers.ReadDataBlocks(stream, false);
        }
        private void Read(Stream stream)
        {
            // Note: at this point, the label (0xF9) has already been read
            var 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);
            }

            var 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];
        }