4 * Header for compression code shared by multiple compression formats.
6 * The author dedicates this file to the public domain.
7 * You can do whatever you want with this file.
10 #ifndef _WIMLIB_COMPRESS_COMMON_H
11 #define _WIMLIB_COMPRESS_COMMON_H
13 #include "wimlib/types.h"
15 /* Variable type that can represent all possible window positions. */
16 #ifndef INPUT_IDX_T_DEFINED
17 #define INPUT_IDX_T_DEFINED
18 typedef u32 input_idx_t;
21 /* Structure to keep track of the current state sending bits and bytes to the
22 * compressed output buffer. */
23 struct output_bitstream {
25 /* Variable that holds up to 16 bits that haven't yet been flushed to
29 /* Number of free bits in @bitbuf; that is, 16 minus the number of valid
33 /* Pointer to the start of the output buffer. */
36 /* Position at which to write the next 16 bits. */
39 /* Next position to write 16 bits, after they are written to bit_output.
40 * This is after @next_bit_output and may be separated from @bit_output
41 * by literal bytes. */
44 /* Next position to write literal bytes. This is after @bit_output and
45 * @next_bit_output, and may be separated from them by literal bytes.
49 /* Number of bytes remaining in the @output buffer. */
50 input_idx_t bytes_remaining;
52 /* Set to true if the buffer has been exhausted. */
57 init_output_bitstream(struct output_bitstream *ostream,
58 void *data, unsigned num_bytes);
61 flush_output_bitstream(struct output_bitstream *ostream);
64 bitstream_put_bits(struct output_bitstream *ostream,
65 u32 bits, unsigned num_bits);
68 bitstream_put_byte(struct output_bitstream *ostream, u8 n);
71 make_canonical_huffman_code(unsigned num_syms,
72 unsigned max_codeword_len,
73 const input_idx_t freq_tab[restrict],
75 u32 codewords[restrict]);
77 #endif /* _WIMLIB_COMPRESS_COMMON_H */