|
|
|
@ -34,11 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
/// </remarks>
|
|
|
|
internal sealed class LzwEncoder : IDisposable |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// The maximum number of bits.
|
|
|
|
/// </summary>
|
|
|
|
private const int Bits = 12; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 80% occupancy
|
|
|
|
/// </summary>
|
|
|
|
@ -53,6 +48,11 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF |
|
|
|
}; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The maximium number of bits/code.
|
|
|
|
/// </summary>
|
|
|
|
private const int MaxBits = 12; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The working pixel array.
|
|
|
|
/// </summary>
|
|
|
|
@ -88,11 +88,6 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
/// </summary>
|
|
|
|
private int bitCount; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// User settable max # bits/code
|
|
|
|
/// </summary>
|
|
|
|
private int maxBits = Bits; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// maximum code, given bitCount
|
|
|
|
/// </summary>
|
|
|
|
@ -101,7 +96,7 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
/// <summary>
|
|
|
|
/// should NEVER generate this code
|
|
|
|
/// </summary>
|
|
|
|
private int maxmaxcode = 1 << Bits; |
|
|
|
private int maxmaxcode = 1 << MaxBits; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// For dynamic table sizing
|
|
|
|
@ -305,7 +300,7 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
{ |
|
|
|
c = this.NextPixel(); |
|
|
|
|
|
|
|
fcode = (c << this.maxBits) + ent; |
|
|
|
fcode = (c << MaxBits) + ent; |
|
|
|
int i = (c << hshift) ^ ent /* = 0 */; |
|
|
|
|
|
|
|
if (Unsafe.Add(ref hashTableRef, i) == fcode) |
|
|
|
@ -427,7 +422,7 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
else |
|
|
|
{ |
|
|
|
++this.bitCount; |
|
|
|
this.maxCode = this.bitCount == this.maxBits |
|
|
|
this.maxCode = this.bitCount == MaxBits |
|
|
|
? this.maxmaxcode |
|
|
|
: GetMaxcode(this.bitCount); |
|
|
|
} |
|
|
|
|