summaryrefslogtreecommitdiffstats
path: root/decoder.c
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-06 11:37:40 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-06 11:37:40 +0000
commitc33e1de813af248d4249725ac859dd3a26393704 (patch)
tree2a277fd093d46566d11b96d68ee4b9ba950e96be /decoder.c
parentAdding upstream version 1.4. (diff)
downloadclzip-c33e1de813af248d4249725ac859dd3a26393704.tar.xz
clzip-c33e1de813af248d4249725ac859dd3a26393704.zip
Adding upstream version 1.5~pre1.upstream/1.5_pre1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r--decoder.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/decoder.c b/decoder.c
index b40dafd..d3f2bf0 100644
--- a/decoder.c
+++ b/decoder.c
@@ -25,7 +25,7 @@
#include <string.h>
#include <unistd.h>
-#include "clzip.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;
@@ -142,7 +142,7 @@ bool LZd_verify_trailer( struct LZ_decoder * const decoder,
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" );
@@ -177,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 ),
@@ -199,84 +199,82 @@ int LZd_decode_member( struct LZ_decoder * const decoder,
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( decoder->rdec );
+ while( !Rd_finished( decoder->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( decoder->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( decoder->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( decoder->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( decoder->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( decoder->rdec, &decoder->bm_rep0[state] ) == 0 ) /* 3rd bit */
+ {
+ if( Rd_decode_bit( decoder->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( decoder->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( decoder->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( decoder->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( decoder->rdec, &decoder->match_len_model, pos_state );
+ dis_slot = Rd_decode_tree6( decoder->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( decoder->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( decoder->rdec, direct_bits - dis_align_bits ) << dis_align_bits;
+ rep0 += Rd_decode_tree_reversed4( decoder->rdec, decoder->bm_align );
if( rep0 == 0xFFFFFFFFU ) /* Marker found */
{
rep0 = rep0_saved;
- Rd_normalize( decoder->range_decoder );
+ Rd_normalize( decoder->rdec );
LZd_flush_data( decoder );
if( len == min_match_len ) /* End Of Stream marker */
{
@@ -284,7 +282,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( decoder->rdec ); continue;
}
if( pp->verbosity >= 0 )
{