summaryrefslogtreecommitdiffstats
path: root/decoder.c
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 05:00:36 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 05:00:36 +0000
commite83684e70d693debd8ec1beee56507507ccd1ec9 (patch)
tree48dc884a806159505f99cf332f0476477f350db7 /decoder.c
parentAdding upstream version 1.2. (diff)
downloadlunzip-e83684e70d693debd8ec1beee56507507ccd1ec9.tar.xz
lunzip-e83684e70d693debd8ec1beee56507507ccd1ec9.zip
Adding upstream version 1.3~rc1.upstream/1.3_rc1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'decoder.c')
-rw-r--r--decoder.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/decoder.c b/decoder.c
index 25f7c73..55259be 100644
--- a/decoder.c
+++ b/decoder.c
@@ -25,7 +25,7 @@
#include <string.h>
#include <unistd.h>
-#include "lunzip.h"
+#include "lzip.h"
#include "decoder.h"
@@ -124,10 +124,10 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
File_trailer trailer;
const int trailer_size = Ft_versioned_size( decoder->member_version );
const unsigned long long member_size =
- Rd_member_position( decoder->range_decoder ) + trailer_size;
+ Rd_member_position( decoder->rdec ) + trailer_size;
bool error = false;
- int size = Rd_read_data( decoder->range_decoder, trailer, trailer_size );
+ int size = Rd_read_data( decoder->rdec, trailer, trailer_size );
if( size < trailer_size )
{
error = true;
@@ -139,8 +139,10 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
}
while( size < trailer_size ) trailer[size++] = 0;
}
+
if( decoder->member_version == 0 ) Ft_set_member_size( trailer, member_size );
- if( decoder->range_decoder->code != 0 )
+
+ if( decoder->rdec->code != 0 )
{
error = true;
Pp_show_msg( pp, "Range decoder final code is not zero" );
@@ -175,7 +177,7 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
Ft_get_member_size( trailer ), member_size, member_size );
}
}
- if( !error && pp->verbosity >= 3 && LZd_data_position( decoder ) > 0 && member_size > 0 )
+ if( !error && pp->verbosity >= 2 && LZd_data_position( decoder ) > 0 && member_size > 0 )
fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
(double)LZd_data_position( decoder ) / member_size,
( 8.0 * member_size ) / LZd_data_position( decoder ),
@@ -193,88 +195,87 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
int LZd_decode_member( struct LZ_decoder * const decoder,
struct Pretty_print * const pp )
{
+ struct Range_decoder * const rdec = decoder->rdec;
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 = 0;
- Rd_load( decoder->range_decoder );
- while( !Rd_finished( decoder->range_decoder ) )
+ Rd_load( rdec );
+ while( !Rd_finished( rdec ) )
{
const int pos_state = LZd_data_position( decoder ) & pos_state_mask;
- if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_match[state][pos_state] ) == 0 )
+ if( Rd_decode_bit( rdec, &decoder->bm_match[state][pos_state] ) == 0 ) /* 1st bit */
{
const uint8_t prev_byte = LZd_get_prev_byte( decoder );
if( St_is_char( state ) )
{
state -= ( state < 4 ) ? state : 3;
- LZd_put_byte( decoder, Rd_decode_tree( decoder->range_decoder,
+ LZd_put_byte( decoder, Rd_decode_tree( rdec,
decoder->bm_literal[get_lit_state(prev_byte)], 8 ) );
}
else
{
state -= ( state < 10 ) ? 3 : 6;
- LZd_put_byte( decoder, Rd_decode_matched( decoder->range_decoder,
- decoder->bm_literal[get_lit_state(prev_byte)], LZd_get_byte( decoder, rep0 ) ) );
+ LZd_put_byte( decoder, Rd_decode_matched( rdec,
+ decoder->bm_literal[get_lit_state(prev_byte)],
+ LZd_get_byte( decoder, rep0 ) ) );
}
}
else
{
int len;
- if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep[state] ) == 1 )
+ if( Rd_decode_bit( rdec, &decoder->bm_rep[state] ) == 1 ) /* 2nd bit */
{
- len = 0;
- if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep0[state] ) == 1 )
+ if( Rd_decode_bit( rdec, &decoder->bm_rep0[state] ) == 0 ) /* 3rd bit */
+ {
+ if( Rd_decode_bit( rdec, &decoder->bm_len[state][pos_state] ) == 0 ) /* 4th bit */
+ { state = St_set_short_rep( state );
+ LZd_put_byte( decoder, LZd_get_byte( decoder, rep0 ) ); continue; }
+ }
+ else
{
unsigned distance;
- if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep1[state] ) == 0 )
+ if( Rd_decode_bit( rdec, &decoder->bm_rep1[state] ) == 0 ) /* 4th bit */
distance = rep1;
else
{
- if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_rep2[state] ) == 0 )
+ if( Rd_decode_bit( rdec, &decoder->bm_rep2[state] ) == 0 ) /* 5th bit */
distance = rep2;
- else { distance = rep3; rep3 = rep2; }
+ else
+ { distance = rep3; rep3 = rep2; }
rep2 = rep1;
}
rep1 = rep0;
rep0 = distance;
}
- else
- {
- if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_len[state][pos_state] ) == 0 )
- { state = St_set_short_rep( state ); len = 1; }
- }
- if( len == 0 )
- {
- state = St_set_rep( state );
- len = min_match_len + Led_decode( &decoder->rep_match_len_decoder, decoder->range_decoder, pos_state );
- }
+ state = St_set_rep( state );
+ len = min_match_len + Rd_decode_len( rdec, &decoder->rep_len_model, pos_state );
}
else
{
int dis_slot;
const unsigned rep0_saved = rep0;
- len = min_match_len + Led_decode( &decoder->len_decoder, decoder->range_decoder, pos_state );
- dis_slot = Rd_decode_tree6( decoder->range_decoder, decoder->bm_dis_slot[get_dis_state(len)] );
+ len = min_match_len + Rd_decode_len( rdec, &decoder->match_len_model, pos_state );
+ dis_slot = Rd_decode_tree6( rdec, decoder->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 += Rd_decode_tree_reversed( decoder->range_decoder,
+ rep0 += Rd_decode_tree_reversed( rdec,
decoder->bm_dis + rep0 - dis_slot - 1,
direct_bits );
else
{
- rep0 += Rd_decode( decoder->range_decoder, direct_bits - dis_align_bits ) << dis_align_bits;
- rep0 += Rd_decode_tree_reversed4( decoder->range_decoder, decoder->bm_align );
+ rep0 += Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits;
+ rep0 += Rd_decode_tree_reversed4( rdec, decoder->bm_align );
if( rep0 == 0xFFFFFFFFU ) /* Marker found */
{
rep0 = rep0_saved;
- Rd_normalize( decoder->range_decoder );
+ Rd_normalize( rdec );
LZd_flush_data( decoder );
if( len == min_match_len ) /* End Of Stream marker */
{
@@ -282,7 +283,7 @@ int LZd_decode_member( struct LZ_decoder * const decoder,
}
if( len == min_match_len + 1 ) /* Sync Flush marker */
{
- Rd_load( decoder->range_decoder ); continue;
+ Rd_load( rdec ); continue;
}
if( pp->verbosity >= 0 )
{