Example #1
0
        async Task ParseImageDescriptorAsync(GIFDecoderStreamReader stream, GIFBitmapDecoder decoder, GIFBitmap previousBitmap, bool ignoreImageData)
        {
            await ParseGIFBitmapHeaderAsync(stream).ConfigureAwait(false);

            if (IsTransparent)
            {
                ColorTable.SetTransparency(TransparencyIndex);
            }

            DataPosition = stream.CurrentPosition;

            if (!ignoreImageData)
            {
                // Decode LZW data stream.
                await decoder.DecodeAsync(stream, _header.Width, _header.Height).ConfigureAwait(false);

                // Compose bitmap from decoded data stream.
                decoder.Compose(_header, this, previousBitmap);

                // Consume block terminator.
                await stream.SkipBlockAsync().ConfigureAwait(false);
            }
            else
            {
                // Read pass variable length LZW data stream.
                // First byte is LZW code size followed by data blocks repeated until block terminator.
                stream.Read();
                await stream.SkipBlockAsync().ConfigureAwait(false);
            }

            if (IsTransparent)
            {
                ColorTable.ResetTransparency();
            }
        }
Example #2
0
        async Task ParseApplicationExtensionAsync(GIFDecoderStreamReader stream)
        {
            var blockSize = await stream.ReadBlockAsync().ConfigureAwait(false);

            if (blockSize >= NetscapeApplicationExtensionID.Length)
            {
                var    buffer     = stream.CurrentBlockBuffer;
                string identifier = System.Text.Encoding.UTF8.GetString(buffer, 0, NetscapeApplicationExtensionID.Length);
                if (identifier.Equals(NetscapeApplicationExtensionID, StringComparison.OrdinalIgnoreCase))
                {
                    await ParseNetscapeApplicationExtensionAsync(stream).ConfigureAwait(false);

                    return;
                }
            }
            await stream.SkipBlockAsync().ConfigureAwait(false);

            return;
        }
Example #3
0
        async Task ParseExtensionAsync(GIFDecoderStreamReader stream)
        {
            int blockCode = stream.Read();

            switch (blockCode)
            {
            case GIFBlockCodes.GraphicsControlExtension:
                ParseGraphicControlExtension(stream);
                break;

            case GIFBlockCodes.ApplicationExtensionBlock:
                await ParseApplicationExtensionAsync(stream).ConfigureAwait(false);

                break;

            default:
                await stream.SkipBlockAsync().ConfigureAwait(false);

                break;
            }
        }