summaryrefslogtreecommitdiffstats
path: root/decoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 09:56:54 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 09:56:54 +0000
commit0aff25f0baaa9ebac7ca3711513fcf855fc017ab (patch)
treeddf52de5d8bd7bb8e95f5881942a1ac919e7f4e5 /decoder.cc
parentAdding debian version 1.14-2. (diff)
downloadlzip-0aff25f0baaa9ebac7ca3711513fcf855fc017ab.tar.xz
lzip-0aff25f0baaa9ebac7ca3711513fcf855fc017ab.zip
Merging upstream version 1.15~pre1.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r--decoder.cc67
1 files changed, 32 insertions, 35 deletions
diff --git a/decoder.cc b/decoder.cc
index 537143f..1d4774f 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -122,10 +122,10 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
File_trailer trailer;
const int trailer_size = File_trailer::size( member_version );
const unsigned long long member_size =
- range_decoder.member_position() + trailer_size;
+ rdec.member_position() + trailer_size;
bool error = false;
- int size = range_decoder.read_data( trailer.data, trailer_size );
+ int size = rdec.read_data( trailer.data, trailer_size );
if( size < trailer_size )
{
error = true;
@@ -140,7 +140,7 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp ) const
if( member_version == 0 ) trailer.member_size( member_size );
- if( !range_decoder.code_is_zero() )
+ if( !rdec.code_is_zero() )
{
error = true;
pp( "Range decoder final code is not zero" );
@@ -201,82 +201,79 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
Bit_model bm_dis_slot[max_dis_states][1<<dis_slot_bits];
Bit_model bm_dis[modeled_distances-end_dis_model];
Bit_model bm_align[dis_align_size];
- Len_decoder len_decoder;
- Len_decoder rep_match_len_decoder;
+ Len_model match_len_model;
+ Len_model rep_len_model;
unsigned rep0 = 0; // rep[0-3] latest four distances
unsigned rep1 = 0; // used for efficient coding of
unsigned rep2 = 0; // repeated distances
unsigned rep3 = 0;
-
State state;
- range_decoder.load();
- while( !range_decoder.finished() )
+ rdec.load();
+ while( !rdec.finished() )
{
const int pos_state = data_position() & pos_state_mask;
- if( range_decoder.decode_bit( bm_match[state()][pos_state] ) == 0 )
+ if( rdec.decode_bit( bm_match[state()][pos_state] ) == 0 )
{
const uint8_t prev_byte = get_prev_byte();
if( state.is_char() )
- put_byte( range_decoder.decode_tree( bm_literal[get_lit_state(prev_byte)], 8 ) );
+ put_byte( rdec.decode_tree( bm_literal[get_lit_state(prev_byte)], 8 ) );
else
- put_byte( range_decoder.decode_matched( bm_literal[get_lit_state(prev_byte)],
- get_byte( rep0 ) ) );
+ put_byte( rdec.decode_matched( bm_literal[get_lit_state(prev_byte)],
+ get_byte( rep0 ) ) );
state.set_char();
}
else
{
int len;
- if( range_decoder.decode_bit( bm_rep[state()] ) == 1 )
+ if( rdec.decode_bit( bm_rep[state()] ) == 1 )
{
- len = 0;
- if( range_decoder.decode_bit( bm_rep0[state()] ) == 1 )
+ if( rdec.decode_bit( bm_rep0[state()] ) == 0 )
+ {
+ if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 )
+ { state.set_short_rep(); put_byte( get_byte( rep0 ) ); continue; }
+ }
+ else
{
unsigned distance;
- if( range_decoder.decode_bit( bm_rep1[state()] ) == 0 )
+ if( rdec.decode_bit( bm_rep1[state()] ) == 0 )
distance = rep1;
else
{
- if( range_decoder.decode_bit( bm_rep2[state()] ) == 0 )
+ if( rdec.decode_bit( bm_rep2[state()] ) == 0 )
distance = rep2;
- else { distance = rep3; rep3 = rep2; }
+ else
+ { distance = rep3; rep3 = rep2; }
rep2 = rep1;
}
rep1 = rep0;
rep0 = distance;
}
- else
- {
- if( range_decoder.decode_bit( bm_len[state()][pos_state] ) == 0 )
- { state.set_short_rep(); len = 1; }
- }
- if( len == 0 )
- {
- state.set_rep();
- len = min_match_len + rep_match_len_decoder.decode( range_decoder, pos_state );
- }
+ len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
+ state.set_rep();
}
else
{
const unsigned rep0_saved = rep0;
- len = min_match_len + len_decoder.decode( range_decoder, pos_state );
- const int dis_slot = range_decoder.decode_tree6( bm_dis_slot[get_dis_state(len)] );
+ len = min_match_len + rdec.decode_len( match_len_model, pos_state );
+ const int dis_slot = rdec.decode_tree6( bm_dis_slot[get_dis_state(len)] );
if( dis_slot < start_dis_model ) rep0 = dis_slot;
else
{
const int direct_bits = ( dis_slot >> 1 ) - 1;
rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
if( dis_slot < end_dis_model )
- rep0 += range_decoder.decode_tree_reversed( bm_dis + rep0 - dis_slot - 1, direct_bits );
+ rep0 += rdec.decode_tree_reversed( bm_dis + rep0 - dis_slot - 1,
+ direct_bits );
else
{
- rep0 += range_decoder.decode( direct_bits - dis_align_bits ) << dis_align_bits;
- rep0 += range_decoder.decode_tree_reversed4( bm_align );
+ rep0 += rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
+ rep0 += rdec.decode_tree_reversed4( bm_align );
if( rep0 == 0xFFFFFFFFU ) // Marker found
{
rep0 = rep0_saved;
- range_decoder.normalize();
+ rdec.normalize();
flush_data();
if( len == min_match_len ) // End Of Stream marker
{
@@ -284,7 +281,7 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
}
if( len == min_match_len + 1 ) // Sync Flush marker
{
- range_decoder.load(); continue;
+ rdec.load(); continue;
}
if( pp.verbosity() >= 0 )
{