BaseTools: Update Brotli Compress to the latest one 1.0.6
https://bugzilla.tianocore.org/show_bug.cgi?id=1201 Update Brotli to the latest version 1.0.6 https://github.com/google/brotli Verify VS2017, GCC5 build. Verify Decompression boot functionality. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
This commit is contained in:
@@ -13,13 +13,14 @@
|
||||
#include <string.h> /* memcpy, memset */
|
||||
|
||||
#include "../common/constants.h"
|
||||
#include "../common/types.h"
|
||||
#include "./context.h"
|
||||
#include "../common/context.h"
|
||||
#include "../common/platform.h"
|
||||
#include <brotli/types.h>
|
||||
#include "./entropy_encode.h"
|
||||
#include "./entropy_encode_static.h"
|
||||
#include "./fast_log.h"
|
||||
#include "./histogram.h"
|
||||
#include "./memory.h"
|
||||
#include "./port.h"
|
||||
#include "./write_bits.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
@@ -27,6 +28,11 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_HUFFMAN_TREE_SIZE (2 * BROTLI_NUM_COMMAND_SYMBOLS + 1)
|
||||
/* The maximum size of Huffman dictionary for distances assuming that
|
||||
NPOSTFIX = 0 and NDIRECT = 0. */
|
||||
#define MAX_SIMPLE_DISTANCE_ALPHABET_SIZE \
|
||||
BROTLI_DISTANCE_ALPHABET_SIZE(0, 0, BROTLI_LARGE_MAX_DISTANCE_BITS)
|
||||
/* MAX_SIMPLE_DISTANCE_ALPHABET_SIZE == 140 */
|
||||
|
||||
/* Represents the range of values belonging to a prefix code:
|
||||
[offset, offset + 2^nbits) */
|
||||
@@ -76,16 +82,16 @@ static BROTLI_INLINE size_t NextBlockTypeCode(
|
||||
return type_code;
|
||||
}
|
||||
|
||||
/* nibblesbits represents the 2 bits to encode MNIBBLES (0-3)
|
||||
/* |nibblesbits| represents the 2 bits to encode MNIBBLES (0-3)
|
||||
REQUIRES: length > 0
|
||||
REQUIRES: length <= (1 << 24) */
|
||||
static void BrotliEncodeMlen(size_t length, uint64_t* bits,
|
||||
size_t* numbits, uint64_t* nibblesbits) {
|
||||
size_t lg = (length == 1) ? 1 : Log2FloorNonZero((uint32_t)(length - 1)) + 1;
|
||||
size_t mnibbles = (lg < 16 ? 16 : (lg + 3)) / 4;
|
||||
assert(length > 0);
|
||||
assert(length <= (1 << 24));
|
||||
assert(lg <= 24);
|
||||
BROTLI_DCHECK(length > 0);
|
||||
BROTLI_DCHECK(length <= (1 << 24));
|
||||
BROTLI_DCHECK(lg <= 24);
|
||||
*nibblesbits = mnibbles - 4;
|
||||
*numbits = mnibbles * 4;
|
||||
*bits = length - 1;
|
||||
@@ -252,7 +258,7 @@ static void StoreSimpleHuffmanTree(const uint8_t* depths,
|
||||
size_t symbols[4],
|
||||
size_t num_symbols,
|
||||
size_t max_bits,
|
||||
size_t *storage_ix, uint8_t *storage) {
|
||||
size_t* storage_ix, uint8_t* storage) {
|
||||
/* value of 1 indicates a simple Huffman code */
|
||||
BrotliWriteBits(2, 1, storage_ix, storage);
|
||||
BrotliWriteBits(2, num_symbols - 1, storage_ix, storage); /* NSYM - 1 */
|
||||
@@ -291,7 +297,7 @@ static void StoreSimpleHuffmanTree(const uint8_t* depths,
|
||||
depths = symbol depths */
|
||||
void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
|
||||
HuffmanTree* tree,
|
||||
size_t *storage_ix, uint8_t *storage) {
|
||||
size_t* storage_ix, uint8_t* storage) {
|
||||
/* Write the Huffman tree into the brotli-representation.
|
||||
The command alphabet is the largest, so this allocation will fit all
|
||||
alphabets. */
|
||||
@@ -305,7 +311,7 @@ void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
|
||||
int num_codes = 0;
|
||||
size_t code = 0;
|
||||
|
||||
assert(num <= BROTLI_NUM_COMMAND_SYMBOLS);
|
||||
BROTLI_DCHECK(num <= BROTLI_NUM_COMMAND_SYMBOLS);
|
||||
|
||||
BrotliWriteHuffmanTree(depths, num, &huffman_tree_size, huffman_tree,
|
||||
huffman_tree_extra_bits);
|
||||
@@ -343,7 +349,7 @@ void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
|
||||
code_length_bitdepth[code] = 0;
|
||||
}
|
||||
|
||||
/* Store the real huffman tree now. */
|
||||
/* Store the real Huffman tree now. */
|
||||
BrotliStoreHuffmanTreeToBitMask(huffman_tree_size,
|
||||
huffman_tree,
|
||||
huffman_tree_extra_bits,
|
||||
@@ -354,8 +360,9 @@ void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
|
||||
|
||||
/* Builds a Huffman tree from histogram[0:length] into depth[0:length] and
|
||||
bits[0:length] and stores the encoded tree to the bit stream. */
|
||||
static void BuildAndStoreHuffmanTree(const uint32_t *histogram,
|
||||
const size_t length,
|
||||
static void BuildAndStoreHuffmanTree(const uint32_t* histogram,
|
||||
const size_t histogram_length,
|
||||
const size_t alphabet_size,
|
||||
HuffmanTree* tree,
|
||||
uint8_t* depth,
|
||||
uint16_t* bits,
|
||||
@@ -365,7 +372,7 @@ static void BuildAndStoreHuffmanTree(const uint32_t *histogram,
|
||||
size_t s4[4] = { 0 };
|
||||
size_t i;
|
||||
size_t max_bits = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
for (i = 0; i < histogram_length; i++) {
|
||||
if (histogram[i]) {
|
||||
if (count < 4) {
|
||||
s4[count] = i;
|
||||
@@ -377,7 +384,7 @@ static void BuildAndStoreHuffmanTree(const uint32_t *histogram,
|
||||
}
|
||||
|
||||
{
|
||||
size_t max_bits_counter = length - 1;
|
||||
size_t max_bits_counter = alphabet_size - 1;
|
||||
while (max_bits_counter) {
|
||||
max_bits_counter >>= 1;
|
||||
++max_bits;
|
||||
@@ -392,14 +399,14 @@ static void BuildAndStoreHuffmanTree(const uint32_t *histogram,
|
||||
return;
|
||||
}
|
||||
|
||||
memset(depth, 0, length * sizeof(depth[0]));
|
||||
BrotliCreateHuffmanTree(histogram, length, 15, tree, depth);
|
||||
BrotliConvertBitDepthsToSymbols(depth, length, bits);
|
||||
memset(depth, 0, histogram_length * sizeof(depth[0]));
|
||||
BrotliCreateHuffmanTree(histogram, histogram_length, 15, tree, depth);
|
||||
BrotliConvertBitDepthsToSymbols(depth, histogram_length, bits);
|
||||
|
||||
if (count <= 4) {
|
||||
StoreSimpleHuffmanTree(depth, s4, count, max_bits, storage_ix, storage);
|
||||
} else {
|
||||
BrotliStoreHuffmanTree(depth, length, tree, storage_ix, storage);
|
||||
BrotliStoreHuffmanTree(depth, histogram_length, tree, storage_ix, storage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +457,7 @@ void BrotliBuildAndStoreHuffmanTreeFast(MemoryManager* m,
|
||||
for (l = length; l != 0;) {
|
||||
--l;
|
||||
if (histogram[l]) {
|
||||
if (PREDICT_TRUE(histogram[l] >= count_limit)) {
|
||||
if (BROTLI_PREDICT_TRUE(histogram[l] >= count_limit)) {
|
||||
InitHuffmanTree(node, histogram[l], -1, (int16_t)l);
|
||||
} else {
|
||||
InitHuffmanTree(node, count_limit, -1, (int16_t)l);
|
||||
@@ -548,7 +555,7 @@ void BrotliBuildAndStoreHuffmanTreeFast(MemoryManager* m,
|
||||
/* Complex Huffman Tree */
|
||||
StoreStaticCodeLengthCode(storage_ix, storage);
|
||||
|
||||
/* Actual rle coding. */
|
||||
/* Actual RLE coding. */
|
||||
for (i = 0; i < length;) {
|
||||
const uint8_t value = depth[i];
|
||||
size_t reps = 1;
|
||||
@@ -613,7 +620,7 @@ static void MoveToFrontTransform(const uint32_t* BROTLI_RESTRICT v_in,
|
||||
for (i = 1; i < v_size; ++i) {
|
||||
if (v_in[i] > max_value) max_value = v_in[i];
|
||||
}
|
||||
assert(max_value < 256u);
|
||||
BROTLI_DCHECK(max_value < 256u);
|
||||
for (i = 0; i <= max_value; ++i) {
|
||||
mtf[i] = (uint8_t)i;
|
||||
}
|
||||
@@ -621,7 +628,7 @@ static void MoveToFrontTransform(const uint32_t* BROTLI_RESTRICT v_in,
|
||||
size_t mtf_size = max_value + 1;
|
||||
for (i = 0; i < v_size; ++i) {
|
||||
size_t index = IndexOf(mtf, mtf_size, (uint8_t)v_in[i]);
|
||||
assert(index < mtf_size);
|
||||
BROTLI_DCHECK(index < mtf_size);
|
||||
v_out[i] = (uint32_t)index;
|
||||
MoveToFront(mtf, index);
|
||||
}
|
||||
@@ -653,7 +660,7 @@ static void RunLengthCodeZeros(const size_t in_size,
|
||||
*max_run_length_prefix = max_prefix;
|
||||
*out_size = 0;
|
||||
for (i = 0; i < in_size;) {
|
||||
assert(*out_size <= i);
|
||||
BROTLI_DCHECK(*out_size <= i);
|
||||
if (v[i] != 0) {
|
||||
v[*out_size] = v[i] + *max_run_length_prefix;
|
||||
++i;
|
||||
@@ -723,6 +730,7 @@ static void EncodeContextMap(MemoryManager* m,
|
||||
}
|
||||
}
|
||||
BuildAndStoreHuffmanTree(histogram, num_clusters + max_run_length_prefix,
|
||||
num_clusters + max_run_length_prefix,
|
||||
tree, depths, bits, storage_ix, storage);
|
||||
for (i = 0; i < num_rle_symbols; ++i) {
|
||||
const uint32_t rle_symbol = rle_symbols[i] & kSymbolMask;
|
||||
@@ -782,10 +790,11 @@ static void BuildAndStoreBlockSplitCode(const uint8_t* types,
|
||||
}
|
||||
StoreVarLenUint8(num_types - 1, storage_ix, storage);
|
||||
if (num_types > 1) { /* TODO: else? could StoreBlockSwitch occur? */
|
||||
BuildAndStoreHuffmanTree(&type_histo[0], num_types + 2, tree,
|
||||
BuildAndStoreHuffmanTree(&type_histo[0], num_types + 2, num_types + 2, tree,
|
||||
&code->type_depths[0], &code->type_bits[0],
|
||||
storage_ix, storage);
|
||||
BuildAndStoreHuffmanTree(&length_histo[0], BROTLI_NUM_BLOCK_LEN_SYMBOLS,
|
||||
BROTLI_NUM_BLOCK_LEN_SYMBOLS,
|
||||
tree, &code->length_depths[0],
|
||||
&code->length_bits[0], storage_ix, storage);
|
||||
StoreBlockSwitch(code, lengths[0], types[0], 1, storage_ix, storage);
|
||||
@@ -816,8 +825,8 @@ static void StoreTrivialContextMap(size_t num_types,
|
||||
for (i = context_bits; i < alphabet_size; ++i) {
|
||||
histogram[i] = 1;
|
||||
}
|
||||
BuildAndStoreHuffmanTree(histogram, alphabet_size, tree,
|
||||
depths, bits, storage_ix, storage);
|
||||
BuildAndStoreHuffmanTree(histogram, alphabet_size, alphabet_size,
|
||||
tree, depths, bits, storage_ix, storage);
|
||||
for (i = 0; i < num_types; ++i) {
|
||||
size_t code = (i == 0 ? 0 : i + context_bits - 1);
|
||||
BrotliWriteBits(depths[code], bits[code], storage_ix, storage);
|
||||
@@ -832,7 +841,7 @@ static void StoreTrivialContextMap(size_t num_types,
|
||||
|
||||
/* Manages the encoding of one block category (literal, command or distance). */
|
||||
typedef struct BlockEncoder {
|
||||
size_t alphabet_size_;
|
||||
size_t histogram_length_;
|
||||
size_t num_block_types_;
|
||||
const uint8_t* block_types_; /* Not owned. */
|
||||
const uint32_t* block_lengths_; /* Not owned. */
|
||||
@@ -845,10 +854,10 @@ typedef struct BlockEncoder {
|
||||
uint16_t* bits_;
|
||||
} BlockEncoder;
|
||||
|
||||
static void InitBlockEncoder(BlockEncoder* self, size_t alphabet_size,
|
||||
static void InitBlockEncoder(BlockEncoder* self, size_t histogram_length,
|
||||
size_t num_block_types, const uint8_t* block_types,
|
||||
const uint32_t* block_lengths, const size_t num_blocks) {
|
||||
self->alphabet_size_ = alphabet_size;
|
||||
self->histogram_length_ = histogram_length;
|
||||
self->num_block_types_ = num_block_types;
|
||||
self->block_types_ = block_types;
|
||||
self->block_lengths_ = block_lengths;
|
||||
@@ -884,7 +893,7 @@ static void StoreSymbol(BlockEncoder* self, size_t symbol, size_t* storage_ix,
|
||||
uint32_t block_len = self->block_lengths_[block_ix];
|
||||
uint8_t block_type = self->block_types_[block_ix];
|
||||
self->block_len_ = block_len;
|
||||
self->entropy_ix_ = block_type * self->alphabet_size_;
|
||||
self->entropy_ix_ = block_type * self->histogram_length_;
|
||||
StoreBlockSwitch(&self->block_split_code_, block_len, block_type, 0,
|
||||
storage_ix, storage);
|
||||
}
|
||||
@@ -913,7 +922,7 @@ static void StoreSymbolWithContext(BlockEncoder* self, size_t symbol,
|
||||
--self->block_len_;
|
||||
{
|
||||
size_t histo_ix = context_map[self->entropy_ix_ + context];
|
||||
size_t ix = histo_ix * self->alphabet_size_ + symbol;
|
||||
size_t ix = histo_ix * self->histogram_length_ + symbol;
|
||||
BrotliWriteBits(self->depths_[ix], self->bits_[ix], storage_ix, storage);
|
||||
}
|
||||
}
|
||||
@@ -939,42 +948,38 @@ static void JumpToByteBoundary(size_t* storage_ix, uint8_t* storage) {
|
||||
}
|
||||
|
||||
void BrotliStoreMetaBlock(MemoryManager* m,
|
||||
const uint8_t* input,
|
||||
size_t start_pos,
|
||||
size_t length,
|
||||
size_t mask,
|
||||
uint8_t prev_byte,
|
||||
uint8_t prev_byte2,
|
||||
BROTLI_BOOL is_last,
|
||||
uint32_t num_direct_distance_codes,
|
||||
uint32_t distance_postfix_bits,
|
||||
ContextType literal_context_mode,
|
||||
const Command *commands,
|
||||
size_t n_commands,
|
||||
const MetaBlockSplit* mb,
|
||||
size_t *storage_ix,
|
||||
uint8_t *storage) {
|
||||
const uint8_t* input, size_t start_pos, size_t length, size_t mask,
|
||||
uint8_t prev_byte, uint8_t prev_byte2, BROTLI_BOOL is_last,
|
||||
const BrotliEncoderParams* params, ContextType literal_context_mode,
|
||||
const Command* commands, size_t n_commands, const MetaBlockSplit* mb,
|
||||
size_t* storage_ix, uint8_t* storage) {
|
||||
|
||||
size_t pos = start_pos;
|
||||
size_t i;
|
||||
size_t num_distance_codes =
|
||||
BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_distance_codes +
|
||||
(48u << distance_postfix_bits);
|
||||
uint32_t num_distance_symbols = params->dist.alphabet_size;
|
||||
uint32_t num_effective_distance_symbols = num_distance_symbols;
|
||||
HuffmanTree* tree;
|
||||
ContextLut literal_context_lut = BROTLI_CONTEXT_LUT(literal_context_mode);
|
||||
BlockEncoder literal_enc;
|
||||
BlockEncoder command_enc;
|
||||
BlockEncoder distance_enc;
|
||||
const BrotliDistanceParams* dist = ¶ms->dist;
|
||||
if (params->large_window &&
|
||||
num_effective_distance_symbols > BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS) {
|
||||
num_effective_distance_symbols = BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS;
|
||||
}
|
||||
|
||||
StoreCompressedMetaBlockHeader(is_last, length, storage_ix, storage);
|
||||
|
||||
tree = BROTLI_ALLOC(m, HuffmanTree, MAX_HUFFMAN_TREE_SIZE);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
InitBlockEncoder(&literal_enc, 256, mb->literal_split.num_types,
|
||||
mb->literal_split.types, mb->literal_split.lengths,
|
||||
mb->literal_split.num_blocks);
|
||||
InitBlockEncoder(&literal_enc, BROTLI_NUM_LITERAL_SYMBOLS,
|
||||
mb->literal_split.num_types, mb->literal_split.types,
|
||||
mb->literal_split.lengths, mb->literal_split.num_blocks);
|
||||
InitBlockEncoder(&command_enc, BROTLI_NUM_COMMAND_SYMBOLS,
|
||||
mb->command_split.num_types, mb->command_split.types,
|
||||
mb->command_split.lengths, mb->command_split.num_blocks);
|
||||
InitBlockEncoder(&distance_enc, num_distance_codes,
|
||||
InitBlockEncoder(&distance_enc, num_effective_distance_symbols,
|
||||
mb->distance_split.num_types, mb->distance_split.types,
|
||||
mb->distance_split.lengths, mb->distance_split.num_blocks);
|
||||
|
||||
@@ -983,9 +988,10 @@ void BrotliStoreMetaBlock(MemoryManager* m,
|
||||
BuildAndStoreBlockSwitchEntropyCodes(
|
||||
&distance_enc, tree, storage_ix, storage);
|
||||
|
||||
BrotliWriteBits(2, distance_postfix_bits, storage_ix, storage);
|
||||
BrotliWriteBits(4, num_direct_distance_codes >> distance_postfix_bits,
|
||||
storage_ix, storage);
|
||||
BrotliWriteBits(2, dist->distance_postfix_bits, storage_ix, storage);
|
||||
BrotliWriteBits(
|
||||
4, dist->num_direct_distance_codes >> dist->distance_postfix_bits,
|
||||
storage_ix, storage);
|
||||
for (i = 0; i < mb->literal_split.num_types; ++i) {
|
||||
BrotliWriteBits(2, literal_context_mode, storage_ix, storage);
|
||||
}
|
||||
@@ -1011,13 +1017,16 @@ void BrotliStoreMetaBlock(MemoryManager* m,
|
||||
}
|
||||
|
||||
BuildAndStoreEntropyCodesLiteral(m, &literal_enc, mb->literal_histograms,
|
||||
mb->literal_histograms_size, tree, storage_ix, storage);
|
||||
mb->literal_histograms_size, BROTLI_NUM_LITERAL_SYMBOLS, tree,
|
||||
storage_ix, storage);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
BuildAndStoreEntropyCodesCommand(m, &command_enc, mb->command_histograms,
|
||||
mb->command_histograms_size, tree, storage_ix, storage);
|
||||
mb->command_histograms_size, BROTLI_NUM_COMMAND_SYMBOLS, tree,
|
||||
storage_ix, storage);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
BuildAndStoreEntropyCodesDistance(m, &distance_enc, mb->distance_histograms,
|
||||
mb->distance_histograms_size, tree, storage_ix, storage);
|
||||
mb->distance_histograms_size, num_distance_symbols, tree,
|
||||
storage_ix, storage);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
BROTLI_FREE(m, tree);
|
||||
|
||||
@@ -1035,7 +1044,8 @@ void BrotliStoreMetaBlock(MemoryManager* m,
|
||||
} else {
|
||||
size_t j;
|
||||
for (j = cmd.insert_len_; j != 0; --j) {
|
||||
size_t context = Context(prev_byte, prev_byte2, literal_context_mode);
|
||||
size_t context =
|
||||
BROTLI_CONTEXT(prev_byte, prev_byte2, literal_context_lut);
|
||||
uint8_t literal = input[pos & mask];
|
||||
StoreSymbolWithContext(&literal_enc, literal, context,
|
||||
mb->literal_context_map, storage_ix, storage,
|
||||
@@ -1050,9 +1060,9 @@ void BrotliStoreMetaBlock(MemoryManager* m,
|
||||
prev_byte2 = input[(pos - 2) & mask];
|
||||
prev_byte = input[(pos - 1) & mask];
|
||||
if (cmd.cmd_prefix_ >= 128) {
|
||||
size_t dist_code = cmd.dist_prefix_;
|
||||
uint32_t distnumextra = cmd.dist_extra_ >> 24;
|
||||
uint64_t distextra = cmd.dist_extra_ & 0xffffff;
|
||||
size_t dist_code = cmd.dist_prefix_ & 0x3FF;
|
||||
uint32_t distnumextra = cmd.dist_prefix_ >> 10;
|
||||
uint64_t distextra = cmd.dist_extra_;
|
||||
if (mb->distance_context_map_size == 0) {
|
||||
StoreSymbol(&distance_enc, dist_code, storage_ix, storage);
|
||||
} else {
|
||||
@@ -1076,7 +1086,7 @@ void BrotliStoreMetaBlock(MemoryManager* m,
|
||||
static void BuildHistograms(const uint8_t* input,
|
||||
size_t start_pos,
|
||||
size_t mask,
|
||||
const Command *commands,
|
||||
const Command* commands,
|
||||
size_t n_commands,
|
||||
HistogramLiteral* lit_histo,
|
||||
HistogramCommand* cmd_histo,
|
||||
@@ -1093,7 +1103,7 @@ static void BuildHistograms(const uint8_t* input,
|
||||
}
|
||||
pos += CommandCopyLen(&cmd);
|
||||
if (CommandCopyLen(&cmd) && cmd.cmd_prefix_ >= 128) {
|
||||
HistogramAddDistance(dist_histo, cmd.dist_prefix_);
|
||||
HistogramAddDistance(dist_histo, cmd.dist_prefix_ & 0x3FF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1101,7 +1111,7 @@ static void BuildHistograms(const uint8_t* input,
|
||||
static void StoreDataWithHuffmanCodes(const uint8_t* input,
|
||||
size_t start_pos,
|
||||
size_t mask,
|
||||
const Command *commands,
|
||||
const Command* commands,
|
||||
size_t n_commands,
|
||||
const uint8_t* lit_depth,
|
||||
const uint16_t* lit_bits,
|
||||
@@ -1128,9 +1138,9 @@ static void StoreDataWithHuffmanCodes(const uint8_t* input,
|
||||
}
|
||||
pos += CommandCopyLen(&cmd);
|
||||
if (CommandCopyLen(&cmd) && cmd.cmd_prefix_ >= 128) {
|
||||
const size_t dist_code = cmd.dist_prefix_;
|
||||
const uint32_t distnumextra = cmd.dist_extra_ >> 24;
|
||||
const uint32_t distextra = cmd.dist_extra_ & 0xffffff;
|
||||
const size_t dist_code = cmd.dist_prefix_ & 0x3FF;
|
||||
const uint32_t distnumextra = cmd.dist_prefix_ >> 10;
|
||||
const uint32_t distextra = cmd.dist_extra_;
|
||||
BrotliWriteBits(dist_depth[dist_code], dist_bits[dist_code],
|
||||
storage_ix, storage);
|
||||
BrotliWriteBits(distnumextra, distextra, storage_ix, storage);
|
||||
@@ -1139,25 +1149,21 @@ static void StoreDataWithHuffmanCodes(const uint8_t* input,
|
||||
}
|
||||
|
||||
void BrotliStoreMetaBlockTrivial(MemoryManager* m,
|
||||
const uint8_t* input,
|
||||
size_t start_pos,
|
||||
size_t length,
|
||||
size_t mask,
|
||||
BROTLI_BOOL is_last,
|
||||
const Command *commands,
|
||||
size_t n_commands,
|
||||
size_t *storage_ix,
|
||||
uint8_t *storage) {
|
||||
const uint8_t* input, size_t start_pos, size_t length, size_t mask,
|
||||
BROTLI_BOOL is_last, const BrotliEncoderParams* params,
|
||||
const Command* commands, size_t n_commands,
|
||||
size_t* storage_ix, uint8_t* storage) {
|
||||
HistogramLiteral lit_histo;
|
||||
HistogramCommand cmd_histo;
|
||||
HistogramDistance dist_histo;
|
||||
uint8_t lit_depth[256];
|
||||
uint16_t lit_bits[256];
|
||||
uint8_t lit_depth[BROTLI_NUM_LITERAL_SYMBOLS];
|
||||
uint16_t lit_bits[BROTLI_NUM_LITERAL_SYMBOLS];
|
||||
uint8_t cmd_depth[BROTLI_NUM_COMMAND_SYMBOLS];
|
||||
uint16_t cmd_bits[BROTLI_NUM_COMMAND_SYMBOLS];
|
||||
uint8_t dist_depth[64];
|
||||
uint16_t dist_bits[64];
|
||||
uint8_t dist_depth[MAX_SIMPLE_DISTANCE_ALPHABET_SIZE];
|
||||
uint16_t dist_bits[MAX_SIMPLE_DISTANCE_ALPHABET_SIZE];
|
||||
HuffmanTree* tree;
|
||||
uint32_t num_distance_symbols = params->dist.alphabet_size;
|
||||
|
||||
StoreCompressedMetaBlockHeader(is_last, length, storage_ix, storage);
|
||||
|
||||
@@ -1172,13 +1178,16 @@ void BrotliStoreMetaBlockTrivial(MemoryManager* m,
|
||||
|
||||
tree = BROTLI_ALLOC(m, HuffmanTree, MAX_HUFFMAN_TREE_SIZE);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
BuildAndStoreHuffmanTree(lit_histo.data_, 256, tree,
|
||||
BuildAndStoreHuffmanTree(lit_histo.data_, BROTLI_NUM_LITERAL_SYMBOLS,
|
||||
BROTLI_NUM_LITERAL_SYMBOLS, tree,
|
||||
lit_depth, lit_bits,
|
||||
storage_ix, storage);
|
||||
BuildAndStoreHuffmanTree(cmd_histo.data_, BROTLI_NUM_COMMAND_SYMBOLS, tree,
|
||||
BuildAndStoreHuffmanTree(cmd_histo.data_, BROTLI_NUM_COMMAND_SYMBOLS,
|
||||
BROTLI_NUM_COMMAND_SYMBOLS, tree,
|
||||
cmd_depth, cmd_bits,
|
||||
storage_ix, storage);
|
||||
BuildAndStoreHuffmanTree(dist_histo.data_, 64, tree,
|
||||
BuildAndStoreHuffmanTree(dist_histo.data_, MAX_SIMPLE_DISTANCE_ALPHABET_SIZE,
|
||||
num_distance_symbols, tree,
|
||||
dist_depth, dist_bits,
|
||||
storage_ix, storage);
|
||||
BROTLI_FREE(m, tree);
|
||||
@@ -1193,15 +1202,14 @@ void BrotliStoreMetaBlockTrivial(MemoryManager* m,
|
||||
}
|
||||
|
||||
void BrotliStoreMetaBlockFast(MemoryManager* m,
|
||||
const uint8_t* input,
|
||||
size_t start_pos,
|
||||
size_t length,
|
||||
size_t mask,
|
||||
BROTLI_BOOL is_last,
|
||||
const Command *commands,
|
||||
size_t n_commands,
|
||||
size_t *storage_ix,
|
||||
uint8_t *storage) {
|
||||
const uint8_t* input, size_t start_pos, size_t length, size_t mask,
|
||||
BROTLI_BOOL is_last, const BrotliEncoderParams* params,
|
||||
const Command* commands, size_t n_commands,
|
||||
size_t* storage_ix, uint8_t* storage) {
|
||||
uint32_t num_distance_symbols = params->dist.alphabet_size;
|
||||
uint32_t distance_alphabet_bits =
|
||||
Log2FloorNonZero(num_distance_symbols - 1) + 1;
|
||||
|
||||
StoreCompressedMetaBlockHeader(is_last, length, storage_ix, storage);
|
||||
|
||||
BrotliWriteBits(13, 0, storage_ix, storage);
|
||||
@@ -1245,8 +1253,8 @@ void BrotliStoreMetaBlockFast(MemoryManager* m,
|
||||
uint16_t lit_bits[BROTLI_NUM_LITERAL_SYMBOLS];
|
||||
uint8_t cmd_depth[BROTLI_NUM_COMMAND_SYMBOLS];
|
||||
uint16_t cmd_bits[BROTLI_NUM_COMMAND_SYMBOLS];
|
||||
uint8_t dist_depth[64];
|
||||
uint16_t dist_bits[64];
|
||||
uint8_t dist_depth[MAX_SIMPLE_DISTANCE_ALPHABET_SIZE];
|
||||
uint16_t dist_bits[MAX_SIMPLE_DISTANCE_ALPHABET_SIZE];
|
||||
HistogramClearLiteral(&lit_histo);
|
||||
HistogramClearCommand(&cmd_histo);
|
||||
HistogramClearDistance(&dist_histo);
|
||||
@@ -1266,7 +1274,8 @@ void BrotliStoreMetaBlockFast(MemoryManager* m,
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
BrotliBuildAndStoreHuffmanTreeFast(m, dist_histo.data_,
|
||||
dist_histo.total_count_,
|
||||
/* max_bits = */ 6,
|
||||
/* max_bits = */
|
||||
distance_alphabet_bits,
|
||||
dist_depth, dist_bits,
|
||||
storage_ix, storage);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
@@ -1285,11 +1294,11 @@ void BrotliStoreMetaBlockFast(MemoryManager* m,
|
||||
/* This is for storing uncompressed blocks (simple raw storage of
|
||||
bytes-as-bytes). */
|
||||
void BrotliStoreUncompressedMetaBlock(BROTLI_BOOL is_final_block,
|
||||
const uint8_t * BROTLI_RESTRICT input,
|
||||
const uint8_t* BROTLI_RESTRICT input,
|
||||
size_t position, size_t mask,
|
||||
size_t len,
|
||||
size_t * BROTLI_RESTRICT storage_ix,
|
||||
uint8_t * BROTLI_RESTRICT storage) {
|
||||
size_t* BROTLI_RESTRICT storage_ix,
|
||||
uint8_t* BROTLI_RESTRICT storage) {
|
||||
size_t masked_pos = position & mask;
|
||||
BrotliStoreUncompressedMetaBlockHeader(len, storage_ix, storage);
|
||||
JumpToByteBoundary(storage_ix, storage);
|
||||
@@ -1317,18 +1326,6 @@ void BrotliStoreUncompressedMetaBlock(BROTLI_BOOL is_final_block,
|
||||
}
|
||||
}
|
||||
|
||||
void BrotliStoreSyncMetaBlock(size_t* BROTLI_RESTRICT storage_ix,
|
||||
uint8_t* BROTLI_RESTRICT storage) {
|
||||
/* Empty metadata meta-block bit pattern:
|
||||
1 bit: is_last (0)
|
||||
2 bits: num nibbles (3)
|
||||
1 bit: reserved (0)
|
||||
2 bits: metadata length bytes (0) */
|
||||
BrotliWriteBits(6, 6, storage_ix, storage);
|
||||
JumpToByteBoundary(storage_ix, storage);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user