summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--decoder.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/decoder.h b/decoder.h
index aaf85a6..290ab97 100644
--- a/decoder.h
+++ b/decoder.h
@@ -18,7 +18,6 @@
class Input_buffer
{
enum { buffer_size = 65536 };
-
uint8_t * const buffer;
int pos;
int stream_pos; // when reached, a new block must be read
@@ -73,6 +72,13 @@ public:
return ibuf.get_byte();
}
+ void reload() throw()
+ {
+ code = 0;
+ range = 0xFFFFFFFF;
+ for( int i = 0; i < 5; ++i ) code = (code << 8) | get_byte();
+ }
+
void normalize()
{
if( range <= 0x00FFFFFF )
@@ -101,8 +107,7 @@ public:
int decode_bit( Bit_model & bm )
{
- if( range <= 0x00FFFFFF )
- { range <<= 8; code = (code << 8) | get_byte(); }
+ normalize();
const uint32_t bound = ( range >> bit_model_total_bits ) * bm.probability;
if( code < bound )
{
@@ -204,12 +209,13 @@ class LZ_decoder
{
long long partial_data_pos;
const int format_version;
+ const int dictionary_size;
const int buffer_size;
uint8_t * const buffer;
int pos;
+ int stream_pos; // first byte not yet written to file
uint32_t crc_;
const int odes_;
- bool member_finished;
Bit_model bm_match[State::states][pos_states];
Bit_model bm_rep[State::states];
@@ -264,12 +270,13 @@ public:
:
partial_data_pos( 0 ),
format_version( header.version ),
- buffer_size( header.dictionary_size() ),
+ dictionary_size( header.dictionary_size() ),
+ buffer_size( std::max( 65536, dictionary_size ) ),
buffer( new uint8_t[buffer_size] ),
pos( 0 ),
+ stream_pos( 0 ),
crc_( 0xFFFFFFFF ),
odes_( odes ),
- member_finished( false ),
range_decoder( sizeof header, ibuf ),
literal_decoder() {}