From: John Koleszar Date: Fri, 16 Nov 2012 18:48:23 +0000 (-0800) Subject: Use boolcoder API instead of inlining X-Git-Tag: v1.3.0~1210^2~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05ec800ea48f5666e2360d67d2e71faff6c0b992;p=libvpx Use boolcoder API instead of inlining This patch changes the token packing to call the bool encoder API rather than inlining it into the token packing function, and similarly removes a special get_signed case from the detokenizer. This allows easier experimentation with changing the bool coder as a whole. Change-Id: I52c3625bbe4960b68cfb873b0e39ade0c82f9e91 --- diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c index 8fe218494..55ce0171a 100644 --- a/vp9/decoder/vp9_detokenize.c +++ b/vp9/decoder/vp9_detokenize.c @@ -60,26 +60,7 @@ static const vp9_prob cat6_prob[15] = { 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) \ diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 498f64752..54d44faec 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -364,11 +364,6 @@ static void vp9_cond_prob_update(vp9_writer *bc, vp9_prob *oldp, vp9_prob upd, 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) { @@ -394,42 +389,8 @@ static void pack_mb_tokens(vp9_writer* const bc, 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); @@ -444,87 +405,16 @@ static void pack_mb_tokens(vp9_writer* const bc, 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; }