14 #ifndef LZMA_RANGE_DECODER_H
15 #define LZMA_RANGE_DECODER_H
54 #define rc_to_local(range_decoder, in_pos) \
55 lzma_range_decoder rc = range_decoder; \
56 size_t rc_in_pos = (in_pos); \
61 #define rc_from_local(range_decoder, in_pos) \
69 #define rc_reset(range_decoder) \
71 (range_decoder).range = UINT32_MAX; \
72 (range_decoder).code = 0; \
73 (range_decoder).init_bytes_left = 5; \
80 #define rc_is_finished(range_decoder) \
81 ((range_decoder).code == 0)
87 #define rc_normalize(seq) \
89 if (rc.range < RC_TOP_VALUE) { \
90 if (unlikely(rc_in_pos == in_size)) { \
91 coder->sequence = seq; \
94 rc.range <<= RC_SHIFT_BITS; \
95 rc.code = (rc.code << RC_SHIFT_BITS) | in[rc_in_pos++]; \
111 #define rc_if_0(prob, seq) \
113 rc_bound = (rc.range >> RC_BIT_MODEL_TOTAL_BITS) * (prob); \
114 if (rc.code < rc_bound)
119 #define rc_update_0(prob) \
121 rc.range = rc_bound; \
122 prob += (RC_BIT_MODEL_TOTAL - (prob)) >> RC_MOVE_BITS; \
128 #define rc_update_1(prob) \
130 rc.range -= rc_bound; \
131 rc.code -= rc_bound; \
132 prob -= (prob) >> RC_MOVE_BITS; \
140 #define rc_bit_last(prob, action0, action1, seq) \
142 rc_if_0(prob, seq) { \
154 #define rc_bit(prob, action0, action1, seq) \
156 symbol <<= 1; action0, \
157 symbol = (symbol << 1) + 1; action1, \
166 #define rc_bit_case(prob, action0, action1, seq) \
167 case seq: rc_bit(prob, action0, action1, seq)
171 #define rc_direct(dest, seq) \
175 rc.code -= rc.range; \
176 rc_bound = UINT32_C(0) - (rc.code >> 31); \
177 rc.code += rc.range & rc_bound; \
178 dest = (dest << 1) + (rc_bound + 1); \
const lzma_allocator const uint8_t size_t * in_pos
const lzma_allocator const uint8_t size_t in_size
const lzma_allocator const uint8_t * in
Common things for range encoder and decoder.
static lzma_ret rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size)
Reads the first five bytes to initialize the range decoder.
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_DATA_ERROR
Data is corrupt.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_OK
Operation completed successfully.