static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size, vp9_coeff_stats *coef_branch_ct, vp9_coeff_probs_model *coef_probs) { vp9_coeff_count *coef_counts = cpi->td.rd_counts.coef_counts[tx_size]; unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = cpi->common.counts.eob_branch[tx_size]; int i, j, k, l, m; for (i = 0; i < PLANE_TYPES; ++i) { for (j = 0; j < REF_TYPES; ++j) { for (k = 0; k < COEF_BANDS; ++k) { for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) { vp9_tree_probs_from_distribution(vp9_coef_tree, coef_branch_ct[i][j][k][l], coef_counts[i][j][k][l]); coef_branch_ct[i][j][k][l][0][1] = eob_branch_ct[i][j][k][l] - coef_branch_ct[i][j][k][l][0][0]; for (m = 0; m < UNCONSTRAINED_NODES; ++m) coef_probs[i][j][k][l][m] = get_binary_prob( coef_branch_ct[i][j][k][l][m][0], coef_branch_ct[i][j][k][l][m][1]); } } } } }
static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE tx_size, unsigned int count_sat, unsigned int update_factor) { FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[tx_size]; vp9_coeff_probs_model *pre_coef_probs = pre_fc->coef_probs[tx_size]; vp9_coeff_count_model *coef_counts = cm->counts.coef[tx_size]; unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] = cm->counts.eob_branch[tx_size]; int t, i, j, k, l; unsigned int branch_ct[UNCONSTRAINED_NODES][2]; vp9_prob coef_probs[UNCONSTRAINED_NODES]; for (i = 0; i < BLOCK_TYPES; ++i) for (j = 0; j < REF_TYPES; ++j) for (k = 0; k < COEF_BANDS; ++k) for (l = 0; l < PREV_COEF_CONTEXTS; ++l) { if (l >= 3 && k == 0) continue; vp9_tree_probs_from_distribution(vp9_coefmodel_tree, coef_probs, branch_ct, coef_counts[i][j][k][l], 0); branch_ct[0][1] = eob_branch_count[i][j][k][l] - branch_ct[0][0]; coef_probs[0] = get_binary_prob(branch_ct[0][0], branch_ct[0][1]); for (t = 0; t < UNCONSTRAINED_NODES; ++t) dst_coef_probs[i][j][k][l][t] = merge_probs( pre_coef_probs[i][j][k][l][t], coef_probs[t], branch_ct[t], count_sat, update_factor); } }
static void prob_diff_update(const vpx_tree_index *tree, vpx_prob probs[/*n - 1*/], const unsigned int counts[/*n - 1*/], int n, vpx_writer *w) { int i; unsigned int branch_ct[32][2]; // Assuming max number of probabilities <= 32 assert(n <= 32); vp9_tree_probs_from_distribution(tree, branch_ct, counts); for (i = 0; i < n - 1; ++i) vp9_cond_prob_diff_update(w, &probs[i], branch_ct[i]); }
static void print_probs(FILE *f, vp9_coeff_accum *context_counters, int block_types, const char *header) { int type, ref, band, pt, t; fprintf(f, "static const vp9_coeff_probs %s = {", header); type = 0; #define Newline(x, spaces) (x ? " " : "\n" spaces) do { fprintf(f, "%s%s{ /* block Type %d */", Comma(type), Newline(type, " "), type); ref = 0; do { fprintf(f, "%s%s{ /* %s */", Comma(band), Newline(band, " "), ref ? "Inter" : "Intra"); band = 0; do { fprintf(f, "%s%s{ /* Coeff Band %d */", Comma(band), Newline(band, " "), band); pt = 0; do { unsigned int branch_ct[ENTROPY_NODES][2]; unsigned int coef_counts[MAX_ENTROPY_TOKENS + 1]; vp9_prob coef_probs[ENTROPY_NODES]; if (pt >= 3 && band == 0) break; for (t = 0; t < MAX_ENTROPY_TOKENS + 1; ++t) coef_counts[t] = context_counters[type][ref][band][pt][t]; vp9_tree_probs_from_distribution(vp9_coef_tree, coef_probs, branch_ct, coef_counts, 0); branch_ct[0][1] = coef_counts[MAX_ENTROPY_TOKENS] - branch_ct[0][0]; coef_probs[0] = get_binary_prob(branch_ct[0][0], branch_ct[0][1]); fprintf(f, "%s\n {", Comma(pt)); t = 0; do { fprintf(f, "%s %3d", Comma(t), coef_probs[t]); } while (++t < ENTROPY_NODES); fprintf(f, " }"); } while (++pt < PREV_COEF_CONTEXTS); fprintf(f, "\n }"); } while (++band < COEF_BANDS); fprintf(f, "\n }"); } while (++ref < REF_TYPES); fprintf(f, "\n }"); } while (++type < block_types); fprintf(f, "\n};\n"); }
static void update_mode_probs(int n_modes, const vp9_tree_index *tree, unsigned int *cnt, vp9_prob *pre_probs, vp9_prob *dst_probs, unsigned int tok0_offset) { #define MAX_PROBS 32 vp9_prob probs[MAX_PROBS]; unsigned int branch_ct[MAX_PROBS][2]; int t; assert(n_modes - 1 < MAX_PROBS); vp9_tree_probs_from_distribution(tree, probs, branch_ct, cnt, tok0_offset); for (t = 0; t < n_modes - 1; ++t) dst_probs[t] = update_ct(pre_probs[t], probs[t], branch_ct[t]); }