ref: e0c3186e65aeafa2853b275dfb534b5a274fab12
parent: 0941aece66b70bfc2b4704cb3ec98068eba1fc52
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Fri Nov 2 11:42:47 EDT 2018
Add simpler version of update_cdf() for boolean symbols
--- a/src/msac.c
+++ b/src/msac.c
@@ -140,8 +140,8 @@
return v < m ? v : (v << 1) - m + msac_decode_bool(c, EC_BOOL_EPROB);
}
-void msac_update_cdf(uint16_t *const cdf, const unsigned val,
- const unsigned n_symbols)
+static void update_cdf(uint16_t *const cdf, const unsigned val,
+ const unsigned n_symbols)
{
const int rate = 4 + (cdf[n_symbols] > 15) + (cdf[n_symbols] > 31) +
(n_symbols > 3);
@@ -151,6 +151,29 @@
for (i = val; i < n_symbols - 1; i++)
cdf[i] -= cdf[i] >> rate;
cdf[n_symbols] += (cdf[n_symbols] < 32);
+}
+
+unsigned msac_decode_symbol_adapt(MsacContext *const c,
+ uint16_t *const cdf, const unsigned n_symbols)
+{
+ const unsigned val = msac_decode_symbol(c, cdf, n_symbols);
+ update_cdf(cdf, val, n_symbols);
+ return val;
+}
+
+unsigned msac_decode_bool_adapt(MsacContext *const c, uint16_t *const cdf) {
+ const unsigned bit = msac_decode_bool(c, *cdf >> EC_PROB_SHIFT);
+
+ // update_cdf() specialized for boolean CDFs
+ const int rate = 4 + (cdf[1] > 15) + (cdf[1] > 31);
+ if (bit) {
+ cdf[0] += (32768 - cdf[0]) >> rate;
+ } else {
+ cdf[0] -= cdf[0] >> rate;
+ }
+ cdf[1] += (cdf[1] < 32);
+
+ return bit;
}
void msac_init(MsacContext *const s, const uint8_t *const data,
--- a/src/msac.h
+++ b/src/msac.h
@@ -48,30 +48,12 @@
void msac_init(MsacContext *c, const uint8_t *data, size_t sz);
unsigned msac_decode_symbol(MsacContext *s, const uint16_t *cdf,
const unsigned n_symbols);
+unsigned msac_decode_symbol_adapt(MsacContext *s, uint16_t *cdf,
+ const unsigned n_symbols);
unsigned msac_decode_bool(MsacContext *s, unsigned f);
+unsigned msac_decode_bool_adapt(MsacContext *s, uint16_t *cdf);
unsigned msac_decode_bools(MsacContext *c, unsigned l);
int msac_decode_subexp(MsacContext *c, int ref, int n, unsigned k);
int msac_decode_uniform(MsacContext *c, unsigned n);
-void msac_update_cdf(uint16_t *cdf, unsigned val, unsigned n_symbols);
-
-static inline unsigned msac_decode_symbol_adapt(MsacContext *const c,
- uint16_t *const cdf,
- const unsigned n_symbols)
-{
- const unsigned val = msac_decode_symbol(c, cdf, n_symbols);
- msac_update_cdf(cdf, val, n_symbols);
- return val;
-}
-
-static inline unsigned msac_decode_bool_adapt(MsacContext *const c,
- uint16_t *const cdf)
-{
- const unsigned bit = msac_decode_bool(c, *cdf >> EC_PROB_SHIFT);
- uint16_t bak_cdf[3] = { cdf[0], 0, cdf[1] };
- msac_update_cdf(bak_cdf, bit, 2);
- cdf[0] = bak_cdf[0];
- cdf[1] = bak_cdf[2];
- return bit;
-}
#endif /* __DAV1D_SRC_MSAC_H__ */