4 * Header for compression code shared by multiple compression formats.
7 #ifndef _WIMLIB_COMPRESS_H
8 #define _WIMLIB_COMPRESS_H
10 #include "wimlib/types.h"
12 /* Variable type that can represent all possible window positions. */
13 #ifndef INPUT_IDX_T_DEFINED
14 #define INPUT_IDX_T_DEFINED
15 typedef u32 input_idx_t;
18 /* Structure to keep track of the current state sending bits and bytes to the
19 * compressed output buffer. */
20 struct output_bitstream {
22 /* Variable that holds up to 16 bits that haven't yet been flushed to
26 /* Number of free bits in @bitbuf; that is, 16 minus the number of valid
30 /* Pointer to the start of the output buffer. */
33 /* Position at which to write the next 16 bits. */
36 /* Next position to write 16 bits, after they are written to bit_output.
37 * This is after @next_bit_output and may be separated from @bit_output
38 * by literal bytes. */
41 /* Next position to write literal bytes. This is after @bit_output and
42 * @next_bit_output, and may be separated from them by literal bytes.
46 /* Number of bytes remaining in the @output buffer. */
47 input_idx_t bytes_remaining;
49 /* Set to true if the buffer has been exhausted. */
54 init_output_bitstream(struct output_bitstream *ostream,
55 void *data, unsigned num_bytes);
58 flush_output_bitstream(struct output_bitstream *ostream);
61 bitstream_put_bits(struct output_bitstream *ostream,
62 u32 bits, unsigned num_bits);
65 bitstream_put_byte(struct output_bitstream *ostream, u8 n);
73 unsigned max_chain_len;
74 unsigned max_lazy_match;
78 typedef void (*lz_record_match_t)(unsigned len, unsigned offset, void *ctx);
79 typedef void (*lz_record_literal_t)(u8 lit, void *ctx);
82 lz_analyze_block(const u8 window[restrict],
83 input_idx_t window_size,
84 lz_record_match_t record_match,
85 lz_record_literal_t record_literal,
87 const struct lz_params *params,
88 input_idx_t prev_tab[restrict]);
91 make_canonical_huffman_code(unsigned num_syms,
92 unsigned max_codeword_len,
93 const input_idx_t freq_tab[restrict],
95 u16 codewords[restrict]);
97 #endif /* _WIMLIB_COMPRESS_H */