mirror of https://github.com/google/brotli
Merge pull request #99 from szabadka/master
Support window bits 10 - 15 in the decoder.
This commit is contained in:
commit
7c277c3ef7
31
dec/decode.c
31
dec/decode.c
|
@ -67,11 +67,19 @@ static const int kDistanceShortCodeValueOffset[NUM_DISTANCE_SHORT_CODES] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static BROTLI_INLINE int DecodeWindowBits(BrotliBitReader* br) {
|
static BROTLI_INLINE int DecodeWindowBits(BrotliBitReader* br) {
|
||||||
if (BrotliReadBits(br, 1)) {
|
int n;
|
||||||
return 17 + (int)BrotliReadBits(br, 3);
|
if (BrotliReadBits(br, 1) == 0) {
|
||||||
} else {
|
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
n = (int)BrotliReadBits(br, 3);
|
||||||
|
if (n > 0) {
|
||||||
|
return 17 + n;
|
||||||
|
}
|
||||||
|
n = (int)BrotliReadBits(br, 3);
|
||||||
|
if (n > 0) {
|
||||||
|
return 8 + n;
|
||||||
|
}
|
||||||
|
return 17;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decodes a number in the range [0..255], by reading 1 - 11 bits. */
|
/* Decodes a number in the range [0..255], by reading 1 - 11 bits. */
|
||||||
|
@ -845,7 +853,13 @@ BrotliResult BrotliDecompressedSize(size_t encoded_size,
|
||||||
val |= (uint64_t)encoded_buffer[i] << (8 * i);
|
val |= (uint64_t)encoded_buffer[i] << (8 * i);
|
||||||
}
|
}
|
||||||
/* Skip the window bits. */
|
/* Skip the window bits. */
|
||||||
bit_pos += (val & 1) ? 4 : 1;
|
++bit_pos;
|
||||||
|
if (val & 1) {
|
||||||
|
bit_pos += 3;
|
||||||
|
if (((val >> 1) & 7) == 0) {
|
||||||
|
bit_pos += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Decode the ISLAST bit. */
|
/* Decode the ISLAST bit. */
|
||||||
is_last = (val >> bit_pos) & 1;
|
is_last = (val >> bit_pos) & 1;
|
||||||
++bit_pos;
|
++bit_pos;
|
||||||
|
@ -859,6 +873,10 @@ BrotliResult BrotliDecompressedSize(size_t encoded_size,
|
||||||
}
|
}
|
||||||
/* Decode the length of the first meta-block. */
|
/* Decode the length of the first meta-block. */
|
||||||
size_nibbles = (int)((val >> bit_pos) & 3) + 4;
|
size_nibbles = (int)((val >> bit_pos) & 3) + 4;
|
||||||
|
if (size_nibbles == 7) {
|
||||||
|
/* First meta-block contains metadata, this case is not supported here. */
|
||||||
|
return BROTLI_RESULT_ERROR;
|
||||||
|
}
|
||||||
bit_pos += 2;
|
bit_pos += 2;
|
||||||
for (i = 0; i < size_nibbles; ++i) {
|
for (i = 0; i < size_nibbles; ++i) {
|
||||||
meta_block_len |= (int)((val >> bit_pos) & 0xf) << (4 * i);
|
meta_block_len |= (int)((val >> bit_pos) & 0xf) << (4 * i);
|
||||||
|
@ -997,6 +1015,11 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
|
||||||
}
|
}
|
||||||
/* Decode window size. */
|
/* Decode window size. */
|
||||||
s->window_bits = DecodeWindowBits(br);
|
s->window_bits = DecodeWindowBits(br);
|
||||||
|
if (s->window_bits == 9) {
|
||||||
|
/* Value 9 is reserved for future use. */
|
||||||
|
result = BROTLI_RESULT_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
s->max_backward_distance = (1 << s->window_bits) - 16;
|
s->max_backward_distance = (1 << s->window_bits) - 16;
|
||||||
|
|
||||||
s->block_type_trees = (HuffmanCode*)malloc(
|
s->block_type_trees = (HuffmanCode*)malloc(
|
||||||
|
|
|
@ -1356,9 +1356,31 @@ previous sections.
|
||||||
The stream header has only the following one field:
|
The stream header has only the following one field:
|
||||||
|
|
||||||
.nf
|
.nf
|
||||||
1-4 bits: WBITS, a value in the range 16 - 24, value 16 is
|
1-7 bits: WBITS, a value in the range 10 - 24, encoded with
|
||||||
encoded with one 0 bit, and values 17 - 24 are
|
the following variable length code (as it appears in
|
||||||
encoded with bit pattern xxx1 (so 0111 is 20)
|
the compressed data, where the bits are parsed from
|
||||||
|
right to left):
|
||||||
|
|
||||||
|
Value Bit Pattern
|
||||||
|
----- -----------
|
||||||
|
10 0100001
|
||||||
|
11 0110001
|
||||||
|
12 1000001
|
||||||
|
13 1010001
|
||||||
|
14 1100001
|
||||||
|
15 1110001
|
||||||
|
16 0
|
||||||
|
17 0000001
|
||||||
|
18 0011
|
||||||
|
19 0101
|
||||||
|
20 0111
|
||||||
|
21 1001
|
||||||
|
22 1011
|
||||||
|
23 1101
|
||||||
|
24 1111
|
||||||
|
|
||||||
|
Note that bit pattern 0010001 is invalid and must not
|
||||||
|
be used.
|
||||||
.fi
|
.fi
|
||||||
|
|
||||||
The size of the sliding window, which is the maximum value of any
|
The size of the sliding window, which is the maximum value of any
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -190,6 +190,9 @@ BrotliCompressor::BrotliCompressor(BrotliParams params)
|
||||||
if (params_.lgwin == 16) {
|
if (params_.lgwin == 16) {
|
||||||
last_byte_ = 0;
|
last_byte_ = 0;
|
||||||
last_byte_bits_ = 1;
|
last_byte_bits_ = 1;
|
||||||
|
} else if (params_.lgwin == 17) {
|
||||||
|
last_byte_ = 1;
|
||||||
|
last_byte_bits_ = 7;
|
||||||
} else {
|
} else {
|
||||||
last_byte_ = ((params_.lgwin - 17) << 1) | 1;
|
last_byte_ = ((params_.lgwin - 17) << 1) | 1;
|
||||||
last_byte_bits_ = 4;
|
last_byte_bits_ = 4;
|
||||||
|
|
|
@ -231,6 +231,9 @@ bool WriteMetaBlockParallel(const BrotliParams& params,
|
||||||
if (params.lgwin == 16) {
|
if (params.lgwin == 16) {
|
||||||
first_byte = 0;
|
first_byte = 0;
|
||||||
first_byte_bits = 1;
|
first_byte_bits = 1;
|
||||||
|
} else if (params.lgwin == 17) {
|
||||||
|
first_byte = 1;
|
||||||
|
first_byte_bits = 7;
|
||||||
} else {
|
} else {
|
||||||
first_byte = ((params.lgwin - 17) << 1) | 1;
|
first_byte = ((params.lgwin - 17) << 1) | 1;
|
||||||
first_byte_bits = 4;
|
first_byte_bits = 4;
|
||||||
|
|
Loading…
Reference in New Issue