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,
uint8_t* lengths,
uint16_t* symbols) {
@ -597,7 +572,8 @@ static void StoreHuffmanTreeToBitMask(
}
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 ok = 0;
int count = 0;
@ -844,24 +820,17 @@ static int EncodeImageInternal(VP8LBitWriter* const bw,
// Store Huffman codes.
for (i = 0; i < histogram_image_size; ++i) {
int k;
int literal_lengths_size;
uint8_t* literal_lengths;
// TODO(vikasa): Evaluate and remove the call to PackLiteralBitLengths.
if (!PackLiteralBitLengths(bit_lengths[5 * i], cache_bits, use_color_cache,
&literal_lengths_size, &literal_lengths)) {
goto Error;
}
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])) {
for (k = 0; k < 5; ++k) {
const uint8_t* const cur_bit_lengths = bit_lengths[5 * i + k];
const int cur_bit_lengths_size = (k == 0) ?
256 + kLengthCodes + (1 << cache_bits) :
bit_lengths_sizes[5 * i + k];
if (!StoreHuffmanCode(bw, cur_bit_lengths, cur_bit_lengths_size)) {
goto Error;
}
}
}
// Free combined histograms.
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* num_symbols,
uint8_t* tree,

View File

@ -34,10 +34,9 @@ extern "C" {
int VP8LCreateHuffmanTree(const int* data, const int length,
const int tree_limit, uint8_t* depth);
// Write a huffman tree from bit depths into the deflate representation
// of a Huffman tree. In deflate, the generated Huffman tree is to be
// Write a huffman tree from bit depths. The generated Huffman tree is
// 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,
uint8_t* tree,
uint8_t* extra_bits_data);