diff --git a/MSZIP/Constants.cs b/MSZIP/Constants.cs deleted file mode 100644 index 69df732..0000000 --- a/MSZIP/Constants.cs +++ /dev/null @@ -1,53 +0,0 @@ -namespace SabreTools.Compression.MSZIP -{ - public static class Constants - { - /// - /// Alphabet for fixed Huffman encoding - /// - public static readonly byte[] FixedAlphabet = new byte[19] - { - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, - }; - - /// - /// Extra bits for length codes 257-285 - /// - public static readonly byte[] MatchExtraBits = new byte[29] - { - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 5, 0, - }; - - /// - /// Initial lengths for length codes 257-285 - /// - public static readonly ushort[] MatchLengths = new ushort[29] - { - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, - 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, - 67, 83, 99, 115, 131, 163, 195, 227, 258, - }; - - /// - /// Extra bits for distance codes 0-29 - /// - public static readonly byte[] DistanceExtraBits = new byte[30] - { - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, - 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, - 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, - }; - - /// - /// Initial lengths for distance codes 0-29 - /// - public static readonly ushort[] DistanceLengths = new ushort[30] - { - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, - 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, - 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 - }; - } -} \ No newline at end of file diff --git a/MSZIP/DeflateDecompressor.cs b/MSZIP/DeflateDecompressor.cs index d858a47..56ee039 100644 --- a/MSZIP/DeflateDecompressor.cs +++ b/MSZIP/DeflateDecompressor.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using SabreTools.Models.Compression.MSZIP; using static SabreTools.Compression.MSZIP.Constants; +using static SabreTools.Models.Compression.MSZIP.Constants; namespace SabreTools.Compression.MSZIP { @@ -140,11 +141,11 @@ namespace SabreTools.Compression.MSZIP uint[] lengthLengths = new uint[19]; for (int i = 0; i < numLength; i++) { - lengthLengths[FixedAlphabet[i]] = (byte)_bitStream.ReadBitsLSB(3); + lengthLengths[BitLengthOrder[i]] = (byte)_bitStream.ReadBitsLSB(3); } for (int i = (int)numLength; i < 19; i++) { - lengthLengths[FixedAlphabet[i]] = 0; + lengthLengths[BitLengthOrder[i]] = 0; } // Make the lengths tree @@ -245,13 +246,13 @@ namespace SabreTools.Compression.MSZIP else { sym -= 257; - uint? length = MatchLengths[sym] + _bitStream.ReadBitsLSB(MatchExtraBits[sym]); + uint? length = CopyLengths[sym] + _bitStream.ReadBitsLSB(LiteralExtraBits[sym]); if (length == null) return null; int distanceCode = distanceTree.Decode(_bitStream); - uint? distance = DistanceLengths[distanceCode] + _bitStream.ReadBitsLSB(DistanceExtraBits[distanceCode]); + uint? distance = CopyOffsets[distanceCode] + _bitStream.ReadBitsLSB(DistanceExtraBits[distanceCode]); if (distance == null) return null;