Commit d9470160 authored by Tristan Laurent's avatar Tristan Laurent Committed by Ronald S. Bultje

Add "disable_cdf_update" support

parent bd747b11
......@@ -2134,7 +2134,7 @@ static void setup_tile(Dav1dTileState *const ts,
ts->last_qidx = f->frame_hdr.quant.yac;
memset(ts->last_delta_lf, 0, sizeof(ts->last_delta_lf));
msac_init(&ts->msac, data, sz);
msac_init(&ts->msac, data, sz, f->frame_hdr.disable_cdf_update);
ts->tiling.row = tile_row;
ts->tiling.col = tile_col;
......
......@@ -157,33 +157,37 @@ 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);
if(c->allow_update_cdf)
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 unsigned count = cdf[1];
const int rate = (count >> 4) | 4;
if (bit) {
cdf[0] += (32768 - cdf[0]) >> rate;
} else {
cdf[0] -= cdf[0] >> rate;
if(c->allow_update_cdf){
// update_cdf() specialized for boolean CDFs
const unsigned count = cdf[1];
const int rate = (count >> 4) | 4;
if (bit) {
cdf[0] += (32768 - cdf[0]) >> rate;
} else {
cdf[0] -= cdf[0] >> rate;
}
cdf[1] = count + (count < 32);
}
cdf[1] = count + (count < 32);
return bit;
}
void msac_init(MsacContext *const s, const uint8_t *const data,
const size_t sz)
const size_t sz, const int disable_cdf_update_flag)
{
s->buf_pos = data;
s->buf_end = data + sz;
s->dif = ((ec_win)1 << (EC_WIN_SIZE - 1)) - 1;
s->rng = 0x8000;
s->cnt = -15;
s->allow_update_cdf = !disable_cdf_update_flag;
ctx_refill(s);
}
......@@ -40,12 +40,13 @@ typedef struct MsacContext {
ec_win dif;
uint16_t rng;
int cnt;
int allow_update_cdf;
} MsacContext;
#define EC_PROB_SHIFT 6
#define EC_BOOL_EPROB 256
void msac_init(MsacContext *c, const uint8_t *data, size_t sz);
void msac_init(MsacContext *c, const uint8_t *data, size_t sz, int disable_cdf_update_flag);
unsigned msac_decode_symbol(MsacContext *s, const uint16_t *cdf,
const unsigned n_symbols);
unsigned msac_decode_symbol_adapt(MsacContext *s, uint16_t *cdf,
......
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