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