Example #1
0
        private void DisposePreviousFrame(GifFrame currentFrame)
        {
            GifFrame previousFrame = this._previousFrame;
            GifGraphicControlExtension controlExtension = previousFrame != null ? previousFrame.GraphicControl : null;

            if (controlExtension != null)
            {
                switch (controlExtension.DisposalMethod)
                {
                case GifFrameDisposalMethod.RestoreBackground:
                    this.ClearArea((IGifRect)this._previousFrame.Descriptor);
                    break;

                case GifFrameDisposalMethod.RestorePrevious:
                    Animator.CopyToBitmap(this._previousBackBuffer, this._bitmap, 0, this._previousBackBuffer.Length);
                    break;
                }
            }
            GifGraphicControlExtension graphicControl = currentFrame.GraphicControl;

            if (graphicControl == null || graphicControl.DisposalMethod != GifFrameDisposalMethod.RestorePrevious)
            {
                return;
            }
            Animator.CopyFromBitmap(this._previousBackBuffer, this._bitmap, 0, this._previousBackBuffer.Length);
        }
Example #2
0
        private void ClearArea(IGifRect rect)
        {
            int length = 4 * rect.Width;

            byte[] buffer = new byte[length];
            for (int index = 0; index < rect.Height; ++index)
            {
                int offset = (rect.Top + index) * this._stride + 4 * rect.Left;
                Animator.CopyToBitmap(buffer, this._bitmap, offset, length);
            }
        }
Example #3
0
        private async Task RenderFrameAsync(int frameIndex, CancellationToken cancellationToken)
        {
            if (frameIndex < 0)
            {
                return;
            }
            GifFrame           frame = this._metadata.Frames[frameIndex];
            GifImageDescriptor desc  = frame.Descriptor;

            using (Stream indexStreamAsync = await this.GetIndexStreamAsync(frame, cancellationToken))
            {
                if (frameIndex < this._previousFrameIndex)
                {
                    this.ClearArea((IGifRect)this._metadata.Header.LogicalScreenDescriptor);
                }
                else
                {
                    this.DisposePreviousFrame(frame);
                }
                int    length               = 4 * desc.Width;
                byte[] buffer               = new byte[desc.Width];
                byte[] numArray             = new byte[length];
                Animator.GifPalette palette = this._palettes[frameIndex];
                int num1 = palette.TransparencyIndex ?? -1;
                foreach (int num2 in frame.Descriptor.Interlace ? Animator.InterlacedRows(frame.Descriptor.Height) : Animator.NormalRows(frame.Descriptor.Height))
                {
                    if (indexStreamAsync.Read(buffer, 0, desc.Width) != desc.Width)
                    {
                        throw new EndOfStreamException();
                    }
                    int offset = (desc.Top + num2) * this._stride + desc.Left * 4;
                    if (num1 >= 0)
                    {
                        Animator.CopyFromBitmap(numArray, this._bitmap, offset, length);
                    }
                    for (int index = 0; index < desc.Width; ++index)
                    {
                        byte num3       = buffer[index];
                        int  startIndex = 4 * index;
                        if ((int)num3 != num1)
                        {
                            Animator.WriteColor(numArray, palette[(int)num3], startIndex);
                        }
                    }
                    Animator.CopyToBitmap(numArray, this._bitmap, offset, length);
                }
                this._bitmap.Invalidate();
                this._previousFrame      = frame;
                this._previousFrameIndex = frameIndex;
            }
        }