mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-18 23:09:52 +02:00
lossy bit-reader clean-up:
* remove LEFT/RIGHT_JUSTIFY distinction. It's all RIGHT_JUSTIFY now. * simplify VP8GetSigned(), and add some masking branch-less code. Much faster on ARM (~13% speed-up). 8% on x86-64, 5% on MacBook. * split critical implementation into separate bit_reader_inl.h file that is only included where needed (vp8.c / tree.c / bit_reader.c) * bumped BITS value from 16 to 24 for x86-32b too, since it's a bit faster. Change-Id: If41ca1da3e5c3dadacf2379d1ba419b151e7fce8
This commit is contained in:
@ -7,17 +7,11 @@
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Boolean decoder
|
||||
// Boolean decoder non-inlined methods
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include "./bit_reader.h"
|
||||
|
||||
#ifndef USE_RIGHT_JUSTIFY
|
||||
#define MK(X) (((range_t)(X) << (BITS)) | (MASK))
|
||||
#else
|
||||
#define MK(X) ((range_t)(X))
|
||||
#endif
|
||||
#include "./bit_reader_inl.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VP8BitReader
|
||||
@ -27,12 +21,13 @@ void VP8InitBitReader(VP8BitReader* const br,
|
||||
assert(br != NULL);
|
||||
assert(start != NULL);
|
||||
assert(start <= end);
|
||||
br->range_ = MK(255 - 1);
|
||||
br->range_ = 255 - 1;
|
||||
br->buf_ = start;
|
||||
br->buf_end_ = end;
|
||||
br->value_ = 0;
|
||||
br->bits_ = -8; // to load the very first 8bits
|
||||
br->eof_ = 0;
|
||||
VP8LoadNewBytes(br);
|
||||
}
|
||||
|
||||
void VP8RemapBitReader(VP8BitReader* const br, ptrdiff_t offset) {
|
||||
@ -54,45 +49,35 @@ const uint8_t kVP8Log2Range[128] = {
|
||||
0
|
||||
};
|
||||
|
||||
// range = (range << kVP8Log2Range[range]) + trailing 1's
|
||||
// range = ((range - 1) << kVP8Log2Range[range]) + 1
|
||||
const range_t kVP8NewRange[128] = {
|
||||
MK(127), MK(127), MK(191), MK(127), MK(159), MK(191), MK(223), MK(127),
|
||||
MK(143), MK(159), MK(175), MK(191), MK(207), MK(223), MK(239), MK(127),
|
||||
MK(135), MK(143), MK(151), MK(159), MK(167), MK(175), MK(183), MK(191),
|
||||
MK(199), MK(207), MK(215), MK(223), MK(231), MK(239), MK(247), MK(127),
|
||||
MK(131), MK(135), MK(139), MK(143), MK(147), MK(151), MK(155), MK(159),
|
||||
MK(163), MK(167), MK(171), MK(175), MK(179), MK(183), MK(187), MK(191),
|
||||
MK(195), MK(199), MK(203), MK(207), MK(211), MK(215), MK(219), MK(223),
|
||||
MK(227), MK(231), MK(235), MK(239), MK(243), MK(247), MK(251), MK(127),
|
||||
MK(129), MK(131), MK(133), MK(135), MK(137), MK(139), MK(141), MK(143),
|
||||
MK(145), MK(147), MK(149), MK(151), MK(153), MK(155), MK(157), MK(159),
|
||||
MK(161), MK(163), MK(165), MK(167), MK(169), MK(171), MK(173), MK(175),
|
||||
MK(177), MK(179), MK(181), MK(183), MK(185), MK(187), MK(189), MK(191),
|
||||
MK(193), MK(195), MK(197), MK(199), MK(201), MK(203), MK(205), MK(207),
|
||||
MK(209), MK(211), MK(213), MK(215), MK(217), MK(219), MK(221), MK(223),
|
||||
MK(225), MK(227), MK(229), MK(231), MK(233), MK(235), MK(237), MK(239),
|
||||
MK(241), MK(243), MK(245), MK(247), MK(249), MK(251), MK(253), MK(127)
|
||||
127, 127, 191, 127, 159, 191, 223, 127,
|
||||
143, 159, 175, 191, 207, 223, 239, 127,
|
||||
135, 143, 151, 159, 167, 175, 183, 191,
|
||||
199, 207, 215, 223, 231, 239, 247, 127,
|
||||
131, 135, 139, 143, 147, 151, 155, 159,
|
||||
163, 167, 171, 175, 179, 183, 187, 191,
|
||||
195, 199, 203, 207, 211, 215, 219, 223,
|
||||
227, 231, 235, 239, 243, 247, 251, 127,
|
||||
129, 131, 133, 135, 137, 139, 141, 143,
|
||||
145, 147, 149, 151, 153, 155, 157, 159,
|
||||
161, 163, 165, 167, 169, 171, 173, 175,
|
||||
177, 179, 181, 183, 185, 187, 189, 191,
|
||||
193, 195, 197, 199, 201, 203, 205, 207,
|
||||
209, 211, 213, 215, 217, 219, 221, 223,
|
||||
225, 227, 229, 231, 233, 235, 237, 239,
|
||||
241, 243, 245, 247, 249, 251, 253, 127
|
||||
};
|
||||
|
||||
#undef MK
|
||||
|
||||
void VP8LoadFinalBytes(VP8BitReader* const br) {
|
||||
assert(br != NULL && br->buf_ != NULL);
|
||||
// Only read 8bits at a time
|
||||
if (br->buf_ < br->buf_end_) {
|
||||
#ifndef USE_RIGHT_JUSTIFY
|
||||
br->value_ |= (bit_t)(*br->buf_++) << ((BITS) - 8 - br->bits_);
|
||||
#else
|
||||
br->value_ = (bit_t)(*br->buf_++) | (br->value_ << 8);
|
||||
#endif
|
||||
br->bits_ += 8;
|
||||
br->value_ = (bit_t)(*br->buf_++) | (br->value_ << 8);
|
||||
} else if (!br->eof_) {
|
||||
#ifdef USE_RIGHT_JUSTIFY
|
||||
// These are not strictly needed, but it makes the behaviour
|
||||
// consistent for both USE_RIGHT_JUSTIFY and !USE_RIGHT_JUSTIFY.
|
||||
br->value_ <<= 8;
|
||||
br->bits_ += 8;
|
||||
#endif
|
||||
br->eof_ = 1;
|
||||
}
|
||||
}
|
||||
@ -222,4 +207,3 @@ uint32_t VP8LReadBits(VP8LBitReader* const br, int n_bits) {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
Reference in New Issue
Block a user