diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index bfd441259..7fa3aa04a 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Gets the text encoding /// - public Encoding TextEncoding { get; private set; } + public Encoding TextEncoding { get; } /// /// Decodes the stream to the image. @@ -311,10 +311,9 @@ namespace SixLabors.ImageSharp.Formats.Gif try { // Determine the color table for this frame. If there is a local one, use it otherwise use the global color table. - int length = this.globalColorTableLength; if (imageDescriptor.LocalColorTableFlag) { - length = imageDescriptor.LocalColorTableSize * 3; + int length = imageDescriptor.LocalColorTableSize * 3; localColorTable = ArrayPool.Shared.Rent(length); this.currentStream.Read(localColorTable, 0, length); } @@ -322,7 +321,7 @@ namespace SixLabors.ImageSharp.Formats.Gif indices = ArrayPool.Shared.Rent(imageDescriptor.Width * imageDescriptor.Height); this.ReadFrameIndices(imageDescriptor, indices); - this.ReadFrameColors(indices, localColorTable ?? this.globalColorTable, length, imageDescriptor); + this.ReadFrameColors(indices, localColorTable ?? this.globalColorTable, imageDescriptor); // Skip any remaining blocks this.Skip(0); @@ -358,18 +357,17 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The indexed pixels. /// The color table containing the available colors. - /// The color table length. /// The - private unsafe void ReadFrameColors(byte[] indices, byte[] colorTable, int colorTableLength, GifImageDescriptor descriptor) + private void ReadFrameColors(byte[] indices, byte[] colorTable, GifImageDescriptor descriptor) { int imageWidth = this.logicalScreenDescriptor.Width; int imageHeight = this.logicalScreenDescriptor.Height; - ImageFrame previousFrame = null; + ImageFrame prevFrame = null; ImageFrame currentFrame = null; - ImageFrame image; + ImageFrame imageFrame; if (this.previousFrame == null) { @@ -378,23 +376,23 @@ namespace SixLabors.ImageSharp.Formats.Gif this.SetFrameMetaData(this.image.Frames.RootFrame.MetaData); - image = this.image.Frames.RootFrame; + imageFrame = this.image.Frames.RootFrame; } else { if (this.graphicsControlExtension != null && this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) { - previousFrame = this.previousFrame; + prevFrame = this.previousFrame; } - currentFrame = this.image.Frames.AddFrame(this.previousFrame); // this clones the frame and adds it the collection + currentFrame = this.image.Frames.AddFrame(this.previousFrame); // This clones the frame and adds it the collection this.SetFrameMetaData(currentFrame.MetaData); - image = currentFrame; + imageFrame = currentFrame; - this.RestoreToBackground(image); + this.RestoreToBackground(imageFrame); } int i = 0; @@ -439,9 +437,9 @@ namespace SixLabors.ImageSharp.Formats.Gif writeY = y; } - Span rowSpan = image.GetPixelRowSpan(writeY); + Span rowSpan = imageFrame.GetPixelRowSpan(writeY); - Rgba32 rgba = new Rgba32(0, 0, 0, 255); + var rgba = new Rgba32(0, 0, 0, 255); for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++) { @@ -463,13 +461,13 @@ namespace SixLabors.ImageSharp.Formats.Gif } } - if (previousFrame != null) + if (prevFrame != null) { - this.previousFrame = previousFrame; + this.previousFrame = prevFrame; return; } - this.previousFrame = currentFrame == null ? this.image.Frames.RootFrame : currentFrame; + this.previousFrame = currentFrame ?? this.image.Frames.RootFrame; if (this.graphicsControlExtension != null && this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToBackground) @@ -518,18 +516,18 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Sets the frames metadata. /// - /// The meta data. + /// The meta data. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void SetFrameMetaData(ImageFrameMetaData metaData) + private void SetFrameMetaData(ImageFrameMetaData meta) { if (this.graphicsControlExtension != null) { if (this.graphicsControlExtension.DelayTime > 0) { - metaData.FrameDelay = this.graphicsControlExtension.DelayTime; + meta.FrameDelay = this.graphicsControlExtension.DelayTime; } - metaData.DisposalMethod = this.graphicsControlExtension.DisposalMethod; + meta.DisposalMethod = this.graphicsControlExtension.DisposalMethod; } } } diff --git a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs index 60c39f936..fd4cc82c9 100644 --- a/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs @@ -1,11 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.IO; using System.Text; -using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Gif {