4 * Header for compression code shared by multiple compression formats.
7 #ifndef _WIMLIB_COMPRESS_H
8 #define _WIMLIB_COMPRESS_H
10 #include "wimlib/endianness.h"
11 #include "wimlib/types.h"
13 typedef u16 output_bitbuf_t;
15 /* Variable type that can represent all possible window positions. */
17 #ifndef INPUT_IDX_T_DEFINED
18 #define INPUT_IDX_T_DEFINED
19 typedef u32 input_idx_t;
22 /* Structure to keep track of the current position in the compressed output. */
23 struct output_bitstream {
25 /* A variable to buffer writing bits to the output and is flushed to the
26 * compressed output when full. */
27 output_bitbuf_t bitbuf;
29 /* Number of free bits in @bitbuf */
32 /* Pointer to the start of the output buffer. */
35 /* Position at which to write the next 16 bits. */
38 /* Next position to write 16 bits, after they are written to bit_output.
39 * This is after @next_bit_output and may be separated from @bit_output
40 * by literal bytes. */
43 /* Next position to write literal bytes. This is after @bit_output and
44 * @next_bit_output, and may be separated from them by literal bytes.
48 /* Bytes remaining in @output buffer. */
49 input_idx_t bytes_remaining;
51 /* Set to true if the buffer has been exhausted. */
56 init_output_bitstream(struct output_bitstream *ostream,
57 void *data, unsigned num_bytes);
60 flush_output_bitstream(struct output_bitstream *ostream);
63 bitstream_put_bits(struct output_bitstream *ostream,
64 u32 bits, unsigned num_bits);
67 bitstream_put_byte(struct output_bitstream *ostream, u8 n);
75 unsigned max_chain_len;
76 unsigned max_lazy_match;
80 typedef void (*lz_record_match_t)(unsigned len, unsigned offset, void *ctx);
81 typedef void (*lz_record_literal_t)(u8 lit, void *ctx);
84 lz_analyze_block(const u8 window[],
85 input_idx_t window_size,
86 lz_record_match_t record_match,
87 lz_record_literal_t record_literal,
89 const struct lz_params *params,
90 input_idx_t prev_tab[]);
93 make_canonical_huffman_code(unsigned num_syms,
94 unsigned max_codeword_len,
95 const freq_t freq_tab[restrict],
97 u16 codewords[restrict]);
99 #endif /* _WIMLIB_COMPRESS_H */