DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
static int get_signed(BOOL_DECODER *br, int value_to_sign) {
- const int split = (br->range + 1) >> 1;
- const VP9_BD_VALUE bigsplit = (VP9_BD_VALUE)split << (VP9_BD_VALUE_SIZE - 8);
- int v;
-
- if (br->count < 0)
- vp9_bool_decoder_fill(br);
-
- if (br->value < bigsplit) {
- br->range = split;
- v = value_to_sign;
- } else {
- br->range = br->range - split;
- br->value = br->value - bigsplit;
- v = -value_to_sign;
- }
- br->range += br->range;
- br->value += br->value;
- --br->count;
-
- return v;
+ return decode_bool(br, 128) ? -value_to_sign : value_to_sign;
}
#define INCREMENT_COUNT(token) \
static void pack_mb_tokens(vp9_writer* const bc,
TOKENEXTRA **tp,
const TOKENEXTRA *const stop) {
- unsigned int split;
- unsigned int shift;
- int count = bc->count;
- unsigned int range = bc->range;
- unsigned int lowvalue = bc->lowvalue;
TOKENEXTRA *p = *tp;
while (p < stop) {
do {
const int bb = (v >> --n) & 1;
- split = 1 + (((range - 1) * pp[i >> 1]) >> 8);
+ encode_bool(bc, bb, pp[i >> 1]);
i = vp9_coef_tree[i + bb];
-
- if (bb) {
- lowvalue += split;
- range = range - split;
- } else {
- range = split;
- }
-
- shift = vp9_norm[range];
- range <<= shift;
- count += shift;
-
- if (count >= 0) {
- int offset = shift - count;
-
- if ((lowvalue << (offset - 1)) & 0x80000000) {
- int x = bc->pos - 1;
-
- while (x >= 0 && bc->buffer[x] == 0xff) {
- bc->buffer[x] = (unsigned char)0;
- x--;
- }
-
- bc->buffer[x] += 1;
- }
-
- bc->buffer[bc->pos++] = (lowvalue >> (24 - offset));
- lowvalue <<= offset;
- shift = count;
- lowvalue &= 0xffffff;
- count -= 8;
- }
-
- lowvalue <<= shift;
} while (n);
do {
const int bb = (v >> --n) & 1;
- split = 1 + (((range - 1) * pp[i >> 1]) >> 8);
+ encode_bool(bc, bb, pp[i >> 1]);
i = b->tree[i + bb];
-
- if (bb) {
- lowvalue += split;
- range = range - split;
- } else {
- range = split;
- }
-
- shift = vp9_norm[range];
- range <<= shift;
- count += shift;
-
- if (count >= 0) {
- int offset = shift - count;
-
- if ((lowvalue << (offset - 1)) & 0x80000000) {
- int x = bc->pos - 1;
-
- while (x >= 0 && bc->buffer[x] == 0xff) {
- bc->buffer[x] = (unsigned char)0;
- x--;
- }
-
- bc->buffer[x] += 1;
- }
-
- bc->buffer[bc->pos++] = (lowvalue >> (24 - offset));
- lowvalue <<= offset;
- shift = count;
- lowvalue &= 0xffffff;
- count -= 8;
- }
-
- lowvalue <<= shift;
} while (n);
}
-
- {
-
- split = (range + 1) >> 1;
-
- if (e & 1) {
- lowvalue += split;
- range = range - split;
- } else {
- range = split;
- }
-
- range <<= 1;
-
- if ((lowvalue & 0x80000000)) {
- int x = bc->pos - 1;
-
- while (x >= 0 && bc->buffer[x] == 0xff) {
- bc->buffer[x] = (unsigned char)0;
- x--;
- }
-
- bc->buffer[x] += 1;
-
- }
-
- lowvalue <<= 1;
-
- if (!++count) {
- count = -8;
- bc->buffer[bc->pos++] = (lowvalue >> 24);
- lowvalue &= 0xffffff;
- }
- }
-
+ encode_bool(bc, e & 1, 128);
}
++p;
}
- bc->count = count;
- bc->lowvalue = lowvalue;
- bc->range = range;
*tp = p;
}