diff options
Diffstat (limited to 'c')
-rw-r--r-- | c/common/dictionary.h | 6 | ||||
-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 | ||||
-rw-r--r-- | c/include/brotli/encode.h | 2 |
5 files changed, 17 insertions, 15 deletions
diff --git a/c/common/dictionary.h b/c/common/dictionary.h index 46fe533..3fa3391 100644 --- a/c/common/dictionary.h +++ b/c/common/dictionary.h @@ -27,13 +27,13 @@ typedef struct BrotliDictionary { * Dictionary consists of words with length of [4..24] bytes. * Values at [0..3] and [25..31] indices should not be addressed. */ - const uint8_t size_bits_by_length[32]; + uint8_t size_bits_by_length[32]; /* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */ - const uint32_t offsets_by_length[32]; + uint32_t offsets_by_length[32]; /* assert(data_size == offsets_by_length[31]) */ - const size_t data_size; + size_t data_size; /* Data array is not bound, and should obey to size_bits_by_length values. Specified size matches default (RFC 7932) dictionary. Its size is 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 diff --git a/c/include/brotli/encode.h b/c/include/brotli/encode.h index e4cf18b..df89928 100644 --- a/c/include/brotli/encode.h +++ b/c/include/brotli/encode.h @@ -283,7 +283,7 @@ BROTLI_ENC_API BROTLI_BOOL BrotliEncoderCompress( * that amount. * * @p total_out, if it is not a null-pointer, will be set to the number - * of bytes decompressed since the last @p state initialization. + * of bytes compressed since the last @p state initialization. * * * |