mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
Added HuffmanTreeCode Struct for tree codes.
To represent tree codes (depth and bits array). Change-Id: I87650886384dd10d95b16ab808dfd3bb573172bc
This commit is contained in:
@ -282,16 +282,19 @@ static uint32_t ReverseBits(int num_bits, uint32_t bits) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
void VP8LConvertBitDepthsToSymbols(const uint8_t* const depth,
|
||||
int len,
|
||||
uint16_t* const bits) {
|
||||
void VP8LConvertBitDepthsToSymbols(HuffmanTreeCode* const tree) {
|
||||
// 0 bit-depth means that the symbol does not exist.
|
||||
int i;
|
||||
int len;
|
||||
uint32_t next_code[MAX_BITS];
|
||||
int depth_count[MAX_BITS] = { 0 };
|
||||
|
||||
assert(tree != NULL);
|
||||
len = tree->num_symbols;
|
||||
for (i = 0; i < len; ++i) {
|
||||
assert(depth[i] < MAX_BITS);
|
||||
++depth_count[depth[i]];
|
||||
const int code_length = tree->code_lengths[i];
|
||||
assert(code_length < MAX_BITS);
|
||||
++depth_count[code_length];
|
||||
}
|
||||
depth_count[0] = 0; // ignore unused symbol
|
||||
next_code[0] = 0;
|
||||
@ -303,7 +306,8 @@ void VP8LConvertBitDepthsToSymbols(const uint8_t* const depth,
|
||||
}
|
||||
}
|
||||
for (i = 0; i < len; ++i) {
|
||||
bits[i] = ReverseBits(depth[i], next_code[depth[i]]++);
|
||||
const int code_length = tree->code_lengths[i];
|
||||
tree->codes[i] = ReverseBits(code_length, next_code[code_length]++);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,9 +40,15 @@ typedef struct {
|
||||
int VP8LCreateCompressedHuffmanTree(const uint8_t* const depth, int len,
|
||||
HuffmanTreeToken* tokens, int max_tokens);
|
||||
|
||||
// Struct to represent the tree codes (depth and bits array).
|
||||
typedef struct {
|
||||
int num_symbols; // Number of symbols.
|
||||
uint8_t* code_lengths; // Code lengths of the symbols.
|
||||
uint16_t* codes; // Symbol Codes.
|
||||
} HuffmanTreeCode;
|
||||
|
||||
// Get the actual bit values for a tree of bit depths.
|
||||
void VP8LConvertBitDepthsToSymbols(const uint8_t* const depth, int len,
|
||||
uint16_t* const bits);
|
||||
void VP8LConvertBitDepthsToSymbols(HuffmanTreeCode* const tree);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
|
Reference in New Issue
Block a user