2007-12-08 23:42:33 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/// \file lzma_encoder_private.h
|
|
|
|
/// \brief Private definitions for LZMA encoder
|
2009-04-13 10:27:40 +02:00
|
|
|
///
|
|
|
|
// Authors: Igor Pavlov
|
|
|
|
// Lasse Collin
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef LZMA_LZMA_ENCODER_PRIVATE_H
|
|
|
|
#define LZMA_LZMA_ENCODER_PRIVATE_H
|
|
|
|
|
|
|
|
#include "lz_encoder.h"
|
2008-01-14 12:42:43 +01:00
|
|
|
#include "range_encoder.h"
|
2008-08-28 21:53:15 +02:00
|
|
|
#include "lzma_common.h"
|
|
|
|
#include "lzma_encoder.h"
|
|
|
|
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
// Macro to compare if the first two bytes in two buffers differ. This is
|
|
|
|
// needed in lzma_lzma_optimum_*() to test if the match is at least
|
|
|
|
// MATCH_LEN_MIN bytes. Unaligned access gives tiny gain so there's no
|
|
|
|
// reason to not use it when it is supported.
|
2009-10-04 21:57:12 +02:00
|
|
|
#ifdef TUKLIB_FAST_UNALIGNED_ACCESS
|
2008-08-28 21:53:15 +02:00
|
|
|
# define not_equal_16(a, b) \
|
|
|
|
(*(const uint16_t *)(a) != *(const uint16_t *)(b))
|
|
|
|
#else
|
|
|
|
# define not_equal_16(a, b) \
|
|
|
|
((a)[0] != (b)[0] || (a)[1] != (b)[1])
|
|
|
|
#endif
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
// Optimal - Number of entries in the optimum array.
|
|
|
|
#define OPTS (1 << 12)
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
probability choice;
|
|
|
|
probability choice2;
|
|
|
|
probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
|
|
|
|
probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
|
|
|
|
probability high[LEN_HIGH_SYMBOLS];
|
|
|
|
|
|
|
|
uint32_t prices[POS_STATES_MAX][LEN_SYMBOLS];
|
|
|
|
uint32_t table_size;
|
|
|
|
uint32_t counters[POS_STATES_MAX];
|
|
|
|
|
|
|
|
} lzma_length_encoder;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2008-03-21 23:57:33 +01:00
|
|
|
lzma_lzma_state state;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
bool prev_1_is_literal;
|
2007-12-08 23:42:33 +01:00
|
|
|
bool prev_2;
|
|
|
|
|
|
|
|
uint32_t pos_prev_2;
|
|
|
|
uint32_t back_prev_2;
|
|
|
|
|
|
|
|
uint32_t price;
|
|
|
|
uint32_t pos_prev; // pos_next;
|
|
|
|
uint32_t back_prev;
|
|
|
|
|
2010-10-26 09:36:41 +02:00
|
|
|
uint32_t backs[REPS];
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
} lzma_optimal;
|
|
|
|
|
|
|
|
|
|
|
|
struct lzma_coder_s {
|
2008-08-28 21:53:15 +02:00
|
|
|
/// Range encoder
|
2007-12-08 23:42:33 +01:00
|
|
|
lzma_range_encoder rc;
|
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
/// State
|
2008-03-21 23:57:33 +01:00
|
|
|
lzma_lzma_state state;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
/// The four most recent match distances
|
2010-10-26 09:36:41 +02:00
|
|
|
uint32_t reps[REPS];
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
/// Array of match candidates
|
|
|
|
lzma_match matches[MATCH_LEN_MAX + 1];
|
|
|
|
|
|
|
|
/// Number of match candidates in matches[]
|
|
|
|
uint32_t matches_count;
|
|
|
|
|
2010-02-12 12:16:15 +01:00
|
|
|
/// Variable to hold the length of the longest match between calls
|
2008-08-28 21:53:15 +02:00
|
|
|
/// to lzma_lzma_optimum_*().
|
|
|
|
uint32_t longest_match_length;
|
|
|
|
|
|
|
|
/// True if using getoptimumfast
|
|
|
|
bool fast_mode;
|
|
|
|
|
|
|
|
/// True if the encoder has been initialized by encoding the first
|
|
|
|
/// byte as a literal.
|
2007-12-08 23:42:33 +01:00
|
|
|
bool is_initialized;
|
2008-08-28 21:53:15 +02:00
|
|
|
|
|
|
|
/// True if the range encoder has been flushed, but not all bytes
|
|
|
|
/// have been written to the output buffer yet.
|
2008-06-01 11:48:17 +02:00
|
|
|
bool is_flushed;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
uint32_t pos_mask; ///< (1 << pos_bits) - 1
|
|
|
|
uint32_t literal_context_bits;
|
|
|
|
uint32_t literal_pos_mask;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
// These are the same as in lzma_decoder.c. See comments there.
|
|
|
|
probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
|
2007-12-08 23:42:33 +01:00
|
|
|
probability is_match[STATES][POS_STATES_MAX];
|
|
|
|
probability is_rep[STATES];
|
|
|
|
probability is_rep0[STATES];
|
|
|
|
probability is_rep1[STATES];
|
|
|
|
probability is_rep2[STATES];
|
|
|
|
probability is_rep0_long[STATES][POS_STATES_MAX];
|
2010-10-26 09:36:41 +02:00
|
|
|
probability dist_slot[DIST_STATES][DIST_SLOTS];
|
|
|
|
probability dist_special[FULL_DISTANCES - DIST_MODEL_END];
|
|
|
|
probability dist_align[ALIGN_SIZE];
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
// These are the same as in lzma_decoder.c except that the encoders
|
|
|
|
// include also price tables.
|
2008-03-21 23:57:33 +01:00
|
|
|
lzma_length_encoder match_len_encoder;
|
|
|
|
lzma_length_encoder rep_len_encoder;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
// Price tables
|
2010-10-26 09:36:41 +02:00
|
|
|
uint32_t dist_slot_prices[DIST_STATES][DIST_SLOTS];
|
|
|
|
uint32_t dist_prices[DIST_STATES][FULL_DISTANCES];
|
2007-12-08 23:42:33 +01:00
|
|
|
uint32_t dist_table_size;
|
|
|
|
uint32_t match_price_count;
|
|
|
|
|
2010-10-26 09:36:41 +02:00
|
|
|
uint32_t align_prices[ALIGN_SIZE];
|
2008-08-28 21:53:15 +02:00
|
|
|
uint32_t align_price_count;
|
2007-12-08 23:42:33 +01:00
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
// Optimal
|
|
|
|
uint32_t opts_end_index;
|
|
|
|
uint32_t opts_current_index;
|
|
|
|
lzma_optimal opts[OPTS];
|
|
|
|
};
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
extern void lzma_lzma_optimum_fast(
|
|
|
|
lzma_coder *restrict coder, lzma_mf *restrict mf,
|
2007-12-08 23:42:33 +01:00
|
|
|
uint32_t *restrict back_res, uint32_t *restrict len_res);
|
|
|
|
|
2008-08-28 21:53:15 +02:00
|
|
|
extern void lzma_lzma_optimum_normal(lzma_coder *restrict coder,
|
|
|
|
lzma_mf *restrict mf, uint32_t *restrict back_res,
|
|
|
|
uint32_t *restrict len_res, uint32_t position);
|
2007-12-08 23:42:33 +01:00
|
|
|
|
|
|
|
#endif
|