Commit af98507c authored by Alex Converse's avatar Alex Converse

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
parent e325478e
......@@ -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 = 1;
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) {
......
......@@ -104,8 +104,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);
#elif CONFIG_DAALA_EC
daala_write_symbol(w, symb, cdf, nsymbs);
......
......@@ -1336,11 +1336,10 @@ void av1_model_to_full_probs(const aom_prob *model, aom_prob *full) {
#if CONFIG_RANS
static void build_token_cdfs(const aom_prob *pdf_model, rans_lut cdf) {
int i;
int i, sum = 0;
assert(pdf_model[2] != 0);
cdf[0] = 0;
for (i = 0; i < ENTROPY_TOKENS - 2; ++i) {
cdf[i + 1] = cdf[i] + av1_pareto8_token_probs[pdf_model[2] - 1][i];
cdf[i] = sum += av1_pareto8_token_probs[pdf_model[2] - 1][i];
}
}
......
......@@ -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;
}
}
......
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