34 =
offset + match_bit + (symbol >> 8);
36 rc_bit(rc, &subcoder[subcoder_index],
bit);
39 offset &= ~(match_byte ^ symbol);
41 }
while (symbol < (
UINT32_C(1) << 16));
81 lc->
counters[pos_state] = table_size;
98 for (;
i < table_size; ++
i)
157 const uint32_t footer_bits = (dist_slot >> 1) - 1;
158 const uint32_t base = (2 | (dist_slot & 1)) << footer_bits;
159 const uint32_t dist_reduced = distance - base;
166 footer_bits, dist_reduced);
180 coder->
reps[0] = distance;
216 coder->
reps[0] = distance;
308 #define LOOP_INPUT_MAX (OPTS + 1)
317 if (!coder->is_initialized && !
encode_init(coder, mf))
339 && (mf->read_pos - mf->read_ahead >=
limit
346 if (mf->read_pos >= mf->read_limit) {
350 if (mf->read_ahead == 0)
365 if (coder->fast_mode)
369 coder, mf, &back, &
len, position);
376 if (!coder->is_flushed) {
377 coder->is_flushed =
true;
398 coder->is_flushed =
false;
454 const uint32_t num_pos_states,
const bool fast_mode)
459 for (
size_t pos_state = 0; pos_state < num_pos_states; ++pos_state) {
467 for (
uint32_t pos_state = 0; pos_state < num_pos_states;
491 for (
size_t i = 0;
i <
REPS; ++
i)
498 for (
size_t j = 0; j <= coder->
pos_mask; ++j) {
554 if (*coder_ptr ==
NULL) {
556 if (*coder_ptr ==
NULL)
599 &&
options->preset_dict_size > 0;
651 assert(*
byte <= (4 * 5 + 4) * 9 + 8);
657 #ifdef HAVE_ENCODER_LZMA1
const lzma_allocator const uint8_t size_t uint8_t size_t * out_pos
const lzma_allocator * allocator
const lzma_allocator const uint8_t size_t uint8_t * out
const lzma_filter * filters
Kind of two-bit version of bit scan reverse.
static uint32_t get_dist_slot(uint32_t dist)
static const char struct stat static buf struct stat static buf static vhangup int options
uint64_t lzma_lz_encoder_memusage(const lzma_lz_options *lz_options)
lzma_ret lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, lzma_ret(*lz_init)(lzma_lz_encoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options))
static uint32_t mf_position(const lzma_mf *mf)
static void mf_skip(lzma_mf *mf, uint32_t amount)
lzma_mode
Compression modes.
@ LZMA_MODE_FAST
Fast compression.
@ LZMA_MODE_NORMAL
Normal compression.
#define LZMA2_CHUNK_MAX
Maximum number of bytes of actual data per chunk (no headers)
#define update_literal(state)
Indicate that the latest state was a literal.
#define is_literal_state(state)
Test if the previous state was a literal.
#define update_match(state)
Indicate that the latest state was a match.
#define get_dist_state(len)
#define literal_subcoder(probs, lc, lp_mask, pos, prev_byte)
static void literal_init(probability(*probs)[LITERAL_CODER_SIZE], uint32_t lc, uint32_t lp)
#define STATES
Total number of states.
#define update_long_rep(state)
Indicate that the latest state was a long repeated match.
static bool is_lclppb_valid(const lzma_options_lzma *options)
Validates lc, lp, and pb.
#define update_short_rep(state)
Indicate that the latest state was a short match.
lzma_ret lzma_lzma_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
lzma_ret lzma_lzma_encode(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, uint32_t limit)
static bool is_options_valid(const lzma_options_lzma *options)
static void literal(lzma_lzma1_encoder *coder, lzma_mf *mf, uint32_t position)
bool lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte)
Encodes lc/lp/pb into one byte. Returns false on success and true on error.
static void literal_matched(lzma_range_encoder *rc, probability *subcoder, uint32_t match_byte, uint32_t symbol)
static void set_lz_options(lzma_lz_options *lz_options, const lzma_options_lzma *options)
static void length(lzma_range_encoder *rc, lzma_length_encoder *lc, const uint32_t pos_state, uint32_t len, const bool fast_mode)
lzma_ret lzma_lzma_encoder_reset(lzma_lzma1_encoder *coder, const lzma_options_lzma *options)
static void encode_symbol(lzma_lzma1_encoder *coder, lzma_mf *mf, uint32_t back, uint32_t len, uint32_t position)
static void length_encoder_reset(lzma_length_encoder *lencoder, const uint32_t num_pos_states, const bool fast_mode)
static lzma_ret lzma_encode(void *coder, lzma_mf *restrict mf, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size)
static bool encode_init(lzma_lzma1_encoder *coder, lzma_mf *mf)
uint64_t lzma_lzma_encoder_memusage(const void *options)
static void encode_eopm(lzma_lzma1_encoder *coder, uint32_t position)
static void match(lzma_lzma1_encoder *coder, const uint32_t pos_state, const uint32_t distance, const uint32_t len)
static lzma_ret lzma_encoder_init(lzma_lz_encoder *lz, const lzma_allocator *allocator, const void *options, lzma_lz_options *lz_options)
lzma_ret lzma_lzma_encoder_create(void **coder_ptr, const lzma_allocator *allocator, const lzma_options_lzma *options, lzma_lz_options *lz_options)
static void rep_match(lzma_lzma1_encoder *coder, const uint32_t pos_state, const uint32_t rep, const uint32_t len)
static void length_update_prices(lzma_length_encoder *lc, const uint32_t pos_state)
lzma_ret lzma_lzma_props_encode(const void *options, uint8_t *out)
struct lzma_lzma1_encoder_s lzma_lzma1_encoder
void lzma_lzma_optimum_fast(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf, uint32_t *restrict back_res, uint32_t *restrict len_res)
void lzma_lzma_optimum_normal(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf, uint32_t *restrict back_res, uint32_t *restrict len_res, uint32_t position)
Private definitions for LZMA encoder.
assert(limit<=UINT32_MAX/2)
static uint32_t const uint8_t uint32_t uint32_t limit
static uint32_t rc_bittree_price(const probability *const probs, const uint32_t bit_levels, uint32_t symbol)
static uint32_t rc_bit_0_price(const probability prob)
static uint32_t rc_bit_1_price(const probability prob)
#define bittree_reset(probs, bit_levels)
uint16_t probability
Type of probabilities used with range coder.
#define rc_direct(dest, seq)
Decode a bit without using a probability.
#define rc_bit(prob, action0, action1, seq)
#define rc_reset(range_decoder)
Resets the range decoder structure.
static bool rc_encode(lzma_range_encoder *rc, uint8_t *out, size_t *out_pos, size_t out_size)
static void rc_bittree(lzma_range_encoder *rc, probability *probs, uint32_t bit_count, uint32_t symbol)
static void rc_bittree_reverse(lzma_range_encoder *rc, probability *probs, uint32_t bit_count, uint32_t symbol)
static uint64_t rc_pending(const lzma_range_encoder *rc)
static void rc_flush(lzma_range_encoder *rc)
Custom functions for memory handling.
probability high[LEN_HIGH_SYMBOLS]
probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS]
uint32_t counters[POS_STATES_MAX]
probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS]
uint32_t prices[POS_STATES_MAX][LEN_SYMBOLS]
lzma_ret(* code)(void *coder, lzma_mf *restrict mf, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size)
Function to encode from *dict to out[].
void * coder
Data specific to the LZ-based encoder.
const uint8_t * preset_dict
TODO: Comment.
uint32_t depth
Maximum search depth.
size_t dict_size
Size of the history buffer.
lzma_match_finder match_finder
Type of the match finder to use.
uint32_t reps[REPS]
The four most recent match distances.
uint32_t match_price_count
probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE]
probability is_rep0_long[STATES][POS_STATES_MAX]
uint32_t align_price_count
probability is_rep1[STATES]
uint32_t pos_mask
(1 << pos_bits) - 1
lzma_range_encoder rc
Range encoder.
probability is_rep0[STATES]
bool fast_mode
True if using getoptimumfast.
probability is_rep2[STATES]
probability dist_special[FULL_DISTANCES - DIST_MODEL_END]
uint32_t literal_context_bits
probability is_rep[STATES]
lzma_length_encoder match_len_encoder
uint32_t opts_current_index
uint32_t literal_pos_mask
probability dist_slot[DIST_STATES][DIST_SLOTS]
lzma_lzma_state state
State.
probability dist_align[ALIGN_SIZE]
probability is_match[STATES][POS_STATES_MAX]
lzma_length_encoder rep_len_encoder
uint8_t * buffer
Pointer to buffer with data to be compressed.
Hold data and function pointers of the next filter in the chain.
Options specific to the LZMA1 and LZMA2 filters.
uint32_t dict_size
Dictionary size in bytes.
void * lzma_alloc(size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
Allocates memory.
#define write32le(buf, num)
lzma_ret
Return values used by several functions in liblzma.
@ LZMA_PROG_ERROR
Programming error.
@ LZMA_MEM_ERROR
Cannot allocate memory.
@ LZMA_STREAM_END
End of stream was reached.
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
@ LZMA_OK
Operation completed successfully.
@ LZMA_SYNC_FLUSH
Make all the input available at output.
@ LZMA_FINISH
Finish the coding operation.
@ LZMA_RUN
Continue coding.
unsigned char lzma_bool
Boolean.