summaryrefslogtreecommitdiffstats
path: root/encoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'encoder.cc')
-rw-r--r--encoder.cc55
1 files changed, 28 insertions, 27 deletions
diff --git a/encoder.cc b/encoder.cc
index a764f1e..0876742 100644
--- a/encoder.cc
+++ b/encoder.cc
@@ -1,4 +1,4 @@
-/* Lzip - Data compressor based on the LZMA algorithm
+/* Lzip - LZMA lossless data compressor
Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
@@ -240,33 +240,34 @@ void Range_encoder::flush_data()
throw Error( "Write error" );
partial_member_pos += pos;
pos = 0;
+ if( verbosity >= 2 ) show_progress();
}
}
-void Len_encoder::encode( Range_encoder & range_encoder, int symbol,
+void Len_encoder::encode( Range_encoder & renc, int symbol,
const int pos_state )
{
symbol -= min_match_len;
if( symbol < len_low_symbols )
{
- range_encoder.encode_bit( choice1, 0 );
- range_encoder.encode_tree( bm_low[pos_state], symbol, len_low_bits );
+ renc.encode_bit( choice1, 0 );
+ renc.encode_tree( bm_low[pos_state], symbol, len_low_bits );
}
else
{
- range_encoder.encode_bit( choice1, 1 );
+ renc.encode_bit( choice1, 1 );
if( symbol < len_low_symbols + len_mid_symbols )
{
- range_encoder.encode_bit( choice2, 0 );
- range_encoder.encode_tree( bm_mid[pos_state], symbol - len_low_symbols,
- len_mid_bits );
+ renc.encode_bit( choice2, 0 );
+ renc.encode_tree( bm_mid[pos_state], symbol - len_low_symbols,
+ len_mid_bits );
}
else
{
- range_encoder.encode_bit( choice2, 1 );
- range_encoder.encode_tree( bm_high, symbol - len_low_symbols - len_mid_symbols,
- len_high_bits );
+ renc.encode_bit( choice2, 1 );
+ renc.encode_tree( bm_high, symbol - len_low_symbols - len_mid_symbols,
+ len_high_bits );
}
}
if( --counters[pos_state] <= 0 ) update_prices( pos_state );
@@ -278,17 +279,17 @@ void LZ_encoder_base::full_flush( const unsigned long long data_position,
const State state )
{
const int pos_state = data_position & pos_state_mask;
- range_encoder.encode_bit( bm_match[state()][pos_state], 1 );
- range_encoder.encode_bit( bm_rep[state()], 0 );
+ renc.encode_bit( bm_match[state()][pos_state], 1 );
+ renc.encode_bit( bm_rep[state()], 0 );
encode_pair( 0xFFFFFFFFU, min_match_len, pos_state );
- range_encoder.flush();
+ renc.flush();
File_trailer trailer;
trailer.data_crc( crc() );
trailer.data_size( data_position );
- trailer.member_size( range_encoder.member_position() + File_trailer::size() );
+ trailer.member_size( renc.member_position() + File_trailer::size() );
for( int i = 0; i < File_trailer::size(); ++i )
- range_encoder.put_byte( trailer.data[i] );
- range_encoder.flush_data();
+ renc.put_byte( trailer.data[i] );
+ renc.flush_data();
}
@@ -680,14 +681,14 @@ bool LZ_encoder::encode_member( const unsigned long long member_size )
for( int i = 0; i < num_rep_distances; ++i ) rep_distances[i] = 0;
if( matchfinder.data_position() != 0 ||
- range_encoder.member_position() != File_header::size )
+ renc.member_position() != File_header::size )
return false; // can be called only once
if( !matchfinder.finished() ) // encode first byte
{
const uint8_t prev_byte = 0;
const uint8_t cur_byte = matchfinder[0];
- range_encoder.encode_bit( bm_match[state()][0], 0 );
+ renc.encode_bit( bm_match[state()][0], 0 );
encode_literal( prev_byte, cur_byte );
crc32.update( crc_, cur_byte );
matchfinder.get_match_pairs();
@@ -714,7 +715,7 @@ bool LZ_encoder::encode_member( const unsigned long long member_size )
const int len = trials[i].price;
bool bit = ( dis < 0 && len == 1 );
- range_encoder.encode_bit( bm_match[state()][pos_state], !bit );
+ renc.encode_bit( bm_match[state()][pos_state], !bit );
if( bit ) // literal byte
{
const uint8_t prev_byte = matchfinder[-ahead-1];
@@ -734,23 +735,23 @@ bool LZ_encoder::encode_member( const unsigned long long member_size )
crc32.update( crc_, matchfinder.ptr_to_current_pos() - ahead, len );
mtf_reps( dis, rep_distances );
bit = ( dis < num_rep_distances );
- range_encoder.encode_bit( bm_rep[state()], bit );
+ renc.encode_bit( bm_rep[state()], bit );
if( bit )
{
bit = ( dis == 0 );
- range_encoder.encode_bit( bm_rep0[state()], !bit );
+ renc.encode_bit( bm_rep0[state()], !bit );
if( bit )
- range_encoder.encode_bit( bm_len[state()][pos_state], len > 1 );
+ renc.encode_bit( bm_len[state()][pos_state], len > 1 );
else
{
- range_encoder.encode_bit( bm_rep1[state()], dis > 1 );
+ renc.encode_bit( bm_rep1[state()], dis > 1 );
if( dis > 1 )
- range_encoder.encode_bit( bm_rep2[state()], dis > 2 );
+ renc.encode_bit( bm_rep2[state()], dis > 2 );
}
if( len == 1 ) state.set_short_rep();
else
{
- rep_len_encoder.encode( range_encoder, len, pos_state );
+ rep_len_encoder.encode( renc, len, pos_state );
state.set_rep();
}
}
@@ -764,7 +765,7 @@ bool LZ_encoder::encode_member( const unsigned long long member_size )
}
}
ahead -= len; i += len;
- if( range_encoder.member_position() >= member_size_limit )
+ if( renc.member_position() >= member_size_limit )
{
if( !matchfinder.dec_pos( ahead ) ) return false;
full_flush( matchfinder.data_position(), state );