"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "decoder.h" between
lzlib-1.11.tar.lz and lzlib-1.12-rc1.tar.lz

About: Lzlib is a data compression library providing in-memory LZMA compression and decompression functions using the lzip format. Release candidate.

decoder.h  (lzlib-1.11.tar.lz):decoder.h  (lzlib-1.12-rc1.tar.lz)
/* Lzlib - Compression library for the lzip format /* Lzlib - Compression library for the lzip format
Copyright (C) 2009-2019 Antonio Diaz Diaz. Copyright (C) 2009-2020 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
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/ */
enum { rd_min_available_bytes = 8 }; enum { rd_min_available_bytes = 8 };
struct Range_decoder struct Range_decoder
{ {
struct Circular_buffer cb; /* input buffer */ struct Circular_buffer cb; /* input buffer */
unsigned long long member_position; unsigned long long member_position;
uint32_t code; uint32_t code;
uint32_t range; uint32_t range;
skipping to change at line 134 skipping to change at line 134
static inline bool Rd_unread_data( struct Range_decoder * const rdec, static inline bool Rd_unread_data( struct Range_decoder * const rdec,
const unsigned size ) const unsigned size )
{ {
if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) ) if( size > rdec->member_position || !Cb_unread_data( &rdec->cb, size ) )
return false; return false;
rdec->member_position -= size; rdec->member_position -= size;
return true; return true;
} }
static bool Rd_try_reload( struct Range_decoder * const rdec, const bool force ) static bool Rd_try_reload( struct Range_decoder * const rdec )
{ {
if( force ) rdec->reload_pending = true;
if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 ) if( rdec->reload_pending && Rd_available_bytes( rdec ) >= 5 )
{ {
int i; int i;
rdec->reload_pending = false; rdec->reload_pending = false;
rdec->code = 0; rdec->code = 0;
for( i = 0; i < 5; ++i ) for( i = 0; i < 5; ++i )
rdec->code = (rdec->code << 8) | Rd_get_byte( rdec ); rdec->code = (rdec->code << 8) | Rd_get_byte( rdec );
rdec->range = 0xFFFFFFFFU; rdec->range = 0xFFFFFFFFU;
rdec->code &= rdec->range; /* make sure that first byte is discarded */ rdec->code &= rdec->range; /* make sure that first byte is discarded */
} }
skipping to change at line 169 skipping to change at line 168
unsigned symbol = 0; unsigned symbol = 0;
int i; int i;
for( i = num_bits; i > 0; --i ) for( i = num_bits; i > 0; --i )
{ {
bool bit; bool bit;
Rd_normalize( rdec ); Rd_normalize( rdec );
rdec->range >>= 1; rdec->range >>= 1;
/* symbol <<= 1; */ /* symbol <<= 1; */
/* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */ /* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */
bit = ( rdec->code >= rdec->range ); bit = ( rdec->code >= rdec->range );
symbol = ( symbol << 1 ) + bit; symbol <<= 1; symbol += bit;
rdec->code -= rdec->range & ( 0U - bit ); rdec->code -= rdec->range & ( 0U - bit );
} }
return symbol; return symbol;
} }
static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec,
Bit_model * const probability ) Bit_model * const probability )
{ {
uint32_t bound; uint32_t bound;
Rd_normalize( rdec ); Rd_normalize( rdec );
bound = ( rdec->range >> bit_model_total_bits ) * *probability; bound = ( rdec->range >> bit_model_total_bits ) * *probability;
if( rdec->code < bound ) if( rdec->code < bound )
{ {
rdec->range = bound;
*probability += (bit_model_total - *probability) >> bit_model_move_bits; *probability += (bit_model_total - *probability) >> bit_model_move_bits;
rdec->range = bound;
return 0; return 0;
} }
else else
{ {
rdec->range -= bound;
rdec->code -= bound;
*probability -= *probability >> bit_model_move_bits; *probability -= *probability >> bit_model_move_bits;
rdec->code -= bound;
rdec->range -= bound;
return 1; return 1;
} }
} }
static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec,
Bit_model bm[] ) Bit_model bm[] )
{ {
unsigned symbol = 1; unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[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] );
return symbol & 7; return symbol & 7;
} }
static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec,
Bit_model bm[] ) Bit_model bm[] )
{ {
unsigned symbol = 1; unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[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] ); 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 & 0x3F; return symbol & 0x3F;
} }
static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree8( struct Range_decoder * const rdec,
Bit_model bm[] ) Bit_model bm[] )
skipping to change at line 239 skipping to change at line 236
static inline unsigned static inline unsigned
Rd_decode_tree_reversed( struct Range_decoder * const rdec, Rd_decode_tree_reversed( struct Range_decoder * const rdec,
Bit_model bm[], const int num_bits ) Bit_model bm[], const int num_bits )
{ {
unsigned model = 1; unsigned model = 1;
unsigned symbol = 0; unsigned symbol = 0;
int i; int i;
for( i = 0; i < num_bits; ++i ) for( i = 0; i < num_bits; ++i )
{ {
const unsigned bit = Rd_decode_bit( rdec, &bm[model] ); const unsigned bit = Rd_decode_bit( rdec, &bm[model] );
model = ( model << 1 ) + bit; model <<= 1; model += bit;
symbol |= ( bit << i ); symbol |= ( bit << i );
} }
return symbol; return symbol;
} }
static inline unsigned static inline unsigned
Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] )
{ {
unsigned symbol = Rd_decode_bit( rdec, &bm[1] ); unsigned symbol = Rd_decode_bit( rdec, &bm[1] );
unsigned model = 2 + symbol; symbol += Rd_decode_bit( rdec, &bm[2+symbol] ) << 1;
unsigned bit = Rd_decode_bit( rdec, &bm[model] ); symbol += Rd_decode_bit( rdec, &bm[4+symbol] ) << 2;
model = ( model << 1 ) + bit; symbol |= ( bit << 1 ); symbol += Rd_decode_bit( rdec, &bm[8+symbol] ) << 3;
bit = Rd_decode_bit( rdec, &bm[model] );
model = ( model << 1 ) + bit; symbol |= ( bit << 2 );
symbol |= ( Rd_decode_bit( rdec, &bm[model] ) << 3 );
return symbol; return symbol;
} }
static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec, static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec,
Bit_model bm[], unsigned match_byte ) Bit_model bm[], unsigned match_byte )
{ {
unsigned symbol = 1; unsigned symbol = 1;
unsigned mask = 0x100; unsigned mask = 0x100;
while( true ) while( true )
{ {
const unsigned match_bit = ( match_byte <<= 1 ) & mask; const unsigned match_bit = ( match_byte <<= 1 ) & mask;
const unsigned bit = Rd_decode_bit( rdec, &bm[symbol+match_bit+mask] ); const unsigned bit = Rd_decode_bit( rdec, &bm[symbol+match_bit+mask] );
symbol = ( symbol << 1 ) + bit; symbol <<= 1; symbol += bit;
if( symbol > 0xFF ) return symbol & 0xFF; if( symbol > 0xFF ) return symbol & 0xFF;
mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */ mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */
} }
} }
static inline unsigned Rd_decode_len( struct Range_decoder * const rdec, static inline unsigned Rd_decode_len( struct Range_decoder * const rdec,
struct Len_model * const lm, struct Len_model * const lm,
const int pos_state ) const int pos_state )
{ {
if( Rd_decode_bit( rdec, &lm->choice1 ) == 0 ) if( Rd_decode_bit( rdec, &lm->choice1 ) == 0 )
 End of changes. 14 change blocks. 
34 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)