Remove the starting zero from ANS CDFs.
This brings it in line with the Daala CDFs and will make it easier to share code. Change-Id: Idfd2d2b33c3b9b2c4e72ce72fb3d8039013448b9 (cherry picked from aom/master commit af98507ca928afe33e9f88fdd2ca168379528d6a)
This commit is contained in:
@@ -36,8 +36,7 @@ typedef uint16_t AnsP10;
|
||||
#define IO_BASE 256
|
||||
// Range I = { L_BASE, L_BASE + 1, ..., L_BASE * IO_BASE - 1 }
|
||||
|
||||
// This is now just a boring cdf. It starts with an explicit zero.
|
||||
// TODO(aconverse): Remove starting zero.
|
||||
// This is now just a boring cdf.
|
||||
typedef uint16_t rans_lut[16];
|
||||
|
||||
void aom_rans_build_cdf_from_pdf(const AnsP10 token_probs[], rans_lut cdf_tab);
|
||||
|
@@ -68,15 +68,16 @@ struct rans_dec_sym {
|
||||
|
||||
static INLINE void fetch_sym(struct rans_dec_sym *out, const rans_lut cdf,
|
||||
AnsP10 rem) {
|
||||
int i = 0;
|
||||
int i;
|
||||
AnsP10 cum_prob = 0, top_prob;
|
||||
// TODO(skal): if critical, could be a binary search.
|
||||
// Or, better, an O(1) alias-table.
|
||||
while (rem >= cdf[i]) {
|
||||
++i;
|
||||
for (i = 0; rem >= (top_prob = cdf[i]); ++i) {
|
||||
cum_prob = top_prob;
|
||||
}
|
||||
out->val = i - 1;
|
||||
out->prob = (AnsP10)(cdf[i] - cdf[i - 1]);
|
||||
out->cum_prob = (AnsP10)cdf[i - 1];
|
||||
out->val = i;
|
||||
out->prob = top_prob - cum_prob;
|
||||
out->cum_prob = cum_prob;
|
||||
}
|
||||
|
||||
static INLINE int rans_read(struct AnsDecoder *ans, const rans_lut tab) {
|
||||
|
@@ -92,8 +92,8 @@ static INLINE void aom_write_symbol(aom_writer *w, int symb,
|
||||
struct rans_sym s;
|
||||
(void)nsymbs;
|
||||
assert(cdf);
|
||||
s.cum_prob = cdf[symb];
|
||||
s.prob = cdf[symb + 1] - s.cum_prob;
|
||||
s.cum_prob = symb > 0 ? cdf[symb - 1] : 0;
|
||||
s.prob = cdf[symb] - s.cum_prob;
|
||||
buf_rans_write(w, &s);
|
||||
#else
|
||||
(void)w;
|
||||
|
@@ -2801,6 +2801,14 @@ void av1_model_to_full_probs(const aom_prob *model, aom_prob *full) {
|
||||
}
|
||||
|
||||
#if CONFIG_ANS
|
||||
static void build_token_cdfs(const aom_prob *pdf_model, rans_lut cdf) {
|
||||
int i, sum = 0;
|
||||
assert(pdf_model[2] != 0);
|
||||
for (i = 0; i < ENTROPY_TOKENS - 2; ++i) {
|
||||
cdf[i] = sum += av1_pareto8_token_probs[pdf_model[2] - 1][i];
|
||||
}
|
||||
}
|
||||
|
||||
void av1_coef_pareto_cdfs(FRAME_CONTEXT *fc) {
|
||||
TX_SIZE t;
|
||||
int i, j, k, l;
|
||||
@@ -2809,11 +2817,8 @@ void av1_coef_pareto_cdfs(FRAME_CONTEXT *fc) {
|
||||
for (j = 0; j < REF_TYPES; ++j)
|
||||
for (k = 0; k < COEF_BANDS; ++k)
|
||||
for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
|
||||
const aom_prob *const tree_probs = fc->coef_probs[t][i][j][k][l];
|
||||
aom_prob pivot = tree_probs[PIVOT_NODE];
|
||||
assert(pivot != 0);
|
||||
aom_rans_build_cdf_from_pdf(av1_pareto8_token_probs[pivot - 1],
|
||||
fc->coef_cdfs[t][i][j][k][l]);
|
||||
build_token_cdfs(fc->coef_probs[t][i][j][k][l],
|
||||
fc->coef_cdfs[t][i][j][k][l]);
|
||||
}
|
||||
}
|
||||
#endif // CONFIG_ANS
|
||||
|
@@ -98,9 +98,9 @@ std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) {
|
||||
}
|
||||
|
||||
void rans_build_dec_tab(const struct rans_sym sym_tab[], rans_lut dec_tab) {
|
||||
dec_tab[0] = 0;
|
||||
for (int i = 1; dec_tab[i - 1] < RANS_PRECISION; ++i) {
|
||||
dec_tab[i] = dec_tab[i - 1] + sym_tab[i - 1].prob;
|
||||
unsigned int sum = 0;
|
||||
for (int i = 0; sum < RANS_PRECISION; ++i) {
|
||||
dec_tab[i] = sum += sym_tab[i].prob;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user