Added HuffmanTreeCode Struct for tree codes.

To represent tree codes (depth and bits array).

Change-Id: I87650886384dd10d95b16ab808dfd3bb573172bc
This commit is contained in:
Vikas Arora
2012-05-14 13:49:45 +05:30
parent 41d8049451
commit 8b85d01c45
3 changed files with 79 additions and 66 deletions

View File

@ -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]++);
}
}

View File

@ -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)
}