Path: blob/master/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h
3156 views
// SPDX-License-Identifier: 0BSD12///////////////////////////////////////////////////////////////////////////////3//4/// \file lzma_encoder_private.h5/// \brief Private definitions for LZMA encoder6///7// Authors: Igor Pavlov8// Lasse Collin9//10///////////////////////////////////////////////////////////////////////////////1112#ifndef LZMA_LZMA_ENCODER_PRIVATE_H13#define LZMA_LZMA_ENCODER_PRIVATE_H1415#include "lz_encoder.h"16#include "range_encoder.h"17#include "lzma_common.h"18#include "lzma_encoder.h"192021// Macro to compare if the first two bytes in two buffers differ. This is22// needed in lzma_lzma_optimum_*() to test if the match is at least23// MATCH_LEN_MIN bytes. Unaligned access gives tiny gain so there's no24// reason to not use it when it is supported.25#ifdef TUKLIB_FAST_UNALIGNED_ACCESS26# define not_equal_16(a, b) (read16ne(a) != read16ne(b))27#else28# define not_equal_16(a, b) \29((a)[0] != (b)[0] || (a)[1] != (b)[1])30#endif313233// Optimal - Number of entries in the optimum array.34#define OPTS (1 << 12)353637typedef struct {38probability choice;39probability choice2;40probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS];41probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS];42probability high[LEN_HIGH_SYMBOLS];4344uint32_t prices[POS_STATES_MAX][LEN_SYMBOLS];45uint32_t table_size;46uint32_t counters[POS_STATES_MAX];4748} lzma_length_encoder;495051typedef struct {52lzma_lzma_state state;5354bool prev_1_is_literal;55bool prev_2;5657uint32_t pos_prev_2;58uint32_t back_prev_2;5960uint32_t price;61uint32_t pos_prev; // pos_next;62uint32_t back_prev;6364uint32_t backs[REPS];6566} lzma_optimal;676869struct lzma_lzma1_encoder_s {70/// Range encoder71lzma_range_encoder rc;7273/// Uncompressed size (doesn't include possible preset dictionary)74uint64_t uncomp_size;7576/// If non-zero, produce at most this much output.77/// Some input may then be missing from the output.78uint64_t out_limit;7980/// If the above out_limit is non-zero, *uncomp_size_ptr is set to81/// the amount of uncompressed data that we were able to fit82/// in the output buffer.83uint64_t *uncomp_size_ptr;8485/// State86lzma_lzma_state state;8788/// The four most recent match distances89uint32_t reps[REPS];9091/// Array of match candidates92lzma_match matches[MATCH_LEN_MAX + 1];9394/// Number of match candidates in matches[]95uint32_t matches_count;9697/// Variable to hold the length of the longest match between calls98/// to lzma_lzma_optimum_*().99uint32_t longest_match_length;100101/// True if using getoptimumfast102bool fast_mode;103104/// True if the encoder has been initialized by encoding the first105/// byte as a literal.106bool is_initialized;107108/// True if the range encoder has been flushed, but not all bytes109/// have been written to the output buffer yet.110bool is_flushed;111112/// True if end of payload marker will be written.113bool use_eopm;114115uint32_t pos_mask; ///< (1 << pos_bits) - 1116uint32_t literal_context_bits;117uint32_t literal_mask;118119// These are the same as in lzma_decoder.c. See comments there.120probability literal[LITERAL_CODERS_MAX * LITERAL_CODER_SIZE];121probability is_match[STATES][POS_STATES_MAX];122probability is_rep[STATES];123probability is_rep0[STATES];124probability is_rep1[STATES];125probability is_rep2[STATES];126probability is_rep0_long[STATES][POS_STATES_MAX];127probability dist_slot[DIST_STATES][DIST_SLOTS];128probability dist_special[FULL_DISTANCES - DIST_MODEL_END];129probability dist_align[ALIGN_SIZE];130131// These are the same as in lzma_decoder.c except that the encoders132// include also price tables.133lzma_length_encoder match_len_encoder;134lzma_length_encoder rep_len_encoder;135136// Price tables137uint32_t dist_slot_prices[DIST_STATES][DIST_SLOTS];138uint32_t dist_prices[DIST_STATES][FULL_DISTANCES];139uint32_t dist_table_size;140uint32_t match_price_count;141142uint32_t align_prices[ALIGN_SIZE];143uint32_t align_price_count;144145// Optimal146uint32_t opts_end_index;147uint32_t opts_current_index;148lzma_optimal opts[OPTS];149};150151152extern void lzma_lzma_optimum_fast(153lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,154uint32_t *restrict back_res, uint32_t *restrict len_res);155156extern void lzma_lzma_optimum_normal(lzma_lzma1_encoder *restrict coder,157lzma_mf *restrict mf, uint32_t *restrict back_res,158uint32_t *restrict len_res, uint32_t position);159160#endif161162163