summaryrefslogtreecommitdiffstats
path: root/encoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'encoder.h')
-rw-r--r--encoder.h38
1 files changed, 15 insertions, 23 deletions
diff --git a/encoder.h b/encoder.h
index e39d7c4..a69f552 100644
--- a/encoder.h
+++ b/encoder.h
@@ -107,9 +107,9 @@ static inline int price_symbol_reversed( const Bit_model bm[], int symbol,
for( i = num_bits; i > 0; --i )
{
const int bit = symbol & 1;
- symbol >>= 1;
price += price_bit( bm[model], bit );
model = ( model << 1 ) | bit;
+ symbol >>= 1;
}
return price;
}
@@ -376,11 +376,7 @@ static inline void Re_encode_matched( struct Range_encoder * const renc,
struct Len_encoder
{
- Bit_model choice1;
- Bit_model choice2;
- Bit_model bm_low[pos_states][len_low_symbols];
- Bit_model bm_mid[pos_states][len_mid_symbols];
- Bit_model bm_high[len_high_symbols];
+ struct Len_model lm;
int prices[pos_states][max_len_symbols];
int len_symbols;
int counters[pos_states];
@@ -390,21 +386,21 @@ static inline void Lee_update_prices( struct Len_encoder * const len_encoder,
const int pos_state )
{
int * const pps = len_encoder->prices[pos_state];
- int tmp = price0( len_encoder->choice1 );
+ int tmp = price0( len_encoder->lm.choice1 );
int len = 0;
for( ; len < len_low_symbols && len < len_encoder->len_symbols; ++len )
pps[len] = tmp +
- price_symbol( len_encoder->bm_low[pos_state], len, len_low_bits );
- tmp = price1( len_encoder->choice1 );
+ price_symbol( len_encoder->lm.bm_low[pos_state], len, len_low_bits );
+ tmp = price1( len_encoder->lm.choice1 );
for( ; len < len_low_symbols + len_mid_symbols && len < len_encoder->len_symbols; ++len )
- pps[len] = tmp + price0( len_encoder->choice2 ) +
- price_symbol( len_encoder->bm_mid[pos_state], len - len_low_symbols, len_mid_bits );
+ pps[len] = tmp + price0( len_encoder->lm.choice2 ) +
+ price_symbol( len_encoder->lm.bm_mid[pos_state], len - len_low_symbols, len_mid_bits );
for( ; len < len_encoder->len_symbols; ++len )
/* using 4 slots per value makes "Lee_price" faster */
len_encoder->prices[3][len] = len_encoder->prices[2][len] =
len_encoder->prices[1][len] = len_encoder->prices[0][len] =
- tmp + price1( len_encoder->choice2 ) +
- price_symbol( len_encoder->bm_high, len - len_low_symbols - len_mid_symbols, len_high_bits );
+ tmp + price1( len_encoder->lm.choice2 ) +
+ price_symbol( len_encoder->lm.bm_high, len - len_low_symbols - len_mid_symbols, len_high_bits );
len_encoder->counters[pos_state] = len_encoder->len_symbols;
}
@@ -412,11 +408,7 @@ static inline void Lee_init( struct Len_encoder * const len_encoder,
const int match_len_limit )
{
int i;
- Bm_init( &len_encoder->choice1 );
- Bm_init( &len_encoder->choice2 );
- Bm_array_init( len_encoder->bm_low[0], pos_states * len_low_symbols );
- Bm_array_init( len_encoder->bm_mid[0], pos_states * len_mid_symbols );
- Bm_array_init( len_encoder->bm_high, len_high_symbols );
+ Lm_init( &len_encoder->lm );
len_encoder->len_symbols = match_len_limit + 1 - min_match_len;
for( i = 0; i < pos_states; ++i ) Lee_update_prices( len_encoder, i );
}
@@ -502,8 +494,8 @@ struct LZ_encoder
struct Matchfinder * matchfinder;
struct Range_encoder range_encoder;
- struct Len_encoder len_encoder;
- struct Len_encoder rep_match_len_encoder;
+ struct Len_encoder match_len_encoder;
+ struct Len_encoder rep_len_encoder;
int num_dis_slots;
struct Pair pairs[max_match_len+1];
@@ -572,7 +564,7 @@ static inline int LZe_price_rep0_len( const struct LZ_encoder * const encoder,
const State state, const int pos_state )
{
return LZe_price_rep( encoder, 0, state, pos_state ) +
- Lee_price( &encoder->rep_match_len_encoder, len, pos_state );
+ Lee_price( &encoder->rep_len_encoder, len, pos_state );
}
static inline int LZe_price_dis( const struct LZ_encoder * const encoder,
@@ -589,7 +581,7 @@ static inline int LZe_price_pair( const struct LZ_encoder * const encoder,
const int dis, const int len,
const int pos_state )
{
- return Lee_price( &encoder->len_encoder, len, pos_state ) +
+ return Lee_price( &encoder->match_len_encoder, len, pos_state ) +
LZe_price_dis( encoder, dis, get_dis_state( len ) );
}
@@ -620,7 +612,7 @@ static inline void LZe_encode_pair( struct LZ_encoder * const encoder,
const int pos_state )
{
const int dis_slot = get_slot( dis );
- Lee_encode( &encoder->len_encoder, &encoder->range_encoder, len, pos_state );
+ Lee_encode( &encoder->match_len_encoder, &encoder->range_encoder, len, pos_state );
Re_encode_tree( &encoder->range_encoder,
encoder->bm_dis_slot[get_dis_state(len)],
dis_slot, dis_slot_bits );