"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "encoder_base.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.

encoder_base.h  (lzlib-1.11.tar.lz):encoder_base.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 { price_shift_bits = 6, enum { price_shift_bits = 6,
price_step_bits = 2 }; price_step_bits = 2 };
static const uint8_t dis_slots[1<<10] = static const uint8_t dis_slots[1<<10] =
{ {
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
skipping to change at line 194 skipping to change at line 194
const int num_bits ) const int num_bits )
{ {
int price = 0; int price = 0;
int model = 1; int model = 1;
int i; int i;
for( i = num_bits; i > 0; --i ) for( i = num_bits; i > 0; --i )
{ {
const bool bit = symbol & 1; const bool bit = symbol & 1;
symbol >>= 1; symbol >>= 1;
price += price_bit( bm[model], bit ); price += price_bit( bm[model], bit );
model = ( model << 1 ) | bit; model <<= 1; model |= bit;
} }
return price; return price;
} }
static inline int price_matched( const Bit_model bm[], unsigned symbol, static inline int price_matched( const Bit_model bm[], unsigned symbol,
unsigned match_byte ) unsigned match_byte )
{ {
int price = 0; int price = 0;
unsigned mask = 0x100; unsigned mask = 0x100;
symbol |= mask; symbol |= mask;
skipping to change at line 235 skipping to change at line 235
int pos; /* current pos in buffer */ int pos; /* current pos in buffer */
int cyclic_pos; /* cycles through [0, dictionary_size] */ int cyclic_pos; /* cycles through [0, dictionary_size] */
int stream_pos; /* first byte not yet read from file */ int stream_pos; /* first byte not yet read from file */
int pos_limit; /* when reached, a new block must be read */ int pos_limit; /* when reached, a new block must be read */
int key4_mask; int key4_mask;
int num_prev_positions23; int num_prev_positions23;
int num_prev_positions; /* size of prev_positions */ int num_prev_positions; /* size of prev_positions */
int pos_array_size; int pos_array_size;
int saved_dictionary_size; /* dictionary_size restored by Mb_reset */ int saved_dictionary_size; /* dictionary_size restored by Mb_reset */
bool at_stream_end; /* stream_pos shows real end of file */ bool at_stream_end; /* stream_pos shows real end of file */
bool flushing; bool sync_flush_pending;
}; };
static bool Mb_normalize_pos( struct Matchfinder_base * const mb ); static bool Mb_normalize_pos( struct Matchfinder_base * const mb );
static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
const int dict_size, const int after_size, const int dict_size, const int after_size,
const int dict_factor, const int num_prev_positions23, const int dict_factor, const int num_prev_positions23,
const int pos_array_factor ); const int pos_array_factor );
static inline void Mb_free( struct Matchfinder_base * const mb ) static inline void Mb_free( struct Matchfinder_base * const mb )
skipping to change at line 260 skipping to change at line 260
{ return mb->buffer[mb->pos-distance]; } { return mb->buffer[mb->pos-distance]; }
static inline int Mb_available_bytes( const struct Matchfinder_base * const mb ) static inline int Mb_available_bytes( const struct Matchfinder_base * const mb )
{ return mb->stream_pos - mb->pos; } { return mb->stream_pos - mb->pos; }
static inline unsigned long long static inline unsigned long long
Mb_data_position( const struct Matchfinder_base * const mb ) Mb_data_position( const struct Matchfinder_base * const mb )
{ return mb->partial_data_pos + mb->pos; } { return mb->partial_data_pos + mb->pos; }
static inline void Mb_finish( struct Matchfinder_base * const mb ) static inline void Mb_finish( struct Matchfinder_base * const mb )
{ mb->at_stream_end = true; mb->flushing = false; } { mb->at_stream_end = true; mb->sync_flush_pending = false; }
static inline bool Mb_data_finished( const struct Matchfinder_base * const mb ) static inline bool Mb_data_finished( const struct Matchfinder_base * const mb )
{ return mb->at_stream_end && !mb->flushing && mb->pos >= mb->stream_pos; } { return mb->at_stream_end && mb->pos >= mb->stream_pos; }
static inline bool Mb_flushing_or_end( const struct Matchfinder_base * const mb ) static inline bool Mb_flushing_or_end( const struct Matchfinder_base * const mb )
{ return mb->at_stream_end || mb->flushing; } { return mb->at_stream_end || mb->sync_flush_pending; }
static inline int Mb_free_bytes( const struct Matchfinder_base * const mb ) static inline int Mb_free_bytes( const struct Matchfinder_base * const mb )
{ if( Mb_flushing_or_end( mb ) ) return 0; { if( Mb_flushing_or_end( mb ) ) return 0;
return mb->buffer_size - mb->stream_pos; } return mb->buffer_size - mb->stream_pos; }
static inline bool Mb_enough_available_bytes( const struct Matchfinder_base * co static inline bool
nst mb ) Mb_enough_available_bytes( const struct Matchfinder_base * const mb )
{ return ( mb->pos + mb->after_size <= mb->stream_pos || { return ( mb->pos + mb->after_size <= mb->stream_pos ||
( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ) ); } ( Mb_flushing_or_end( mb ) && mb->pos < mb->stream_pos ) ); }
static inline const uint8_t * static inline const uint8_t *
Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb ) Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb )
{ return mb->buffer + mb->pos; } { return mb->buffer + mb->pos; }
static int Mb_write_data( struct Matchfinder_base * const mb, static int Mb_write_data( struct Matchfinder_base * const mb,
const uint8_t * const inbuf, const int size ) const uint8_t * const inbuf, const int size )
{ {
skipping to change at line 420 skipping to change at line 421
renc->low += bound; renc->low += bound;
renc->range -= bound; renc->range -= bound;
*probability -= *probability >> bit_model_move_bits; *probability -= *probability >> bit_model_move_bits;
} }
if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); } if( renc->range <= 0x00FFFFFFU ) { renc->range <<= 8; Re_shift_low( renc ); }
} }
static inline void Re_encode_tree3( struct Range_encoder * const renc, static inline void Re_encode_tree3( struct Range_encoder * const renc,
Bit_model bm[], const int symbol ) Bit_model bm[], const int symbol )
{ {
int model = 1; int model;
bool bit = ( symbol >> 2 ) & 1; bool bit = ( symbol >> 2 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[1], bit );
model = 2 | bit;
bit = ( symbol >> 1 ) & 1; bit = ( symbol >> 1 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit;
Re_encode_bit( renc, &bm[model], symbol & 1 ); Re_encode_bit( renc, &bm[model], symbol & 1 );
} }
static inline void Re_encode_tree6( struct Range_encoder * const renc, static inline void Re_encode_tree6( struct Range_encoder * const renc,
Bit_model bm[], const unsigned symbol ) Bit_model bm[], const unsigned symbol )
{ {
int model = 1; int model;
bool bit = ( symbol >> 5 ) & 1; bool bit = ( symbol >> 5 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[1], bit );
model = 2 | bit;
bit = ( symbol >> 4 ) & 1; bit = ( symbol >> 4 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit;
bit = ( symbol >> 3 ) & 1; bit = ( symbol >> 3 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit;
bit = ( symbol >> 2 ) & 1; bit = ( symbol >> 2 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit;
bit = ( symbol >> 1 ) & 1; bit = ( symbol >> 1 ) & 1;
Re_encode_bit( renc, &bm[model], bit ); model = ( model << 1 ) | bit; Re_encode_bit( renc, &bm[model], bit ); model <<= 1; model |= bit;
Re_encode_bit( renc, &bm[model], symbol & 1 ); Re_encode_bit( renc, &bm[model], symbol & 1 );
} }
static inline void Re_encode_tree8( struct Range_encoder * const renc, static inline void Re_encode_tree8( struct Range_encoder * const renc,
Bit_model bm[], const int symbol ) Bit_model bm[], const int symbol )
{ {
int model = 1; int model = 1;
int i; int i;
for( i = 7; i >= 0; --i ) for( i = 7; i >= 0; --i )
{ {
const bool bit = ( symbol >> i ) & 1; const bool bit = ( symbol >> i ) & 1;
Re_encode_bit( renc, &bm[model], bit ); Re_encode_bit( renc, &bm[model], bit );
model = ( model << 1 ) | bit; model <<= 1; model |= bit;
} }
} }
static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, static inline void Re_encode_tree_reversed( struct Range_encoder * const renc,
Bit_model bm[], int symbol, const int num_bits ) Bit_model bm[], int symbol, const int num_bits )
{ {
int model = 1; int model = 1;
int i; int i;
for( i = num_bits; i > 0; --i ) for( i = num_bits; i > 0; --i )
{ {
const bool bit = symbol & 1; const bool bit = symbol & 1;
symbol >>= 1; symbol >>= 1;
Re_encode_bit( renc, &bm[model], bit ); Re_encode_bit( renc, &bm[model], bit );
model = ( model << 1 ) | bit; model <<= 1; model |= bit;
} }
} }
static inline void Re_encode_matched( struct Range_encoder * const renc, static inline void Re_encode_matched( struct Range_encoder * const renc,
Bit_model bm[], unsigned symbol, Bit_model bm[], unsigned symbol,
unsigned match_byte ) unsigned match_byte )
{ {
unsigned mask = 0x100; unsigned mask = 0x100;
symbol |= mask; symbol |= mask;
while( true ) while( true )
skipping to change at line 554 skipping to change at line 557
{ {
if( !Mb_init( &eb->mb, before_size, dict_size, after_size, dict_factor, if( !Mb_init( &eb->mb, before_size, dict_size, after_size, dict_factor,
num_prev_positions23, pos_array_factor ) ) return false; num_prev_positions23, pos_array_factor ) ) return false;
if( !Re_init( &eb->renc, eb->mb.dictionary_size, min_free_bytes ) ) if( !Re_init( &eb->renc, eb->mb.dictionary_size, min_free_bytes ) )
return false; return false;
LZeb_reset( eb, member_size ); LZeb_reset( eb, member_size );
return true; return true;
} }
static inline bool LZeb_member_finished( const struct LZ_encoder_base * const eb ) static inline bool LZeb_member_finished( const struct LZ_encoder_base * const eb )
{ return ( eb->member_finished && !Cb_used_bytes( &eb->renc.cb ) ); } { return ( eb->member_finished && Cb_empty( &eb->renc.cb ) ); }
static inline void LZeb_free( struct LZ_encoder_base * const eb ) static inline void LZeb_free( struct LZ_encoder_base * const eb )
{ Re_free( &eb->renc ); Mb_free( &eb->mb ); } { Re_free( &eb->renc ); Mb_free( &eb->mb ); }
static inline unsigned LZeb_crc( const struct LZ_encoder_base * const eb ) static inline unsigned LZeb_crc( const struct LZ_encoder_base * const eb )
{ return eb->crc ^ 0xFFFFFFFFU; } { return eb->crc ^ 0xFFFFFFFFU; }
static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb, static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb,
const uint8_t prev_byte, const uint8_t symbol ) const uint8_t prev_byte, const uint8_t symbol )
{ return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); } { return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); }
 End of changes. 20 change blocks. 
35 lines changed or deleted 37 lines changed or added

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