Get rid of PackLiteralBitLengths()

[and in turn a malloc]. Also, a few related const fixes.

Change-Id: I229519b1c34d41c78d9ad2403f1e25feab3c9d93
This commit is contained in:
Urvang Joshi 2012-04-13 07:14:16 +00:00 committed by James Zern
parent d673b6b9a0
commit 352a4f49ab
3 changed files with 12 additions and 44 deletions

View File

@ -507,31 +507,6 @@ static void ShiftHistogramImage(uint32_t* image , int image_size) {
} }
} }
static int PackLiteralBitLengths(const uint8_t* bit_lengths,
int cache_bits, int use_color_cache,
int* new_length_size,
uint8_t** new_lengths) {
int i;
int num_codes = 256;
const int cache_size = 1 << cache_bits;
*new_length_size = 256 + kLengthCodes;
if (use_color_cache) {
*new_length_size += cache_size;
}
*new_lengths = (uint8_t*)malloc(*new_length_size);
if (*new_lengths == NULL) {
return 0;
}
num_codes += kLengthCodes;
if (use_color_cache) {
num_codes += cache_size;
}
for (i = 0; i < num_codes; ++i) {
(*new_lengths)[i] = bit_lengths[i];
}
return 1;
}
static void ClearHuffmanTreeIfOnlyOneSymbol(const int num_symbols, static void ClearHuffmanTreeIfOnlyOneSymbol(const int num_symbols,
uint8_t* lengths, uint8_t* lengths,
uint16_t* symbols) { uint16_t* symbols) {
@ -597,7 +572,8 @@ static void StoreHuffmanTreeToBitMask(
} }
static int StoreHuffmanCode(VP8LBitWriter* const bw, static int StoreHuffmanCode(VP8LBitWriter* const bw,
uint8_t* bit_lengths, int bit_lengths_size) { const uint8_t* const bit_lengths,
int bit_lengths_size) {
int i; int i;
int ok = 0; int ok = 0;
int count = 0; int count = 0;
@ -844,24 +820,17 @@ static int EncodeImageInternal(VP8LBitWriter* const bw,
// Store Huffman codes. // Store Huffman codes.
for (i = 0; i < histogram_image_size; ++i) { for (i = 0; i < histogram_image_size; ++i) {
int k; int k;
int literal_lengths_size; for (k = 0; k < 5; ++k) {
uint8_t* literal_lengths; const uint8_t* const cur_bit_lengths = bit_lengths[5 * i + k];
// TODO(vikasa): Evaluate and remove the call to PackLiteralBitLengths. const int cur_bit_lengths_size = (k == 0) ?
if (!PackLiteralBitLengths(bit_lengths[5 * i], cache_bits, use_color_cache, 256 + kLengthCodes + (1 << cache_bits) :
&literal_lengths_size, &literal_lengths)) { bit_lengths_sizes[5 * i + k];
goto Error; if (!StoreHuffmanCode(bw, cur_bit_lengths, cur_bit_lengths_size)) {
}
if (!StoreHuffmanCode(bw, literal_lengths, literal_lengths_size)) {
goto Error;
}
free(literal_lengths);
for (k = 1; k < 5; ++k) {
if (!StoreHuffmanCode(bw, bit_lengths[5 * i + k],
bit_lengths_sizes[5 * i + k])) {
goto Error; goto Error;
} }
} }
} }
// Free combined histograms. // Free combined histograms.
DeleteHistograms(histogram_image_size, histogram_image); DeleteHistograms(histogram_image_size, histogram_image);

View File

@ -241,7 +241,7 @@ static void WriteHuffmanTreeRepetitionsZeros(
} }
} }
void VP8LCreateCompressedHuffmanTree(const uint8_t* depth, void VP8LCreateCompressedHuffmanTree(const uint8_t* const depth,
int depth_size, int depth_size,
int* num_symbols, int* num_symbols,
uint8_t* tree, uint8_t* tree,

View File

@ -34,10 +34,9 @@ extern "C" {
int VP8LCreateHuffmanTree(const int* data, const int length, int VP8LCreateHuffmanTree(const int* data, const int length,
const int tree_limit, uint8_t* depth); const int tree_limit, uint8_t* depth);
// Write a huffman tree from bit depths into the deflate representation // Write a huffman tree from bit depths. The generated Huffman tree is
// of a Huffman tree. In deflate, the generated Huffman tree is to be
// compressed once more using a Huffman tree. // compressed once more using a Huffman tree.
void VP8LCreateCompressedHuffmanTree(const uint8_t* depth, int len, void VP8LCreateCompressedHuffmanTree(const uint8_t* const depth, int len,
int* num_symbols, int* num_symbols,
uint8_t* tree, uint8_t* tree,
uint8_t* extra_bits_data); uint8_t* extra_bits_data);