Skip to content

Commit

Permalink
Merge pull request #56 from lvandeve/master
Browse files Browse the repository at this point in the history
bugfixes affecting streaming decoding
  • Loading branch information
lvandeve committed Mar 30, 2015
2 parents ad354af + f9e5a2d commit d44a174
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dec/decode.c
Expand Up @@ -432,7 +432,6 @@ static BrotliResult DecodeContextMap(int context_map_size,
BrotliBitReader* br = &s->br;
BrotliResult result = BROTLI_RESULT_SUCCESS;
int use_rle_for_zeros;
int max_run_length_prefix = 0;

switch(s->sub_state[0]) {
case BROTLI_STATE_SUB_NONE:
Expand All @@ -457,7 +456,9 @@ static BrotliResult DecodeContextMap(int context_map_size,

use_rle_for_zeros = (int)BrotliReadBits(br, 1);
if (use_rle_for_zeros) {
max_run_length_prefix = (int)BrotliReadBits(br, 4) + 1;
s->max_run_length_prefix = (int)BrotliReadBits(br, 4) + 1;
} else {
s->max_run_length_prefix = 0;
}
s->context_map_table = (HuffmanCode*)malloc(
BROTLI_HUFFMAN_MAX_TABLE_SIZE * sizeof(*s->context_map_table));
Expand All @@ -467,8 +468,8 @@ static BrotliResult DecodeContextMap(int context_map_size,
s->sub_state[0] = BROTLI_STATE_SUB_CONTEXT_MAP_HUFFMAN;
/* No break, continue to next state. */
case BROTLI_STATE_SUB_CONTEXT_MAP_HUFFMAN:
result = ReadHuffmanCode(
*num_htrees + max_run_length_prefix, s->context_map_table, NULL, s);
result = ReadHuffmanCode(*num_htrees + s->max_run_length_prefix,
s->context_map_table, NULL, s);
if (result != BROTLI_RESULT_SUCCESS) return result;
s->sub_state[0] = BROTLI_STATE_SUB_CONTEXT_MAPS;
/* No break, continue to next state. */
Expand All @@ -482,7 +483,7 @@ static BrotliResult DecodeContextMap(int context_map_size,
if (code == 0) {
(*context_map)[s->context_index] = 0;
++s->context_index;
} else if (code <= max_run_length_prefix) {
} else if (code <= s->max_run_length_prefix) {
int reps = 1 + (1 << code) + (int)BrotliReadBits(br, code);
while (--reps) {
if (s->context_index >= context_map_size) {
Expand All @@ -493,7 +494,7 @@ static BrotliResult DecodeContextMap(int context_map_size,
}
} else {
(*context_map)[s->context_index] =
(uint8_t)(code - max_run_length_prefix);
(uint8_t)(code - s->max_run_length_prefix);
++s->context_index;
}
}
Expand Down Expand Up @@ -960,14 +961,14 @@ BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
break;
}
if (s->is_uncompressed) {
BrotliSetBitPos(br, (s->br.bit_pos_ + 7) & (uint32_t)(~7UL));
s->state = BROTLI_STATE_UNCOMPRESSED;
break;
}
i = 0;
s->state = BROTLI_STATE_HUFFMAN_CODE_0;
break;
case BROTLI_STATE_UNCOMPRESSED:
BrotliSetBitPos(br, (s->br.bit_pos_ + 7) & (uint32_t)(~7UL));
initial_remaining_len = s->meta_block_remaining_len;
/* pos is given as argument since s->pos is only updated at the end. */
result = CopyUncompressedBlockToOutput(output, pos, s);
Expand Down
1 change: 1 addition & 0 deletions dec/state.h
Expand Up @@ -150,6 +150,7 @@ typedef struct {

/* For DecodeContextMap */
int context_index;
int max_run_length_prefix;
HuffmanCode* context_map_table;
} BrotliState;

Expand Down

0 comments on commit d44a174

Please sign in to comment.