]> wimlib.net Git - wimlib/blob - include/wimlib/compress_common.h
9910d412c8574605ba3528f3a9b98d0d51558453
[wimlib] / include / wimlib / compress_common.h
1 /*
2  * compress_common.h
3  *
4  * Header for compression code shared by multiple compression formats.
5  *
6  * The author dedicates this file to the public domain.
7  * You can do whatever you want with this file.
8  */
9
10 #ifndef _WIMLIB_COMPRESS_COMMON_H
11 #define _WIMLIB_COMPRESS_COMMON_H
12
13 #include "wimlib/types.h"
14
15 /* Structure to keep track of the current state sending bits and bytes to the
16  * compressed output buffer.  */
17 struct output_bitstream {
18
19         /* Variable that holds up to 16 bits that haven't yet been flushed to
20          * the output.  */
21         u16 bitbuf;
22
23         /* Number of free bits in @bitbuf; that is, 16 minus the number of valid
24          * bits in @bitbuf.  */
25         unsigned free_bits;
26
27         /* Pointer to the start of the output buffer.  */
28         u8 *output_start;
29
30         /* Position at which to write the next 16 bits.  */
31         u8 *bit_output;
32
33         /* Next position to write 16 bits, after they are written to bit_output.
34          * This is after @next_bit_output and may be separated from @bit_output
35          * by literal bytes.  */
36         u8 *next_bit_output;
37
38         /* Next position to write literal bytes.  This is after @bit_output and
39          * @next_bit_output, and may be separated from them by literal bytes.
40          */
41         u8 *output;
42
43         /* Number of bytes remaining in the @output buffer.  */
44         u32 bytes_remaining;
45
46         /* Set to true if the buffer has been exhausted.  */
47         bool overrun;
48 };
49
50 extern void
51 init_output_bitstream(struct output_bitstream *ostream,
52                       void *data, unsigned num_bytes);
53
54 extern u32
55 flush_output_bitstream(struct output_bitstream *ostream);
56
57 extern void
58 bitstream_put_bits(struct output_bitstream *ostream,
59                    u32 bits, unsigned num_bits);
60
61 extern void
62 bitstream_put_byte(struct output_bitstream *ostream, u8 n);
63
64 extern void
65 make_canonical_huffman_code(unsigned num_syms,
66                             unsigned max_codeword_len,
67                             const u32 freq_tab[restrict],
68                             u8 lens[restrict],
69                             u32 codewords[restrict]);
70
71 #endif /* _WIMLIB_COMPRESS_COMMON_H */