summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--decoder.h71
1 files changed, 26 insertions, 45 deletions
diff --git a/decoder.h b/decoder.h
index 29b164a..7bf78bc 100644
--- a/decoder.h
+++ b/decoder.h
@@ -140,24 +140,24 @@ static inline int Rd_decode_bit( struct Range_decoder * const rdec,
static inline int Rd_decode_tree( struct Range_decoder * const rdec,
Bit_model bm[], const int num_bits )
{
- int model = 1;
+ int symbol = 1;
int i;
for( i = num_bits; i > 0; --i )
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- return model - (1 << num_bits);
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ return symbol - (1 << num_bits);
}
static inline int Rd_decode_tree6( struct Range_decoder * const rdec,
Bit_model bm[] )
{
- int model = 1;
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- model = ( model << 1 ) | Rd_decode_bit( rdec, &bm[model] );
- return model - (1 << 6);
+ int symbol = 1;
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] );
+ return symbol - (1 << 6);
}
static inline int Rd_decode_tree_reversed( struct Range_decoder * const rdec,
@@ -213,36 +213,17 @@ static inline int Rd_decode_matched( struct Range_decoder * const rdec,
return symbol - 0x100;
}
-
-struct Len_decoder
- {
- 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];
- };
-
-static inline void Led_init( struct Len_decoder * const len_decoder )
- {
- Bm_init( &len_decoder->choice1 );
- Bm_init( &len_decoder->choice2 );
- Bm_array_init( len_decoder->bm_low[0], pos_states * len_low_symbols );
- Bm_array_init( len_decoder->bm_mid[0], pos_states * len_mid_symbols );
- Bm_array_init( len_decoder->bm_high, len_high_symbols );
- }
-
-static inline int Led_decode( struct Len_decoder * const len_decoder,
- struct Range_decoder * const rdec,
- const int pos_state )
+static inline int Rd_decode_len( struct Range_decoder * const rdec,
+ struct Len_model * const lm,
+ const int pos_state )
{
- if( Rd_decode_bit( rdec, &len_decoder->choice1 ) == 0 )
- return Rd_decode_tree( rdec, len_decoder->bm_low[pos_state], len_low_bits );
- if( Rd_decode_bit( rdec, &len_decoder->choice2 ) == 0 )
+ if( Rd_decode_bit( rdec, &lm->choice1 ) == 0 )
+ return Rd_decode_tree( rdec, lm->bm_low[pos_state], len_low_bits );
+ if( Rd_decode_bit( rdec, &lm->choice2 ) == 0 )
return len_low_symbols +
- Rd_decode_tree( rdec, len_decoder->bm_mid[pos_state], len_mid_bits );
+ Rd_decode_tree( rdec, lm->bm_mid[pos_state], len_mid_bits );
return len_low_symbols + len_mid_symbols +
- Rd_decode_tree( rdec, len_decoder->bm_high, len_high_bits );
+ Rd_decode_tree( rdec, lm->bm_high, len_high_bits );
}
@@ -269,9 +250,9 @@ struct LZ_decoder
Bit_model bm_dis[modeled_distances-end_dis_model];
Bit_model bm_align[dis_align_size];
- struct Range_decoder * range_decoder;
- struct Len_decoder len_decoder;
- struct Len_decoder rep_match_len_decoder;
+ struct Range_decoder * rdec;
+ struct Len_model match_len_model;
+ struct Len_model rep_len_model;
};
void LZd_flush_data( struct LZ_decoder * const decoder );
@@ -322,7 +303,7 @@ static inline void LZd_copy_block( struct LZ_decoder * const decoder,
static inline bool LZd_init( struct LZ_decoder * const decoder,
const File_header header,
- struct Range_decoder * const rdec, const int ofd )
+ struct Range_decoder * const rde, const int ofd )
{
decoder->partial_data_pos = 0;
decoder->dictionary_size = Fh_get_dictionary_size( header );
@@ -346,9 +327,9 @@ static inline bool LZd_init( struct LZ_decoder * const decoder,
Bm_array_init( decoder->bm_dis, modeled_distances - end_dis_model );
Bm_array_init( decoder->bm_align, dis_align_size );
- decoder->range_decoder = rdec;
- Led_init( &decoder->len_decoder );
- Led_init( &decoder->rep_match_len_decoder );
+ decoder->rdec = rde;
+ Lm_init( &decoder->match_len_model );
+ Lm_init( &decoder->rep_len_model );
decoder->buffer[decoder->buffer_size-1] = 0; /* prev_byte of first_byte */
return true;
}