decoder.c (lzlib-1.12.tar.lz) | : | decoder.c (lzlib-1.13.tar.lz) | ||
---|---|---|---|---|
/* Lzlib - Compression library for the lzip format | /* Lzlib - Compression library for the lzip format | |||
Copyright (C) 2009-2021 Antonio Diaz Diaz. | Copyright (C) 2009-2022 Antonio Diaz Diaz. | |||
This library is free software. Redistribution and use in source and | This library is free software. Redistribution and use in source and | |||
binary forms, with or without modification, are permitted provided | binary forms, with or without modification, are permitted provided | |||
that the following conditions are met: | that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright | 1. Redistributions of source code must retain the above copyright | |||
notice, this list of conditions, and the following disclaimer. | notice, this list of conditions, and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright | 2. Redistributions in binary form must reproduce the above copyright | |||
notice, this list of conditions, and the following disclaimer in the | notice, this list of conditions, and the following disclaimer in the | |||
skipping to change at line 51 | skipping to change at line 51 | |||
State * const state = &d->state; | State * const state = &d->state; | |||
/* unsigned old_mpos = rdec->member_position; */ | /* unsigned old_mpos = rdec->member_position; */ | |||
if( d->member_finished ) return 0; | if( d->member_finished ) return 0; | |||
if( !Rd_try_reload( rdec ) ) | if( !Rd_try_reload( rdec ) ) | |||
{ if( !rdec->at_stream_end ) return 0; else return 2; } | { if( !rdec->at_stream_end ) return 0; else return 2; } | |||
if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d ); | if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d ); | |||
while( !Rd_finished( rdec ) ) | while( !Rd_finished( rdec ) ) | |||
{ | { | |||
int len; | ||||
const int pos_state = LZd_data_position( d ) & pos_state_mask; | ||||
/* const unsigned mpos = rdec->member_position; | /* const unsigned mpos = rdec->member_position; | |||
if( mpos - old_mpos > rd_min_available_bytes ) return 5; | if( mpos - old_mpos > rd_min_available_bytes ) return 5; | |||
old_mpos = mpos; */ | old_mpos = mpos; */ | |||
if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ | if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ | |||
{ if( !rdec->at_stream_end ) return 0; | { if( !rdec->at_stream_end ) return 0; | |||
if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */ | if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */ | |||
if( !LZd_enough_free_bytes( d ) ) return 0; | if( !LZd_enough_free_bytes( d ) ) return 0; | |||
const int pos_state = LZd_data_position( d ) & pos_state_mask; | ||||
if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ | if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ | |||
{ | { | |||
/* literal byte */ | /* literal byte */ | |||
Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))]; | Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))]; | |||
if( St_is_char( *state ) ) | if( ( *state = St_set_char( *state ) ) < 4 ) | |||
{ | ||||
*state -= ( *state < 4 ) ? *state : 3; | ||||
LZd_put_byte( d, Rd_decode_tree8( rdec, bm ) ); | LZd_put_byte( d, Rd_decode_tree8( rdec, bm ) ); | |||
} | ||||
else | else | |||
{ | ||||
*state -= ( *state < 10 ) ? 3 : 6; | ||||
LZd_put_byte( d, Rd_decode_matched( rdec, bm, LZd_peek( d, d->rep0 ) ) ) ; | LZd_put_byte( d, Rd_decode_matched( rdec, bm, LZd_peek( d, d->rep0 ) ) ) ; | |||
} | ||||
continue; | continue; | |||
} | } | |||
/* match or repeated match */ | /* match or repeated match */ | |||
int len; | ||||
if( Rd_decode_bit( rdec, &d->bm_rep[*state] ) != 0 ) /* 2nd bit */ | if( Rd_decode_bit( rdec, &d->bm_rep[*state] ) != 0 ) /* 2nd bit */ | |||
{ | { | |||
if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ | if( Rd_decode_bit( rdec, &d->bm_rep0[*state] ) == 0 ) /* 3rd bit */ | |||
{ | { | |||
if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) / * 4th bit */ | if( Rd_decode_bit( rdec, &d->bm_len[*state][pos_state] ) == 0 ) / * 4th bit */ | |||
{ *state = St_set_short_rep( *state ); | { *state = St_set_short_rep( *state ); | |||
LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } | LZd_put_byte( d, LZd_peek( d, d->rep0 ) ); continue; } | |||
} | } | |||
else | else | |||
{ | { | |||
skipping to change at line 102 | skipping to change at line 96 | |||
if( Rd_decode_bit( rdec, &d->bm_rep2[*state] ) == 0 ) /* 5th bi t */ | if( Rd_decode_bit( rdec, &d->bm_rep2[*state] ) == 0 ) /* 5th bi t */ | |||
distance = d->rep2; | distance = d->rep2; | |||
else | else | |||
{ distance = d->rep3; d->rep3 = d->rep2; } | { distance = d->rep3; d->rep3 = d->rep2; } | |||
d->rep2 = d->rep1; | d->rep2 = d->rep1; | |||
} | } | |||
d->rep1 = d->rep0; | d->rep1 = d->rep0; | |||
d->rep0 = distance; | d->rep0 = distance; | |||
} | } | |||
*state = St_set_rep( *state ); | *state = St_set_rep( *state ); | |||
len = min_match_len + Rd_decode_len( rdec, &d->rep_len_model, pos_state ); | len = Rd_decode_len( rdec, &d->rep_len_model, pos_state ); | |||
} | } | |||
else /* match */ | else /* match */ | |||
{ | { | |||
unsigned distance; | len = Rd_decode_len( rdec, &d->match_len_model, pos_state ); | |||
len = min_match_len + Rd_decode_len( rdec, &d->match_len_model, pos_state | unsigned distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(le | |||
); | n)] ); | |||
distance = Rd_decode_tree6( rdec, d->bm_dis_slot[get_len_state(len)] ); | ||||
if( distance >= start_dis_model ) | if( distance >= start_dis_model ) | |||
{ | { | |||
const unsigned dis_slot = distance; | const unsigned dis_slot = distance; | |||
const int direct_bits = ( dis_slot >> 1 ) - 1; | const int direct_bits = ( dis_slot >> 1 ) - 1; | |||
distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits; | distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits; | |||
if( dis_slot < end_dis_model ) | if( dis_slot < end_dis_model ) | |||
distance += Rd_decode_tree_reversed( rdec, | distance += Rd_decode_tree_reversed( rdec, | |||
d->bm_dis + ( distance - dis_slot ), direct_bits ); | d->bm_dis + ( distance - dis_slot ), direct_bits ); | |||
else | else | |||
{ | { | |||
End of changes. 10 change blocks. | ||||
15 lines changed or deleted | 8 lines changed or added |