]> wimlib.net Git - wimlib/blob - include/wimlib/lzx_constants.h
wim_inode: Remove i_list, leaving only i_hlist
[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 /* 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
28
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 */
35
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
39
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))
44
45 /* Number of symbols in the length code.  */
46 #define LZX_LENCODE_NUM_SYMBOLS         (LZX_NUM_LENS - LZX_NUM_PRIMARY_LENS)
47
48 /* Number of symbols in the pre-code.  */
49 #define LZX_PRECODE_NUM_SYMBOLS         20
50
51 /* Number of bits in which each pre-code codeword length is represented.  */
52 #define LZX_PRECODE_ELEMENT_SIZE        4
53
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
57
58 /* Number of symbols in the aligned offset code.  */
59 #define LZX_ALIGNEDCODE_NUM_SYMBOLS     (1 << LZX_NUM_ALIGNED_OFFSET_BITS)
60
61 /* Mask for the match offset bits that are entropy-encoded in aligned offset
62  * blocks.  */
63 #define LZX_ALIGNED_OFFSET_BITMASK      ((1 << LZX_NUM_ALIGNED_OFFSET_BITS) - 1)
64
65 /* Number of bits in which each aligned offset codeword length is represented.  */
66 #define LZX_ALIGNEDCODE_ELEMENT_SIZE    3
67
68 /* Maximum lengths (in bits) for length-limited Huffman code construction.  */
69 #define LZX_MAX_MAIN_CODEWORD_LEN       16
70 #define LZX_MAX_LEN_CODEWORD_LEN        16
71 #define LZX_MAX_PRE_CODEWORD_LEN        ((1 << LZX_PRECODE_ELEMENT_SIZE) - 1)
72 #define LZX_MAX_ALIGNED_CODEWORD_LEN    ((1 << LZX_ALIGNEDCODE_ELEMENT_SIZE) - 1)
73
74 /* For LZX-compressed blocks in WIM resources, this value is always used as the
75  * filesize parameter for the call instruction (0xe8 byte) preprocessing, even
76  * though the blocks themselves are not this size, and the size of the actual
77  * file resource in the WIM file is very likely to be something entirely
78  * different as well.  */
79 #define LZX_WIM_MAGIC_FILESIZE  12000000
80
81 /* Assumed LZX block size when the encoded block size begins with a 0 bit.
82  * This is probably WIM-specific.  */
83 #define LZX_DEFAULT_BLOCK_SIZE  32768
84
85 /* Number of offsets in the recent (or "repeat") offsets queue.  */
86 #define LZX_NUM_RECENT_OFFSETS  3
87
88 /* An offset of n bytes is actually encoded as (n + LZX_OFFSET_ADJUSTMENT).  */
89 #define LZX_OFFSET_ADJUSTMENT   (LZX_NUM_RECENT_OFFSETS - 1)
90
91 #endif /* _LZX_CONSTANTS_H */