summaryrefslogtreecommitdiffstats
path: root/encoder.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--encoder.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/encoder.c b/encoder.c
index 597a173..20180d7 100644
--- a/encoder.c
+++ b/encoder.c
@@ -388,23 +388,25 @@ int LZe_sequence_optimizer( struct LZ_encoder * const encoder,
return 1;
}
- {
- const int normal_match_price = match_price + price0( encoder->bm_rep[state] );
- int len = min_match_len;
if( main_len <= replens[rep_index] )
{
+ int len;
main_len = replens[rep_index];
- for( ; len <= main_len; ++len )
+ for( len = min_match_len; len <= main_len; ++len )
encoder->trials[len].price = infinite_price;
}
- else for( ; len <= main_len; ++len )
+ else
{
- encoder->trials[len].dis = encoder->match_distances[len] + num_rep_distances;
- encoder->trials[len].prev_index = 0;
- encoder->trials[len].price = normal_match_price +
- LZe_price_pair( encoder, encoder->match_distances[len], len, pos_state );
+ int len;
+ const int normal_match_price = match_price + price0( encoder->bm_rep[state] );
+ for( len = min_match_len; len <= main_len; ++len )
+ {
+ encoder->trials[len].dis = encoder->match_distances[len] + num_rep_distances;
+ encoder->trials[len].prev_index = 0;
+ encoder->trials[len].price = normal_match_price +
+ LZe_price_pair( encoder, encoder->match_distances[len], len, pos_state );
+ }
}
- }
for( rep = 0; rep < num_rep_distances; ++rep )
{
@@ -513,13 +515,31 @@ int LZe_sequence_optimizer( struct LZ_encoder * const encoder,
const int normal_match_price = match_price +
price0( encoder->bm_rep[cur_trial->state] );
int len;
+ int dis = encoder->match_distances[min_match_len];
+ int dis_state = get_dis_state( min_match_len );
+ int dis_price = infinite_price;
+
while( num_trials < cur + newlen )
encoder->trials[++num_trials].price = infinite_price;
- for( len = min_match_len; len <= newlen; ++len )
- Tr_update( &encoder->trials[cur+len], encoder->match_distances[len] + num_rep_distances,
- cur, normal_match_price +
- LZe_price_pair( encoder, encoder->match_distances[len], len, pos_state ) );
+ if( dis < modeled_distances )
+ Tr_update( &encoder->trials[cur+min_match_len], dis + num_rep_distances,
+ cur, normal_match_price + encoder->dis_prices[dis_state][dis] +
+ Lee_price( &encoder->len_encoder, min_match_len, pos_state ) );
+
+ for( len = min_match_len + 1; len <= newlen; ++len )
+ {
+ if( dis != encoder->match_distances[len] ||
+ dis_state < max_dis_states - 1 )
+ {
+ dis = encoder->match_distances[len];
+ dis_state = get_dis_state( len );
+ dis_price = LZe_price_dis( encoder, dis, dis_state );
+ }
+ Tr_update( &encoder->trials[cur+len], dis + num_rep_distances, cur,
+ normal_match_price + dis_price +
+ Lee_price( &encoder->len_encoder, len, pos_state ) );
+ }
}
}
}