mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 22:28:22 +01:00
address cosmetic comments from patch #71380
Change-Id: Iaba301b9e77aa4febe0efe1e6016fab42d5589f3
This commit is contained in:
parent
f75dfbf23d
commit
77d4c7e337
@ -78,7 +78,8 @@ static const uint8_t kCodeToPlane[CODE_TO_PLANE_CODES] = {
|
|||||||
// respectively. Size of green alphabet depends on color cache size and is equal
|
// respectively. Size of green alphabet depends on color cache size and is equal
|
||||||
// to 256 (green component values) + 24 (length prefix values)
|
// to 256 (green component values) + 24 (length prefix values)
|
||||||
// + color_cache_size (between 0 and 2048).
|
// + color_cache_size (between 0 and 2048).
|
||||||
// All values computed for 8-bit first level lookup with tests/tools/enough.cc.
|
// All values computed for 8-bit first level lookup with Mark Adler's tool:
|
||||||
|
// http://www.hdfgroup.org/ftp/lib-external/zlib/zlib-1.2.5/examples/enough.c
|
||||||
#define FIXED_TABLE_SIZE (630 * 3 + 410)
|
#define FIXED_TABLE_SIZE (630 * 3 + 410)
|
||||||
static const int kTableSize[12] = {
|
static const int kTableSize[12] = {
|
||||||
FIXED_TABLE_SIZE + 654,
|
FIXED_TABLE_SIZE + 654,
|
||||||
@ -203,15 +204,13 @@ static int ReadHuffmanCodeLengths(
|
|||||||
if (!VP8LBuildHuffmanTable(table, LENGTHS_TABLE_BITS,
|
if (!VP8LBuildHuffmanTable(table, LENGTHS_TABLE_BITS,
|
||||||
code_length_code_lengths,
|
code_length_code_lengths,
|
||||||
NUM_CODE_LENGTH_CODES)) {
|
NUM_CODE_LENGTH_CODES)) {
|
||||||
dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
|
goto End;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VP8LReadBits(br, 1)) { // use length
|
if (VP8LReadBits(br, 1)) { // use length
|
||||||
const int length_nbits = 2 + 2 * VP8LReadBits(br, 3);
|
const int length_nbits = 2 + 2 * VP8LReadBits(br, 3);
|
||||||
max_symbol = 2 + VP8LReadBits(br, length_nbits);
|
max_symbol = 2 + VP8LReadBits(br, length_nbits);
|
||||||
if (max_symbol > num_symbols) {
|
if (max_symbol > num_symbols) {
|
||||||
dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
|
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -220,11 +219,11 @@ static int ReadHuffmanCodeLengths(
|
|||||||
|
|
||||||
symbol = 0;
|
symbol = 0;
|
||||||
while (symbol < num_symbols) {
|
while (symbol < num_symbols) {
|
||||||
const HuffmanCode* p = table;
|
const HuffmanCode* p;
|
||||||
int code_len;
|
int code_len;
|
||||||
if (max_symbol-- == 0) break;
|
if (max_symbol-- == 0) break;
|
||||||
VP8LFillBitWindow(br);
|
VP8LFillBitWindow(br);
|
||||||
p += VP8LPrefetchBits(br) & LENGTHS_TABLE_MASK;
|
p = &table[VP8LPrefetchBits(br) & LENGTHS_TABLE_MASK];
|
||||||
VP8LSetBitPos(br, br->bit_pos_ + p->bits);
|
VP8LSetBitPos(br, br->bit_pos_ + p->bits);
|
||||||
code_len = p->value;
|
code_len = p->value;
|
||||||
if (code_len < kCodeLengthLiterals) {
|
if (code_len < kCodeLengthLiterals) {
|
||||||
@ -237,7 +236,6 @@ static int ReadHuffmanCodeLengths(
|
|||||||
const int repeat_offset = kCodeLengthRepeatOffsets[slot];
|
const int repeat_offset = kCodeLengthRepeatOffsets[slot];
|
||||||
int repeat = VP8LReadBits(br, extra_bits) + repeat_offset;
|
int repeat = VP8LReadBits(br, extra_bits) + repeat_offset;
|
||||||
if (symbol + repeat > num_symbols) {
|
if (symbol + repeat > num_symbols) {
|
||||||
dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
|
|
||||||
goto End;
|
goto End;
|
||||||
} else {
|
} else {
|
||||||
const int length = use_prev ? prev_code_len : 0;
|
const int length = use_prev ? prev_code_len : 0;
|
||||||
@ -248,6 +246,7 @@ static int ReadHuffmanCodeLengths(
|
|||||||
ok = 1;
|
ok = 1;
|
||||||
|
|
||||||
End:
|
End:
|
||||||
|
dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +347,7 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
huffman_tables = (HuffmanCode*)WebPSafeMalloc(num_htree_groups * table_size,
|
huffman_tables = (HuffmanCode*)WebPSafeMalloc(num_htree_groups * table_size,
|
||||||
sizeof(HuffmanCode));
|
sizeof(*huffman_tables));
|
||||||
htree_groups = VP8LHtreeGroupsNew(num_htree_groups);
|
htree_groups = VP8LHtreeGroupsNew(num_htree_groups);
|
||||||
code_lengths = (int*)WebPSafeCalloc((uint64_t)max_alphabet_size,
|
code_lengths = (int*)WebPSafeCalloc((uint64_t)max_alphabet_size,
|
||||||
sizeof(*code_lengths));
|
sizeof(*code_lengths));
|
||||||
|
@ -76,17 +76,16 @@ static WEBP_INLINE int NextTableBitSize(const int* const count,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
const int* const code_lengths,
|
const int code_lengths[], int code_lengths_size) {
|
||||||
int code_lengths_size) {
|
HuffmanCode* table = root_table; // next available space in table
|
||||||
HuffmanCode* table; // next available space in table
|
int total_size = 1 << root_bits; // total size root table + 2nd level table
|
||||||
int len; // current code length
|
int* sorted = NULL; // symbols sorted by code length
|
||||||
int symbol; // symbol index in original or sorted table
|
int len; // current code length
|
||||||
int total_size; // sum of root table size and 2nd level table sizes
|
int symbol; // symbol index in original or sorted table
|
||||||
int* sorted = NULL; // symbols sorted by code length
|
// number of codes of each length:
|
||||||
int count[MAX_ALLOWED_CODE_LENGTH + 1] = { 0 };
|
int count[MAX_ALLOWED_CODE_LENGTH + 1] = { 0 };
|
||||||
// number of codes of each length
|
// offsets in sorted table for each length:
|
||||||
int offset[MAX_ALLOWED_CODE_LENGTH + 1];
|
int offset[MAX_ALLOWED_CODE_LENGTH + 1];
|
||||||
// offsets in sorted table for each length
|
|
||||||
|
|
||||||
assert(code_lengths_size != 0);
|
assert(code_lengths_size != 0);
|
||||||
assert(code_lengths != NULL);
|
assert(code_lengths != NULL);
|
||||||
@ -128,9 +127,6 @@ int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table = root_table;
|
|
||||||
total_size = 1 << root_bits;
|
|
||||||
|
|
||||||
// Special case code with only one value.
|
// Special case code with only one value.
|
||||||
if (offset[MAX_ALLOWED_CODE_LENGTH] == 1) {
|
if (offset[MAX_ALLOWED_CODE_LENGTH] == 1) {
|
||||||
HuffmanCode code;
|
HuffmanCode code;
|
||||||
|
@ -53,8 +53,7 @@ void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups);
|
|||||||
// Returns built table size or 0 in case of error (invalid tree or
|
// Returns built table size or 0 in case of error (invalid tree or
|
||||||
// memory error).
|
// memory error).
|
||||||
int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
||||||
const int* const code_lengths,
|
const int code_lengths[], int code_lengths_size);
|
||||||
int code_lengths_size);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
Loading…
Reference in New Issue
Block a user