From: Alex Converse Date: Mon, 21 Mar 2016 21:56:58 +0000 (-0700) Subject: Add some ANS helpers needed to replace the vpx bool coder with pure ANS. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b9cb8c4897b637d015311f5ae816e101ff8b673;p=libvpx Add some ANS helpers needed to replace the vpx bool coder with pure ANS. Change-Id: I32b63fca020c410cef16e93379b4e6e281ccbccd --- diff --git a/vp10/common/ans.h b/vp10/common/ans.h index 6bd3012cd..0d6726da5 100644 --- a/vp10/common/ans.h +++ b/vp10/common/ans.h @@ -230,6 +230,18 @@ static INLINE int uabs_read_bit(struct AnsDecoder *ans) { return s; } +static INLINE int uabs_read_literal(struct AnsDecoder *ans, int bits) { + int literal = 0, bit; + assert(bits < 31); + + // TODO(aconverse): Investigate ways to read/write literals faster, + // e.g. 8-bit chunks. + for (bit = bits - 1; bit >= 0; bit--) + literal |= uabs_read_bit(ans) << bit; + + return literal; +} + struct rans_sym { AnsP8 prob; AnsP8 cum_prob; // not-inclusive @@ -327,6 +339,10 @@ static INLINE int ans_read_init(struct AnsDecoder *const ans, static INLINE int ans_read_end(struct AnsDecoder *const ans) { return ans->state == l_base; } + +static INLINE int ans_reader_has_error(const struct AnsDecoder *const ans) { + return ans->state < l_base && ans->buf_offset == 0; +} #undef ANS_DIVREM #ifdef __cplusplus } // extern "C" diff --git a/vp10/encoder/buf_ans.h b/vp10/encoder/buf_ans.h index ae768734f..549ce1b76 100644 --- a/vp10/encoder/buf_ans.h +++ b/vp10/encoder/buf_ans.h @@ -81,6 +81,18 @@ static INLINE void buf_ans_flush(const struct BufAnsCoder *const c, } } +static INLINE void buf_uabs_write_bit(struct BufAnsCoder *c, int bit) { + buf_uabs_write(c, bit, 128); +} + +static INLINE void buf_uabs_write_literal(struct BufAnsCoder *c, + int literal, int bits) { + int bit; + + assert(bits < 31); + for (bit = bits - 1; bit >= 0; bit--) + buf_uabs_write_bit(c, 1 & (literal >> bit)); +} #ifdef __cplusplus } // extern "C" #endif // __cplusplus