mirror of
https://github.com/google/brotli.git
synced 2024-11-21 19:20:09 +00:00
Fix name collisions with libwebp.
Prefix all externally visible function names with Brotli and make all other functions static.
This commit is contained in:
parent
8f30907d0f
commit
e0346c8262
25
dec/decode.c
25
dec/decode.c
@ -141,7 +141,7 @@ static int ReadHuffmanCodeLengths(
|
||||
int prev_code_len = kDefaultCodeLength;
|
||||
HuffmanTree tree;
|
||||
|
||||
if (!HuffmanTreeBuildImplicit(&tree, code_length_code_lengths,
|
||||
if (!BrotliHuffmanTreeBuildImplicit(&tree, code_length_code_lengths,
|
||||
CODE_LENGTH_CODES)) {
|
||||
printf("[ReadHuffmanCodeLengths] Building code length tree failed: ");
|
||||
PrintIntVector(code_length_code_lengths, CODE_LENGTH_CODES);
|
||||
@ -199,7 +199,7 @@ static int ReadHuffmanCodeLengths(
|
||||
ok = 1;
|
||||
|
||||
End:
|
||||
HuffmanTreeRelease(&tree);
|
||||
BrotliHuffmanTreeRelease(&tree);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ static int ReadHuffmanCode(int alphabet_size,
|
||||
BROTLI_LOG_UINT(first_symbol_len_code);
|
||||
BROTLI_LOG_UINT(symbols[0]);
|
||||
BROTLI_LOG_UINT(symbols[1]);
|
||||
ok = HuffmanTreeBuildExplicit(tree, code_lengths, codes, symbols,
|
||||
ok = BrotliHuffmanTreeBuildExplicit(tree, code_lengths, codes, symbols,
|
||||
alphabet_size, num_symbols);
|
||||
if (!ok) {
|
||||
printf("[ReadHuffmanCode] HuffmanTreeBuildExplicit failed: ");
|
||||
@ -312,7 +312,7 @@ static int ReadHuffmanCode(int alphabet_size,
|
||||
code_lengths, br) &&
|
||||
RepairHuffmanCodeLengths(alphabet_size, code_lengths);
|
||||
if (ok) {
|
||||
ok = HuffmanTreeBuildImplicit(tree, code_lengths, alphabet_size);
|
||||
ok = BrotliHuffmanTreeBuildImplicit(tree, code_lengths, alphabet_size);
|
||||
if (!ok) {
|
||||
printf("[ReadHuffmanCode] HuffmanTreeBuildImplicit failed: ");
|
||||
PrintIntVector(code_lengths, alphabet_size);
|
||||
@ -422,22 +422,23 @@ typedef struct {
|
||||
HuffmanTree* htrees;
|
||||
} HuffmanTreeGroup;
|
||||
|
||||
void HuffmanTreeGroupInit(HuffmanTreeGroup* group, int alphabet_size,
|
||||
static void HuffmanTreeGroupInit(HuffmanTreeGroup* group, int alphabet_size,
|
||||
int ntrees) {
|
||||
group->alphabet_size = alphabet_size;
|
||||
group->num_htrees = ntrees;
|
||||
group->htrees = (HuffmanTree*)malloc(sizeof(HuffmanTree) * ntrees);
|
||||
}
|
||||
|
||||
void HuffmanTreeGroupRelease(HuffmanTreeGroup* group) {
|
||||
static void HuffmanTreeGroupRelease(HuffmanTreeGroup* group) {
|
||||
int i;
|
||||
for (i = 0; i < group->num_htrees; ++i) {
|
||||
HuffmanTreeRelease(&group->htrees[i]);
|
||||
BrotliHuffmanTreeRelease(&group->htrees[i]);
|
||||
}
|
||||
free(group->htrees);
|
||||
}
|
||||
|
||||
int HuffmanTreeGroupDecode(HuffmanTreeGroup* group, BrotliBitReader* br) {
|
||||
static int HuffmanTreeGroupDecode(HuffmanTreeGroup* group,
|
||||
BrotliBitReader* br) {
|
||||
int i;
|
||||
for (i = 0; i < group->num_htrees; ++i) {
|
||||
ReadHuffmanCode(group->alphabet_size, &group->htrees[i], br);
|
||||
@ -445,7 +446,7 @@ int HuffmanTreeGroupDecode(HuffmanTreeGroup* group, BrotliBitReader* br) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DecodeContextMap(int num_block_types,
|
||||
static int DecodeContextMap(int num_block_types,
|
||||
int stream_type,
|
||||
int* context_mode,
|
||||
int* contexts_per_block,
|
||||
@ -522,7 +523,7 @@ int DecodeContextMap(int num_block_types,
|
||||
(*context_map)[i] = ReadSymbol(&tree_index_htree, br);
|
||||
}
|
||||
}
|
||||
HuffmanTreeRelease(&tree_index_htree);
|
||||
BrotliHuffmanTreeRelease(&tree_index_htree);
|
||||
if (BrotliReadBits(br, 1)) {
|
||||
InverseMoveToFrontTransform(*context_map, context_map_size);
|
||||
}
|
||||
@ -775,8 +776,8 @@ int BrotliDecompressBuffer(size_t encoded_size,
|
||||
free(dist_context_map);
|
||||
for (i = 0; i < 3; ++i) {
|
||||
HuffmanTreeGroupRelease(&hgroup[i]);
|
||||
HuffmanTreeRelease(&block_type_trees[i]);
|
||||
HuffmanTreeRelease(&block_len_trees[i]);
|
||||
BrotliHuffmanTreeRelease(&block_type_trees[i]);
|
||||
BrotliHuffmanTreeRelease(&block_len_trees[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ static int TreeInit(HuffmanTree* const tree, int num_leaves) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void HuffmanTreeRelease(HuffmanTree* const tree) {
|
||||
void BrotliHuffmanTreeRelease(HuffmanTree* const tree) {
|
||||
if (tree != NULL) {
|
||||
free(tree->root_);
|
||||
tree->root_ = NULL;
|
||||
@ -81,8 +81,12 @@ void HuffmanTreeRelease(HuffmanTree* const tree) {
|
||||
}
|
||||
}
|
||||
|
||||
int HuffmanCodeLengthsToCodes(const int* const code_lengths,
|
||||
int code_lengths_size, int* const huff_codes) {
|
||||
// Utility: converts Huffman code lengths to corresponding Huffman codes.
|
||||
// 'huff_codes' should be pre-allocated.
|
||||
// Returns false in case of error (memory allocation, invalid codes).
|
||||
static int HuffmanCodeLengthsToCodes(const int* const code_lengths,
|
||||
int code_lengths_size,
|
||||
int* const huff_codes) {
|
||||
int symbol;
|
||||
int code_len;
|
||||
int code_length_hist[MAX_ALLOWED_CODE_LENGTH + 1] = { 0 };
|
||||
@ -201,7 +205,7 @@ static int TreeAddSymbol(HuffmanTree* const tree,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int HuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
int BrotliHuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
const int* const code_lengths,
|
||||
int code_lengths_size) {
|
||||
int symbol;
|
||||
@ -227,7 +231,7 @@ int HuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
if (num_symbols == 1) { // Trivial case.
|
||||
const int max_symbol = code_lengths_size;
|
||||
if (root_symbol < 0 || root_symbol >= max_symbol) {
|
||||
HuffmanTreeRelease(tree);
|
||||
BrotliHuffmanTreeRelease(tree);
|
||||
return 0;
|
||||
}
|
||||
return TreeAddSymbol(tree, root_symbol, 0, 0);
|
||||
@ -255,15 +259,16 @@ int HuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
End:
|
||||
free(codes);
|
||||
ok = ok && IsFull(tree);
|
||||
if (!ok) HuffmanTreeRelease(tree);
|
||||
if (!ok) BrotliHuffmanTreeRelease(tree);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
int HuffmanTreeBuildExplicit(HuffmanTree* const tree,
|
||||
int BrotliHuffmanTreeBuildExplicit(HuffmanTree* const tree,
|
||||
const int* const code_lengths,
|
||||
const int* const codes,
|
||||
const int* const symbols, int max_symbol,
|
||||
const int* const symbols,
|
||||
int max_symbol,
|
||||
int num_symbols) {
|
||||
int ok = 0;
|
||||
int i;
|
||||
@ -290,7 +295,7 @@ int HuffmanTreeBuildExplicit(HuffmanTree* const tree,
|
||||
ok = 1;
|
||||
End:
|
||||
ok = ok && IsFull(tree);
|
||||
if (!ok) HuffmanTreeRelease(tree);
|
||||
if (!ok) BrotliHuffmanTreeRelease(tree);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -60,30 +60,24 @@ static BROTLI_INLINE const HuffmanTreeNode* HuffmanTreeNextNode(
|
||||
|
||||
// Releases the nodes of the Huffman tree.
|
||||
// Note: It does NOT free 'tree' itself.
|
||||
void HuffmanTreeRelease(HuffmanTree* const tree);
|
||||
void BrotliHuffmanTreeRelease(HuffmanTree* const tree);
|
||||
|
||||
// Builds Huffman tree assuming code lengths are implicitly in symbol order.
|
||||
// Returns false in case of error (invalid tree or memory error).
|
||||
int HuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
int BrotliHuffmanTreeBuildImplicit(HuffmanTree* const tree,
|
||||
const int* const code_lengths,
|
||||
int code_lengths_size);
|
||||
|
||||
// Build a Huffman tree with explicitly given lists of code lengths, codes
|
||||
// and symbols. Verifies that all symbols added are smaller than max_symbol.
|
||||
// Returns false in case of an invalid symbol, invalid tree or memory error.
|
||||
int HuffmanTreeBuildExplicit(HuffmanTree* const tree,
|
||||
int BrotliHuffmanTreeBuildExplicit(HuffmanTree* const tree,
|
||||
const int* const code_lengths,
|
||||
const int* const codes,
|
||||
const int* const symbols, int max_symbol,
|
||||
const int* const symbols,
|
||||
int max_symbol,
|
||||
int num_symbols);
|
||||
|
||||
// Utility: converts Huffman code lengths to corresponding Huffman codes.
|
||||
// 'huff_codes' should be pre-allocated.
|
||||
// Returns false in case of error (memory allocation, invalid codes).
|
||||
int HuffmanCodeLengthsToCodes(const int* const code_lengths,
|
||||
int code_lengths_size, int* const huff_codes);
|
||||
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user