mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-28 14:38:21 +01:00
VP8LEnc: remove use of BitsLog2Ceiling()
was only used once. Better fall back for Log2Floor. Change-Id: Ibcc26505440971bffe62ba6aca3d179ca85791d4
This commit is contained in:
parent
ec5036e475
commit
28c37ebd5a
@ -93,14 +93,6 @@ static WEBP_INLINE float VP8LFastSLog2(uint32_t v) {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// PrefixEncode()
|
// PrefixEncode()
|
||||||
|
|
||||||
static WEBP_INLINE int VP8LBitsLog2Ceiling(uint32_t n) {
|
|
||||||
const int log_floor = BitsLog2Floor(n);
|
|
||||||
if (n == (n & ~(n - 1))) { // zero or a power of two.
|
|
||||||
return log_floor;
|
|
||||||
}
|
|
||||||
return log_floor + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Splitting of distance and length codes into prefixes and
|
// Splitting of distance and length codes into prefixes and
|
||||||
// extra bits. The prefixes are encoded with an entropy code
|
// extra bits. The prefixes are encoded with an entropy code
|
||||||
// while the extra bits are stored just as normal bits.
|
// while the extra bits are stored just as normal bits.
|
||||||
|
@ -600,12 +600,17 @@ static void StoreFullHuffmanCode(VP8LBitWriter* const bw,
|
|||||||
length = write_trimmed_length ? trimmed_length : num_tokens;
|
length = write_trimmed_length ? trimmed_length : num_tokens;
|
||||||
VP8LPutBits(bw, write_trimmed_length, 1);
|
VP8LPutBits(bw, write_trimmed_length, 1);
|
||||||
if (write_trimmed_length) {
|
if (write_trimmed_length) {
|
||||||
const int nbits = VP8LBitsLog2Ceiling(trimmed_length - 1);
|
if (trimmed_length == 2) {
|
||||||
const int nbitpairs = (nbits == 0) ? 1 : (nbits + 1) / 2;
|
VP8LPutBits(bw, 0, 3 + 2); // nbitpairs=1, trimmed_length=2
|
||||||
|
} else {
|
||||||
|
const int nbits = BitsLog2Floor(trimmed_length - 2);
|
||||||
|
const int nbitpairs = nbits / 2 + 1;
|
||||||
|
assert(trimmed_length > 2);
|
||||||
|
assert(nbitpairs - 1 < 8);
|
||||||
VP8LPutBits(bw, nbitpairs - 1, 3);
|
VP8LPutBits(bw, nbitpairs - 1, 3);
|
||||||
assert(trimmed_length >= 2);
|
|
||||||
VP8LPutBits(bw, trimmed_length - 2, nbitpairs * 2);
|
VP8LPutBits(bw, trimmed_length - 2, nbitpairs * 2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
StoreHuffmanTreeToBitMask(bw, tokens, length, &huffman_code);
|
StoreHuffmanTreeToBitMask(bw, tokens, length, &huffman_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user