diff options
author | Eugene Kliuchnikov <eustas@google.com> | 2017-10-13 14:50:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-13 14:50:51 +0200 |
commit | 3e58ea5f90798a4c80f638a98f2d75b07a72af39 (patch) | |
tree | 29e58e31a5bec75235b5ea603b53b13ea7ae71c3 /c/enc | |
parent | 39ef4bbdcffd6316b5d3e95904cf9b0aa5e19504 (diff) | |
download | brotli-3e58ea5f90798a4c80f638a98f2d75b07a72af39.zip brotli-3e58ea5f90798a4c80f638a98f2d75b07a72af39.tar.gz brotli-3e58ea5f90798a4c80f638a98f2d75b07a72af39.tar.bz2 |
Update (#617)
* remove `const` on `BrotliDictionary` members
* extend `ZofliNode` distance range to 128MiB
* add missing `port.h` include to `quality.h`
* fix typo in encoder API-doc
* regenerate `decode.min.js`
Diffstat (limited to 'c/enc')
-rw-r--r-- | c/enc/backward_references_hq.c | 17 | ||||
-rw-r--r-- | c/enc/backward_references_hq.h | 6 | ||||
-rw-r--r-- | c/enc/quality.h | 1 |
3 files changed, 13 insertions, 11 deletions
diff --git a/c/enc/backward_references_hq.c b/c/enc/backward_references_hq.c index 335b55c..92ce8fb 100644 --- a/c/enc/backward_references_hq.c +++ b/c/enc/backward_references_hq.c @@ -54,11 +54,11 @@ static BROTLI_INLINE uint32_t ZopfliNodeLengthCode(const ZopfliNode* self) { } static BROTLI_INLINE uint32_t ZopfliNodeCopyDistance(const ZopfliNode* self) { - return self->distance & 0x1ffffff; + return self->distance & 0x7ffffff; } static BROTLI_INLINE uint32_t ZopfliNodeDistanceCode(const ZopfliNode* self) { - const uint32_t short_code = self->distance >> 25; + const uint32_t short_code = self->distance >> 27; return short_code == 0 ? ZopfliNodeCopyDistance(self) + BROTLI_NUM_DISTANCE_SHORT_CODES - 1 : short_code - 1; @@ -222,7 +222,7 @@ static BROTLI_INLINE void UpdateZopfliNode(ZopfliNode* nodes, size_t pos, size_t short_code, float cost) { ZopfliNode* next = &nodes[pos + len]; next->length = (uint32_t)(len | ((len + 9u - len_code) << 24)); - next->distance = (uint32_t)(dist | (short_code << 25)); + next->distance = (uint32_t)(dist | (short_code << 27)); next->insert_length = (uint32_t)(pos - start_pos); next->u.cost = cost; } @@ -560,7 +560,6 @@ void BrotliZopfliCreateCommands(const size_t num_bytes, BROTLI_MIN(size_t, block_start + pos, max_backward_limit); BROTLI_BOOL is_dictionary = TO_BROTLI_BOOL(distance > max_distance + gap); size_t dist_code = ZopfliNodeDistanceCode(next); - InitCommand(&commands[i], insert_length, copy_length, (int)len_code - (int)copy_length, dist_code); @@ -638,11 +637,12 @@ size_t BrotliZopfliComputeShortestPath(MemoryManager* m, const size_t max_zopfli_len = MaxZopfliLen(params); ZopfliCostModel model; StartPosQueue queue; - BackwardMatch matches[MAX_NUM_MATCHES_H10]; + BackwardMatch matches[2 * (MAX_NUM_MATCHES_H10 + 64)]; const size_t store_end = num_bytes >= StoreLookaheadH10() ? position + num_bytes - StoreLookaheadH10() + 1 : position; size_t i; size_t gap = 0; + size_t lz_matches_offset = 0; nodes[0].length = 0; nodes[0].u.cost = 0; InitZopfliCostModel(m, &model, num_bytes); @@ -655,7 +655,7 @@ size_t BrotliZopfliComputeShortestPath(MemoryManager* m, const size_t max_distance = BROTLI_MIN(size_t, pos, max_backward_limit); size_t num_matches = FindAllMatchesH10(hasher, dictionary, ringbuffer, ringbuffer_mask, pos, num_bytes - i, max_distance, gap, params, - matches); + &matches[lz_matches_offset]); size_t skip; if (num_matches > 0 && BackwardMatchLength(&matches[num_matches - 1]) > max_zopfli_len) { @@ -728,6 +728,7 @@ void BrotliCreateHqZopfliBackwardReferences( ZopfliNode* nodes; BackwardMatch* matches = BROTLI_ALLOC(m, BackwardMatch, matches_size); size_t gap = 0; + size_t shadow_matches = 0; if (BROTLI_IS_OOM(m)) return; for (i = 0; i + HashTypeLengthH10() - 1 < num_bytes; ++i) { const size_t pos = position + i; @@ -738,11 +739,11 @@ void BrotliCreateHqZopfliBackwardReferences( size_t j; /* Ensure that we have enough free slots. */ BROTLI_ENSURE_CAPACITY(m, BackwardMatch, matches, matches_size, - cur_match_pos + MAX_NUM_MATCHES_H10); + cur_match_pos + MAX_NUM_MATCHES_H10 + shadow_matches); if (BROTLI_IS_OOM(m)) return; num_found_matches = FindAllMatchesH10(hasher, dictionary, ringbuffer, ringbuffer_mask, pos, max_length, max_distance, gap, params, - &matches[cur_match_pos]); + &matches[cur_match_pos + shadow_matches]); cur_match_end = cur_match_pos + num_found_matches; for (j = cur_match_pos; j + 1 < cur_match_end; ++j) { assert(BackwardMatchLength(&matches[j]) <= diff --git a/c/enc/backward_references_hq.h b/c/enc/backward_references_hq.h index 7e3bd7e..02bb278 100644 --- a/c/enc/backward_references_hq.h +++ b/c/enc/backward_references_hq.h @@ -40,9 +40,9 @@ typedef struct ZopfliNode { /* best length to get up to this byte (not including this byte itself) highest 8 bit is used to reconstruct the length code */ uint32_t length; - /* distance associated with the length - highest 7 bit contains distance short code + 1 (or zero if no short code) - */ + /* distance associated with the length; highest 5 bits contain distance + short code + 1 (or zero if no short code); this way only distances shorter + than 128MiB are allowed here */ uint32_t distance; /* number of literal inserts before this copy */ uint32_t insert_length; diff --git a/c/enc/quality.h b/c/enc/quality.h index 09a5fdc..5791470 100644 --- a/c/enc/quality.h +++ b/c/enc/quality.h @@ -11,6 +11,7 @@ #define BROTLI_ENC_QUALITY_H_ #include <brotli/encode.h> +#include "./port.h" #define FAST_ONE_PASS_COMPRESSION_QUALITY 0 #define FAST_TWO_PASS_COMPRESSION_QUALITY 1 |