* 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`
This commit is contained in:
Eugene Kliuchnikov 2017-10-13 14:50:51 +02:00 committed by GitHub
parent 39ef4bbdcf
commit 3e58ea5f90
7 changed files with 19 additions and 17 deletions

View File

@ -27,13 +27,13 @@ typedef struct BrotliDictionary {
* Dictionary consists of words with length of [4..24] bytes. * Dictionary consists of words with length of [4..24] bytes.
* Values at [0..3] and [25..31] indices should not be addressed. * 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)) */ /* 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]) */ /* 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. /* Data array is not bound, and should obey to size_bits_by_length values.
Specified size matches default (RFC 7932) dictionary. Its size is Specified size matches default (RFC 7932) dictionary. Its size is

View File

@ -54,11 +54,11 @@ static BROTLI_INLINE uint32_t ZopfliNodeLengthCode(const ZopfliNode* self) {
} }
static BROTLI_INLINE uint32_t ZopfliNodeCopyDistance(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) { 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 ? return short_code == 0 ?
ZopfliNodeCopyDistance(self) + BROTLI_NUM_DISTANCE_SHORT_CODES - 1 : ZopfliNodeCopyDistance(self) + BROTLI_NUM_DISTANCE_SHORT_CODES - 1 :
short_code - 1; short_code - 1;
@ -222,7 +222,7 @@ static BROTLI_INLINE void UpdateZopfliNode(ZopfliNode* nodes, size_t pos,
size_t short_code, float cost) { size_t short_code, float cost) {
ZopfliNode* next = &nodes[pos + len]; ZopfliNode* next = &nodes[pos + len];
next->length = (uint32_t)(len | ((len + 9u - len_code) << 24)); 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->insert_length = (uint32_t)(pos - start_pos);
next->u.cost = cost; 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_MIN(size_t, block_start + pos, max_backward_limit);
BROTLI_BOOL is_dictionary = TO_BROTLI_BOOL(distance > max_distance + gap); BROTLI_BOOL is_dictionary = TO_BROTLI_BOOL(distance > max_distance + gap);
size_t dist_code = ZopfliNodeDistanceCode(next); size_t dist_code = ZopfliNodeDistanceCode(next);
InitCommand(&commands[i], insert_length, InitCommand(&commands[i], insert_length,
copy_length, (int)len_code - (int)copy_length, dist_code); 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); const size_t max_zopfli_len = MaxZopfliLen(params);
ZopfliCostModel model; ZopfliCostModel model;
StartPosQueue queue; StartPosQueue queue;
BackwardMatch matches[MAX_NUM_MATCHES_H10]; BackwardMatch matches[2 * (MAX_NUM_MATCHES_H10 + 64)];
const size_t store_end = num_bytes >= StoreLookaheadH10() ? const size_t store_end = num_bytes >= StoreLookaheadH10() ?
position + num_bytes - StoreLookaheadH10() + 1 : position; position + num_bytes - StoreLookaheadH10() + 1 : position;
size_t i; size_t i;
size_t gap = 0; size_t gap = 0;
size_t lz_matches_offset = 0;
nodes[0].length = 0; nodes[0].length = 0;
nodes[0].u.cost = 0; nodes[0].u.cost = 0;
InitZopfliCostModel(m, &model, num_bytes); 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); const size_t max_distance = BROTLI_MIN(size_t, pos, max_backward_limit);
size_t num_matches = FindAllMatchesH10(hasher, dictionary, ringbuffer, size_t num_matches = FindAllMatchesH10(hasher, dictionary, ringbuffer,
ringbuffer_mask, pos, num_bytes - i, max_distance, gap, params, ringbuffer_mask, pos, num_bytes - i, max_distance, gap, params,
matches); &matches[lz_matches_offset]);
size_t skip; size_t skip;
if (num_matches > 0 && if (num_matches > 0 &&
BackwardMatchLength(&matches[num_matches - 1]) > max_zopfli_len) { BackwardMatchLength(&matches[num_matches - 1]) > max_zopfli_len) {
@ -728,6 +728,7 @@ void BrotliCreateHqZopfliBackwardReferences(
ZopfliNode* nodes; ZopfliNode* nodes;
BackwardMatch* matches = BROTLI_ALLOC(m, BackwardMatch, matches_size); BackwardMatch* matches = BROTLI_ALLOC(m, BackwardMatch, matches_size);
size_t gap = 0; size_t gap = 0;
size_t shadow_matches = 0;
if (BROTLI_IS_OOM(m)) return; if (BROTLI_IS_OOM(m)) return;
for (i = 0; i + HashTypeLengthH10() - 1 < num_bytes; ++i) { for (i = 0; i + HashTypeLengthH10() - 1 < num_bytes; ++i) {
const size_t pos = position + i; const size_t pos = position + i;
@ -738,11 +739,11 @@ void BrotliCreateHqZopfliBackwardReferences(
size_t j; size_t j;
/* Ensure that we have enough free slots. */ /* Ensure that we have enough free slots. */
BROTLI_ENSURE_CAPACITY(m, BackwardMatch, matches, matches_size, 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; if (BROTLI_IS_OOM(m)) return;
num_found_matches = FindAllMatchesH10(hasher, dictionary, ringbuffer, num_found_matches = FindAllMatchesH10(hasher, dictionary, ringbuffer,
ringbuffer_mask, pos, max_length, max_distance, gap, params, 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; cur_match_end = cur_match_pos + num_found_matches;
for (j = cur_match_pos; j + 1 < cur_match_end; ++j) { for (j = cur_match_pos; j + 1 < cur_match_end; ++j) {
assert(BackwardMatchLength(&matches[j]) <= assert(BackwardMatchLength(&matches[j]) <=

View File

@ -40,9 +40,9 @@ typedef struct ZopfliNode {
/* best length to get up to this byte (not including this byte itself) /* best length to get up to this byte (not including this byte itself)
highest 8 bit is used to reconstruct the length code */ highest 8 bit is used to reconstruct the length code */
uint32_t length; uint32_t length;
/* distance associated with the length /* distance associated with the length; highest 5 bits contain distance
highest 7 bit contains distance short code + 1 (or zero if no short code) short code + 1 (or zero if no short code); this way only distances shorter
*/ than 128MiB are allowed here */
uint32_t distance; uint32_t distance;
/* number of literal inserts before this copy */ /* number of literal inserts before this copy */
uint32_t insert_length; uint32_t insert_length;

View File

@ -11,6 +11,7 @@
#define BROTLI_ENC_QUALITY_H_ #define BROTLI_ENC_QUALITY_H_
#include <brotli/encode.h> #include <brotli/encode.h>
#include "./port.h"
#define FAST_ONE_PASS_COMPRESSION_QUALITY 0 #define FAST_ONE_PASS_COMPRESSION_QUALITY 0
#define FAST_TWO_PASS_COMPRESSION_QUALITY 1 #define FAST_TWO_PASS_COMPRESSION_QUALITY 1

View File

@ -283,7 +283,7 @@ BROTLI_ENC_API BROTLI_BOOL BrotliEncoderCompress(
* that amount. * that amount.
* *
* @p total_out, if it is not a null-pointer, will be set to the number * @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.
* *
* *
* *

View File

@ -335,7 +335,7 @@ Compresses input stream to output stream\&. The values \fC*available_in\fP and \
.PP .PP
After each call, \fC*available_in\fP will be decremented by the amount of input bytes consumed, and the \fC*next_in\fP pointer will be incremented by that amount\&. Similarly, \fC*available_out\fP will be decremented by the amount of output bytes written, and the \fC*next_out\fP pointer will be incremented by that amount\&. After each call, \fC*available_in\fP will be decremented by the amount of input bytes consumed, and the \fC*next_in\fP pointer will be incremented by that amount\&. Similarly, \fC*available_out\fP will be decremented by the amount of output bytes written, and the \fC*next_out\fP pointer will be incremented by that amount\&.
.PP .PP
\fCtotal_out\fP, if it is not a null-pointer, will be set to the number of bytes decompressed since the last \fCstate\fP initialization\&. \fCtotal_out\fP, if it is not a null-pointer, will be set to the number of bytes compressed since the last \fCstate\fP initialization\&.
.PP .PP
Internally workflow consists of 3 tasks: Internally workflow consists of 3 tasks:
.IP "1." 4 .IP "1." 4

2
js/decode.min.js vendored Normal file → Executable file

File diff suppressed because one or more lines are too long