summaryrefslogtreecommitdiffstats
path: root/lzip_decompress.c
diff options
context:
space:
mode:
Diffstat (limited to 'lzip_decompress.c')
-rw-r--r--lzip_decompress.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/lzip_decompress.c b/lzip_decompress.c
index 9c5b8fb..8fa8bf1 100644
--- a/lzip_decompress.c
+++ b/lzip_decompress.c
@@ -1,7 +1,7 @@
/*
* LZIP decompressor
*
- * Copyright (C) 2016-2018 Antonio Diaz Diaz.
+ * Copyright (C) 2016-2020 Antonio Diaz Diaz.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
@@ -48,7 +48,7 @@ static inline State St_set_short_rep(const State st)
enum {
min_dictionary_bits = 12,
- min_dictionary_size = 1 << min_dictionary_bits,
+ min_dictionary_size = 1 << min_dictionary_bits, /* >= modeled_distances */
max_dictionary_bits = 29,
max_dictionary_size = 1 << max_dictionary_bits,
literal_context_bits = 3,
@@ -84,7 +84,7 @@ static inline int get_len_state(const int len)
static inline int get_lit_state(const uint8_t prev_byte)
{
- return (prev_byte >> (8 - literal_context_bits));
+ return prev_byte >> (8 - literal_context_bits);
}
@@ -191,7 +191,7 @@ STATIC_RW_DATA const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZI
typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
/* 4 version */
- /* 5 coded_dict_size */
+ /* 5 coded dictionary size */
enum { Lh_size = 6 };
static inline bool Lh_verify_magic(const Lzip_header data)
@@ -391,7 +391,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;
@@ -419,25 +419,23 @@ 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;
+ 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]);
return symbol & 7;
}
static inline unsigned Rd_decode_tree6(struct Range_decoder * const rdec,
Bit_model bm[])
{
- unsigned symbol = 1;
+ 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]);
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]);
return symbol & 0x3F;
}
@@ -463,7 +461,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;
@@ -473,13 +471,10 @@ 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;
}
@@ -493,7 +488,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; */