From bcf82cf503ed8c1c4db16d1200beb879434b5de7 Mon Sep 17 00:00:00 2001 From: Yaowu Xu Date: Fri, 19 Apr 2013 16:28:20 -0700 Subject: [PATCH] Merge two similar functions into one Function set_mb_row() and set_mb_col() do similar work and are always called together, this commit merged them into a single function for clarity and easy maintainence. This was a TODO item. Change-Id: I956bd9ed6afb8b2b0469b20fd8bc893b26f8a0f3 --- vp9/common/vp9_onyxc_int.h | 20 +++++++------------- vp9/decoder/vp9_decodemv.c | 3 +-- vp9/decoder/vp9_decodframe.c | 3 +-- vp9/encoder/vp9_bitstream.c | 8 ++++---- vp9/encoder/vp9_encodeframe.c | 3 +-- vp9/encoder/vp9_firstpass.c | 6 +++--- vp9/encoder/vp9_segmentation.c | 3 +-- 7 files changed, 18 insertions(+), 28 deletions(-) diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index 3e09c864c..eea0894c4 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -341,24 +341,18 @@ static int mb_cols_aligned_to_sb(VP9_COMMON *cm) { return (cm->mb_cols + 3) & ~3; } -// TODO(debargha): merge the two functions -static void set_mb_row(VP9_COMMON *cm, MACROBLOCKD *xd, - int mb_row, int block_size) { +static void set_mb_row_col(VP9_COMMON *cm, MACROBLOCKD *xd, + int mb_row, int bh, + int mb_col, int bw) { xd->mb_to_top_edge = -((mb_row * 16) << 3); - xd->mb_to_bottom_edge = ((cm->mb_rows - block_size - mb_row) * 16) << 3; - - // Are edges available for intra prediction? - xd->up_available = (mb_row != 0); -} - -static void set_mb_col(VP9_COMMON *cm, MACROBLOCKD *xd, - int mb_col, int block_size) { + xd->mb_to_bottom_edge = ((cm->mb_rows - bh - mb_row) * 16) << 3; xd->mb_to_left_edge = -((mb_col * 16) << 3); - xd->mb_to_right_edge = ((cm->mb_cols - block_size - mb_col) * 16) << 3; + xd->mb_to_right_edge = ((cm->mb_cols - bw - mb_col) * 16) << 3; // Are edges available for intra prediction? + xd->up_available = (mb_row != 0); xd->left_available = (mb_col > cm->cur_tile_mb_col_start); - xd->right_available = (mb_col + block_size < cm->cur_tile_mb_col_end); + xd->right_available = (mb_col + bw < cm->cur_tile_mb_col_end); } static int get_mb_row(const MACROBLOCKD *xd) { diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index a0733524d..65e81b997 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -620,8 +620,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, // Distance of Mb to the various image edges. // These specified to 8th pel as they are always compared to MV values // that are in 1/8th pel units - set_mb_row(cm, xd, mb_row, bh); - set_mb_col(cm, xd, mb_col, bw); + set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw); mb_to_top_edge = xd->mb_to_top_edge - LEFT_TOP_MARGIN; mb_to_bottom_edge = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index a3445c03a..a51c82853 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -801,8 +801,7 @@ static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize, // Distance of Mb to the various image edges. These are specified to 8th pel // as they are always compared to values that are in 1/8th pel units - set_mb_row(cm, xd, mb_row, bh); - set_mb_col(cm, xd, mb_col, bw); + set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw); xd->plane[0].dst.buf = dst_fb->y_buffer + recon_yoffset; xd->plane[1].dst.buf = dst_fb->u_buffer + recon_uvoffset; diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 978fdcdfe..df58a9113 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -710,8 +710,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m, // These specified to 8th pel as they are always compared to MV // values that are in 1/8th pel units - set_mb_row(pc, xd, mb_row, bh); - set_mb_col(pc, xd, mb_col, bw); + set_mb_row_col(pc, xd, mb_row, bh, mb_col, bw); #ifdef ENTROPY_STATS active_section = 9; @@ -1151,8 +1150,9 @@ static void write_modes_b(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc, MACROBLOCKD *const xd = &cpi->mb.e_mbd; xd->mode_info_context = m; - set_mb_row(&cpi->common, xd, mb_row, 1 << mb_height_log2(m->mbmi.sb_type)); - set_mb_col(&cpi->common, xd, mb_col, 1 << mb_width_log2(m->mbmi.sb_type)); + set_mb_row_col(&cpi->common, xd, mb_row, + 1 << mb_height_log2(m->mbmi.sb_type), + mb_col, 1 << mb_width_log2(m->mbmi.sb_type)); if (cm->frame_type == KEY_FRAME) { write_mb_modes_kf(cpi, m, bc, cm->mb_rows - mb_row, cm->mb_cols - mb_col); diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 5bc164400..7dc77d91f 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -579,8 +579,7 @@ static void set_offsets(VP9_COMP *cpi, // Set up distance of MB to edge of frame in 1/8th pel units assert(!(mb_col & (bw - 1)) && !(mb_row & (bh - 1))); - set_mb_row(cm, xd, mb_row, bh); - set_mb_col(cm, xd, mb_col, bw); + set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw); /* set up source buffers */ setup_pred_block(&x->src, cpi->Source, mb_row, mb_col, NULL, NULL); diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index e441107e7..6e61250d4 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -524,15 +524,15 @@ void vp9_first_pass(VP9_COMP *cpi) { x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + (VP9BORDERINPIXELS - 16); - set_mb_row(cm, xd, mb_row, 1 << mb_height_log2(BLOCK_SIZE_MB16X16)); - // for each macroblock col in image for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { int this_error; int gf_motion_error = INT_MAX; int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); - set_mb_col(cm, xd, mb_col, 1 << mb_height_log2(BLOCK_SIZE_MB16X16)); + set_mb_row_col(cm, xd, + mb_row, 1 << mb_height_log2(BLOCK_SIZE_MB16X16), + mb_col, 1 << mb_height_log2(BLOCK_SIZE_MB16X16)); xd->plane[0].dst.buf = new_yv12->y_buffer + recon_yoffset; xd->plane[1].dst.buf = new_yv12->u_buffer + recon_uvoffset; xd->plane[2].dst.buf = new_yv12->v_buffer + recon_uvoffset; diff --git a/vp9/encoder/vp9_segmentation.c b/vp9/encoder/vp9_segmentation.c index 56484e693..40b187975 100644 --- a/vp9/encoder/vp9_segmentation.c +++ b/vp9/encoder/vp9_segmentation.c @@ -133,8 +133,7 @@ static void count_segs(VP9_COMP *cpi, const int segment_id = mi->mbmi.segment_id; xd->mode_info_context = mi; - set_mb_row(cm, xd, mb_row, bh); - set_mb_col(cm, xd, mb_col, bw); + set_mb_row_col(cm, xd, mb_row, bh, mb_col, bw); // Count the number of hits on each segment with no prediction no_pred_segcounts[segment_id]++; -- 2.40.0