4 * Declarations shared between LZMS compression and decompression.
10 #include "wimlib/compiler.h"
11 #include "wimlib/lzms_constants.h"
12 #include "wimlib/types.h"
14 /* Offset slot tables */
15 extern const u32 lzms_offset_slot_base[LZMS_MAX_NUM_OFFSET_SYMS + 1];
16 extern const u8 lzms_extra_offset_bits[LZMS_MAX_NUM_OFFSET_SYMS];
18 /* Length slot tables */
19 extern const u32 lzms_length_slot_base[LZMS_NUM_LENGTH_SYMS + 1];
20 extern const u8 lzms_extra_length_bits[LZMS_NUM_LENGTH_SYMS];
23 lzms_get_slot(u32 value, const u32 slot_base_tab[], unsigned num_slots);
25 /* Return the offset slot for the specified offset */
26 static inline unsigned
27 lzms_get_offset_slot(u32 offset)
29 return lzms_get_slot(offset, lzms_offset_slot_base, LZMS_MAX_NUM_OFFSET_SYMS);
32 /* Return the length slot for the specified length */
33 static inline unsigned
34 lzms_get_length_slot(u32 length)
36 return lzms_get_slot(length, lzms_length_slot_base, LZMS_NUM_LENGTH_SYMS);
40 lzms_get_num_offset_slots(size_t uncompressed_size);
43 /* Probability entry for use by the range coder when in a specific state */
44 struct lzms_probability_entry {
46 /* The number of zeroes in the most recent LZMS_PROBABILITY_DENOMINATOR
47 * bits that have been decoded or encoded using this probability entry.
48 * The probability of the next bit being 0 is this value over
49 * LZMS_PROBABILITY_DENOMINATOR, except for the cases where this would
50 * imply 0% or 100% probability. */
51 u32 num_recent_zero_bits;
53 /* The most recent LZMS_PROBABILITY_DENOMINATOR bits that have been
54 * coded using this probability entry. The bits are ordered such that
55 * low order is newest and high order is oldest. */
60 lzms_init_probability_entries(struct lzms_probability_entry *entries, size_t count);
62 /* Given a decoded or encoded bit, update the probability entry. */
64 lzms_update_probability_entry(struct lzms_probability_entry *entry, int bit)
66 BUILD_BUG_ON(LZMS_PROBABILITY_DENOMINATOR != sizeof(entry->recent_bits) * 8);
68 s32 delta_zero_bits = (s32)(entry->recent_bits >>
69 (LZMS_PROBABILITY_DENOMINATOR - 1)) - bit;
71 entry->num_recent_zero_bits += delta_zero_bits;
72 entry->recent_bits = (entry->recent_bits << 1) | bit;
75 /* Given a probability entry, return the chance out of
76 * LZMS_PROBABILITY_DENOMINATOR that the next decoded bit will be a 0. */
78 lzms_get_probability(const struct lzms_probability_entry *prob_entry)
80 u32 prob = prob_entry->num_recent_zero_bits;
82 /* 0% and 100% probabilities aren't allowed. */
85 else if (prob == LZMS_PROBABILITY_DENOMINATOR)
91 lzms_init_symbol_frequencies(u32 freqs[], unsigned num_syms);
94 lzms_dilute_symbol_frequencies(u32 freqs[], unsigned num_syms);
96 /* Pre/post-processing */
98 lzms_x86_filter(u8 data[], s32 size, s32 last_target_usages[], bool undo);
100 #endif /* _LZMS_COMMON_H */