The Graphic Control Extension contains parameters used when processing a graphic rendering block.
Пример #1
0
        private void ReadGraphicalControlExtension()
        {
            byte[] buffer = new byte[6];

            _stream.Read(buffer, 0, buffer.Length);

            byte packed = buffer[1];

            _graphicsControl                   = new GifGraphicsControlExtension();
            _graphicsControl.DelayTime         = BitConverter.ToInt16(buffer, 2);
            _graphicsControl.TransparencyIndex = buffer[4];
            _graphicsControl.TransparencyFlag  = (packed & 0x01) == 1;
            _graphicsControl.DisposalMethod    = (DisposalMethod)((packed & 0x1C) >> 2);
        }
Пример #2
0
        private void ReadGraphicalControlExtension()
        {
            byte[] buffer = new byte[6];

            _stream.Read(buffer, 0, buffer.Length);

            byte packed = buffer[1];

            _graphicsControl = new GifGraphicsControlExtension();
            _graphicsControl.DelayTime = BitConverter.ToInt16(buffer, 2);
            _graphicsControl.TransparencyIndex = buffer[4];
            _graphicsControl.TransparencyFlag = (packed & 0x01) == 1;
            _graphicsControl.DisposalMethod = (DisposalMethod)((packed & 0x1C) >> 2);
        }
Пример #3
0
        /// <summary>
        /// Decodes the image from the specified stream and sets
        /// the data to image.
        /// </summary>
        /// <param name="image">The image, where the data should be set to.
        /// Cannot be null (Nothing in Visual Basic).</param>
        /// <param name="stream">The stream, where the image should be
        /// decoded from. Cannot be null (Nothing in Visual Basic).</param>
        /// <exception cref="ArgumentNullException">
        ///     <para><paramref name="image"/> is null (Nothing in Visual Basic).</para>
        ///     <para>- or -</para>
        ///     <para><paramref name="stream"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        public void Decode(ExtendedImage image, Stream stream)
        {
            try
            {
                _image = image;

                _stream = stream;
                _stream.Seek(6, SeekOrigin.Current);

                ReadLogicalScreenDescriptor();

                if (_logicalScreenDescriptor.GlobalColorTableFlag == true)
                {
                    _globalColorTable = new byte[_logicalScreenDescriptor.GlobalColorTableSize * 3];

                    // Read the global color table from the stream
                    stream.Read(_globalColorTable, 0, _globalColorTable.Length);
                }

                int nextFlag = stream.ReadByte();
                while (nextFlag != -1)
                {
                    if (nextFlag == ImageLabel)
                    {
                        ReadFrame();
                    }
                    else if (nextFlag == ExtensionIntroducer)
                    {
                        int gcl = stream.ReadByte();
                        switch (gcl)
                        {
                        case GraphicControlLabel:
                            ReadGraphicalControlExtension();
                            break;

                        case CommentLabel:
                            ReadComments();
                            break;

                        case ApplicationExtensionLabel:
                            Skip(12);
                            break;

                        case PlainTextLabel:
                            Skip(13);
                            break;
                        }
                    }
                    else if (nextFlag == EndIntroducer)
                    {
                        break;
                    }
                    nextFlag = stream.ReadByte();
                }
            }
            catch (Exception e)
            {
                this._currentFrame     = null;
                this._globalColorTable = null;
                this._graphicsControl  = null;
                if (this._image != null)
                {
                    this._image.UriSource = null;
                }
                this._image = null;
                this._logicalScreenDescriptor = null;
                this._stream = null;

                throw new Exception("Gif failed to decode");
            }
        }