diff --git a/av1/common/generic_code.c b/av1/common/generic_code.c index aae929430..76923b182 100644 --- a/av1/common/generic_code.c +++ b/av1/common/generic_code.c @@ -17,16 +17,6 @@ #include "generic_code.h" -void aom_cdf_init(uint16_t *cdf, int ncdfs, int nsyms, int val, int first) { - int i; - int j; - for (i = 0; i < ncdfs; i++) { - for (j = 0; j < nsyms; j++) { - cdf[i*nsyms + j] = val*j + first; - } - } -} - void aom_cdf_init_q15_1D(uint16_t *cdf, int nsyms, int cdf_size) { int i; for (i = 0; i < nsyms; i++) diff --git a/av1/common/generic_code.h b/av1/common/generic_code.h index e10b17473..c9d87799d 100644 --- a/av1/common/generic_code.h +++ b/av1/common/generic_code.h @@ -35,14 +35,12 @@ typedef struct { void generic_model_init(generic_encoder *model); -#define OD_CDFS_INIT(cdf, val) aom_cdf_init(&cdf[0][0], \ - sizeof(cdf)/sizeof(cdf[0]), sizeof(cdf[0])/sizeof(cdf[0][0]), val, val) - -#define OD_SINGLE_CDF_INIT(cdf, val) aom_cdf_init(cdf, \ - 1, sizeof(cdf)/sizeof(cdf[0]), val, val) - -#define OD_SINGLE_CDF_INIT_FIRST(cdf, val, first) aom_cdf_init(cdf, \ - 1, sizeof(cdf)/sizeof(cdf[0]), val, first) +/* Initialize a CDF for use by aom_write_symbol_pvq()/aom_read_symbol_pvq(). + This is used for CDFs whose size might not match the declared array size. + The only real requirement is that the first value of every CDF be zero. + Then aom_cdf_init_q15_1D() will be called with the real size the first time + the CDF is used. */ +#define OD_CDFS_INIT_DYNAMIC(cdf) (memset(cdf, 0, sizeof(cdf))) // WARNING: DO NOT USE this init function, // if the size of cdf is different from what is declared by code. diff --git a/av1/common/pvq.c b/av1/common/pvq.c index 25736f6f0..75fe761d7 100644 --- a/av1/common/pvq.c +++ b/av1/common/pvq.c @@ -187,16 +187,16 @@ void od_adapt_pvq_ctx_reset(od_pvq_adapt_ctx *state, int is_keyframe) { int pli; int bs; ctx = &state->pvq_codeword_ctx; - OD_CDFS_INIT(state->pvq_param_model[0].cdf, 0); - OD_CDFS_INIT(state->pvq_param_model[1].cdf, 0); - OD_CDFS_INIT(state->pvq_param_model[2].cdf, 0); + OD_CDFS_INIT_DYNAMIC(state->pvq_param_model[0].cdf); + OD_CDFS_INIT_DYNAMIC(state->pvq_param_model[1].cdf); + OD_CDFS_INIT_DYNAMIC(state->pvq_param_model[2].cdf); for (i = 0; i < 2*OD_TXSIZES; i++) { ctx->pvq_adapt[4*i + OD_ADAPT_K_Q8] = 384; ctx->pvq_adapt[4*i + OD_ADAPT_SUM_EX_Q8] = 256; ctx->pvq_adapt[4*i + OD_ADAPT_COUNT_Q8] = 104; ctx->pvq_adapt[4*i + OD_ADAPT_COUNT_EX_Q8] = 128; } - OD_CDFS_INIT(ctx->pvq_k1_cdf, 0); + OD_CDFS_INIT_DYNAMIC(ctx->pvq_k1_cdf); for (pli = 0; pli < OD_NPLANES_MAX; pli++) { for (bs = 0; bs < OD_TXSIZES; bs++) for (i = 0; i < PVQ_MAX_PARTITIONS; i++) { @@ -206,9 +206,9 @@ void od_adapt_pvq_ctx_reset(od_pvq_adapt_ctx *state, int is_keyframe) { for (i = 0; i < OD_TXSIZES*PVQ_MAX_PARTITIONS; i++) { state->pvq_ext[i] = is_keyframe ? 24576 : 2 << 16; } - OD_CDFS_INIT(state->pvq_gaintheta_cdf, 0); + OD_CDFS_INIT_DYNAMIC(state->pvq_gaintheta_cdf); OD_CDFS_INIT_Q15(state->pvq_skip_dir_cdf); - OD_CDFS_INIT(ctx->pvq_split_cdf, 0); + OD_CDFS_INIT_DYNAMIC(ctx->pvq_split_cdf); } /* QMs are arranged from smallest to largest blocksizes, first for diff --git a/av1/common/pvq_state.c b/av1/common/pvq_state.c index 2f4aba219..197b9b3a8 100644 --- a/av1/common/pvq_state.c +++ b/av1/common/pvq_state.c @@ -18,7 +18,7 @@ void od_adapt_ctx_reset(od_adapt_ctx *adapt, int is_keyframe) { OD_CDFS_INIT_Q15(adapt->skip_cdf); for (pli = 0; pli < OD_NPLANES_MAX; pli++) { int i; - OD_CDFS_INIT(adapt->model_dc[pli].cdf, 0); + OD_CDFS_INIT_DYNAMIC(adapt->model_dc[pli].cdf); for (i = 0; i < OD_TXSIZES; i++) { int j; adapt->ex_g[pli][i] = 8;