4 * Functions useful for compression, mainly bitstreams.
7 #ifndef _WIMLIB_COMPRESS_H
8 #define _WIMLIB_COMPRESS_H
11 #include "endianness.h"
13 typedef u16 output_bitbuf_t;
15 /* Structure to keep track of the current position in the compressed output. */
16 struct output_bitstream {
18 /* A variable to buffer writing bits to the output and is flushed to the
19 * compressed output when full. */
20 output_bitbuf_t bitbuf;
22 /* Number of free bits in @bitbuf */
28 /* Pointer to the next byte in the compressed output. */
32 /* Number of bytes left in the memory pointed to by @output. */
33 int num_bytes_remaining;
36 static inline int bitstream_put_byte(struct output_bitstream *ostream,
39 if (ostream->num_bytes_remaining < 1)
43 ostream->num_bytes_remaining--;
47 static inline int bitstream_put_two_bytes(struct output_bitstream *ostream,
50 if (ostream->num_bytes_remaining < 2)
52 *(u16*)ostream->output = cpu_to_le16(n);
54 ostream->num_bytes_remaining -= 2;
63 unsigned max_chain_len;
64 unsigned max_lazy_match;
68 typedef unsigned (*lz_record_match_t)(unsigned, unsigned, void *, void *);
69 typedef unsigned (*lz_record_literal_t)(u8, void *);
71 extern unsigned lz_analyze_block(const u8 uncompressed_data[],
72 unsigned uncompressed_len,
74 lz_record_match_t record_match,
75 lz_record_literal_t record_literal,
76 void *record_match_arg1,
77 void *record_match_arg2,
78 void *record_literal_arg,
79 const struct lz_params *params);
81 extern int bitstream_put_bits(struct output_bitstream *ostream,
82 output_bitbuf_t bits, unsigned num_bits);
84 extern void init_output_bitstream(struct output_bitstream *ostream,
85 void *data, unsigned num_bytes);
87 extern int flush_output_bitstream(struct output_bitstream *ostream);
89 extern void make_canonical_huffman_code(unsigned num_syms,
90 unsigned max_codeword_len,
95 #endif /* _WIMLIB_COMPRESS_H */