From cac54404b9c80eccf66f359be268f396690bee56 Mon Sep 17 00:00:00 2001 From: Yunqing Wang Date: Wed, 26 Jan 2011 12:03:13 -0500 Subject: [PATCH] Remove copies of same functions Reduce the code size. Change-Id: I2e1998557a3c8776e262c442fd758c25e17aff7a --- vp8/common/findnearmv.c | 42 +++------------------------------- vp8/common/findnearmv.h | 39 ++++++++++++++++++++++++++++---- vp8/encoder/onyx_int.h | 7 +----- vp8/encoder/rdopt.c | 60 ++++++++----------------------------------------- 4 files changed, 48 insertions(+), 100 deletions(-) diff --git a/vp8/common/findnearmv.c b/vp8/common/findnearmv.c index e63d4ef..cab0403 100644 --- a/vp8/common/findnearmv.c +++ b/vp8/common/findnearmv.c @@ -16,42 +16,6 @@ /* Predict motion vectors using those from already-decoded nearby blocks. Note that we only consider one 4x4 subblock from each candidate 16x16 macroblock. */ - -typedef union -{ - unsigned int as_int; - MV as_mv; -} int_mv; /* facilitates rapid equality tests */ - -static void mv_bias(const MODE_INFO *x, int refframe, int_mv *mvp, const int *ref_frame_sign_bias) -{ - MV xmv; - xmv = x->mbmi.mv.as_mv; - - if (ref_frame_sign_bias[x->mbmi.ref_frame] != ref_frame_sign_bias[refframe]) - { - xmv.row *= -1; - xmv.col *= -1; - } - - mvp->as_mv = xmv; -} - - -void vp8_clamp_mv(MV *mv, const MACROBLOCKD *xd) -{ - if (mv->col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN)) - mv->col = xd->mb_to_left_edge - LEFT_TOP_MARGIN; - else if (mv->col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN) - mv->col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN; - - if (mv->row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN)) - mv->row = xd->mb_to_top_edge - LEFT_TOP_MARGIN; - else if (mv->row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN) - mv->row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; -} - - void vp8_find_near_mvs ( MACROBLOCKD *xd, @@ -82,7 +46,7 @@ void vp8_find_near_mvs if (above->mbmi.mv.as_int) { (++mv)->as_int = above->mbmi.mv.as_int; - mv_bias(above, refframe, mv, ref_frame_sign_bias); + mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], refframe, mv, ref_frame_sign_bias); ++cntx; } @@ -97,7 +61,7 @@ void vp8_find_near_mvs int_mv this_mv; this_mv.as_int = left->mbmi.mv.as_int; - mv_bias(left, refframe, &this_mv, ref_frame_sign_bias); + mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], refframe, &this_mv, ref_frame_sign_bias); if (this_mv.as_int != mv->as_int) { @@ -119,7 +83,7 @@ void vp8_find_near_mvs int_mv this_mv; this_mv.as_int = aboveleft->mbmi.mv.as_int; - mv_bias(aboveleft, refframe, &this_mv, ref_frame_sign_bias); + mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], refframe, &this_mv, ref_frame_sign_bias); if (this_mv.as_int != mv->as_int) { diff --git a/vp8/common/findnearmv.h b/vp8/common/findnearmv.h index 1a6c72b..cb5a58e 100644 --- a/vp8/common/findnearmv.h +++ b/vp8/common/findnearmv.h @@ -17,6 +17,41 @@ #include "modecont.h" #include "treecoder.h" +typedef union +{ + unsigned int as_int; + MV as_mv; +} int_mv; /* facilitates rapid equality tests */ + +static void mv_bias(int refmb_ref_frame_sign_bias, int refframe, int_mv *mvp, const int *ref_frame_sign_bias) +{ + MV xmv; + xmv = mvp->as_mv; + + if (refmb_ref_frame_sign_bias != ref_frame_sign_bias[refframe]) + { + xmv.row *= -1; + xmv.col *= -1; + } + + mvp->as_mv = xmv; +} + +#define LEFT_TOP_MARGIN (16 << 3) +#define RIGHT_BOTTOM_MARGIN (16 << 3) +static void vp8_clamp_mv(MV *mv, const MACROBLOCKD *xd) +{ + if (mv->col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN)) + mv->col = xd->mb_to_left_edge - LEFT_TOP_MARGIN; + else if (mv->col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN) + mv->col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN; + + if (mv->row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN)) + mv->row = xd->mb_to_top_edge - LEFT_TOP_MARGIN; + else if (mv->row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN) + mv->row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; +} + void vp8_find_near_mvs ( MACROBLOCKD *xd, @@ -35,8 +70,4 @@ const B_MODE_INFO *vp8_left_bmi(const MODE_INFO *cur_mb, int b); const B_MODE_INFO *vp8_above_bmi(const MODE_INFO *cur_mb, int b, int mi_stride); -#define LEFT_TOP_MARGIN (16 << 3) -#define RIGHT_BOTTOM_MARGIN (16 << 3) - - #endif diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 8a97e98..ccf7b32 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -28,6 +28,7 @@ #include "vpx/internal/vpx_codec_internal.h" #include "mcomp.h" #include "temporal_filter.h" +#include "findnearmv.h" //#define SPEEDSTATS 1 #define MIN_GF_INTERVAL 4 @@ -245,12 +246,6 @@ enum BLOCK_MAX_SEGMENTS }; -typedef union -{ - unsigned int as_int; - MV as_mv; -} int_mv; /* facilitates rapid equality tests */ - typedef struct { diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index f04a746..5b8c7e9 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -1421,48 +1421,6 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x, return bsi.segment_rd; } - -static void mv_bias(const MODE_INFO *x, int refframe, int_mv *mvp, const int *ref_frame_sign_bias) -{ - MV xmv; - xmv = x->mbmi.mv.as_mv; - - if (ref_frame_sign_bias[x->mbmi.ref_frame] != ref_frame_sign_bias[refframe]) - { - xmv.row *= -1; - xmv.col *= -1; - } - - mvp->as_mv = xmv; -} - -static void lf_mv_bias(const int lf_ref_frame_sign_bias, int refframe, int_mv *mvp, const int *ref_frame_sign_bias) -{ - MV xmv; - xmv = mvp->as_mv; - - if (lf_ref_frame_sign_bias != ref_frame_sign_bias[refframe]) - { - xmv.row *= -1; - xmv.col *= -1; - } - - mvp->as_mv = xmv; -} - -static void vp8_clamp_mv(MV *mv, const MACROBLOCKD *xd) -{ - if (mv->col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN)) - mv->col = xd->mb_to_left_edge - LEFT_TOP_MARGIN; - else if (mv->col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN) - mv->col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN; - - if (mv->row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN)) - mv->row = xd->mb_to_top_edge - LEFT_TOP_MARGIN; - else if (mv->row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN) - mv->row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN; -} - static void swap(int *x,int *y) { int tmp; @@ -1546,7 +1504,7 @@ static void quicksortsad(int arr[],int idx[], int left, int right) } //The improved MV prediction -static void vp8_mv_pred +void vp8_mv_pred ( VP8_COMP *cpi, MACROBLOCKD *xd, @@ -1583,21 +1541,21 @@ static void vp8_mv_pred if (above->mbmi.ref_frame != INTRA_FRAME) { near_mvs[vcnt].as_int = above->mbmi.mv.as_int; - mv_bias(above, refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = above->mbmi.ref_frame; } vcnt++; if (left->mbmi.ref_frame != INTRA_FRAME) { near_mvs[vcnt].as_int = left->mbmi.mv.as_int; - mv_bias(left, refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = left->mbmi.ref_frame; } vcnt++; if (aboveleft->mbmi.ref_frame != INTRA_FRAME) { near_mvs[vcnt].as_int = aboveleft->mbmi.mv.as_int; - mv_bias(aboveleft, refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = aboveleft->mbmi.ref_frame; } vcnt++; @@ -1611,7 +1569,7 @@ static void vp8_mv_pred if (cpi->lf_ref_frame[mb_offset] != INTRA_FRAME) { near_mvs[vcnt].as_int = cpi->lfmv[mb_offset].as_int; - lf_mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset], refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = cpi->lf_ref_frame[mb_offset]; } vcnt++; @@ -1620,7 +1578,7 @@ static void vp8_mv_pred if (cpi->lf_ref_frame[mb_offset - xd->mode_info_stride-1] != INTRA_FRAME) { near_mvs[vcnt].as_int = cpi->lfmv[mb_offset - xd->mode_info_stride-1].as_int; - lf_mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset - xd->mode_info_stride-1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset - xd->mode_info_stride-1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = cpi->lf_ref_frame[mb_offset - xd->mode_info_stride-1]; } vcnt++; @@ -1629,7 +1587,7 @@ static void vp8_mv_pred if (cpi->lf_ref_frame[mb_offset-1] != INTRA_FRAME) { near_mvs[vcnt].as_int = cpi->lfmv[mb_offset -1].as_int; - lf_mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset -1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset -1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = cpi->lf_ref_frame[mb_offset - 1]; } vcnt++; @@ -1638,7 +1596,7 @@ static void vp8_mv_pred if (cpi->lf_ref_frame[mb_offset +1] != INTRA_FRAME) { near_mvs[vcnt].as_int = cpi->lfmv[mb_offset +1].as_int; - lf_mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = cpi->lf_ref_frame[mb_offset +1]; } vcnt++; @@ -1647,7 +1605,7 @@ static void vp8_mv_pred if (cpi->lf_ref_frame[mb_offset + xd->mode_info_stride +1] != INTRA_FRAME) { near_mvs[vcnt].as_int = cpi->lfmv[mb_offset + xd->mode_info_stride +1].as_int; - lf_mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset + xd->mode_info_stride +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); + mv_bias(cpi->lf_ref_frame_sign_bias[mb_offset + xd->mode_info_stride +1], refframe, &near_mvs[vcnt], ref_frame_sign_bias); near_ref[vcnt] = cpi->lf_ref_frame[mb_offset + xd->mode_info_stride +1]; } vcnt++; -- 2.7.4