Commit e0c3186e authored by Ronald S. Bultje's avatar Ronald S. Bultje Committed by Jean-Baptiste Kempf

Add simpler version of update_cdf() for boolean symbols

parent 0941aece
......@@ -140,8 +140,8 @@ int msac_decode_uniform(MsacContext *const c, const unsigned n) {
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);
......@@ -153,6 +153,29 @@ void msac_update_cdf(uint16_t *const cdf, const unsigned val,
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,
const size_t sz)
{
......
......@@ -48,30 +48,12 @@ typedef struct MsacContext {
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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment