diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
index 60bc56dc5a..32ba6015bb 100644
--- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs
@@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
};
///
- /// The working pixel array
+ /// The working pixel array.
///
private readonly byte[] pixelArray;
@@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// The current pixel
///
- private int currentPixel;
+ private int position;
///
/// Number of bits/code
@@ -212,7 +212,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
// Write "initial code size" byte
stream.WriteByte((byte)this.initialCodeSize);
- this.currentPixel = 0;
+ this.position = 0;
// Compress and write the pixel data
this.Compress(this.initialCodeSize + 1, stream);
@@ -221,13 +221,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
stream.WriteByte(GifConstants.Terminator);
}
- ///
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- this.Dispose(true);
- }
-
///
/// Gets the maximum code value
///
@@ -326,8 +319,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.Span);
ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.Span);
- while ((c = this.NextPixel()) != Eof)
+ while (this.position < this.pixelArray.Length)
{
+ c = this.NextPixel();
+
fcode = (c << this.maxbits) + ent;
int i = (c << hshift) ^ ent /* = 0 */;
@@ -404,15 +399,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
///
/// The
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
private int NextPixel()
{
- if (this.currentPixel == this.pixelArray.Length)
- {
- return Eof;
- }
-
- this.currentPixel++;
- return this.pixelArray[this.currentPixel - 1] & 0xff;
+ return this.pixelArray[this.position++] & 0xff;
}
///
@@ -478,6 +468,13 @@ namespace SixLabors.ImageSharp.Formats.Gif
}
}
+ ///
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
+ this.Dispose(true);
+ }
+
///
/// Disposes the object and frees resources for the Garbage Collector.
///