diff options
Diffstat (limited to '')
-rw-r--r-- | decoder.h | 45 |
1 files changed, 20 insertions, 25 deletions
@@ -1,18 +1,18 @@ -/* Clzip - LZMA lossless data compressor - Copyright (C) 2010-2019 Antonio Diaz Diaz. +/* Clzip - LZMA lossless data compressor + Copyright (C) 2010-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/>. */ enum { rd_buffer_size = 16384 }; @@ -107,7 +107,7 @@ static inline unsigned Rd_decode( struct Range_decoder * const rdec, /* symbol <<= 1; */ /* if( rdec->code >= rdec->range ) { rdec->code -= rdec->range; symbol |= 1; } */ bit = ( rdec->code >= rdec->range ); - symbol = ( symbol << 1 ) + bit; + symbol <<= 1; symbol += bit; rdec->code -= rdec->range & ( 0U - bit ); } return symbol; @@ -137,8 +137,7 @@ static inline unsigned Rd_decode_bit( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, Bit_model bm[] ) { - unsigned symbol = 1; - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[1] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); return symbol & 7; @@ -147,8 +146,7 @@ static inline unsigned Rd_decode_tree3( struct Range_decoder * const rdec, static inline unsigned Rd_decode_tree6( struct Range_decoder * const rdec, Bit_model bm[] ) { - unsigned symbol = 1; - symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); + unsigned symbol = 2 | Rd_decode_bit( rdec, &bm[1] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); symbol = ( symbol << 1 ) | Rd_decode_bit( rdec, &bm[symbol] ); @@ -177,7 +175,7 @@ Rd_decode_tree_reversed( struct Range_decoder * const rdec, for( i = 0; i < num_bits; ++i ) { const unsigned bit = Rd_decode_bit( rdec, &bm[model] ); - model = ( model << 1 ) + bit; + model <<= 1; model += bit; symbol |= ( bit << i ); } return symbol; @@ -187,12 +185,9 @@ static inline unsigned Rd_decode_tree_reversed4( struct Range_decoder * const rdec, Bit_model bm[] ) { unsigned symbol = Rd_decode_bit( rdec, &bm[1] ); - unsigned model = 2 + symbol; - unsigned bit = Rd_decode_bit( rdec, &bm[model] ); - model = ( model << 1 ) + bit; symbol |= ( bit << 1 ); - bit = Rd_decode_bit( rdec, &bm[model] ); - model = ( model << 1 ) + bit; symbol |= ( bit << 2 ); - symbol |= ( Rd_decode_bit( rdec, &bm[model] ) << 3 ); + symbol += Rd_decode_bit( rdec, &bm[2+symbol] ) << 1; + symbol += Rd_decode_bit( rdec, &bm[4+symbol] ) << 2; + symbol += Rd_decode_bit( rdec, &bm[8+symbol] ) << 3; return symbol; } @@ -205,7 +200,7 @@ static inline unsigned Rd_decode_matched( struct Range_decoder * const rdec, { const unsigned match_bit = ( match_byte <<= 1 ) & mask; const unsigned bit = Rd_decode_bit( rdec, &bm[symbol+match_bit+mask] ); - symbol = ( symbol << 1 ) + bit; + symbol <<= 1; symbol += bit; if( symbol > 0xFF ) return symbol & 0xFF; mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */ } |