Merging upstream version 1.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
cea93fa52c
commit
7b6a2620b1
14 changed files with 508 additions and 366 deletions
59
encoder.h
59
encoder.h
|
@ -53,7 +53,8 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
extern const Dis_slots dis_slots;
|
||||
namespace Lzlib_namespace { extern const Dis_slots dis_slots; }
|
||||
using Lzlib_namespace::dis_slots;
|
||||
|
||||
|
||||
class Prob_prices
|
||||
|
@ -74,11 +75,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
int operator[]( const int symbol ) const throw()
|
||||
{ return data[symbol >> 2]; }
|
||||
int operator[]( const int probability ) const throw()
|
||||
{ return data[probability >> 2]; }
|
||||
};
|
||||
|
||||
extern const Prob_prices prob_prices;
|
||||
namespace Lzlib_namespace { extern const Prob_prices prob_prices; }
|
||||
using Lzlib_namespace::prob_prices;
|
||||
|
||||
|
||||
inline int price0( const Bit_model & bm ) throw()
|
||||
|
@ -130,14 +132,14 @@ inline int price_matched( const Bit_model bm[], const int symbol,
|
|||
for( int i = 7; i >= 0; --i )
|
||||
{
|
||||
const int match_bit = ( match_byte >> i ) & 1;
|
||||
const int bit = ( symbol >> i ) & 1;
|
||||
int bit = ( symbol >> i ) & 1;
|
||||
price += price_bit( bm[(match_bit<<8)+model+0x100], bit );
|
||||
model = ( model << 1 ) | bit;
|
||||
if( match_bit != bit )
|
||||
{
|
||||
while( --i >= 0 )
|
||||
{
|
||||
const int bit = ( symbol >> i ) & 1;
|
||||
bit = ( symbol >> i ) & 1;
|
||||
price += price_bit( bm[model], bit );
|
||||
model = ( model << 1 ) | bit;
|
||||
}
|
||||
|
@ -236,14 +238,14 @@ class Range_encoder : public Circular_buffer
|
|||
void shift_low()
|
||||
{
|
||||
const uint32_t carry = low >> 32;
|
||||
if( low < 0xFF000000LL || carry == 1 )
|
||||
if( low < 0xFF000000U || carry == 1 )
|
||||
{
|
||||
put_byte( cache + carry );
|
||||
for( ; ff_count > 0; --ff_count ) put_byte( 0xFF + carry );
|
||||
cache = low >> 24;
|
||||
}
|
||||
else ++ff_count;
|
||||
low = ( low & 0x00FFFFFFLL ) << 8;
|
||||
low = ( low & 0x00FFFFFFU ) << 8;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -252,7 +254,7 @@ public:
|
|||
Circular_buffer( 65536 + min_free_bytes ),
|
||||
low( 0 ),
|
||||
partial_member_pos( 0 ),
|
||||
range( 0xFFFFFFFF ),
|
||||
range( 0xFFFFFFFFU ),
|
||||
ff_count( 0 ),
|
||||
cache( 0 ) {}
|
||||
|
||||
|
@ -270,7 +272,7 @@ public:
|
|||
{
|
||||
for( int i = 0; i < 5; ++i ) shift_low();
|
||||
low = 0;
|
||||
range = 0xFFFFFFFF;
|
||||
range = 0xFFFFFFFFU;
|
||||
ff_count = 0;
|
||||
cache = 0;
|
||||
}
|
||||
|
@ -284,7 +286,7 @@ public:
|
|||
{
|
||||
range >>= 1;
|
||||
if( (symbol >> i) & 1 ) low += range;
|
||||
if( range <= 0x00FFFFFF ) { range <<= 8; shift_low(); }
|
||||
if( range <= 0x00FFFFFFU ) { range <<= 8; shift_low(); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +304,7 @@ public:
|
|||
range -= bound;
|
||||
bm.probability -= bm.probability >> bit_model_move_bits;
|
||||
}
|
||||
if( range <= 0x00FFFFFF ) { range <<= 8; shift_low(); }
|
||||
if( range <= 0x00FFFFFFU ) { range <<= 8; shift_low(); }
|
||||
}
|
||||
|
||||
void encode_tree( Bit_model bm[], const int symbol, const int num_bits )
|
||||
|
@ -335,15 +337,15 @@ public:
|
|||
int model = 1;
|
||||
for( int i = 7; i >= 0; --i )
|
||||
{
|
||||
const int bit = ( symbol >> i ) & 1;
|
||||
const int match_bit = ( match_byte >> i ) & 1;
|
||||
int bit = ( symbol >> i ) & 1;
|
||||
encode_bit( bm[(match_bit<<8)+model+0x100], bit );
|
||||
model = ( model << 1 ) | bit;
|
||||
if( match_bit != bit )
|
||||
{
|
||||
while( --i >= 0 )
|
||||
{
|
||||
const int bit = ( symbol >> i ) & 1;
|
||||
bit = ( symbol >> i ) & 1;
|
||||
encode_bit( bm[model], bit );
|
||||
model = ( model << 1 ) | bit;
|
||||
}
|
||||
|
@ -368,17 +370,17 @@ class Len_encoder
|
|||
void update_prices( const int pos_state ) throw()
|
||||
{
|
||||
int * const pps = prices[pos_state];
|
||||
int price = price0( choice1 );
|
||||
int tmp = price0( choice1 );
|
||||
int len = 0;
|
||||
for( ; len < len_low_symbols && len < len_symbols; ++len )
|
||||
pps[len] = price +
|
||||
pps[len] = tmp +
|
||||
price_symbol( bm_low[pos_state], len, len_low_bits );
|
||||
price = price1( choice1 );
|
||||
tmp = price1( choice1 );
|
||||
for( ; len < len_low_symbols + len_mid_symbols && len < len_symbols; ++len )
|
||||
pps[len] = price + price0( choice2 ) +
|
||||
pps[len] = tmp + price0( choice2 ) +
|
||||
price_symbol( bm_mid[pos_state], len - len_low_symbols, len_mid_bits );
|
||||
for( ; len < len_symbols; ++len )
|
||||
pps[len] = price + price1( choice2 ) +
|
||||
pps[len] = tmp + price1( choice2 ) +
|
||||
price_symbol( bm_high, len - len_low_symbols - len_mid_symbols, len_high_bits );
|
||||
counters[pos_state] = len_symbols;
|
||||
}
|
||||
|
@ -402,21 +404,21 @@ class Literal_encoder
|
|||
{
|
||||
Bit_model bm_literal[1<<literal_context_bits][0x300];
|
||||
|
||||
int state( const int prev_byte ) const throw()
|
||||
int lstate( const int prev_byte ) const throw()
|
||||
{ return ( prev_byte >> ( 8 - literal_context_bits ) ); }
|
||||
|
||||
public:
|
||||
void encode( Range_encoder & range_encoder, uint8_t prev_byte, uint8_t symbol )
|
||||
{ range_encoder.encode_tree( bm_literal[state(prev_byte)], symbol, 8 ); }
|
||||
{ range_encoder.encode_tree( bm_literal[lstate(prev_byte)], symbol, 8 ); }
|
||||
|
||||
void encode_matched( Range_encoder & range_encoder, uint8_t prev_byte, uint8_t match_byte, uint8_t symbol )
|
||||
{ range_encoder.encode_matched( bm_literal[state(prev_byte)], symbol, match_byte ); }
|
||||
{ range_encoder.encode_matched( bm_literal[lstate(prev_byte)], symbol, match_byte ); }
|
||||
|
||||
int price_matched( uint8_t prev_byte, uint8_t symbol, uint8_t match_byte ) const throw()
|
||||
{ return ::price_matched( bm_literal[state(prev_byte)], symbol, match_byte ); }
|
||||
{ return ::price_matched( bm_literal[lstate(prev_byte)], symbol, match_byte ); }
|
||||
|
||||
int price_symbol( uint8_t prev_byte, uint8_t symbol ) const throw()
|
||||
{ return ::price_symbol( bm_literal[state(prev_byte)], symbol, 8 ); }
|
||||
{ return ::price_symbol( bm_literal[lstate(prev_byte)], symbol, 8 ); }
|
||||
};
|
||||
|
||||
|
||||
|
@ -468,14 +470,15 @@ class LZ_encoder
|
|||
int align_prices[dis_align_size];
|
||||
int align_price_count;
|
||||
int fill_counter;
|
||||
State state;
|
||||
State main_state;
|
||||
bool member_finished_;
|
||||
|
||||
void fill_align_prices() throw();
|
||||
void fill_distance_prices() throw();
|
||||
|
||||
uint32_t crc() const throw() { return crc_ ^ 0xFFFFFFFF; }
|
||||
uint32_t crc() const throw() { return crc_ ^ 0xFFFFFFFFU; }
|
||||
|
||||
// move-to-front dis in/into reps
|
||||
void mtf_reps( const int dis, int reps[num_rep_distances] ) throw()
|
||||
{
|
||||
if( dis >= num_rep_distances )
|
||||
|
@ -582,10 +585,10 @@ class LZ_encoder
|
|||
}
|
||||
}
|
||||
|
||||
int best_pair_sequence( const int reps[num_rep_distances],
|
||||
int sequence_optimizer( const int reps[num_rep_distances],
|
||||
const State & state );
|
||||
|
||||
bool full_flush();
|
||||
bool full_flush( const State & state );
|
||||
|
||||
public:
|
||||
LZ_encoder( Matchfinder & mf, const File_header & header,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue