Commit 11206c60 authored by Alex Converse's avatar Alex Converse

Remove custom rans types

Change-Id: Ic74d9d8850b8c80a51e55e425bbf472a67e2653f
parent 35d93d5a
......@@ -15,7 +15,7 @@
#include "aom_dsp/ans.h"
#include "aom_dsp/prob.h"
static int find_largest(const AnsP10 *const pdf_tab, int num_syms) {
static int find_largest(const aom_cdf_prob *const pdf_tab, int num_syms) {
int largest_idx = -1;
int largest_p = -1;
int i;
......@@ -29,8 +29,9 @@ static int find_largest(const AnsP10 *const pdf_tab, int num_syms) {
return largest_idx;
}
void aom_rans_merge_prob8_pdf(AnsP10 *const out_pdf, const AnsP8 node_prob,
const AnsP10 *const src_pdf, int in_syms) {
void aom_rans_merge_prob8_pdf(aom_cdf_prob *const out_pdf,
const AnsP8 node_prob,
const aom_cdf_prob *const src_pdf, int in_syms) {
int i;
int adjustment = RANS_PRECISION;
const int round_fact = ANS_P8_PRECISION >> 1;
......
......@@ -26,21 +26,16 @@ extern "C" {
typedef uint8_t AnsP8;
#define ANS_P8_PRECISION 256u
#define ANS_P8_SHIFT 8
typedef uint16_t AnsP10;
#define ANS_P10_PRECISION 1024u
#define RANS_PRECISION 1024u
#define RANS_PROB_BITS 10
#define RANS_PRECISION ANS_P10_PRECISION
#define L_BASE (ANS_P10_PRECISION * 4) // L_BASE % precision must be 0
#define L_BASE (RANS_PRECISION * 4) // L_BASE % precision must be 0
#define IO_BASE 256
// Range I = { L_BASE, L_BASE + 1, ..., L_BASE * IO_BASE - 1 }
// This is now just a boring cdf.
typedef uint16_t rans_lut[16];
void aom_rans_merge_prob8_pdf(AnsP10 *const out_pdf, const AnsP8 node_prob,
const AnsP10 *const src_pdf, int in_syms);
void aom_rans_merge_prob8_pdf(aom_cdf_prob *const out_pdf,
const AnsP8 node_prob,
const aom_cdf_prob *const src_pdf, int in_syms);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
......
......@@ -62,14 +62,14 @@ static INLINE int uabs_read_bit(struct AnsDecoder *ans) {
struct rans_dec_sym {
uint8_t val;
AnsP10 prob;
AnsP10 cum_prob; // not-inclusive
aom_cdf_prob prob;
aom_cdf_prob cum_prob; // not-inclusive
};
static INLINE void fetch_sym(struct rans_dec_sym *out, const rans_lut cdf,
AnsP10 rem) {
static INLINE void fetch_sym(struct rans_dec_sym *out, const aom_cdf_prob *cdf,
aom_cdf_prob rem) {
int i;
AnsP10 cum_prob = 0, top_prob;
aom_cdf_prob cum_prob = 0, top_prob;
// TODO(skal): if critical, could be a binary search.
// Or, better, an O(1) alias-table.
for (i = 0; rem >= (top_prob = cdf[i]); ++i) {
......@@ -80,7 +80,7 @@ static INLINE void fetch_sym(struct rans_dec_sym *out, const rans_lut cdf,
out->cum_prob = cum_prob;
}
static INLINE int rans_read(struct AnsDecoder *ans, const rans_lut tab) {
static INLINE int rans_read(struct AnsDecoder *ans, const aom_cdf_prob *tab) {
unsigned rem;
unsigned quo;
struct rans_dec_sym sym;
......
......@@ -90,8 +90,8 @@ static INLINE void uabs_write(struct AnsCoder *ans, int val, AnsP8 p0) {
}
struct rans_sym {
AnsP10 prob;
AnsP10 cum_prob; // not-inclusive
aom_cdf_prob prob;
aom_cdf_prob cum_prob; // not-inclusive
};
// rANS with normalization
......@@ -99,7 +99,7 @@ struct rans_sym {
// ANS_P10_PRECISION is m
static INLINE void rans_write(struct AnsCoder *ans,
const struct rans_sym *const sym) {
const AnsP10 p = sym->prob;
const aom_cdf_prob p = sym->prob;
unsigned quot, rem;
while (ans->state >= L_BASE / RANS_PRECISION * IO_BASE * p) {
ans->buf[ans->buf_offset++] = ans->state % IO_BASE;
......
......@@ -79,13 +79,13 @@ bool check_uabs(const PvVec &pv_vec, uint8_t *buf) {
const rans_sym rans_sym_tab[] = {
{ 67, 0 }, { 99, 67 }, { 575, 166 }, { 283, 741 },
};
const int kRansSymbols =
static_cast<int>(sizeof(rans_sym_tab) / sizeof(rans_sym));
std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) {
std::vector<int> p_to_sym;
int i = 0;
while (p_to_sym.size() < RANS_PRECISION) {
for (int i = 0; i < kRansSymbols; ++i) {
p_to_sym.insert(p_to_sym.end(), tab[i].prob, i);
++i;
}
assert(p_to_sym.size() == RANS_PRECISION);
std::vector<int> ret;
......@@ -97,7 +97,8 @@ std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) {
return ret;
}
void rans_build_dec_tab(const struct rans_sym sym_tab[], rans_lut dec_tab) {
void rans_build_dec_tab(const struct rans_sym sym_tab[],
aom_cdf_prob *dec_tab) {
unsigned int sum = 0;
for (int i = 0; sum < RANS_PRECISION; ++i) {
dec_tab[i] = sum += sym_tab[i].prob;
......@@ -108,7 +109,7 @@ bool check_rans(const std::vector<int> &sym_vec, const rans_sym *const tab,
uint8_t *buf) {
AnsCoder a;
ans_write_init(&a, buf);
rans_lut dec_tab;
aom_cdf_prob dec_tab[kRansSymbols];
rans_build_dec_tab(tab, dec_tab);
std::clock_t start = std::clock();
......
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