diff options
-rw-r--r-- | vp9/common/vp9_common.h | 6 | ||||
-rw-r--r-- | vp9/common/vp9_entropy.c | 8 | ||||
-rw-r--r-- | vp9/common/vp9_entropymode.c | 202 | ||||
-rw-r--r-- | vp9/common/vp9_entropymv.c | 42 | ||||
-rw-r--r-- | vp9/common/vp9_filter.c | 74 | ||||
-rw-r--r-- | vp9/common/vp9_idctllm.c | 31 | ||||
-rw-r--r-- | vp9/common/vp9_pred_common.c | 20 | ||||
-rw-r--r-- | vp9/common/vp9_recon.c | 75 | ||||
-rw-r--r-- | vp9/common/vp9_reconinter.c | 10 | ||||
-rw-r--r-- | vp9/common/vp9_reconintra.c | 26 | ||||
-rw-r--r-- | vp9/common/vp9_reconintra4x4.c | 100 | ||||
-rw-r--r-- | vp9/common/vp9_treecoder.c | 29 | ||||
-rw-r--r-- | vp9/common/vp9_treecoder.h | 27 | ||||
-rw-r--r-- | vp9/decoder/vp9_dequantize.c | 19 | ||||
-rw-r--r-- | vp9/encoder/vp9_bitstream.c | 30 | ||||
-rw-r--r-- | vp9/encoder/vp9_mcomp.c | 11 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_if.c | 41 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.c | 10 | ||||
-rw-r--r-- | vp9/encoder/vp9_segmentation.c | 39 | ||||
-rw-r--r-- | vp9/encoder/vp9_tokenize.c | 3 |
20 files changed, 237 insertions, 566 deletions
diff --git a/vp9/common/vp9_common.h b/vp9/common/vp9_common.h index 893a3f8b3..d6887afa0 100644 --- a/vp9/common/vp9_common.h +++ b/vp9/common/vp9_common.h @@ -17,7 +17,7 @@ /* Interface header for common constant data structures and lookup tables */ #include "vpx_mem/vpx_mem.h" - +#include "vpx/vpx_integer.h" #include "vp9/common/vp9_common_types.h" /* Only need this for fixed-size arrays, for structs just assign. */ @@ -38,4 +38,8 @@ #define vp9_zero_array( Dest, N) vpx_memset( Dest, 0, N * sizeof( *Dest)); +static __inline uint8_t clip_pixel(int val) { + return (val > 255) ? 255u : (val < 0) ? 0u : val; +} + #endif /* common_h */ diff --git a/vp9/common/vp9_entropy.c b/vp9/common/vp9_entropy.c index 9d8e924d5..60885f4e8 100644 --- a/vp9/common/vp9_entropy.c +++ b/vp9/common/vp9_entropy.c @@ -360,15 +360,13 @@ static void update_coef_probs(vp9_coeff_probs *dst_coef_probs, vp9_tree_probs_from_distribution(MAX_ENTROPY_TOKENS, vp9_coef_encodings, vp9_coef_tree, coef_probs, branch_ct, - coef_counts[i][j][k], 256, 1); + coef_counts[i][j][k]); for (t = 0; t < ENTROPY_NODES; ++t) { - int prob; count = branch_ct[t][0] + branch_ct[t][1]; count = count > count_sat ? count_sat : count; factor = (update_factor * count / count_sat); - prob = ((int)pre_coef_probs[i][j][k][t] * (256 - factor) + - (int)coef_probs[t] * factor + 128) >> 8; - dst_coef_probs[i][j][k][t] = clip_prob(prob); + dst_coef_probs[i][j][k][t] = weighted_prob(pre_coef_probs[i][j][k][t], + coef_probs[t], factor); } } } diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c index cda217670..d7c2d8e06 100644 --- a/vp9/common/vp9_entropymode.c +++ b/vp9/common/vp9_entropymode.c @@ -309,24 +309,24 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) { vp9_tree_probs_from_distribution(VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree, x->fc.ymode_prob, - bct, y_mode_cts, 256, 1); + bct, y_mode_cts); #if CONFIG_SUPERBLOCKS vp9_tree_probs_from_distribution(VP9_I32X32_MODES, vp9_sb_ymode_encodings, vp9_sb_ymode_tree, x->fc.sb_ymode_prob, - bct, y_mode_cts, 256, 1); + bct, y_mode_cts); #endif { int i; for (i = 0; i < 8; i++) { vp9_tree_probs_from_distribution(VP9_YMODES, vp9_kf_ymode_encodings, vp9_kf_ymode_tree, x->kf_ymode_prob[i], - bct, kf_y_mode_cts[i], 256, 1); + bct, kf_y_mode_cts[i]); #if CONFIG_SUPERBLOCKS vp9_tree_probs_from_distribution(VP9_I32X32_MODES, vp9_sb_kf_ymode_encodings, vp9_sb_kf_ymode_tree, x->sb_kf_ymode_prob[i], bct, - kf_y_mode_cts[i], 256, 1); + kf_y_mode_cts[i]); #endif } } @@ -335,16 +335,16 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) { for (i = 0; i < VP9_YMODES; i++) { vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, vp9_uv_mode_tree, x->kf_uv_mode_prob[i], - bct, kf_uv_mode_cts[i], 256, 1); + bct, kf_uv_mode_cts[i]); vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, vp9_uv_mode_tree, x->fc.uv_mode_prob[i], - bct, uv_mode_cts[i], 256, 1); + bct, uv_mode_cts[i]); } } vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings, vp9_i8x8_mode_tree, x->fc.i8x8_mode_prob, - bct, i8x8_mode_cts, 256, 1); + bct, i8x8_mode_cts); vpx_memcpy(x->fc.sub_mv_ref_prob, vp9_sub_mv_ref_prob2, sizeof(vp9_sub_mv_ref_prob2)); @@ -362,7 +362,7 @@ static void intra_bmode_probs_from_distribution( unsigned int branch_ct[VP9_NKF_BINTRAMODES - 1][2], const unsigned int events[VP9_NKF_BINTRAMODES]) { vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, - vp9_bmode_tree, p, branch_ct, events, 256, 1); + vp9_bmode_tree, p, branch_ct, events); } void vp9_default_bmode_probs(vp9_prob p[VP9_NKF_BINTRAMODES - 1]) { @@ -375,7 +375,7 @@ static void intra_kf_bmode_probs_from_distribution( unsigned int branch_ct[VP9_KF_BINTRAMODES - 1][2], const unsigned int events[VP9_KF_BINTRAMODES]) { vp9_tree_probs_from_distribution(VP9_KF_BINTRAMODES, vp9_kf_bmode_encodings, - vp9_kf_bmode_tree, p, branch_ct, events, 256, 1); + vp9_kf_bmode_tree, p, branch_ct, events); } void vp9_kf_default_bmode_probs(vp9_prob p[VP9_KF_BINTRAMODES] @@ -495,17 +495,14 @@ void vp9_update_mode_context(VP9_COMMON *pc) { for (j = 0; j < INTER_MODE_CONTEXTS; j++) { for (i = 0; i < 4; i++) { - int this_prob; - int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1]; - int factor; - { - this_prob = count > 0 ? 256 * mv_ref_ct[j][i][0] / count : 128; - count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count; - factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT); - this_prob = (pc->fc.vp9_mode_contexts[j][i] * (256 - factor) + - this_prob * factor + 128) >> 8; - mode_context[j][i] = clip_prob(this_prob); - } + int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1], factor; + + count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count; + factor = (MVREF_MAX_UPDATE_FACTOR * count / MVREF_COUNT_SAT); + mode_context[j][i] = weighted_prob(pc->fc.vp9_mode_contexts[j][i], + get_binary_prob(mv_ref_ct[j][i][0], + mv_ref_ct[j][i][1]), + factor); } } } @@ -531,25 +528,33 @@ void print_mode_contexts(VP9_COMMON *pc) { } #endif -// #define MODE_COUNT_TESTING #define MODE_COUNT_SAT 20 #define MODE_MAX_UPDATE_FACTOR 144 +static void update_mode_probs(int n_modes, struct vp9_token_struct *encoding, + const vp9_tree_index *tree, unsigned int *cnt, + vp9_prob *pre_probs, vp9_prob *dst_probs) { +#define MAX_PROBS 32 + vp9_prob probs[MAX_PROBS]; + unsigned int branch_ct[MAX_PROBS][2]; + int t, count, factor; + + assert(n_modes - 1 < MAX_PROBS); + vp9_tree_probs_from_distribution(n_modes, encoding, tree, probs, + branch_ct, cnt); + for (t = 0; t < n_modes - 1; ++t) { + count = branch_ct[t][0] + branch_ct[t][1]; + count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; + factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); + dst_probs[t] = weighted_prob(pre_probs[t], probs[t], factor); + } +} + +// #define MODE_COUNT_TESTING void vp9_adapt_mode_probs(VP9_COMMON *cm) { - int i, t, count, factor; - unsigned int branch_ct[32][2]; - vp9_prob ymode_probs[VP9_YMODES - 1]; -#if CONFIG_SUPERBLOCKS - vp9_prob sb_ymode_probs[VP9_I32X32_MODES - 1]; -#endif - vp9_prob uvmode_probs[VP9_UV_MODES - 1]; - vp9_prob bmode_probs[VP9_NKF_BINTRAMODES - 1]; - vp9_prob i8x8_mode_probs[VP9_I8X8_MODES - 1]; - vp9_prob sub_mv_ref_probs[VP9_SUBMVREFS - 1]; - vp9_prob mbsplit_probs[VP9_NUMMBSPLITS - 1]; -#if CONFIG_COMP_INTERINTRA_PRED - vp9_prob interintra_prob; -#endif + int i; #ifdef MODE_COUNT_TESTING + int t; + printf("static const unsigned int\nymode_counts" "[VP9_YMODES] = {\n"); for (t = 0; t < VP9_YMODES; ++t) printf("%d, ", cm->fc.ymode_counts[t]); @@ -590,116 +595,45 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { printf("};\n"); #endif #endif - vp9_tree_probs_from_distribution( - VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree, - ymode_probs, branch_ct, cm->fc.ymode_counts, - 256, 1); - for (t = 0; t < VP9_YMODES - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_ymode_prob[t] * (256 - factor) + - (int)ymode_probs[t] * factor + 128) >> 8; - cm->fc.ymode_prob[t] = clip_prob(prob); - } + + update_mode_probs(VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree, + cm->fc.ymode_counts, cm->fc.pre_ymode_prob, + cm->fc.ymode_prob); #if CONFIG_SUPERBLOCKS - vp9_tree_probs_from_distribution(VP9_I32X32_MODES, - vp9_sb_ymode_encodings, vp9_sb_ymode_tree, - sb_ymode_probs, branch_ct, - cm->fc.sb_ymode_counts, - 256, 1); - for (t = 0; t < VP9_I32X32_MODES - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_sb_ymode_prob[t] * (256 - factor) + - (int)sb_ymode_probs[t] * factor + 128) >> 8; - cm->fc.sb_ymode_prob[t] = clip_prob(prob); - } + update_mode_probs(VP9_I32X32_MODES, vp9_sb_ymode_encodings, vp9_sb_ymode_tree, + cm->fc.sb_ymode_counts, cm->fc.pre_sb_ymode_prob, + cm->fc.sb_ymode_prob); #endif for (i = 0; i < VP9_YMODES; ++i) { - vp9_tree_probs_from_distribution(VP9_UV_MODES, vp9_uv_mode_encodings, - vp9_uv_mode_tree, uvmode_probs, branch_ct, - cm->fc.uv_mode_counts[i], 256, 1); - for (t = 0; t < VP9_UV_MODES - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_uv_mode_prob[i][t] * (256 - factor) + - (int)uvmode_probs[t] * factor + 128) >> 8; - cm->fc.uv_mode_prob[i][t] = clip_prob(prob); - } - } - vp9_tree_probs_from_distribution(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, - vp9_bmode_tree, bmode_probs, branch_ct, - cm->fc.bmode_counts, 256, 1); - for (t = 0; t < VP9_NKF_BINTRAMODES - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_bmode_prob[t] * (256 - factor) + - (int)bmode_probs[t] * factor + 128) >> 8; - cm->fc.bmode_prob[t] = clip_prob(prob); - } - vp9_tree_probs_from_distribution(VP9_I8X8_MODES, vp9_i8x8_mode_encodings, - vp9_i8x8_mode_tree, i8x8_mode_probs, - branch_ct, cm->fc.i8x8_mode_counts, 256, 1); - for (t = 0; t < VP9_I8X8_MODES - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_i8x8_mode_prob[t] * (256 - factor) + - (int)i8x8_mode_probs[t] * factor + 128) >> 8; - cm->fc.i8x8_mode_prob[t] = clip_prob(prob); + update_mode_probs(VP9_UV_MODES, vp9_uv_mode_encodings, vp9_uv_mode_tree, + cm->fc.uv_mode_counts[i], cm->fc.pre_uv_mode_prob[i], + cm->fc.uv_mode_prob[i]); } + update_mode_probs(VP9_NKF_BINTRAMODES, vp9_bmode_encodings, vp9_bmode_tree, + cm->fc.bmode_counts, cm->fc.pre_bmode_prob, + cm->fc.bmode_prob); + update_mode_probs(VP9_I8X8_MODES, vp9_i8x8_mode_encodings, + vp9_i8x8_mode_tree, cm->fc.i8x8_mode_counts, + cm->fc.pre_i8x8_mode_prob, cm->fc.i8x8_mode_prob); for (i = 0; i < SUBMVREF_COUNT; ++i) { - vp9_tree_probs_from_distribution(VP9_SUBMVREFS, - vp9_sub_mv_ref_encoding_array, - vp9_sub_mv_ref_tree, sub_mv_ref_probs, - branch_ct, cm->fc.sub_mv_ref_counts[i], - 256, 1); - for (t = 0; t < VP9_SUBMVREFS - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_sub_mv_ref_prob[i][t] * (256 - factor) + - (int)sub_mv_ref_probs[t] * factor + 128) >> 8; - cm->fc.sub_mv_ref_prob[i][t] = clip_prob(prob); - } - } - vp9_tree_probs_from_distribution(VP9_NUMMBSPLITS, vp9_mbsplit_encodings, - vp9_mbsplit_tree, mbsplit_probs, branch_ct, - cm->fc.mbsplit_counts, 256, 1); - for (t = 0; t < VP9_NUMMBSPLITS - 1; ++t) { - int prob; - count = branch_ct[t][0] + branch_ct[t][1]; - count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; - factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_mbsplit_prob[t] * (256 - factor) + - (int)mbsplit_probs[t] * factor + 128) >> 8; - cm->fc.mbsplit_prob[t] = clip_prob(prob); + update_mode_probs(VP9_SUBMVREFS, vp9_sub_mv_ref_encoding_array, + vp9_sub_mv_ref_tree, cm->fc.sub_mv_ref_counts[i], + cm->fc.pre_sub_mv_ref_prob[i], cm->fc.sub_mv_ref_prob[i]); } + update_mode_probs(VP9_NUMMBSPLITS, vp9_mbsplit_encodings, vp9_mbsplit_tree, + cm->fc.mbsplit_counts, cm->fc.pre_mbsplit_prob, + cm->fc.mbsplit_prob); #if CONFIG_COMP_INTERINTRA_PRED if (cm->use_interintra) { - int prob; - interintra_prob = vp9_bin_prob_from_distribution(cm->fc.interintra_counts); + int factor, interintra_prob, count; + + interintra_prob = get_binary_prob(cm->fc.interintra_counts[0], + cm->fc.interintra_counts[1]); count = cm->fc.interintra_counts[0] + cm->fc.interintra_counts[1]; count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count; factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT); - prob = ((int)cm->fc.pre_interintra_prob * (256 - factor) + - (int)interintra_prob * factor + 128) >> 8; - if (prob <= 0) - cm->fc.interintra_prob = 1; - else if (prob > 255) - cm->fc.interintra_prob = 255; - else - cm->fc.interintra_prob = prob; + cm->fc.interintra_prob = weighted_prob(cm->fc.pre_interintra_prob, + interintra_prob, factor); } #endif } diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c index 94543c54d..99e3c2e8c 100644 --- a/vp9/common/vp9_entropymv.c +++ b/vp9/common/vp9_entropymv.c @@ -213,16 +213,12 @@ void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx, static void adapt_prob(vp9_prob *dest, vp9_prob prep, vp9_prob newp, unsigned int ct[2]) { - int factor; - int prob; int count = ct[0] + ct[1]; + if (count) { count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count; - factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT); - prob = ((int)prep * (256 - factor) + (int)(newp) * factor + 128) >> 8; - prob += !prob; - prob = (prob > 255 ? 255 : prob); - *dest = prob; + *dest = weighted_prob(prep, newp, + MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT); } } @@ -251,11 +247,10 @@ void vp9_counts_to_nmv_context( vp9_mv_joint_tree, prob->joints, branch_ct_joint, - NMVcount->joints, - 256, 1); + NMVcount->joints); for (i = 0; i < 2; ++i) { - prob->comps[i].sign = - vp9_bin_prob_from_distribution(NMVcount->comps[i].sign); + prob->comps[i].sign = get_binary_prob(NMVcount->comps[i].sign[0], + NMVcount->comps[i].sign[1]); branch_ct_sign[i][0] = NMVcount->comps[i].sign[0]; branch_ct_sign[i][1] = NMVcount->comps[i].sign[1]; vp9_tree_probs_from_distribution(MV_CLASSES, @@ -263,18 +258,16 @@ void vp9_counts_to_nmv_context( vp9_mv_class_tree, prob->comps[i].classes, branch_ct_classes[i], - NMVcount->comps[i].classes, - 256, 1); + NMVcount->comps[i].classes); vp9_tree_probs_from_distribution(CLASS0_SIZE, vp9_mv_class0_encodings, vp9_mv_class0_tree, prob->comps[i].class0, branch_ct_class0[i], - NMVcount->comps[i].class0, - 256, 1); + NMVcount->comps[i].class0); for (j = 0; j < MV_OFFSET_BITS; ++j) { - prob->comps[i].bits[j] = vp9_bin_prob_from_distribution( - NMVcount->comps[i].bits[j]); + prob->comps[i].bits[j] = get_binary_prob(NMVcount->comps[i].bits[j][0], + NMVcount->comps[i].bits[j][1]); branch_ct_bits[i][j][0] = NMVcount->comps[i].bits[j][0]; branch_ct_bits[i][j][1] = NMVcount->comps[i].bits[j][1]; } @@ -286,26 +279,25 @@ void vp9_counts_to_nmv_context( vp9_mv_fp_tree, prob->comps[i].class0_fp[k], branch_ct_class0_fp[i][k], - NMVcount->comps[i].class0_fp[k], - 256, 1); + NMVcount->comps[i].class0_fp[k]); } vp9_tree_probs_from_distribution(4, vp9_mv_fp_encodings, vp9_mv_fp_tree, prob->comps[i].fp, branch_ct_fp[i], - NMVcount->comps[i].fp, - 256, 1); + NMVcount->comps[i].fp); } if (usehp) { for (i = 0; i < 2; ++i) { - prob->comps[i].class0_hp = vp9_bin_prob_from_distribution( - NMVcount->comps[i].class0_hp); + prob->comps[i].class0_hp = + get_binary_prob(NMVcount->comps[i].class0_hp[0], + NMVcount->comps[i].class0_hp[1]); branch_ct_class0_hp[i][0] = NMVcount->comps[i].class0_hp[0]; branch_ct_class0_hp[i][1] = NMVcount->comps[i].class0_hp[1]; - prob->comps[i].hp = - vp9_bin_prob_from_distribution(NMVcount->comps[i].hp); + prob->comps[i].hp = get_binary_prob(NMVcount->comps[i].hp[0], + NMVcount->comps[i].hp[1]); branch_ct_hp[i][0] = NMVcount->comps[i].hp[0]; branch_ct_hp[i][1] = NMVcount->comps[i].hp[1]; } diff --git a/vp9/common/vp9_filter.c b/vp9/common/vp9_filter.c index 18217e627..710b3917e 100644 --- a/vp9/common/vp9_filter.c +++ b/vp9/common/vp9_filter.c @@ -13,6 +13,7 @@ #include "vp9/common/vp9_filter.h" #include "vpx_ports/mem.h" #include "vp9_rtcd.h" +#include "vp9/common/vp9_common.h" DECLARE_ALIGNED(16, const short, vp9_bilinear_filters[SUBPEL_SHIFTS][2]) = { { 128, 0 }, @@ -148,11 +149,11 @@ static void filter_block2d_first_pass_6(unsigned char *src_ptr, unsigned int output_width, const short *vp9_filter) { unsigned int i, j; - int Temp; + int temp; for (i = 0; i < output_height; i++) { for (j = 0; j < output_width; j++) { - Temp = ((int)src_ptr[-2 * (int)pixel_step] * vp9_filter[0]) + + temp = ((int)src_ptr[-2 * (int)pixel_step] * vp9_filter[0]) + ((int)src_ptr[-1 * (int)pixel_step] * vp9_filter[1]) + ((int)src_ptr[0] * vp9_filter[2]) + ((int)src_ptr[pixel_step] * vp9_filter[3]) + @@ -161,14 +162,7 @@ static void filter_block2d_first_pass_6(unsigned char *src_ptr, (VP9_FILTER_WEIGHT >> 1); /* Rounding */ /* Normalize back to 0-255 */ - Temp = Temp >> VP9_FILTER_SHIFT; - - if (Temp < 0) - Temp = 0; - else if (Temp > 255) - Temp = 255; - - output_ptr[j] = Temp; + output_ptr[j] = clip_pixel(temp >> VP9_FILTER_SHIFT); src_ptr++; } @@ -187,12 +181,12 @@ static void filter_block2d_second_pass_6(int *src_ptr, unsigned int output_width, const short *vp9_filter) { unsigned int i, j; - int Temp; + int temp; for (i = 0; i < output_height; i++) { for (j = 0; j < output_width; j++) { /* Apply filter */ - Temp = ((int)src_ptr[-2 * (int)pixel_step] * vp9_filter[0]) + + temp = ((int)src_ptr[-2 * (int)pixel_step] * vp9_filter[0]) + ((int)src_ptr[-1 * (int)pixel_step] * vp9_filter[1]) + ((int)src_ptr[0] * vp9_filter[2]) + ((int)src_ptr[pixel_step] * vp9_filter[3]) + @@ -201,14 +195,7 @@ static void filter_block2d_second_pass_6(int *src_ptr, (VP9_FILTER_WEIGHT >> 1); /* Rounding */ /* Normalize back to 0-255 */ - Temp = Temp >> VP9_FILTER_SHIFT; - - if (Temp < 0) - Temp = 0; - else if (Temp > 255) - Temp = 255; - - output_ptr[j] = (unsigned char)Temp; + output_ptr[j] = clip_pixel(temp >> VP9_FILTER_SHIFT); src_ptr++; } @@ -235,12 +222,12 @@ static void filter_block2d_second_pass_avg_6(int *src_ptr, unsigned int output_width, const short *vp9_filter) { unsigned int i, j; - int Temp; + int temp; for (i = 0; i < output_height; i++) { for (j = 0; j < output_width; j++) { /* Apply filter */ - Temp = ((int)src_ptr[-2 * (int)pixel_step] * vp9_filter[0]) + + temp = ((int)src_ptr[-2 * (int)pixel_step] * vp9_filter[0]) + ((int)src_ptr[-1 * (int)pixel_step] * vp9_filter[1]) + ((int)src_ptr[0] * vp9_filter[2]) + ((int)src_ptr[pixel_step] * vp9_filter[3]) + @@ -249,14 +236,8 @@ static void filter_block2d_second_pass_avg_6(int *src_ptr, (VP9_FILTER_WEIGHT >> 1); /* Rounding */ /* Normalize back to 0-255 */ - Temp = Temp >> VP9_FILTER_SHIFT; - - if (Temp < 0) - Temp = 0; - else if (Temp > 255) - Temp = 255; - - output_ptr[j] = (unsigned char)((output_ptr[j] + Temp + 1) >> 1); + output_ptr[j] = (clip_pixel(temp >> VP9_FILTER_SHIFT) + + output_ptr[j] + 1) >> 1; src_ptr++; } @@ -539,14 +520,8 @@ static void filter_block2d_8_c(const unsigned char *src_ptr, (VP9_FILTER_WEIGHT >> 1); // Rounding // Normalize back to 0-255... - temp >>= VP9_FILTER_SHIFT; - if (temp < 0) { - temp = 0; - } else if (temp > 255) { - temp = 255; - } + *output_ptr = clip_pixel(temp >> VP9_FILTER_SHIFT); src_ptr++; - *output_ptr = temp; output_ptr += intermediate_height; } src_ptr += src_next_row_stride; @@ -573,15 +548,8 @@ static void filter_block2d_8_c(const unsigned char *src_ptr, (VP9_FILTER_WEIGHT >> 1); // Rounding // Normalize back to 0-255... - temp >>= VP9_FILTER_SHIFT; - if (temp < 0) { - temp = 0; - } else if (temp > 255) { - temp = 255; - } - + *dst_ptr++ = clip_pixel(temp >> VP9_FILTER_SHIFT); src_ptr += intermediate_height; - *dst_ptr++ = (unsigned char)temp; } src_ptr += intermediate_next_stride; dst_ptr += dst_next_row_stride; @@ -940,15 +908,15 @@ static void filter_block2d_bil_second_pass(unsigned short *src_ptr, unsigned int width, const short *vp9_filter) { unsigned int i, j; - int Temp; + int temp; for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { /* Apply filter */ - Temp = ((int)src_ptr[0] * vp9_filter[0]) + + temp = ((int)src_ptr[0] * vp9_filter[0]) + ((int)src_ptr[width] * vp9_filter[1]) + (VP9_FILTER_WEIGHT / 2); - dst_ptr[j] = (unsigned int)(Temp >> VP9_FILTER_SHIFT); + dst_ptr[j] = (unsigned int)(temp >> VP9_FILTER_SHIFT); src_ptr++; } @@ -973,15 +941,15 @@ static void filter_block2d_bil_second_pass_avg(unsigned short *src_ptr, unsigned int width, const short *vp9_filter) { unsigned int i, j; - int Temp; + int temp; for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { /* Apply filter */ - Temp = ((int)src_ptr[0] * vp9_filter[0]) + - ((int)src_ptr[width] * vp9_filter[1]) + - (VP9_FILTER_WEIGHT / 2); - dst_ptr[j] = (unsigned int)(((Temp >> VP9_FILTER_SHIFT) + dst_ptr[j] + 1) >> 1); + temp = (((int)src_ptr[0] * vp9_filter[0]) + + ((int)src_ptr[width] * vp9_filter[1]) + + (VP9_FILTER_WEIGHT / 2)) >> VP9_FILTER_SHIFT; + dst_ptr[j] = (unsigned int)((temp + dst_ptr[j] + 1) >> 1); src_ptr++; } diff --git a/vp9/common/vp9_idctllm.c b/vp9/common/vp9_idctllm.c index cc685b99e..9074da22f 100644 --- a/vp9/common/vp9_idctllm.c +++ b/vp9/common/vp9_idctllm.c @@ -26,8 +26,8 @@ #include <math.h> #include "vpx_ports/config.h" #include "vp9/common/vp9_systemdependent.h" - #include "vp9/common/vp9_blockd.h" +#include "vp9/common/vp9_common.h" static const int cospi8sqrt2minus1 = 20091; static const int sinpi8sqrt2 = 35468; @@ -562,15 +562,7 @@ void vp9_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr, for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { - int a = a1 + pred_ptr[c]; - - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(a1 + pred_ptr[c]); } dst_ptr += stride; @@ -765,14 +757,7 @@ void vp9_dc_only_inv_walsh_add_c(short input_dc, unsigned char *pred_ptr, for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { - int a = tmp[r * 4 + c] + pred_ptr[c]; - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(tmp[r * 4 + c] + pred_ptr[c]); } dst_ptr += stride; @@ -792,15 +777,7 @@ void vp9_dc_only_idct_add_8x8_c(short input_dc, for (b = 0; b < 4; b++) { for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { - int a = a1 + pred_ptr[c]; - - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(a1 + pred_ptr[c]); } dst_ptr += stride; diff --git a/vp9/common/vp9_pred_common.c b/vp9/common/vp9_pred_common.c index 2abae34b2..e8a3c4f5e 100644 --- a/vp9/common/vp9_pred_common.c +++ b/vp9/common/vp9_pred_common.c @@ -11,6 +11,7 @@ #include "vp9/common/vp9_pred_common.h" #include "vp9/common/vp9_seg_common.h" +#include "vp9/common/vp9_treecoder.h" // TBD prediction functions for various bitstream signals @@ -383,26 +384,13 @@ void vp9_calc_ref_probs(int *count, vp9_prob *probs) { int tot_count; tot_count = count[0] + count[1] + count[2] + count[3]; - if (tot_count) { - probs[0] = (vp9_prob)((count[0] * 255 + (tot_count >> 1)) / tot_count); - probs[0] += !probs[0]; - } else - probs[0] = 128; + probs[0] = get_prob(count[0], tot_count); tot_count -= count[0]; - if (tot_count) { - probs[1] = (vp9_prob)((count[1] * 255 + (tot_count >> 1)) / tot_count); - probs[1] += !probs[1]; - } else - probs[1] = 128; + probs[1] = get_prob(count[1], tot_count); tot_count -= count[1]; - if (tot_count) { - probs[2] = (vp9_prob)((count[2] * 255 + (tot_count >> 1)) / tot_count); - probs[2] += !probs[2]; - } else - probs[2] = 128; - + probs[2] = get_prob(count[2], tot_count); } // Computes a set of modified conditional probabilities for the reference frame diff --git a/vp9/common/vp9_recon.c b/vp9/common/vp9_recon.c index e567bac8d..d8bcd77c0 100644 --- a/vp9/common/vp9_recon.c +++ b/vp9/common/vp9_recon.c @@ -24,15 +24,7 @@ void vp9_recon_b_c for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { - int a = diff_ptr[c] + pred_ptr[c]; - - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(diff_ptr[c] + pred_ptr[c]); } dst_ptr += stride; @@ -52,15 +44,7 @@ void vp9_recon_uv_b_c for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { - int a = diff_ptr[c] + pred_ptr[c]; - - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(diff_ptr[c] + pred_ptr[c]); } dst_ptr += stride; @@ -79,15 +63,7 @@ void vp9_recon4b_c for (r = 0; r < 4; r++) { for (c = 0; c < 16; c++) { - int a = diff_ptr[c] + pred_ptr[c]; - - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(diff_ptr[c] + pred_ptr[c]); } dst_ptr += stride; @@ -107,15 +83,7 @@ void vp9_recon2b_c for (r = 0; r < 4; r++) { for (c = 0; c < 8; c++) { - int a = diff_ptr[c] + pred_ptr[c]; - - if (a < 0) - a = 0; - - if (a > 255) - a = 255; - - dst_ptr[c] = (unsigned char) a; + dst_ptr[c] = clip_pixel(diff_ptr[c] + pred_ptr[c]); } dst_ptr += stride; @@ -133,12 +101,7 @@ void vp9_recon_mby_s_c(MACROBLOCKD *xd, uint8_t *dst) { for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) { - int a = dst[x] + diff[x]; - if (a < 0) - a = 0; - else if (a > 255) - a = 255; - dst[x] = a; + dst[x] = clip_pixel(dst[x] + diff[x]); } dst += stride; diff += 16; @@ -156,12 +119,7 @@ void vp9_recon_mbuv_s_c(MACROBLOCKD *xd, uint8_t *udst, uint8_t *vdst) { for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { - int a = dst[x] + diff[x]; - if (a < 0) - a = 0; - else if (a > 255) - a = 255; - dst[x] = a; + dst[x] = clip_pixel(dst[x] + diff[x]); } dst += stride; diff += 8; @@ -176,12 +134,7 @@ void vp9_recon_sby_s_c(MACROBLOCKD *xd, uint8_t *dst) { for (y = 0; y < 32; y++) { for (x = 0; x < 32; x++) { - int a = dst[x] + diff[x]; - if (a < 0) - a = 0; - else if (a > 255) - a = 255; - dst[x] = a; + dst[x] = clip_pixel(dst[x] + diff[x]); } dst += stride; diff += 32; @@ -195,18 +148,8 @@ void vp9_recon_sbuv_s_c(MACROBLOCKD *xd, uint8_t *udst, uint8_t *vdst) { for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) { - int u = udst[x] + udiff[x]; - int v = vdst[x] + vdiff[x]; - if (u < 0) - u = 0; - else if (u > 255) - u = 255; - if (v < 0) - v = 0; - else if (v > 255) - v = 255; - udst[x] = u; - vdst[x] = v; + udst[x] = clip_pixel(udst[x] + udiff[x]); + vdst[x] = clip_pixel(vdst[x] + vdiff[x]); } udst += stride; vdst += stride; diff --git a/vp9/common/vp9_reconinter.c b/vp9/common/vp9_reconinter.c index fb4906e6a..11d1c97b1 100644 --- a/vp9/common/vp9_reconinter.c +++ b/vp9/common/vp9_reconinter.c @@ -332,8 +332,8 @@ void filter_mb(unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int width, int height) { int i, j, k; - unsigned int Temp[32 * 32]; - unsigned int *pTmp = Temp; + unsigned int temp[32 * 32]; + unsigned int *pTmp = temp; unsigned char *pSrc = src - (1 + src_stride) * (PRED_FILT_LEN / 2); // Horizontal @@ -350,7 +350,7 @@ void filter_mb(unsigned char *src, int src_stride, } // Vertical - pTmp = Temp; + pTmp = temp; for (i = 0; i < width; i++) { unsigned char *pDst = dst + i; for (j = 0; j < height; j++) { @@ -358,8 +358,8 @@ void filter_mb(unsigned char *src, int src_stride, for (k = 0; k < PRED_FILT_LEN; k++) sum += pTmp[(j + k) * width] * pred_filter[k]; // Round - sum = (sum + ((1 << (filt_shift << 1)) >> 1)) >> (filt_shift << 1); - pDst[j * dst_stride] = (sum < 0 ? 0 : sum > 255 ? 255 : sum); + pDst[j * dst_stride] = (sum + ((1 << (filt_shift << 1)) >> 1)) >> + (filt_shift << 1); } ++pTmp; } diff --git a/vp9/common/vp9_reconintra.c b/vp9/common/vp9_reconintra.c index 92492aa5b..14f94820d 100644 --- a/vp9/common/vp9_reconintra.c +++ b/vp9/common/vp9_reconintra.c @@ -124,18 +124,20 @@ static void d45_predictor(uint8_t *ypred_ptr, int y_stride, int n, } } for (c = 0; c <= r; ++c) { - int yabove_ext = yabove_row[r]; // 2*yabove_row[r] - yabove_row[r-1]; - int yleft_ext = yleft_col[r]; // 2*yleft_col[r] - yleft_col[r-1]; - yabove_ext = (yabove_ext > 255 ? 255 : (yabove_ext < 0 ? 0 : yabove_ext)); - yleft_ext = (yleft_ext > 255 ? 255 : (yleft_ext < 0 ? 0 : yleft_ext)); + int yabove_ext = yabove_row[r]; // clip_pixel(2 * yabove_row[r] - + // yabove_row[r - 1]); + int yleft_ext = yleft_col[r]; // clip_pixel(2 * yleft_col[r] - + // yleft_col[r-1]); ypred_ptr[(r - c) * y_stride + c] = (yabove_ext * (c + 1) + yleft_ext * (r - c + 1) + r / 2 + 1) / (r + 2); } for (r = 1; r < n; ++r) { - for (c = n - r; c < n; ++c) - ypred_ptr[r * y_stride + c] = (ypred_ptr[(r - 1) * y_stride + c] + - ypred_ptr[r * y_stride + c - 1] + 1) >> 1; + for (c = n - r; c < n; ++c) { + const int yabove_ext = ypred_ptr[(r - 1) * y_stride + c]; + const int yleft_ext = ypred_ptr[r * y_stride + c - 1]; + ypred_ptr[r * y_stride + c] = (yabove_ext + yleft_ext + 1) >> 1; + } } } @@ -321,15 +323,7 @@ void vp9_build_intra_predictors_internal(unsigned char *src, int src_stride, case TM_PRED: { for (r = 0; r < bsize; r++) { for (c = 0; c < bsize; c++) { - int pred = yleft_col[r] + yabove_row[ c] - ytop_left; - - if (pred < 0) - pred = 0; - - if (pred > 255) - pred = 255; - - ypred_ptr[c] = pred; + ypred_ptr[c] = clip_pixel(yleft_col[r] + yabove_row[c] - ytop_left); } ypred_ptr += y_stride; diff --git a/vp9/common/vp9_reconintra4x4.c b/vp9/common/vp9_reconintra4x4.c index f542acb3d..82338901a 100644 --- a/vp9/common/vp9_reconintra4x4.c +++ b/vp9/common/vp9_reconintra4x4.c @@ -156,14 +156,14 @@ void vp9_intra4x4_predict(BLOCKD *x, unsigned char *predictor) { int i, r, c; - unsigned char *Above = *(x->base_dst) + x->dst - x->dst_stride; - unsigned char Left[4]; - unsigned char top_left = Above[-1]; + unsigned char *above = *(x->base_dst) + x->dst - x->dst_stride; + unsigned char left[4]; + unsigned char top_left = above[-1]; - Left[0] = (*(x->base_dst))[x->dst - 1]; - Left[1] = (*(x->base_dst))[x->dst - 1 + x->dst_stride]; - Left[2] = (*(x->base_dst))[x->dst - 1 + 2 * x->dst_stride]; - Left[3] = (*(x->base_dst))[x->dst - 1 + 3 * x->dst_stride]; + left[0] = (*(x->base_dst))[x->dst - 1]; + left[1] = (*(x->base_dst))[x->dst - 1 + x->dst_stride]; + left[2] = (*(x->base_dst))[x->dst - 1 + 2 * x->dst_stride]; + left[3] = (*(x->base_dst))[x->dst - 1 + 3 * x->dst_stride]; #if CONFIG_NEWBINTRAMODES if (b_mode == B_CONTEXT_PRED) @@ -175,8 +175,8 @@ void vp9_intra4x4_predict(BLOCKD *x, int expected_dc = 0; for (i = 0; i < 4; i++) { - expected_dc += Above[i]; - expected_dc += Left[i]; + expected_dc += above[i]; + expected_dc += left[i]; } expected_dc = (expected_dc + 4) >> 3; @@ -194,15 +194,7 @@ void vp9_intra4x4_predict(BLOCKD *x, /* prediction similar to true_motion prediction */ for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { - int pred = Above[c] - top_left + Left[r]; - - if (pred < 0) - pred = 0; - - if (pred > 255) - pred = 255; - - predictor[c] = pred; + predictor[c] = clip_pixel(above[c] - top_left + left[r]); } predictor += 16; @@ -213,10 +205,10 @@ void vp9_intra4x4_predict(BLOCKD *x, case B_VE_PRED: { unsigned int ap[4]; - ap[0] = Above[0]; - ap[1] = Above[1]; - ap[2] = Above[2]; - ap[3] = Above[3]; + ap[0] = above[0]; + ap[1] = above[1]; + ap[2] = above[2]; + ap[3] = above[3]; for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { @@ -234,10 +226,10 @@ void vp9_intra4x4_predict(BLOCKD *x, case B_HE_PRED: { unsigned int lp[4]; - lp[0] = Left[0]; - lp[1] = Left[1]; - lp[2] = Left[2]; - lp[3] = Left[3]; + lp[0] = left[0]; + lp[1] = left[1]; + lp[2] = left[2]; + lp[3] = left[3]; for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { @@ -249,7 +241,7 @@ void vp9_intra4x4_predict(BLOCKD *x, } break; case B_LD_PRED: { - unsigned char *ptr = Above; + unsigned char *ptr = above; predictor[0 * 16 + 0] = (ptr[0] + ptr[1] * 2 + ptr[2] + 2) >> 2; predictor[0 * 16 + 1] = predictor[1 * 16 + 0] = (ptr[1] + ptr[2] * 2 + ptr[3] + 2) >> 2; @@ -273,15 +265,15 @@ void vp9_intra4x4_predict(BLOCKD *x, unsigned char pp[9]; - pp[0] = Left[3]; - pp[1] = Left[2]; - pp[2] = Left[1]; - pp[3] = Left[0]; + pp[0] = left[3]; + pp[1] = left[2]; + pp[2] = left[1]; + pp[3] = left[0]; pp[4] = top_left; - pp[5] = Above[0]; - pp[6] = Above[1]; - pp[7] = Above[2]; - pp[8] = Above[3]; + pp[5] = above[0]; + pp[6] = above[1]; + pp[7] = above[2]; + pp[8] = above[3]; predictor[3 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; predictor[3 * 16 + 1] = @@ -306,15 +298,15 @@ void vp9_intra4x4_predict(BLOCKD *x, unsigned char pp[9]; - pp[0] = Left[3]; - pp[1] = Left[2]; - pp[2] = Left[1]; - pp[3] = Left[0]; + pp[0] = left[3]; + pp[1] = left[2]; + pp[2] = left[1]; + pp[3] = left[0]; pp[4] = top_left; - pp[5] = Above[0]; - pp[6] = Above[1]; - pp[7] = Above[2]; - pp[8] = Above[3]; + pp[5] = above[0]; + pp[6] = above[1]; + pp[7] = above[2]; + pp[8] = above[3]; predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2; @@ -338,7 +330,7 @@ void vp9_intra4x4_predict(BLOCKD *x, break; case B_VL_PRED: { - unsigned char *pp = Above; + unsigned char *pp = above; predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1; predictor[1 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; @@ -361,15 +353,15 @@ void vp9_intra4x4_predict(BLOCKD *x, case B_HD_PRED: { unsigned char pp[9]; - pp[0] = Left[3]; - pp[1] = Left[2]; - pp[2] = Left[1]; - pp[3] = Left[0]; + pp[0] = left[3]; + pp[1] = left[2]; + pp[2] = left[1]; + pp[3] = left[0]; pp[4] = top_left; - pp[5] = Above[0]; - pp[6] = Above[1]; - pp[7] = Above[2]; - pp[8] = Above[3]; + pp[5] = above[0]; + pp[6] = above[1]; + pp[7] = above[2]; + pp[8] = above[3]; predictor[3 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1; @@ -393,7 +385,7 @@ void vp9_intra4x4_predict(BLOCKD *x, case B_HU_PRED: { - unsigned char *pp = Left; + unsigned char *pp = left; predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1; predictor[0 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2; predictor[0 * 16 + 2] = @@ -418,7 +410,7 @@ void vp9_intra4x4_predict(BLOCKD *x, break; /* case B_CORNER_PRED: - corner_predictor(predictor, 16, 4, Above, Left); + corner_predictor(predictor, 16, 4, above, left); break; */ #endif diff --git a/vp9/common/vp9_treecoder.c b/vp9/common/vp9_treecoder.c index 64018a100..fbc8a38cd 100644 --- a/vp9/common/vp9_treecoder.c +++ b/vp9/common/vp9_treecoder.c @@ -100,9 +100,7 @@ void vp9_tree_probs_from_distribution( vp9_tree tree, vp9_prob probs [ /* n-1 */ ], unsigned int branch_ct [ /* n-1 */ ] [2], - const unsigned int num_events[ /* n */ ], - unsigned int Pfac, - int rd + const unsigned int num_events[ /* n */ ] ) { const int tree_len = n - 1; int t = 0; @@ -110,29 +108,6 @@ void vp9_tree_probs_from_distribution( branch_counts(n, tok, tree, branch_ct, num_events); do { - const unsigned int *const c = branch_ct[t]; - const unsigned int tot = c[0] + c[1]; - -#if CONFIG_DEBUG - assert(tot < (1 << 24)); /* no overflow below */ -#endif - - if (tot) { - const unsigned int p = ((c[0] * Pfac) + (rd ? tot >> 1 : 0)) / tot; - probs[t] = p < 256 ? (p ? p : 1) : 255; /* agree w/old version for now */ - } else - probs[t] = vp9_prob_half; + probs[t] = get_binary_prob(branch_ct[t][0], branch_ct[t][1]); } while (++t < tree_len); } - -vp9_prob vp9_bin_prob_from_distribution(const unsigned int counts[2]) { - int tot_count = counts[0] + counts[1]; - vp9_prob prob; - if (tot_count) { - prob = (counts[0] * 255 + (tot_count >> 1)) / tot_count; - prob += !prob; - } else { - prob = 128; - } - return prob; -} diff --git a/vp9/common/vp9_treecoder.h b/vp9/common/vp9_treecoder.h index bbf7e74d7..525b77dc8 100644 --- a/vp9/common/vp9_treecoder.h +++ b/vp9/common/vp9_treecoder.h @@ -12,6 +12,8 @@ #ifndef VP9_COMMON_VP9_TREECODER_H_ #define VP9_COMMON_VP9_TREECODER_H_ +#include "vpx/vpx_integer.h" + typedef unsigned char vp9_prob; #define vp9_prob_half ( (vp9_prob) 128) @@ -65,19 +67,24 @@ void vp9_tree_probs_from_distribution( vp9_tree tree, vp9_prob probs [ /* n-1 */ ], unsigned int branch_ct [ /* n-1 */ ] [2], - const unsigned int num_events[ /* n */ ], - unsigned int Pfactor, - int Round + const unsigned int num_events[ /* n */ ] ); -static __inline int clip_prob(int p) { - if (p > 255) - return 255; - else if (p < 1) - return 1; - return p; +static __inline vp9_prob clip_prob(int p) { + return (p > 255) ? 255u : (p < 1) ? 1u : p; +} + +static __inline vp9_prob get_prob(int num, int den) { + return (den == 0) ? 128u : clip_prob((num * 256 + (den >> 1)) / den); } -vp9_prob vp9_bin_prob_from_distribution(const unsigned int counts[2]); +static __inline vp9_prob get_binary_prob(int n0, int n1) { + return get_prob(n0, n0 + n1); +} + +/* this function assumes prob1 and prob2 are already within [1,255] range */ +static __inline vp9_prob weighted_prob(int prob1, int prob2, int factor) { + return (prob1 * (256 - factor) + prob2 * factor + 128) >> 8; +} #endif diff --git a/vp9/decoder/vp9_dequantize.c b/vp9/decoder/vp9_dequantize.c index 22a66716f..9e382914b 100644 --- a/vp9/decoder/vp9_dequantize.c +++ b/vp9/decoder/vp9_dequantize.c @@ -13,6 +13,7 @@ #include "vp9/decoder/vp9_dequantize.h" #include "vpx_mem/vpx_mem.h" #include "vp9/decoder/vp9_onyxd_int.h" +#include "vp9/common/vp9_common.h" static void add_residual(const int16_t *diff, const uint8_t *pred, int pitch, uint8_t *dest, int stride, int width, int height) { @@ -20,14 +21,7 @@ static void add_residual(const int16_t *diff, const uint8_t *pred, int pitch, for (r = 0; r < height; r++) { for (c = 0; c < width; c++) { - int a = diff[c] + pred[c]; - - if (a < 0) - a = 0; - else if (a > 255) - a = 255; - - dest[c] = (uint8_t) a; + dest[c] = clip_pixel(diff[c] + pred[c]); } dest += stride; @@ -43,14 +37,7 @@ static void add_constant_residual(const int16_t diff, const uint8_t *pred, for (r = 0; r < height; r++) { for (c = 0; c < width; c++) { - int a = diff + pred[c]; - - if (a < 0) - a = 0; - else if (a > 255) - a = 255; - - dest[c] = (uint8_t) a; + dest[c] = clip_pixel(diff + pred[c]); } dest += stride; diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 09d0e9929..498f64752 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -30,6 +30,7 @@ #include "vp9/encoder/vp9_encodemv.h" #include "vp9/common/vp9_entropymv.h" #include "vp9/common/vp9_mvref_common.h" +#include "vp9/common/vp9_treecoder.h" #if defined(SECTIONBITS_OUTPUT) unsigned __int64 Sectionbits[500]; @@ -110,11 +111,8 @@ static void update_mode( unsigned int new_b = 0, old_b = 0; int i = 0; - vp9_tree_probs_from_distribution( - n--, tok, tree, - Pnew, bct, num_events, - 256, 1 - ); + vp9_tree_probs_from_distribution(n--, tok, tree, + Pnew, bct, num_events); do { new_b += cost_branch(bct[i], Pnew[i]); @@ -155,18 +153,6 @@ static void update_mbintra_mode_probs(VP9_COMP* const cpi, } } -static int get_prob(int num, int den) { - int p; - if (den <= 0) - return 128; - p = (num * 255 + (den >> 1)) / den; - return clip_prob(p); -} - -static int get_binary_prob(int n0, int n1) { - return get_prob(n0, n0 + n1); -} - void vp9_update_skip_probs(VP9_COMP *cpi) { VP9_COMMON *const pc = &cpi->common; int k; @@ -187,7 +173,7 @@ static void update_switchable_interp_probs(VP9_COMP *cpi, VP9_SWITCHABLE_FILTERS, vp9_switchable_interp_encodings, vp9_switchable_interp_tree, pc->fc.switchable_interp_prob[j], branch_ct, - cpi->switchable_interp_count[j], 256, 1); + cpi->switchable_interp_count[j]); for (i = 0; i < VP9_SWITCHABLE_FILTERS - 1; ++i) { if (pc->fc.switchable_interp_prob[j][i] < 1) pc->fc.switchable_interp_prob[j][i] = 1; @@ -257,13 +243,11 @@ static void update_mode_probs(VP9_COMMON *cm, for (i = 0; i < INTER_MODE_CONTEXTS; i++) { for (j = 0; j < 4; j++) { - int new_prob, count, old_cost, new_cost; + int new_prob, old_cost, new_cost; // Work out cost of coding branches with the old and optimal probability old_cost = cost_branch256(mv_ref_ct[i][j], mode_context[i][j]); - count = mv_ref_ct[i][j][0] + mv_ref_ct[i][j][1]; - new_prob = count > 0 ? (255 * mv_ref_ct[i][j][0]) / count : 128; - new_prob = (new_prob > 0) ? new_prob : 1; + new_prob = get_binary_prob(mv_ref_ct[i][j][0], mv_ref_ct[i][j][1]); new_cost = cost_branch256(mv_ref_ct[i][j], new_prob); // If cost saving is >= 14 bits then update the mode probability. @@ -1404,7 +1388,7 @@ static void build_tree_distribution(vp9_coeff_probs *coef_probs, vp9_coef_encodings, vp9_coef_tree, coef_probs[i][j][k], coef_branch_ct[i][j][k], - coef_counts[i][j][k], 256, 1); + coef_counts[i][j][k]); #ifdef ENTROPY_STATS if (!cpi->dummy_packing) for (t = 0; t < MAX_ENTROPY_TOKENS; ++t) diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 04ee3f610..61ccc7ecb 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -2153,17 +2153,10 @@ void print_mode_context(void) { fprintf(f, " "); for (i = 0; i < 4; i++) { int this_prob; - int count; // context probs - count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1]; - if (count) - this_prob = 256 * mv_ref_ct[j][i][0] / count; - else - this_prob = 128; - - if (this_prob == 0) - this_prob = 1; + this_prob = get_binary_prob(mv_ref_ct[j][i][0], mv_ref_ct[j][i][1]); + fprintf(f, "%5d, ", this_prob); } fprintf(f, " },\n"); diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index bdc39c1af..07a3a0444 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -216,7 +216,7 @@ static void set_mvcost(MACROBLOCK *mb) { static void init_base_skip_probs(void) { int i; double q; - int skip_prob, t; + int t; for (i = 0; i < QINDEX_RANGE; i++) { q = vp9_convert_qindex_to_q(i); @@ -225,26 +225,9 @@ static void init_base_skip_probs(void) { // Based on crude best fit of old table. t = (int)(564.25 * pow(2.71828, (-0.012 * q))); - skip_prob = t; - if (skip_prob < 1) - skip_prob = 1; - else if (skip_prob > 255) - skip_prob = 255; - base_skip_false_prob[i][1] = skip_prob; - - skip_prob = t * 3 / 4; - if (skip_prob < 1) - skip_prob = 1; - else if (skip_prob > 255) - skip_prob = 255; - base_skip_false_prob[i][2] = skip_prob; - - skip_prob = t * 5 / 4; - if (skip_prob < 1) - skip_prob = 1; - else if (skip_prob > 255) - skip_prob = 255; - base_skip_false_prob[i][0] = skip_prob; + base_skip_false_prob[i][1] = clip_prob(t); + base_skip_false_prob[i][2] = clip_prob(t * 3 / 4); + base_skip_false_prob[i][0] = clip_prob(t * 5 / 4); } } @@ -2875,23 +2858,11 @@ void select_pred_filter_mode(VP9_COMP *cpi) { void update_pred_filt_prob(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; - int prob_pred_filter_off; // Based on the selection in the previous frame determine what mode // to use for the current frame and work out the signaling probability - if (cpi->pred_filter_on_count + cpi->pred_filter_off_count) { - prob_pred_filter_off = cpi->pred_filter_off_count * 256 / - (cpi->pred_filter_on_count + cpi->pred_filter_off_count); - - if (prob_pred_filter_off < 1) - prob_pred_filter_off = 1; - - if (prob_pred_filter_off > 255) - prob_pred_filter_off = 255; - - cm->prob_pred_filter_off = prob_pred_filter_off; - } else - cm->prob_pred_filter_off = 128; + cm->prob_pred_filter_off = get_binary_prob(cpi->pred_filter_off_count, + cpi->pred_filter_on_count); /* { FILE *fp = fopen("filt_use.txt", "a"); diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 9b87713f9..9265a0237 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -3045,7 +3045,6 @@ static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id, unsigned int int pred_flag; int pred_ctx; int i; - int tot_count; vp9_prob pred_prob, new_pred_prob; int seg_ref_active; @@ -3069,13 +3068,8 @@ static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id, unsigned int // Predict probability for current frame based on stats so far pred_ctx = vp9_get_pred_context(cm, xd, PRED_REF); - tot_count = cpi->ref_pred_count[pred_ctx][0] + cpi->ref_pred_count[pred_ctx][1]; - if (tot_count) { - new_pred_prob = - (cpi->ref_pred_count[pred_ctx][0] * 255 + (tot_count >> 1)) / tot_count; - new_pred_prob += !new_pred_prob; - } else - new_pred_prob = 128; + new_pred_prob = get_binary_prob(cpi->ref_pred_count[pred_ctx][0], + cpi->ref_pred_count[pred_ctx][1]); // Get the set of probabilities to use if prediction fails mod_refprobs = cm->mod_refprobs[pred_ref]; diff --git a/vp9/encoder/vp9_segmentation.c b/vp9/encoder/vp9_segmentation.c index 5e8d94c8c..ee90f4fc3 100644 --- a/vp9/encoder/vp9_segmentation.c +++ b/vp9/encoder/vp9_segmentation.c @@ -107,31 +107,15 @@ static void calc_segtree_probs(MACROBLOCKD *xd, int *segcounts, vp9_prob *segment_tree_probs) { int count1, count2; - int tot_count; - int i; - - // Blank the strtucture to start with - vpx_memset(segment_tree_probs, 0, - MB_FEATURE_TREE_PROBS * sizeof(*segment_tree_probs)); // Total count for all segments count1 = segcounts[0] + segcounts[1]; count2 = segcounts[2] + segcounts[3]; - tot_count = count1 + count2; // Work out probabilities of each segment - if (tot_count) - segment_tree_probs[0] = (count1 * 255) / tot_count; - if (count1 > 0) - segment_tree_probs[1] = (segcounts[0] * 255) / count1; - if (count2 > 0) - segment_tree_probs[2] = (segcounts[2] * 255) / count2; - - // Clamp probabilities to minimum allowed value - for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) { - if (segment_tree_probs[i] == 0) - segment_tree_probs[i] = 1; - } + segment_tree_probs[0] = get_binary_prob(count1, count2); + segment_tree_probs[1] = get_prob(segcounts[0], count1); + segment_tree_probs[2] = get_prob(segcounts[2], count2); } // Based on set of segment counts and probabilities calculate a cost estimate @@ -165,7 +149,6 @@ void vp9_choose_segmap_coding_method(VP9_COMP *cpi) { MACROBLOCKD *const xd = &cpi->mb.e_mbd; int i; - int tot_count; int no_pred_cost; int t_pred_cost = INT_MAX; int pred_context; @@ -297,20 +280,8 @@ void vp9_choose_segmap_coding_method(VP9_COMP *cpi) { // Add in the cost of the signalling for each prediction context for (i = 0; i < PREDICTION_PROBS; i++) { - tot_count = temporal_predictor_count[i][0] + - temporal_predictor_count[i][1]; - - // Work out the context probabilities for the segment - // prediction flag - if (tot_count) { - t_nopred_prob[i] = (temporal_predictor_count[i][0] * 255) / - tot_count; - - // Clamp to minimum allowed value - if (t_nopred_prob[i] < 1) - t_nopred_prob[i] = 1; - } else - t_nopred_prob[i] = 1; + t_nopred_prob[i] = get_binary_prob(temporal_predictor_count[i][0], + temporal_predictor_count[i][1]); // Add in the predictor signaling cost t_pred_cost += (temporal_predictor_count[i][0] * diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c index 9a0e8f3d9..bcc3b1f81 100644 --- a/vp9/encoder/vp9_tokenize.c +++ b/vp9/encoder/vp9_tokenize.c @@ -627,8 +627,7 @@ static void print_probs(FILE *f, vp9_coeff_accum *context_counters, coef_counts[t] = context_counters[type][band][pt][t]; vp9_tree_probs_from_distribution(MAX_ENTROPY_TOKENS, vp9_coef_encodings, vp9_coef_tree, - coef_probs, branch_ct, coef_counts, - 256, 1); + coef_probs, branch_ct, coef_counts); fprintf(f, "%s\n {", Comma(pt)); t = 0; |