From 5720143261facc1fa51ba184947c2efe2712bb7e Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Fri, 11 Sep 2015 15:07:50 -0700 Subject: [PATCH] fencepost Change-Id: Ib0f988e11f80d3684d37119f457ca795f0ad16fa --- vp10/encoder/bitstream.c | 5 ++--- vp10/encoder/treewriter.h | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/vp10/encoder/bitstream.c b/vp10/encoder/bitstream.c index 9e0b1ff06..d6203df21 100644 --- a/vp10/encoder/bitstream.c +++ b/vp10/encoder/bitstream.c @@ -9,7 +9,6 @@ */ #include -#include #include #include "vpx/vpx_encoder.h" @@ -201,7 +200,7 @@ static void pack_mb_tokens_ans(struct AnsCoder *const ans, vpx_bit_depth_t bit_depth) { const TOKENEXTRA *p; - for (p = stop; p >= start; --p) { + for (p = stop - 1; p >= start; --p) { const int t = p->token; //TODO: remove EOSB_TOKEN if (t != EOSB_TOKEN) { @@ -227,8 +226,8 @@ static void pack_mb_tokens_ans(struct AnsCoder *const ans, // Write extra bits first if (b->base_val) { const int e = p->extra, l = b->len; + rabs_write(ans, e & 1, 128); if (l) { - rabs_write(ans, e & 1, 128); vp10_write_tree_r(ans, b->tree, b->prob, e >> 1, l, 0); } } diff --git a/vp10/encoder/treewriter.h b/vp10/encoder/treewriter.h index 10f8e9d7b..dd6dabb9c 100644 --- a/vp10/encoder/treewriter.h +++ b/vp10/encoder/treewriter.h @@ -40,14 +40,13 @@ static INLINE void vp10_write_tree_r(struct AnsCoder *const ans, struct { uint8_t bit; vpx_prob prob; } scratch[VP10_TOKEN_SCRATCH_LEN]; // assert(len < VP10_TOKEN_SCRATCH_LEN); - for (i = 0; i < len; ++i) { - const int bit = bits & 1; - bits >>= 1; + for (i = len - 1; i >= 0; --i) { + const int bit = (bits >> i) & 1; scratch[i].bit = bit; scratch[i].prob = probs[tidx >> 1]; tidx = tree[tidx + bit]; } - for (i = len; i >= 0; --i) { + for (i = 0; i < len; ++i) { rabs_write(ans, scratch[i].bit, scratch[i].prob); } }