4 * Constants for the LZX compression format.
7 #ifndef _LZX_CONSTANTS_H
8 #define _LZX_CONSTANTS_H
10 /* Number of literal byte values. */
11 #define LZX_NUM_CHARS 256
13 /* The smallest and largest allowed match lengths. */
14 #define LZX_MIN_MATCH_LEN 2
15 #define LZX_MAX_MATCH_LEN 257
17 /* Number of distinct match lengths that can be represented. */
18 #define LZX_NUM_LENS (LZX_MAX_MATCH_LEN - LZX_MIN_MATCH_LEN + 1)
20 /* Number of match lengths for which no length symbol is required. */
21 #define LZX_NUM_PRIMARY_LENS 7
22 #define LZX_NUM_LEN_HEADERS (LZX_NUM_PRIMARY_LENS + 1)
24 /* Valid values of the 3-bit block type field. */
25 #define LZX_BLOCKTYPE_VERBATIM 1
26 #define LZX_BLOCKTYPE_ALIGNED 2
27 #define LZX_BLOCKTYPE_UNCOMPRESSED 3
29 /* 'LZX_MIN_WINDOW_SIZE' and 'LZX_MAX_WINDOW_SIZE' are the minimum and maximum
30 * sizes of the sliding window. */
31 #define LZX_MIN_WINDOW_ORDER 15
32 #define LZX_MAX_WINDOW_ORDER 21
33 #define LZX_MIN_WINDOW_SIZE (1UL << LZX_MIN_WINDOW_ORDER) /* 32768 */
34 #define LZX_MAX_WINDOW_SIZE (1UL << LZX_MAX_WINDOW_ORDER) /* 2097152 */
36 /* Maximum number of offset slots. (The actual number of offset slots depends
37 * on the window size.) */
38 #define LZX_MAX_OFFSET_SLOTS 50
40 /* Maximum number of symbols in the main code. (The actual number of symbols in
41 * the main code depends on the window size.) */
42 #define LZX_MAINCODE_MAX_NUM_SYMBOLS \
43 (LZX_NUM_CHARS + (LZX_MAX_OFFSET_SLOTS * LZX_NUM_LEN_HEADERS))
45 /* Number of symbols in the length code. */
46 #define LZX_LENCODE_NUM_SYMBOLS (LZX_NUM_LENS - LZX_NUM_PRIMARY_LENS)
48 /* Number of symbols in the pre-code. */
49 #define LZX_PRECODE_NUM_SYMBOLS 20
51 /* Number of bits in which each pre-code codeword length is represented. */
52 #define LZX_PRECODE_ELEMENT_SIZE 4
54 /* Number of low-order bits of each match offset that are entropy-encoded in
55 * aligned offset blocks. */
56 #define LZX_NUM_ALIGNED_OFFSET_BITS 3
58 /* Number of symbols in the aligned offset code. */
59 #define LZX_ALIGNEDCODE_NUM_SYMBOLS (1 << LZX_NUM_ALIGNED_OFFSET_BITS)
61 /* Mask for the match offset bits that are entropy-encoded in aligned offset
63 #define LZX_ALIGNED_OFFSET_BITMASK ((1 << LZX_NUM_ALIGNED_OFFSET_BITS) - 1)
65 /* Number of bits in which each aligned offset codeword length is represented. */
66 #define LZX_ALIGNEDCODE_ELEMENT_SIZE 3
68 /* The first offset slot which requires an aligned offset symbol in aligned
70 #define LZX_MIN_ALIGNED_OFFSET_SLOT 8
72 /* The offset slot base for LZX_MIN_ALIGNED_OFFSET_SLOT. */
73 #define LZX_MIN_ALIGNED_OFFSET 14
75 /* The maximum number of extra offset bits in verbatim blocks. (One would need
76 * to subtract LZX_NUM_ALIGNED_OFFSET_BITS to get the number of extra offset
77 * bits in *aligned* blocks.) */
78 #define LZX_MAX_NUM_EXTRA_BITS 17
80 /* Maximum lengths (in bits) for length-limited Huffman code construction. */
81 #define LZX_MAX_MAIN_CODEWORD_LEN 16
82 #define LZX_MAX_LEN_CODEWORD_LEN 16
83 #define LZX_MAX_PRE_CODEWORD_LEN ((1 << LZX_PRECODE_ELEMENT_SIZE) - 1)
84 #define LZX_MAX_ALIGNED_CODEWORD_LEN ((1 << LZX_ALIGNEDCODE_ELEMENT_SIZE) - 1)
86 /* For LZX-compressed blocks in WIM resources, this value is always used as the
87 * filesize parameter for the call instruction (0xe8 byte) preprocessing, even
88 * though the blocks themselves are not this size, and the size of the actual
89 * file resource in the WIM file is very likely to be something entirely
90 * different as well. */
91 #define LZX_WIM_MAGIC_FILESIZE 12000000
93 /* Assumed LZX block size when the encoded block size begins with a 0 bit.
94 * This is probably WIM-specific. */
95 #define LZX_DEFAULT_BLOCK_SIZE 32768
97 /* Number of offsets in the recent (or "repeat") offsets queue. */
98 #define LZX_NUM_RECENT_OFFSETS 3
100 /* An offset of n bytes is actually encoded as (n + LZX_OFFSET_ADJUSTMENT). */
101 #define LZX_OFFSET_ADJUSTMENT (LZX_NUM_RECENT_OFFSETS - 1)
103 #endif /* _LZX_CONSTANTS_H */