diff options
Diffstat (limited to 'vp9/encoder')
-rw-r--r-- | vp9/encoder/vp9_bitstream.c | 32 | ||||
-rw-r--r-- | vp9/encoder/vp9_encodemv.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_encoder.c | 19 | ||||
-rw-r--r-- | vp9/encoder/vp9_pickmode.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_rd.c | 8 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_tokenize.c | 2 | ||||
-rw-r--r-- | vp9/encoder/x86/vp9_denoiser_sse2.c | 132 |
8 files changed, 97 insertions, 102 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 421e04969..4166d3106 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -84,7 +84,7 @@ static void write_selected_tx_size(const VP9_COMMON *cm, vp9_writer *w) { const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; const vp9_prob *const tx_probs = get_tx_probs2(max_tx_size, xd, - &cm->fc.tx_probs); + &cm->fc->tx_probs); vp9_write(w, tx_size != TX_4X4, tx_probs[0]); if (tx_size != TX_4X4 && max_tx_size >= TX_16X16) { vp9_write(w, tx_size != TX_8X8, tx_probs[1]); @@ -108,14 +108,14 @@ static void update_skip_probs(VP9_COMMON *cm, vp9_writer *w) { int k; for (k = 0; k < SKIP_CONTEXTS; ++k) - vp9_cond_prob_diff_update(w, &cm->fc.skip_probs[k], cm->counts.skip[k]); + vp9_cond_prob_diff_update(w, &cm->fc->skip_probs[k], cm->counts.skip[k]); } static void update_switchable_interp_probs(VP9_COMMON *cm, vp9_writer *w) { int j; for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) prob_diff_update(vp9_switchable_interp_tree, - cm->fc.switchable_interp_prob[j], + cm->fc->switchable_interp_prob[j], cm->counts.switchable_interp[j], SWITCHABLE_FILTERS, w); } @@ -237,7 +237,7 @@ static void write_ref_frames(const VP9_COMMON *cm, const MACROBLOCKD *xd, static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi, vp9_writer *w) { VP9_COMMON *const cm = &cpi->common; - const nmv_context *nmvc = &cm->fc.nmvc; + const nmv_context *nmvc = &cm->fc->nmvc; const MACROBLOCK *const x = &cpi->mb; const MACROBLOCKD *const xd = &x->e_mbd; const struct segmentation *const seg = &cm->seg; @@ -275,7 +275,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi, if (!is_inter) { if (bsize >= BLOCK_8X8) { - write_intra_mode(w, mode, cm->fc.y_mode_prob[size_group_lookup[bsize]]); + write_intra_mode(w, mode, cm->fc->y_mode_prob[size_group_lookup[bsize]]); } else { int idx, idy; const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; @@ -283,14 +283,14 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi, for (idy = 0; idy < 2; idy += num_4x4_h) { for (idx = 0; idx < 2; idx += num_4x4_w) { const PREDICTION_MODE b_mode = mi->bmi[idy * 2 + idx].as_mode; - write_intra_mode(w, b_mode, cm->fc.y_mode_prob[0]); + write_intra_mode(w, b_mode, cm->fc->y_mode_prob[0]); } } } - write_intra_mode(w, mbmi->uv_mode, cm->fc.uv_mode_prob[mode]); + write_intra_mode(w, mbmi->uv_mode, cm->fc->uv_mode_prob[mode]); } else { const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; - const vp9_prob *const inter_probs = cm->fc.inter_mode_probs[mode_ctx]; + const vp9_prob *const inter_probs = cm->fc->inter_mode_probs[mode_ctx]; write_ref_frames(cm, xd, w); // If segment skip is not enabled code the mode. @@ -304,7 +304,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi, if (cm->interp_filter == SWITCHABLE) { const int ctx = vp9_get_pred_context_switchable_interp(xd); vp9_write_token(w, vp9_switchable_interp_tree, - cm->fc.switchable_interp_prob[ctx], + cm->fc->switchable_interp_prob[ctx], &switchable_interp_encodings[mbmi->interp_filter]); ++cpi->interp_filter_selected[0][mbmi->interp_filter]; } else { @@ -528,7 +528,7 @@ static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, TX_SIZE tx_size, vp9_coeff_stats *frame_branch_ct, vp9_coeff_probs_model *new_coef_probs) { - vp9_coeff_probs_model *old_coef_probs = cpi->common.fc.coef_probs[tx_size]; + vp9_coeff_probs_model *old_coef_probs = cpi->common.fc->coef_probs[tx_size]; const vp9_prob upd = DIFF_UPDATE_PROB; const int entropy_nodes_update = UNCONSTRAINED_NODES; int i, j, k, l, t; @@ -830,20 +830,20 @@ static void encode_txfm_probs(VP9_COMMON *cm, vp9_writer *w) { for (i = 0; i < TX_SIZE_CONTEXTS; i++) { tx_counts_to_branch_counts_8x8(cm->counts.tx.p8x8[i], ct_8x8p); for (j = 0; j < TX_SIZES - 3; j++) - vp9_cond_prob_diff_update(w, &cm->fc.tx_probs.p8x8[i][j], ct_8x8p[j]); + vp9_cond_prob_diff_update(w, &cm->fc->tx_probs.p8x8[i][j], ct_8x8p[j]); } for (i = 0; i < TX_SIZE_CONTEXTS; i++) { tx_counts_to_branch_counts_16x16(cm->counts.tx.p16x16[i], ct_16x16p); for (j = 0; j < TX_SIZES - 2; j++) - vp9_cond_prob_diff_update(w, &cm->fc.tx_probs.p16x16[i][j], + vp9_cond_prob_diff_update(w, &cm->fc->tx_probs.p16x16[i][j], ct_16x16p[j]); } for (i = 0; i < TX_SIZE_CONTEXTS; i++) { tx_counts_to_branch_counts_32x32(cm->counts.tx.p32x32[i], ct_32x32p); for (j = 0; j < TX_SIZES - 1; j++) - vp9_cond_prob_diff_update(w, &cm->fc.tx_probs.p32x32[i][j], + vp9_cond_prob_diff_update(w, &cm->fc->tx_probs.p32x32[i][j], ct_32x32p[j]); } } @@ -1161,7 +1161,7 @@ static void write_uncompressed_header(VP9_COMP *cpi, static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) { VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &cpi->mb.e_mbd; - FRAME_CONTEXT *const fc = &cm->fc; + FRAME_CONTEXT *const fc = cm->fc; vp9_writer header_bc; vp9_start_encode(&header_bc, data); @@ -1178,7 +1178,7 @@ static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) { int i; for (i = 0; i < INTER_MODE_CONTEXTS; ++i) - prob_diff_update(vp9_inter_mode_tree, cm->fc.inter_mode_probs[i], + prob_diff_update(vp9_inter_mode_tree, cm->fc->inter_mode_probs[i], cm->counts.inter_mode[i], INTER_MODES, &header_bc); vp9_zero(cm->counts.inter_mode); @@ -1219,7 +1219,7 @@ static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) { cm->counts.comp_ref[i]); for (i = 0; i < BLOCK_SIZE_GROUPS; ++i) - prob_diff_update(vp9_intra_mode_tree, cm->fc.y_mode_prob[i], + prob_diff_update(vp9_intra_mode_tree, cm->fc->y_mode_prob[i], cm->counts.y_mode[i], INTRA_MODES, &header_bc); for (i = 0; i < PARTITION_CONTEXTS; ++i) diff --git a/vp9/encoder/vp9_encodemv.c b/vp9/encoder/vp9_encodemv.c index 089839567..f36d76e3d 100644 --- a/vp9/encoder/vp9_encodemv.c +++ b/vp9/encoder/vp9_encodemv.c @@ -163,7 +163,7 @@ static void write_mv_update(const vp9_tree_index *tree, void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vp9_writer *w) { int i, j; - nmv_context *const mvc = &cm->fc.nmvc; + nmv_context *const mvc = &cm->fc->nmvc; nmv_context_counts *const counts = &cm->counts.mv; write_mv_update(vp9_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w); diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index c5e872607..9b6e9a290 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -134,7 +134,7 @@ static void setup_frame(VP9_COMP *cpi) { cpi->refresh_alt_ref_frame = 1; vp9_zero(cpi->interp_filter_selected); } else { - cm->fc = cm->frame_contexts[cm->frame_context_idx]; + *cm->fc = cm->frame_contexts[cm->frame_context_idx]; vp9_zero(cpi->interp_filter_selected[0]); } } @@ -160,6 +160,11 @@ static void dealloc_compressor_data(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; int i; + vpx_free(cm->fc); + cm->fc = NULL; + vpx_free(cm->frame_contexts); + cm->frame_contexts = NULL; + // Delete sementation map vpx_free(cpi->segmentation_map); cpi->segmentation_map = NULL; @@ -257,7 +262,7 @@ static void save_coding_context(VP9_COMP *cpi) { vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); - cc->fc = cm->fc; + cc->fc = *cm->fc; } static void restore_coding_context(VP9_COMP *cpi) { @@ -286,7 +291,7 @@ static void restore_coding_context(VP9_COMP *cpi) { vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); - cm->fc = cc->fc; + *cm->fc = cc->fc; } static void configure_static_seg_features(VP9_COMP *cpi) { @@ -1374,6 +1379,12 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { cm->error.setjmp = 1; + CHECK_MEM_ERROR(cm, cm->fc, + (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); + CHECK_MEM_ERROR(cm, cm->frame_contexts, + (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, + sizeof(*cm->frame_contexts))); + cpi->use_svc = 0; init_config(cpi, oxcf); @@ -3638,7 +3649,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } if (cm->refresh_frame_context) - cm->frame_contexts[cm->frame_context_idx] = cm->fc; + cm->frame_contexts[cm->frame_context_idx] = *cm->fc; // Frame was dropped, release scaled references. if (*size == 0) { diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 56240ca95..1826885c7 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -634,7 +634,7 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, // motion vector is at sub-pixel accuracy level for luma component, i.e., // the last three bits are all zeros. if (cpi->sf.reuse_inter_pred_sby) { - if (this_mode == NEARESTMV) { + if (!this_mode_pred) { this_mode_pred = &tmp[3]; } else { this_mode_pred = &tmp[get_pred_buffer(tmp, 3)]; diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c index 7f526fc42..d758430c3 100644 --- a/vp9/encoder/vp9_rd.c +++ b/vp9/encoder/vp9_rd.c @@ -65,7 +65,7 @@ static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES] = { }; static void fill_mode_costs(VP9_COMP *cpi) { - const FRAME_CONTEXT *const fc = &cpi->common.fc; + const FRAME_CONTEXT *const fc = cpi->common.fc; int i, j; for (i = 0; i < INTRA_MODES; ++i) @@ -280,7 +280,7 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) { set_block_thresholds(cm, rd); if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) { - fill_token_costs(x->token_costs, cm->fc.coef_probs); + fill_token_costs(x->token_costs, cm->fc->coef_probs); for (i = 0; i < PARTITION_CONTEXTS; ++i) vp9_cost_tokens(cpi->partition_cost[i], get_partition_probs(cm, i), @@ -295,11 +295,11 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) { vp9_build_nmv_cost_table(x->nmvjointcost, cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost, - &cm->fc.nmvc, cm->allow_high_precision_mv); + &cm->fc->nmvc, cm->allow_high_precision_mv); for (i = 0; i < INTER_MODE_CONTEXTS; ++i) vp9_cost_tokens((int *)cpi->inter_mode_cost[i], - cm->fc.inter_mode_probs[i], vp9_inter_mode_tree); + cm->fc->inter_mode_probs[i], vp9_inter_mode_tree); } } } diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index eca8e5880..97d2c25e1 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -639,7 +639,7 @@ static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, int64_t best_rd = INT64_MAX; TX_SIZE best_tx = max_tx_size; - const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); + const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc->tx_probs); assert(skip_prob > 0); s0 = vp9_cost_bit(skip_prob, 0); s1 = vp9_cost_bit(skip_prob, 1); diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c index adf01bf35..0166a50a0 100644 --- a/vp9/encoder/vp9_tokenize.c +++ b/vp9/encoder/vp9_tokenize.c @@ -313,7 +313,7 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize, unsigned int (*const counts)[COEFF_CONTEXTS][ENTROPY_TOKENS] = cpi->coef_counts[tx_size][type][ref]; vp9_prob (*const coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] = - cpi->common.fc.coef_probs[tx_size][type][ref]; + cpi->common.fc->coef_probs[tx_size][type][ref]; unsigned int (*const eob_branch)[COEFF_CONTEXTS] = cpi->common.counts.eob_branch[tx_size][type][ref]; const uint8_t *const band = get_band_translate(tx_size); diff --git a/vp9/encoder/x86/vp9_denoiser_sse2.c b/vp9/encoder/x86/vp9_denoiser_sse2.c index bf5fa889f..09969b0d9 100644 --- a/vp9/encoder/x86/vp9_denoiser_sse2.c +++ b/vp9/encoder/x86/vp9_denoiser_sse2.c @@ -23,18 +23,17 @@ // Compute the sum of all pixel differences of this MB. static INLINE int sum_diff_16x1(__m128i acc_diff) { const __m128i k_1 = _mm_set1_epi16(1); - const __m128i acc_diff_lo = _mm_srai_epi16( - _mm_unpacklo_epi8(acc_diff, acc_diff), 8); - const __m128i acc_diff_hi = _mm_srai_epi16( - _mm_unpackhi_epi8(acc_diff, acc_diff), 8); + const __m128i acc_diff_lo = + _mm_srai_epi16(_mm_unpacklo_epi8(acc_diff, acc_diff), 8); + const __m128i acc_diff_hi = + _mm_srai_epi16(_mm_unpackhi_epi8(acc_diff, acc_diff), 8); const __m128i acc_diff_16 = _mm_add_epi16(acc_diff_lo, acc_diff_hi); const __m128i hg_fe_dc_ba = _mm_madd_epi16(acc_diff_16, k_1); - const __m128i hgfe_dcba = _mm_add_epi32(hg_fe_dc_ba, - _mm_srli_si128(hg_fe_dc_ba, 8)); - const __m128i hgfedcba = _mm_add_epi32(hgfe_dcba, - _mm_srli_si128(hgfe_dcba, 4)); - int sum_diff = _mm_cvtsi128_si32(hgfedcba); - return sum_diff; + const __m128i hgfe_dcba = + _mm_add_epi32(hg_fe_dc_ba, _mm_srli_si128(hg_fe_dc_ba, 8)); + const __m128i hgfedcba = + _mm_add_epi32(hgfe_dcba, _mm_srli_si128(hgfe_dcba, 4)); + return _mm_cvtsi128_si32(hgfedcba); } // Denoise a 16x1 vector. @@ -51,8 +50,8 @@ static INLINE __m128i vp9_denoiser_16x1_sse2(const uint8_t *sig, __m128i acc_diff) { // Calculate differences const __m128i v_sig = _mm_loadu_si128((const __m128i *)(&sig[0])); - const __m128i v_mc_running_avg_y = _mm_loadu_si128( - (const __m128i *)(&mc_running_avg_y[0])); + const __m128i v_mc_running_avg_y = + _mm_loadu_si128((const __m128i *)(&mc_running_avg_y[0])); __m128i v_running_avg_y; const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig); const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y); @@ -60,8 +59,8 @@ static INLINE __m128i vp9_denoiser_16x1_sse2(const uint8_t *sig, const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, *k_0); // Clamp absolute difference to 16 to be used to get mask. Doing this // allows us to use _mm_cmpgt_epi8, which operates on signed byte. - const __m128i clamped_absdiff = _mm_min_epu8( - _mm_or_si128(pdiff, ndiff), *k_16); + const __m128i clamped_absdiff = + _mm_min_epu8(_mm_or_si128(pdiff, ndiff), *k_16); // Get masks for l2 l1 and l0 adjustments. const __m128i mask2 = _mm_cmpgt_epi8(*k_16, clamped_absdiff); const __m128i mask1 = _mm_cmpgt_epi8(*k_8, clamped_absdiff); @@ -95,24 +94,22 @@ static INLINE __m128i vp9_denoiser_16x1_sse2(const uint8_t *sig, } // Denoise a 16x1 vector with a weaker filter. -static INLINE __m128i vp9_denoiser_adj_16x1_sse2(const uint8_t *sig, - const uint8_t *mc_running_avg_y, - uint8_t *running_avg_y, - const __m128i k_0, - const __m128i k_delta, - __m128i acc_diff) { +static INLINE __m128i vp9_denoiser_adj_16x1_sse2( + const uint8_t *sig, const uint8_t *mc_running_avg_y, + uint8_t *running_avg_y, const __m128i k_0, + const __m128i k_delta, __m128i acc_diff) { __m128i v_running_avg_y = _mm_loadu_si128((__m128i *)(&running_avg_y[0])); // Calculate differences. const __m128i v_sig = _mm_loadu_si128((const __m128i *)(&sig[0])); const __m128i v_mc_running_avg_y = - _mm_loadu_si128((const __m128i *)(&mc_running_avg_y[0])); + _mm_loadu_si128((const __m128i *)(&mc_running_avg_y[0])); const __m128i pdiff = _mm_subs_epu8(v_mc_running_avg_y, v_sig); const __m128i ndiff = _mm_subs_epu8(v_sig, v_mc_running_avg_y); // Obtain the sign. FF if diff is negative. const __m128i diff_sign = _mm_cmpeq_epi8(pdiff, k_0); // Clamp absolute difference to delta to get the adjustment. const __m128i adj = - _mm_min_epu8(_mm_or_si128(pdiff, ndiff), k_delta); + _mm_min_epu8(_mm_or_si128(pdiff, ndiff), k_delta); // Restore the sign and get positive and negative adjustments. __m128i padj, nadj; padj = _mm_andnot_si128(diff_sign, adj); @@ -135,12 +132,11 @@ static int vp9_denoiser_4xM_sse2(const uint8_t *sig, int sig_stride, int increase_denoising, BLOCK_SIZE bs, int motion_magnitude) { - int sum_diff_thresh; - int r; - int shift_inc = (increase_denoising && - motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 1 : 0; - unsigned char sig_buffer[2][16], mc_running_buffer[2][16], - running_buffer[2][16]; + int sum_diff_thresh, r, sum_diff = 0; + const int shift_inc = (increase_denoising && + motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? + 1 : 0; + uint8_t sig_buffer[2][16], mc_running_buffer[2][16], running_buffer[2][16]; __m128i acc_diff = _mm_setzero_si128(); const __m128i k_0 = _mm_setzero_si128(); const __m128i k_4 = _mm_set1_epi8(4 + shift_inc); @@ -148,13 +144,11 @@ static int vp9_denoiser_4xM_sse2(const uint8_t *sig, int sig_stride, const __m128i k_16 = _mm_set1_epi8(16); // Modify each level's adjustment according to motion_magnitude. const __m128i l3 = _mm_set1_epi8( - (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? - 7 + shift_inc : 6); + (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 7 + shift_inc : 6); // Difference between level 3 and level 2 is 2. const __m128i l32 = _mm_set1_epi8(2); // Difference between level 2 and level 1 is 1. const __m128i l21 = _mm_set1_epi8(1); - int sum_diff = 0; for (r = 0; r < ((4 << b_height_log2_lookup[bs]) >> 2); ++r) { vpx_memcpy(sig_buffer[r], sig, 4); @@ -197,17 +191,17 @@ static int vp9_denoiser_4xM_sse2(const uint8_t *sig, int sig_stride, sum_diff_thresh = total_adj_strong_thresh(bs, increase_denoising); if (abs(sum_diff) > sum_diff_thresh) { // Before returning to copy the block (i.e., apply no denoising), - // checK if we can still apply some (weaker) temporal filtering to + // check if we can still apply some (weaker) temporal filtering to // this block, that would otherwise not be denoised at all. Simplest // is to apply an additional adjustment to running_avg_y to bring it // closer to sig. The adjustment is capped by a maximum delta, and // chosen such that in most cases the resulting sum_diff will be - // within the accceptable range given by sum_diff_thresh. + // within the acceptable range given by sum_diff_thresh. // The delta is set by the excess of absolute pixel diff over the // threshold. - int delta = ((abs(sum_diff) - sum_diff_thresh) - >> num_pels_log2_lookup[bs]) + 1; + const int delta = ((abs(sum_diff) - sum_diff_thresh) >> + num_pels_log2_lookup[bs]) + 1; // Only apply the adjustment for max delta up to 3. if (delta < 4) { const __m128i k_delta = _mm_set1_epi8(delta); @@ -215,9 +209,8 @@ static int vp9_denoiser_4xM_sse2(const uint8_t *sig, int sig_stride, sum_diff = 0; for (r = 0; r < ((4 << b_height_log2_lookup[bs]) >> 2); ++r) { acc_diff = vp9_denoiser_adj_16x1_sse2( - sig_buffer[r], mc_running_buffer[r], - running_buffer[r], k_0, k_delta, - acc_diff); + sig_buffer[r], mc_running_buffer[r], running_buffer[r], + k_0, k_delta, acc_diff); vpx_memcpy(running_avg_y, running_buffer[r], 4); vpx_memcpy(running_avg_y + avg_y_stride, running_buffer[r] + 4, 4); vpx_memcpy(running_avg_y + avg_y_stride * 2, @@ -246,12 +239,11 @@ static int vp9_denoiser_8xM_sse2(const uint8_t *sig, int sig_stride, int increase_denoising, BLOCK_SIZE bs, int motion_magnitude) { - int sum_diff_thresh; - int r; - int shift_inc = (increase_denoising && - motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 1 : 0; - unsigned char sig_buffer[8][16], mc_running_buffer[8][16], - running_buffer[8][16]; + int sum_diff_thresh, r, sum_diff = 0; + const int shift_inc = (increase_denoising && + motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? + 1 : 0; + uint8_t sig_buffer[8][16], mc_running_buffer[8][16], running_buffer[8][16]; __m128i acc_diff = _mm_setzero_si128(); const __m128i k_0 = _mm_setzero_si128(); const __m128i k_4 = _mm_set1_epi8(4 + shift_inc); @@ -259,13 +251,11 @@ static int vp9_denoiser_8xM_sse2(const uint8_t *sig, int sig_stride, const __m128i k_16 = _mm_set1_epi8(16); // Modify each level's adjustment according to motion_magnitude. const __m128i l3 = _mm_set1_epi8( - (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? - 7 + shift_inc : 6); + (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 7 + shift_inc : 6); // Difference between level 3 and level 2 is 2. const __m128i l32 = _mm_set1_epi8(2); // Difference between level 2 and level 1 is 1. const __m128i l21 = _mm_set1_epi8(1); - int sum_diff = 0; for (r = 0; r < ((4 << b_height_log2_lookup[bs]) >> 1); ++r) { vpx_memcpy(sig_buffer[r], sig, 8); @@ -294,26 +284,25 @@ static int vp9_denoiser_8xM_sse2(const uint8_t *sig, int sig_stride, sum_diff_thresh = total_adj_strong_thresh(bs, increase_denoising); if (abs(sum_diff) > sum_diff_thresh) { // Before returning to copy the block (i.e., apply no denoising), - // checK if we can still apply some (weaker) temporal filtering to + // check if we can still apply some (weaker) temporal filtering to // this block, that would otherwise not be denoised at all. Simplest // is to apply an additional adjustment to running_avg_y to bring it // closer to sig. The adjustment is capped by a maximum delta, and // chosen such that in most cases the resulting sum_diff will be - // within the accceptable range given by sum_diff_thresh. + // within the acceptable range given by sum_diff_thresh. // The delta is set by the excess of absolute pixel diff over the // threshold. - int delta = ((abs(sum_diff) - sum_diff_thresh) - >> num_pels_log2_lookup[bs]) + 1; + const int delta = ((abs(sum_diff) - sum_diff_thresh) + >> num_pels_log2_lookup[bs]) + 1; // Only apply the adjustment for max delta up to 3. if (delta < 4) { const __m128i k_delta = _mm_set1_epi8(delta); running_avg_y -= avg_y_stride * (4 << b_height_log2_lookup[bs]); for (r = 0; r < ((4 << b_height_log2_lookup[bs]) >> 1); ++r) { acc_diff = vp9_denoiser_adj_16x1_sse2( - sig_buffer[r], mc_running_buffer[r], - running_buffer[r], k_0, k_delta, - acc_diff); + sig_buffer[r], mc_running_buffer[r], running_buffer[r], + k_0, k_delta, acc_diff); vpx_memcpy(running_avg_y, running_buffer[r], 8); vpx_memcpy(running_avg_y + avg_y_stride, running_buffer[r] + 8, 8); // Update pointers for next iteration. @@ -324,7 +313,7 @@ static int vp9_denoiser_8xM_sse2(const uint8_t *sig, int sig_stride, return COPY_BLOCK; } } else { - return COPY_BLOCK; + return COPY_BLOCK; } } } @@ -338,10 +327,10 @@ static int vp9_denoiser_64_32_16xM_sse2(const uint8_t *sig, int sig_stride, int avg_y_stride, int increase_denoising, BLOCK_SIZE bs, int motion_magnitude) { - int sum_diff_thresh; - int r, c; - int shift_inc = (increase_denoising && - motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 1 : 0; + int sum_diff_thresh, r, c, sum_diff = 0; + const int shift_inc = (increase_denoising && + motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? + 1 : 0; __m128i acc_diff[4][4]; const __m128i k_0 = _mm_setzero_si128(); const __m128i k_4 = _mm_set1_epi8(4 + shift_inc); @@ -349,13 +338,11 @@ static int vp9_denoiser_64_32_16xM_sse2(const uint8_t *sig, int sig_stride, const __m128i k_16 = _mm_set1_epi8(16); // Modify each level's adjustment according to motion_magnitude. const __m128i l3 = _mm_set1_epi8( - (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? - 7 + shift_inc : 6); + (motion_magnitude <= MOTION_MAGNITUDE_THRESHOLD) ? 7 + shift_inc : 6); // Difference between level 3 and level 2 is 2. const __m128i l32 = _mm_set1_epi8(2); // Difference between level 2 and level 1 is 1. const __m128i l21 = _mm_set1_epi8(1); - int sum_diff = 0; for (c = 0; c < 4; ++c) { for (r = 0; r < 4; ++r) { @@ -363,13 +350,11 @@ static int vp9_denoiser_64_32_16xM_sse2(const uint8_t *sig, int sig_stride, } } - for (r = 0; r < (4 << b_height_log2_lookup[bs]); r++) { + for (r = 0; r < (4 << b_height_log2_lookup[bs]); ++r) { for (c = 0; c < (4 << b_width_log2_lookup[bs]); c += 16) { acc_diff[c>>4][r>>4] = vp9_denoiser_16x1_sse2( - sig, mc_running_avg_y, - running_avg_y, - &k_0, &k_4, &k_8, &k_16, - &l3, &l32, &l21, acc_diff[c>>4][r>>4]); + sig, mc_running_avg_y, running_avg_y, &k_0, &k_4, + &k_8, &k_16, &l3, &l32, &l21, acc_diff[c>>4][r>>4]); // Update pointers for next iteration. sig += 16; mc_running_avg_y += 16; @@ -385,8 +370,8 @@ static int vp9_denoiser_64_32_16xM_sse2(const uint8_t *sig, int sig_stride, // Update pointers for next iteration. sig = sig - 16 * ((4 << b_width_log2_lookup[bs]) >> 4) + sig_stride; mc_running_avg_y = mc_running_avg_y - - 16 * ((4 << b_width_log2_lookup[bs]) >> 4) + - mc_avg_y_stride; + 16 * ((4 << b_width_log2_lookup[bs]) >> 4) + + mc_avg_y_stride; running_avg_y = running_avg_y - 16 * ((4 << b_width_log2_lookup[bs]) >> 4) + avg_y_stride; @@ -395,8 +380,8 @@ static int vp9_denoiser_64_32_16xM_sse2(const uint8_t *sig, int sig_stride, { sum_diff_thresh = total_adj_strong_thresh(bs, increase_denoising); if (abs(sum_diff) > sum_diff_thresh) { - int delta = ((abs(sum_diff) - sum_diff_thresh) - >> num_pels_log2_lookup[bs]) + 1; + const int delta = ((abs(sum_diff) - sum_diff_thresh) >> + num_pels_log2_lookup[bs]) + 1; // Only apply the adjustment for max delta up to 3. if (delta < 4) { @@ -408,9 +393,8 @@ static int vp9_denoiser_64_32_16xM_sse2(const uint8_t *sig, int sig_stride, for (r = 0; r < (4 << b_height_log2_lookup[bs]); ++r) { for (c = 0; c < (4 << b_width_log2_lookup[bs]); c += 16) { acc_diff[c>>4][r>>4] = vp9_denoiser_adj_16x1_sse2( - sig, mc_running_avg_y, - running_avg_y, k_0, - k_delta, acc_diff[c>>4][r>>4]); + sig, mc_running_avg_y, running_avg_y, k_0, + k_delta, acc_diff[c>>4][r>>4]); // Update pointers for next iteration. sig += 16; mc_running_avg_y += 16; |