summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:46:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:46:42 +0000
commite74d15e54c99ce6d8210d28d68732ec61e924c72 (patch)
treeff66615c35389f6a1cbe1e0293bab664e0944219 /decoder.h
parentReleasing debian version 1.21-8. (diff)
downloadlzip-e74d15e54c99ce6d8210d28d68732ec61e924c72.tar.xz
lzip-e74d15e54c99ce6d8210d28d68732ec61e924c72.zip
Merging upstream version 1.22.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h60
1 files changed, 29 insertions, 31 deletions
diff --git a/decoder.h b/decoder.h
index 48f9e29..36daef0 100644
--- a/decoder.h
+++ b/decoder.h
@@ -1,18 +1,18 @@
-/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2019 Antonio Diaz Diaz.
+/* Lzip - LZMA lossless data compressor
+ Copyright (C) 2008-2021 Antonio Diaz Diaz.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class Range_decoder
@@ -48,7 +48,9 @@ public:
~Range_decoder() { delete[] buffer; }
bool finished() { return pos >= stream_pos && !read_block(); }
- unsigned long long member_position() const { return partial_member_pos + pos; }
+
+ unsigned long long member_position() const
+ { return partial_member_pos + pos; }
void reset_member_position()
{ partial_member_pos = 0; partial_member_pos -= pos; }
@@ -76,7 +78,7 @@ public:
void load()
{
code = 0;
- for( int i = 0; i < 5; ++i ) code = (code << 8) | get_byte();
+ for( int i = 0; i < 5; ++i ) code = ( code << 8 ) | get_byte();
range = 0xFFFFFFFFU;
code &= range; // make sure that first byte is discarded
}
@@ -84,7 +86,7 @@ public:
void normalize()
{
if( range <= 0x00FFFFFFU )
- { range <<= 8; code = (code << 8) | get_byte(); }
+ { range <<= 8; code = ( code << 8 ) | get_byte(); }
}
unsigned decode( const int num_bits )
@@ -97,7 +99,7 @@ public:
// symbol <<= 1;
// if( code >= range ) { code -= range; symbol |= 1; }
const bool bit = ( code >= range );
- symbol = ( symbol << 1 ) + bit;
+ symbol <<= 1; symbol += bit;
code -= range & ( 0U - bit );
}
return symbol;
@@ -110,7 +112,8 @@ public:
if( code < bound )
{
range = bound;
- bm.probability += (bit_model_total - bm.probability) >> bit_model_move_bits;
+ bm.probability +=
+ ( bit_model_total - bm.probability ) >> bit_model_move_bits;
return 0;
}
else
@@ -124,8 +127,7 @@ public:
unsigned decode_tree3( Bit_model bm[] )
{
- unsigned symbol = 1;
- symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
+ unsigned symbol = 2 | decode_bit( bm[1] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
return symbol & 7;
@@ -133,8 +135,7 @@ public:
unsigned decode_tree6( Bit_model bm[] )
{
- unsigned symbol = 1;
- symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
+ unsigned symbol = 2 | decode_bit( bm[1] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );
@@ -158,7 +159,7 @@ public:
for( int i = 0; i < num_bits; ++i )
{
const unsigned bit = decode_bit( bm[model] );
- model = ( model << 1 ) + bit;
+ model <<= 1; model += bit;
symbol |= ( bit << i );
}
return symbol;
@@ -167,12 +168,9 @@ public:
unsigned decode_tree_reversed4( Bit_model bm[] )
{
unsigned symbol = decode_bit( bm[1] );
- unsigned model = 2 + symbol;
- unsigned bit = decode_bit( bm[model] );
- model = ( model << 1 ) + bit; symbol |= ( bit << 1 );
- bit = decode_bit( bm[model] );
- model = ( model << 1 ) + bit; symbol |= ( bit << 2 );
- symbol |= ( decode_bit( bm[model] ) << 3 );
+ symbol += decode_bit( bm[2+symbol] ) << 1;
+ symbol += decode_bit( bm[4+symbol] ) << 2;
+ symbol += decode_bit( bm[8+symbol] ) << 3;
return symbol;
}
@@ -183,9 +181,9 @@ public:
while( symbol < 0x100 )
{
const unsigned match_bit = ( match_byte <<= 1 ) & 0x100;
- const unsigned bit = decode_bit( bm1[match_bit+symbol] );
- symbol = ( symbol << 1 ) | bit;
- if( match_bit != bit << 8 )
+ const bool bit = decode_bit( bm1[symbol+match_bit] );
+ symbol <<= 1; symbol |= bit;
+ if( match_bit >> 8 != bit )
{
while( symbol < 0x100 )
symbol = ( symbol << 1 ) | decode_bit( bm[symbol] );