diff options
Diffstat (limited to '')
-rw-r--r-- | encoder_base.h | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/encoder_base.h b/encoder_base.h index c947904..0a1bd5d 100644 --- a/encoder_base.h +++ b/encoder_base.h @@ -174,36 +174,36 @@ struct Matchfinder_base bool at_stream_end; /* stream_pos shows real end of file */ }; -bool Mb_read_block( struct Matchfinder_base * const mb ); -void Mb_normalize_pos( struct Matchfinder_base * const mb ); +bool Mb_read_block( Matchfinder_base * const mb ); +void Mb_normalize_pos( Matchfinder_base * const mb ); -bool Mb_init( struct Matchfinder_base * const mb, const int before_size, +bool Mb_init( Matchfinder_base * const mb, const int before_size, const int dict_size, const int after_size, const int dict_factor, const int num_prev_positions23, const int pos_array_factor, const int ifd ); -static inline void Mb_free( struct Matchfinder_base * const mb ) +static inline void Mb_free( Matchfinder_base * const mb ) { free( mb->prev_positions ); free( mb->buffer ); } -static inline uint8_t Mb_peek( const struct Matchfinder_base * const mb, +static inline uint8_t Mb_peek( const Matchfinder_base * const mb, const int 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 Matchfinder_base * const mb ) { return mb->stream_pos - mb->pos; } static inline unsigned long long -Mb_data_position( const struct Matchfinder_base * const mb ) +Mb_data_position( const Matchfinder_base * const mb ) { return mb->partial_data_pos + mb->pos; } -static inline bool Mb_data_finished( const struct Matchfinder_base * const mb ) +static inline bool Mb_data_finished( const Matchfinder_base * const mb ) { return mb->at_stream_end && mb->pos >= mb->stream_pos; } static inline const uint8_t * -Mb_ptr_to_current_pos( const struct Matchfinder_base * const mb ) +Mb_ptr_to_current_pos( const Matchfinder_base * const mb ) { return mb->buffer + mb->pos; } -static inline int Mb_true_match_len( const struct Matchfinder_base * const mb, +static inline int Mb_true_match_len( const Matchfinder_base * const mb, const int index, const int distance ) { const uint8_t * const data = mb->buffer + mb->pos; @@ -213,18 +213,18 @@ static inline int Mb_true_match_len( const struct Matchfinder_base * const mb, return i; } -static inline void Mb_move_pos( struct Matchfinder_base * const mb ) +static inline void Mb_move_pos( Matchfinder_base * const mb ) { if( ++mb->cyclic_pos > mb->dictionary_size ) mb->cyclic_pos = 0; if( ++mb->pos >= mb->pos_limit ) Mb_normalize_pos( mb ); } -void Mb_reset( struct Matchfinder_base * const mb ); +void Mb_reset( Matchfinder_base * const mb ); enum { re_buffer_size = 65536 }; -struct Range_encoder +typedef struct Range_encoder { uint64_t low; unsigned long long partial_member_pos; @@ -235,22 +235,21 @@ struct Range_encoder int outfd; /* output file descriptor */ uint8_t cache; Lzip_header header; - }; + } Range_encoder; -void Re_flush_data( struct Range_encoder * const renc ); +void Re_flush_data( Range_encoder * const renc ); -static inline void Re_put_byte( struct Range_encoder * const renc, - const uint8_t b ) +static inline void Re_put_byte( Range_encoder * const renc, const uint8_t b ) { renc->buffer[renc->pos] = b; if( ++renc->pos >= re_buffer_size ) Re_flush_data( renc ); } -static inline void Re_shift_low( struct Range_encoder * const renc ) +static inline void Re_shift_low( Range_encoder * const renc ) { if( renc->low >> 24 != 0xFF ) { - const bool carry = ( renc->low > 0xFFFFFFFFU ); + const bool carry = renc->low > 0xFFFFFFFFU; Re_put_byte( renc, renc->cache + carry ); for( ; renc->ff_count > 0; --renc->ff_count ) Re_put_byte( renc, 0xFF + carry ); @@ -260,7 +259,7 @@ static inline void Re_shift_low( struct Range_encoder * const renc ) renc->low = ( renc->low & 0x00FFFFFFU ) << 8; } -static inline void Re_reset( struct Range_encoder * const renc, +static inline void Re_reset( Range_encoder * const renc, const unsigned dictionary_size ) { renc->low = 0; @@ -273,7 +272,7 @@ static inline void Re_reset( struct Range_encoder * const renc, int i; for( i = 0; i < Lh_size; ++i ) Re_put_byte( renc, renc->header[i] ); } -static inline bool Re_init( struct Range_encoder * const renc, +static inline bool Re_init( Range_encoder * const renc, const unsigned dictionary_size, const int ofd ) { renc->buffer = (uint8_t *)malloc( re_buffer_size ); @@ -284,17 +283,17 @@ static inline bool Re_init( struct Range_encoder * const renc, return true; } -static inline void Re_free( struct Range_encoder * const renc ) +static inline void Re_free( Range_encoder * const renc ) { free( renc->buffer ); } static inline unsigned long long -Re_member_position( const struct Range_encoder * const renc ) +Re_member_position( const Range_encoder * const renc ) { return renc->partial_member_pos + renc->pos + renc->ff_count; } -static inline void Re_flush( struct Range_encoder * const renc ) +static inline void Re_flush( Range_encoder * const renc ) { int i; for( i = 0; i < 5; ++i ) Re_shift_low( renc ); } -static inline void Re_encode( struct Range_encoder * const renc, +static inline void Re_encode( Range_encoder * const renc, const int symbol, const int num_bits ) { unsigned mask; @@ -306,7 +305,7 @@ static inline void Re_encode( struct Range_encoder * const renc, } } -static inline void Re_encode_bit( struct Range_encoder * const renc, +static inline void Re_encode_bit( Range_encoder * const renc, Bit_model * const probability, const bool bit ) { const uint32_t bound = ( renc->range >> bit_model_total_bits ) * *probability; @@ -324,7 +323,7 @@ static inline void Re_encode_bit( struct Range_encoder * const 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( Range_encoder * const renc, Bit_model bm[], const int symbol ) { bool bit = ( symbol >> 2 ) & 1; @@ -335,7 +334,7 @@ static inline void Re_encode_tree3( struct Range_encoder * const renc, 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( Range_encoder * const renc, Bit_model bm[], const unsigned symbol ) { bool bit = ( symbol >> 5 ) & 1; @@ -352,7 +351,7 @@ static inline void Re_encode_tree6( struct Range_encoder * const renc, 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( Range_encoder * const renc, Bit_model bm[], const int symbol ) { int model = 1; @@ -365,7 +364,7 @@ static inline void Re_encode_tree8( struct Range_encoder * const renc, } } -static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, +static inline void Re_encode_tree_reversed( Range_encoder * const renc, Bit_model bm[], int symbol, const int num_bits ) { int model = 1; @@ -379,7 +378,7 @@ static inline void Re_encode_tree_reversed( struct Range_encoder * const renc, } } -static inline void Re_encode_matched( struct Range_encoder * const renc, +static inline void Re_encode_matched( Range_encoder * const renc, Bit_model bm[], unsigned symbol, unsigned match_byte ) { @@ -395,17 +394,17 @@ static inline void Re_encode_matched( struct Range_encoder * const renc, } } -static inline void Re_encode_len( struct Range_encoder * const renc, - struct Len_model * const lm, +static inline void Re_encode_len( Range_encoder * const renc, + Len_model * const lm, int symbol, const int pos_state ) { - bool bit = ( ( symbol -= min_match_len ) >= len_low_symbols ); + bool bit = ( symbol -= min_match_len ) >= len_low_symbols; Re_encode_bit( renc, &lm->choice1, bit ); if( !bit ) Re_encode_tree3( renc, lm->bm_low[pos_state], symbol ); else { - bit = ( ( symbol -= len_low_symbols ) >= len_mid_symbols ); + bit = ( symbol -= len_low_symbols ) >= len_mid_symbols; Re_encode_bit( renc, &lm->choice2, bit ); if( !bit ) Re_encode_tree3( renc, lm->bm_mid[pos_state], symbol ); @@ -418,9 +417,9 @@ static inline void Re_encode_len( struct Range_encoder * const renc, enum { max_marker_size = 16, num_rep_distances = 4 }; /* must be 4 */ -struct LZ_encoder_base +typedef struct LZ_encoder_base { - struct Matchfinder_base mb; + Matchfinder_base mb; uint32_t crc; Bit_model bm_literal[1<<literal_context_bits][0x300]; @@ -433,14 +432,14 @@ struct LZ_encoder_base Bit_model bm_dis_slot[len_states][1<<dis_slot_bits]; Bit_model bm_dis[modeled_distances-end_dis_model+1]; Bit_model bm_align[dis_align_size]; - struct Len_model match_len_model; - struct Len_model rep_len_model; - struct Range_encoder renc; - }; + Len_model match_len_model; + Len_model rep_len_model; + Range_encoder renc; + } LZ_encoder_base; -void LZeb_reset( struct LZ_encoder_base * const eb ); +void LZeb_reset( LZ_encoder_base * const eb ); -static inline bool LZeb_init( struct LZ_encoder_base * const eb, +static inline bool LZeb_init( LZ_encoder_base * const eb, const int before_size, const int dict_size, const int after_size, const int dict_factor, const int num_prev_positions23, @@ -454,31 +453,31 @@ static inline bool LZeb_init( struct LZ_encoder_base * const eb, return true; } -static inline void LZeb_free( struct LZ_encoder_base * const eb ) +static inline void LZeb_free( LZ_encoder_base * const eb ) { 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 LZ_encoder_base * const eb ) { return eb->crc ^ 0xFFFFFFFFU; } -static inline int LZeb_price_literal( const struct LZ_encoder_base * const eb, +static inline int LZeb_price_literal( const LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol ) { return price_symbol8( eb->bm_literal[get_lit_state(prev_byte)], symbol ); } -static inline int LZeb_price_matched( const struct LZ_encoder_base * const eb, +static inline int LZeb_price_matched( const LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) { return price_matched( eb->bm_literal[get_lit_state(prev_byte)], symbol, match_byte ); } -static inline void LZeb_encode_literal( struct LZ_encoder_base * const eb, +static inline void LZeb_encode_literal( LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol ) { Re_encode_tree8( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol ); } -static inline void LZeb_encode_matched( struct LZ_encoder_base * const eb, +static inline void LZeb_encode_matched( LZ_encoder_base * const eb, const uint8_t prev_byte, const uint8_t symbol, const uint8_t match_byte ) { Re_encode_matched( &eb->renc, eb->bm_literal[get_lit_state(prev_byte)], symbol, match_byte ); } -static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb, +static inline void LZeb_encode_pair( LZ_encoder_base * const eb, const unsigned dis, const int len, const int pos_state ) { @@ -504,4 +503,4 @@ static inline void LZeb_encode_pair( struct LZ_encoder_base * const eb, } } -void LZeb_full_flush( struct LZ_encoder_base * const eb, const State state ); +void LZeb_full_flush( LZ_encoder_base * const eb, const State state ); |