1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file lzma_encoder_private.h
4 /// \brief Private definitions for LZMA encoder
6 // Copyright (C) 1999-2006 Igor Pavlov
7 // Copyright (C) 2007 Lasse Collin
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 ///////////////////////////////////////////////////////////////////////////////
21 #ifndef LZMA_LZMA_ENCODER_PRIVATE_H
22 #define LZMA_LZMA_ENCODER_PRIVATE_H
24 #include "lz_encoder.h"
25 #include "range_encoder.h"
26 #include "lzma_common.h"
27 #include "lzma_encoder.h"
30 // Macro to compare if the first two bytes in two buffers differ. This is
31 // needed in lzma_lzma_optimum_*() to test if the match is at least
32 // MATCH_LEN_MIN bytes. Unaligned access gives tiny gain so there's no
33 // reason to not use it when it is supported.
34 #ifdef HAVE_FAST_UNALIGNED_ACCESS
35 # define not_equal_16(a, b) \
36 (*(const uint16_t *)(a) != *(const uint16_t *)(b))
38 # define not_equal_16(a, b) \
39 ((a)[0] != (b)[0] || (a)[1] != (b)[1])
43 // Optimal - Number of entries in the optimum array.
44 #define OPTS (1 << 12)
50 probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
51 probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
52 probability high[LEN_HIGH_SYMBOLS];
54 uint32_t prices[POS_STATES_MAX][LEN_SYMBOLS];
56 uint32_t counters[POS_STATES_MAX];
58 } lzma_length_encoder;
62 lzma_lzma_state state;
64 bool prev_1_is_literal;
71 uint32_t pos_prev; // pos_next;
74 uint32_t backs[REP_DISTANCES];
81 lzma_range_encoder rc;
84 lzma_lzma_state state;
86 /// The four most recent match distances
87 uint32_t reps[REP_DISTANCES];
89 /// Array of match candidates
90 lzma_match matches[MATCH_LEN_MAX + 1];
92 /// Number of match candidates in matches[]
93 uint32_t matches_count;
95 /// Varibale to hold the length of the longest match between calls
96 /// to lzma_lzma_optimum_*().
97 uint32_t longest_match_length;
99 /// True if using getoptimumfast
102 /// True if the encoder has been initialized by encoding the first
103 /// byte as a literal.
106 /// True if the range encoder has been flushed, but not all bytes
107 /// have been written to the output buffer yet.
110 uint32_t pos_mask; ///< (1 << pos_bits) - 1
111 uint32_t literal_context_bits;
112 uint32_t literal_pos_mask;
114 // These are the same as in lzma_decoder.c. See comments there.
115 probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
116 probability is_match[STATES][POS_STATES_MAX];
117 probability is_rep[STATES];
118 probability is_rep0[STATES];
119 probability is_rep1[STATES];
120 probability is_rep2[STATES];
121 probability is_rep0_long[STATES][POS_STATES_MAX];
122 probability pos_slot[LEN_TO_POS_STATES][POS_SLOTS];
123 probability pos_special[FULL_DISTANCES - END_POS_MODEL_INDEX];
124 probability pos_align[ALIGN_TABLE_SIZE];
126 // These are the same as in lzma_decoder.c except that the encoders
127 // include also price tables.
128 lzma_length_encoder match_len_encoder;
129 lzma_length_encoder rep_len_encoder;
132 uint32_t pos_slot_prices[LEN_TO_POS_STATES][POS_SLOTS];
133 uint32_t distances_prices[LEN_TO_POS_STATES][FULL_DISTANCES];
134 uint32_t dist_table_size;
135 uint32_t match_price_count;
137 uint32_t align_prices[ALIGN_TABLE_SIZE];
138 uint32_t align_price_count;
141 uint32_t opts_end_index;
142 uint32_t opts_current_index;
143 lzma_optimal opts[OPTS];
147 extern void lzma_lzma_optimum_fast(
148 lzma_coder *restrict coder, lzma_mf *restrict mf,
149 uint32_t *restrict back_res, uint32_t *restrict len_res);
151 extern void lzma_lzma_optimum_normal(lzma_coder *restrict coder,
152 lzma_mf *restrict mf, uint32_t *restrict back_res,
153 uint32_t *restrict len_res, uint32_t position);