ref: f7c17b89f0b5d2312d92932cf9b4bb4e92b57eb6
parent: 6be2b750b8968a0b19180a6474864c0b6a41db13
parent: 3b3f1d8303a44438018fa1050b2eea7ef7db8a2d
author: Dmitry Kovalev <[email protected]>
date: Mon Feb 3 05:53:21 EST 2014
Merge "Cleaning up vp9_mcomp.{c, h}."
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -184,7 +184,8 @@
return (x & 7) << 1;
}
-static INLINE uint8_t *pre(uint8_t *buf, int stride, int r, int c, int offset) {
+static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c,
+ int offset) {
return &buf[(r >> 3) * stride + (c >> 3) - offset];
}
@@ -273,7 +274,7 @@
} \
}
-int vp9_find_best_sub_pixel_tree(MACROBLOCK *x,
+int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x,
MV *bestmv, const MV *ref_mv,
int allow_hp,
int error_per_bit,
@@ -283,9 +284,9 @@
int *mvjcost, int *mvcost[2],
int *distortion,
unsigned int *sse1) {
- uint8_t *z = x->plane[0].src.buf;
+ const uint8_t *z = x->plane[0].src.buf;
const int src_stride = x->plane[0].src.stride;
- MACROBLOCKD *xd = &x->e_mbd;
+ const MACROBLOCKD *xd = &x->e_mbd;
unsigned int besterr = INT_MAX;
unsigned int sse;
unsigned int whichdir;
@@ -296,7 +297,7 @@
const int y_stride = xd->plane[0].pre[0].stride;
const int offset = bestmv->row * y_stride + bestmv->col;
- uint8_t *y = xd->plane[0].pre[0].buf + offset;
+ const uint8_t *y = xd->plane[0].pre[0].buf + offset;
int rr = ref_mv->row;
int rc = ref_mv->col;
@@ -365,7 +366,7 @@
vfp->svaf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), \
z, src_stride, &sse, second_pred)
-int vp9_find_best_sub_pixel_comp_tree(MACROBLOCK *x,
+int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x,
MV *bestmv, const MV *ref_mv,
int allow_hp,
int error_per_bit,
@@ -377,9 +378,9 @@
unsigned int *sse1,
const uint8_t *second_pred,
int w, int h) {
- uint8_t *z = x->plane[0].src.buf;
+ const uint8_t *z = x->plane[0].src.buf;
const int src_stride = x->plane[0].src.stride;
- MACROBLOCKD *xd = &x->e_mbd;
+ const MACROBLOCKD *xd = &x->e_mbd;
unsigned int besterr = INT_MAX;
unsigned int sse;
unsigned int whichdir;
@@ -391,7 +392,7 @@
DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64);
const int y_stride = xd->plane[0].pre[0].stride;
const int offset = bestmv->row * y_stride + bestmv->col;
- uint8_t *y = xd->plane[0].pre[0].buf + offset;
+ const uint8_t *y = xd->plane[0].pre[0].buf + offset;
int rr = ref_mv->row;
int rc = ref_mv->col;
@@ -484,14 +485,11 @@
#define CHECK_BETTER \
{\
- if (thissad < bestsad)\
- {\
+ if (thissad < bestsad) {\
if (use_mvcost) \
thissad += mvsad_err_cost(&this_mv, &fcenter_mv, \
- mvjsadcost, mvsadcost, \
- sad_per_bit);\
- if (thissad < bestsad)\
- {\
+ mvjsadcost, mvsadcost, sad_per_bit);\
+ if (thissad < bestsad) {\
bestsad = thissad;\
best_site = i;\
}\
@@ -535,11 +533,11 @@
MV this_mv;
int bestsad = INT_MAX;
int thissad;
- uint8_t *base_offset;
- uint8_t *this_offset;
+ const uint8_t *base_offset;
+ const uint8_t *this_offset;
int k = -1;
int best_site = -1;
- MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
int best_init_s = search_param_to_steps[search_param];
const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
@@ -550,7 +548,7 @@
bc = ref_mv->col;
// Work out the start point for the search
- base_offset = (uint8_t *)(xd->plane[0].pre[0].buf);
+ base_offset = xd->plane[0].pre[0].buf;
this_offset = base_offset + (br * in_what_stride) + bc;
this_mv.row = br;
this_mv.col = bc;
@@ -708,7 +706,7 @@
bestsad);
CHECK_BETTER
}
- }
+ }
if (best_site == -1) {
break;
@@ -737,7 +735,7 @@
}
-int vp9_hex_search(MACROBLOCK *x,
+int vp9_hex_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int sad_per_bit,
@@ -765,14 +763,13 @@
{{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024},
{ -1024, 0}},
};
- return
- vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
- do_init_search, 0, vfp, use_mvcost,
- center_mv, best_mv,
- hex_num_candidates, hex_candidates);
+ return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
+ do_init_search, 0, vfp, use_mvcost,
+ center_mv, best_mv,
+ hex_num_candidates, hex_candidates);
}
-int vp9_bigdia_search(MACROBLOCK *x,
+int vp9_bigdia_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int sad_per_bit,
@@ -813,7 +810,7 @@
bigdia_num_candidates, bigdia_candidates);
}
-int vp9_square_search(MACROBLOCK *x,
+int vp9_square_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int sad_per_bit,
@@ -861,11 +858,11 @@
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
int *mvcost[2], const MV *center_mv) {
const MACROBLOCKD *const xd = &x->e_mbd;
- uint8_t *what = x->plane[0].src.buf;
- int what_stride = x->plane[0].src.stride;
- uint8_t *in_what;
- int in_what_stride = xd->plane[0].pre[0].stride;
- uint8_t *best_address;
+ const uint8_t *what = x->plane[0].src.buf;
+ const int what_stride = x->plane[0].src.stride;
+ const uint8_t *in_what;
+ const int in_what_stride = xd->plane[0].pre[0].stride;
+ const uint8_t *best_address;
MV this_mv;
@@ -872,7 +869,6 @@
int bestsad = INT_MAX;
int ref_row, ref_col;
- uint8_t *check_here;
int thissad;
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
@@ -896,8 +892,7 @@
best_mv->col = ref_col;
// Work out the start point for the search
- in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
- (ref_row * (xd->plane[0].pre[0].stride)) + ref_col);
+ in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col;
best_address = in_what;
// Check the starting position
@@ -936,7 +931,7 @@
}
} else {
for (i = 0; i < end_col - tc; ++i) {
- check_here = in_what + tr * in_what_stride + tc + i;
+ const uint8_t *check_here = in_what + tr * in_what_stride + tc + i;
thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
bestsad);
@@ -982,11 +977,10 @@
const MACROBLOCKD *const xd = &x->e_mbd;
const uint8_t *what = x->plane[0].src.buf;
const int what_stride = x->plane[0].src.stride;
- uint8_t *in_what;
+ const uint8_t *in_what;
const int in_what_stride = xd->plane[0].pre[0].stride;
- uint8_t *best_address;
+ const uint8_t *best_address;
- int tot_steps;
MV this_mv;
int bestsad = INT_MAX;
@@ -995,11 +989,16 @@
int ref_row, ref_col;
int this_row_offset, this_col_offset;
- search_site *ss;
- uint8_t *check_here;
+ // search_param determines the length of the initial step and hence the number
+ // of iterations
+ // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 =
+ // (MAX_FIRST_STEP/4) pel... etc.
+ const search_site *const ss = &x->ss[search_param * x->searches_per_step];
+ const int tot_steps = (x->ss_count / x->searches_per_step) - search_param;
+
int thissad;
- MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
@@ -1012,8 +1011,7 @@
best_mv->col = ref_col;
// Work out the start point for the search
- in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
- ref_row * in_what_stride + ref_col);
+ in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col;
best_address = in_what;
// Check the starting position
@@ -1021,13 +1019,6 @@
+ mvsad_err_cost(best_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
- // search_param determines the length of the initial step and hence the number
- // of iterations
- // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 =
- // (MAX_FIRST_STEP/4) pel... etc.
- ss = &x->ss[search_param * x->searches_per_step];
- tot_steps = (x->ss_count / x->searches_per_step) - search_param;
-
i = 1;
for (step = 0; step < tot_steps; step++) {
@@ -1040,7 +1031,7 @@
(this_col_offset < x->mv_col_max) &&
(this_row_offset > x->mv_row_min) &&
(this_row_offset < x->mv_row_max)) {
- check_here = ss[i].offset + best_address;
+ const uint8_t *const check_here = ss[i].offset + best_address;
thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
bestsad);
@@ -1120,12 +1111,11 @@
const MACROBLOCKD *const xd = &x->e_mbd;
uint8_t *what = x->plane[0].src.buf;
- int what_stride = x->plane[0].src.stride;
- uint8_t *in_what;
- int in_what_stride = xd->plane[0].pre[0].stride;
- uint8_t *best_address;
+ const int what_stride = x->plane[0].src.stride;
+ const uint8_t *in_what;
+ const int in_what_stride = xd->plane[0].pre[0].stride;
+ const uint8_t *best_address;
- int tot_steps;
MV this_mv;
unsigned int bestsad = INT_MAX;
@@ -1136,9 +1126,15 @@
int ref_col;
int this_row_offset;
int this_col_offset;
- search_site *ss;
- uint8_t *check_here;
+ // search_param determines the length of the initial step and hence the number
+ // of iterations.
+ // 0 = initial step (MAX_FIRST_STEP) pel
+ // 1 = (MAX_FIRST_STEP/2) pel,
+ // 2 = (MAX_FIRST_STEP/4) pel...
+ const search_site *ss = &x->ss[search_param * x->searches_per_step];
+ const int tot_steps = (x->ss_count / x->searches_per_step) - search_param;
+
unsigned int thissad;
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
@@ -1153,8 +1149,7 @@
best_mv->col = ref_col;
// Work out the start point for the search
- in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
- ref_row * in_what_stride + ref_col);
+ in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col;
best_address = in_what;
// Check the starting position
@@ -1162,14 +1157,6 @@
+ mvsad_err_cost(best_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
- // search_param determines the length of the initial step and hence the number
- // of iterations.
- // 0 = initial step (MAX_FIRST_STEP) pel
- // 1 = (MAX_FIRST_STEP/2) pel,
- // 2 = (MAX_FIRST_STEP/4) pel...
- ss = &x->ss[search_param * x->searches_per_step];
- tot_steps = (x->ss_count / x->searches_per_step) - search_param;
-
i = 1;
for (step = 0; step < tot_steps; step++) {
@@ -1221,7 +1208,7 @@
(this_col_offset < x->mv_col_max) &&
(this_row_offset > x->mv_row_min) &&
(this_row_offset < x->mv_row_max)) {
- check_here = ss[i].offset + best_address;
+ const uint8_t *const check_here = ss[i].offset + best_address;
thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
bestsad);
@@ -1359,12 +1346,12 @@
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
int *mvcost[2],
const MV *center_mv, int n) {
- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
const uint8_t *const what = x->plane[0].src.buf;
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
- MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv;
+ MV *best_mv = &xd->mi_8x8[0]->bmi[n].as_mv[0].as_mv;
MV this_mv;
int bestsad = INT_MAX;
int r, c;
@@ -1432,12 +1419,12 @@
int sad_per_bit, int distance,
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
int *mvcost[2], const MV *center_mv, int n) {
- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
const uint8_t *const what = x->plane[0].src.buf;
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
- MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv;
+ MV *best_mv = &xd->mi_8x8[0]->bmi[n].as_mv[0].as_mv;
MV this_mv;
unsigned int bestsad = INT_MAX;
int r, c;
@@ -1538,12 +1525,12 @@
vp9_variance_fn_ptr_t *fn_ptr,
int *mvjcost, int *mvcost[2],
const MV *center_mv, int n) {
- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
const uint8_t *const what = x->plane[0].src.buf;
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
- MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv;
+ MV *best_mv = &xd->mi_8x8[0]->bmi[n].as_mv[0].as_mv;
MV this_mv;
unsigned int bestsad = INT_MAX;
int r, c;
@@ -1747,7 +1734,7 @@
int search_range, vp9_variance_fn_ptr_t *fn_ptr,
int *mvjcost, int *mvcost[2],
const MV *center_mv) {
- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
int i, j;
int this_row_offset, this_col_offset;
@@ -1760,16 +1747,15 @@
ref_mv->col;
unsigned int thissad;
MV this_mv;
- unsigned int bestsad = INT_MAX;
- MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
+
const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
- bestsad = fn_ptr->sdf(what, what_stride, best_address,
- in_what_stride, 0x7fffffff) +
- mvsad_err_cost(ref_mv, &fcenter_mv,
- mvjsadcost, mvsadcost, error_per_bit);
+ unsigned int bestsad = fn_ptr->sdf(what, what_stride, best_address,
+ in_what_stride, 0x7fffffff) +
+ mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit);
for (i = 0; i < search_range; i++) {
int best_site = -1;
--- a/vp9/encoder/vp9_mcomp.h
+++ b/vp9/encoder/vp9_mcomp.h
@@ -48,7 +48,7 @@
vp9_variance_fn_ptr_t *fn_ptr,
const MV *ref_mv, int_mv *dst_mv);
-int vp9_hex_search(MACROBLOCK *x,
+int vp9_hex_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int error_per_bit,
@@ -57,7 +57,7 @@
int use_mvcost,
const MV *center_mv,
MV *best_mv);
-int vp9_bigdia_search(MACROBLOCK *x,
+int vp9_bigdia_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int error_per_bit,
@@ -66,7 +66,7 @@
int use_mvcost,
const MV *center_mv,
MV *best_mv);
-int vp9_square_search(MACROBLOCK *x,
+int vp9_square_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int error_per_bit,
@@ -77,7 +77,7 @@
MV *best_mv);
typedef int (fractional_mv_step_fp) (
- MACROBLOCK *x,
+ const MACROBLOCK *x,
MV *bestmv, const MV *ref_mv,
int allow_hp,
int error_per_bit,
@@ -92,7 +92,7 @@
extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
typedef int (fractional_mv_step_comp_fp) (
- MACROBLOCK *x,
+ const MACROBLOCK *x,
MV *bestmv, const MV *ref_mv,
int allow_hp,
int error_per_bit,