Browse Source

Cleanup LzwEncoder

af/merge-core
Jason Nelson 8 years ago
parent
commit
0dc94609be
  1. 31
      src/ImageSharp/Formats/Gif/LzwEncoder.cs

31
src/ImageSharp/Formats/Gif/LzwEncoder.cs

@ -34,11 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// </remarks> /// </remarks>
internal sealed class LzwEncoder : IDisposable internal sealed class LzwEncoder : IDisposable
{ {
/// <summary>
/// The end-of-file marker
/// </summary>
private const int Eof = -1;
/// <summary> /// <summary>
/// The maximum number of bits. /// The maximum number of bits.
/// </summary> /// </summary>
@ -84,7 +79,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private readonly byte[] accumulators = new byte[256]; private readonly byte[] accumulators = new byte[256];
/// <summary> /// <summary>
/// The current pixel /// The current position within the pixelArray.
/// </summary> /// </summary>
private int position; private int position;
@ -96,12 +91,12 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// User settable max # bits/code /// User settable max # bits/code
/// </summary> /// </summary>
private int maxbits = Bits; private int maxBits = Bits;
/// <summary> /// <summary>
/// maximum code, given bitCount /// maximum code, given bitCount
/// </summary> /// </summary>
private int maxcode; private int maxCode;
/// <summary> /// <summary>
/// should NEVER generate this code /// should NEVER generate this code
@ -209,7 +204,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
} }
/// <summary> /// <summary>
/// Gets the maximum code value /// Gets the maximum code value.
/// </summary> /// </summary>
/// <param name="bitCount">The number of bits</param> /// <param name="bitCount">The number of bits</param>
/// <returns>See <see cref="int"/></returns> /// <returns>See <see cref="int"/></returns>
@ -237,7 +232,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
} }
/// <summary> /// <summary>
/// Table clear for block compress /// Table clear for block compress.
/// </summary> /// </summary>
/// <param name="stream">The output stream.</param> /// <param name="stream">The output stream.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -272,13 +267,13 @@ namespace SixLabors.ImageSharp.Formats.Gif
int hsizeReg; int hsizeReg;
int hshift; int hshift;
// Set up the globals: globalInitialBits - initial number of bits // Set up the globals: globalInitialBits - initial number of bits
this.globalInitialBits = intialBits; this.globalInitialBits = intialBits;
// Set up the necessary values // Set up the necessary values
this.clearFlag = false; this.clearFlag = false;
this.bitCount = this.globalInitialBits; this.bitCount = this.globalInitialBits;
this.maxcode = GetMaxcode(this.bitCount); this.maxCode = GetMaxcode(this.bitCount);
this.clearCode = 1 << (intialBits - 1); this.clearCode = 1 << (intialBits - 1);
this.eofCode = this.clearCode + 1; this.eofCode = this.clearCode + 1;
@ -310,7 +305,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{ {
c = this.NextPixel(); c = this.NextPixel();
fcode = (c << this.maxbits) + ent; fcode = (c << this.maxBits) + ent;
int i = (c << hshift) ^ ent /* = 0 */; int i = (c << hshift) ^ ent /* = 0 */;
if (Unsafe.Add(ref hashTableRef, i) == fcode) if (Unsafe.Add(ref hashTableRef, i) == fcode)
@ -369,7 +364,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
} }
/// <summary> /// <summary>
/// Flush the packet to disk, and reset the accumulator. /// Flush the packet to disk and reset the accumulator.
/// </summary> /// </summary>
/// <param name="outStream">The output stream.</param> /// <param name="outStream">The output stream.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -381,7 +376,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
} }
/// <summary> /// <summary>
/// Return the next pixel from the image /// Reads the next pixel from the image.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// The <see cref="int"/> /// The <see cref="int"/>
@ -422,17 +417,17 @@ namespace SixLabors.ImageSharp.Formats.Gif
// If the next entry is going to be too big for the code size, // If the next entry is going to be too big for the code size,
// then increase it, if possible. // then increase it, if possible.
if (this.freeEntry > this.maxcode || this.clearFlag) if (this.freeEntry > this.maxCode || this.clearFlag)
{ {
if (this.clearFlag) if (this.clearFlag)
{ {
this.maxcode = GetMaxcode(this.bitCount = this.globalInitialBits); this.maxCode = GetMaxcode(this.bitCount = this.globalInitialBits);
this.clearFlag = false; this.clearFlag = false;
} }
else else
{ {
++this.bitCount; ++this.bitCount;
this.maxcode = this.bitCount == this.maxbits this.maxCode = this.bitCount == this.maxBits
? this.maxmaxcode ? this.maxmaxcode
: GetMaxcode(this.bitCount); : GetMaxcode(this.bitCount);
} }

Loading…
Cancel
Save