diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-01-25 13:36:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-01-25 13:36:25 +0000 |
commit | 74ffb1c96335d84fce50806b5313fce38a82cb10 (patch) | |
tree | d74d1b7076e0a7bc39aba2f7c70d361c09eaef1d /decoder.h | |
parent | Releasing debian version 1.11-10. (diff) | |
download | lunzip-74ffb1c96335d84fce50806b5313fce38a82cb10.tar.xz lunzip-74ffb1c96335d84fce50806b5313fce38a82cb10.zip |
Merging upstream version 1.12.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'decoder.h')
-rw-r--r-- | decoder.h | 47 |
1 files changed, 20 insertions, 27 deletions
@@ -1,18 +1,18 @@ -/* Lunzip - Decompressor for the lzip format - Copyright (C) 2010-2019 Antonio Diaz Diaz. +/* Lunzip - Decompressor for the lzip format + 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; */ } @@ -235,7 +230,6 @@ struct LZ_decoder uint32_t crc; int outfd; /* output file descriptor */ bool pos_wrapped; - bool pos_wrapped_dic; }; void LZd_flush_data( struct LZ_decoder * const d ); @@ -333,7 +327,6 @@ static inline bool LZd_init( struct LZ_decoder * const d, d->crc = 0xFFFFFFFFU; d->outfd = ofd; d->pos_wrapped = false; - d->pos_wrapped_dic = false; /* prev_byte of first byte; also for LZd_peek( 0 ) on corrupt file */ d->buffer[d->buffer_size-1] = 0; return true; |