#include "./vpx_config.h"
#include "./vpx_dsp_rtcd.h"
+#include "vpx_dsp/vpx_dsp_common.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem.h"
int col_max = (mv->col >> 3) + MAX_FULL_PEL_VAL;
int row_max = (mv->row >> 3) + MAX_FULL_PEL_VAL;
- col_min = MAX(col_min, (MV_LOW >> 3) + 1);
- row_min = MAX(row_min, (MV_LOW >> 3) + 1);
- col_max = MIN(col_max, (MV_UPP >> 3) - 1);
- row_max = MIN(row_max, (MV_UPP >> 3) - 1);
+ col_min = VPXMAX(col_min, (MV_LOW >> 3) + 1);
+ row_min = VPXMAX(row_min, (MV_LOW >> 3) + 1);
+ col_max = VPXMIN(col_max, (MV_UPP >> 3) - 1);
+ row_max = VPXMIN(row_max, (MV_UPP >> 3) - 1);
// Get intersection of UMV window and valid MV window to reduce # of checks
// in diamond search.
int vp9_init_search_range(int size) {
int sr = 0;
// Minimum search size no matter what the passed in value.
- size = MAX(16, size);
+ size = VPXMAX(16, size);
while ((size << sr) < MAX_FULL_PEL_VAL)
sr++;
- sr = MIN(sr, MAX_MVSEARCH_STEPS - 2);
+ sr = VPXMIN(sr, MAX_MVSEARCH_STEPS - 2);
return sr;
}
}
void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride) {
- int len, ss_count = 1;
-
- cfg->ss[0].mv.col = cfg->ss[0].mv.row = 0;
- cfg->ss[0].offset = 0;
+ int len;
+ int ss_count = 0;
for (len = MAX_FIRST_STEP; len > 0; len /= 2) {
// Generate offsets for 4 search sites per step.
const MV ss_mvs[] = {{-len, 0}, {len, 0}, {0, -len}, {0, len}};
int i;
- for (i = 0; i < 4; ++i) {
- search_site *const ss = &cfg->ss[ss_count++];
- ss->mv = ss_mvs[i];
- ss->offset = ss->mv.row * stride + ss->mv.col;
+ for (i = 0; i < 4; ++i, ++ss_count) {
+ cfg->ss_mv[ss_count] = ss_mvs[i];
+ cfg->ss_os[ss_count] = ss_mvs[i].row * stride + ss_mvs[i].col;
}
}
- cfg->ss_count = ss_count;
cfg->searches_per_step = 4;
+ cfg->total_steps = ss_count / cfg->searches_per_step;
}
void vp9_init3smotion_compensation(search_site_config *cfg, int stride) {
- int len, ss_count = 1;
-
- cfg->ss[0].mv.col = cfg->ss[0].mv.row = 0;
- cfg->ss[0].offset = 0;
+ int len;
+ int ss_count = 0;
for (len = MAX_FIRST_STEP; len > 0; len /= 2) {
// Generate offsets for 8 search sites per step.
{-len, -len}, {-len, len}, {len, -len}, {len, len}
};
int i;
- for (i = 0; i < 8; ++i) {
- search_site *const ss = &cfg->ss[ss_count++];
- ss->mv = ss_mvs[i];
- ss->offset = ss->mv.row * stride + ss->mv.col;
+ for (i = 0; i < 8; ++i, ++ss_count) {
+ cfg->ss_mv[ss_count] = ss_mvs[i];
+ cfg->ss_os[ss_count] = ss_mvs[i].row * stride + ss_mvs[i].col;
}
}
- cfg->ss_count = ss_count;
cfg->searches_per_step = 8;
+ cfg->total_steps = ss_count / cfg->searches_per_step;
}
/*
int br = bestmv->row * 8; \
int bc = bestmv->col * 8; \
int hstep = 4; \
- const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \
- const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); \
- const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); \
- const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \
+ const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \
+ const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); \
+ const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); \
+ const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \
int tr = br; \
int tc = bc; \
\
int bc = bestmv->col * 8;
int hstep = 4;
int iter, round = 3 - forced_stop;
- const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
- const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
- const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
- const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
+ const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
+ const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
+ const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
+ const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
int tr = br;
int tc = bc;
const MV *search_step = search_step_table;
x->mvcost, x->errorperbit) : 0);
}
-int vp9_hex_search(const MACROBLOCK *x,
- MV *ref_mv,
- int search_param,
- int sad_per_bit,
- int do_init_search,
- int *cost_list,
- const vp9_variance_fn_ptr_t *vfp,
- int use_mvcost,
- const MV *center_mv, MV *best_mv) {
+static int hex_search(const MACROBLOCK *x,
+ MV *ref_mv,
+ int search_param,
+ int sad_per_bit,
+ int do_init_search,
+ int *cost_list,
+ const vp9_variance_fn_ptr_t *vfp,
+ int use_mvcost,
+ const MV *center_mv, MV *best_mv) {
// First scale has 8-closest points, the rest have 6 points in hex shape
// at increasing scales
static const int hex_num_candidates[MAX_PATTERN_SCALES] = {
hex_num_candidates, hex_candidates);
}
-int vp9_bigdia_search(const MACROBLOCK *x,
- MV *ref_mv,
- int search_param,
- int sad_per_bit,
- int do_init_search,
- int *cost_list,
- const vp9_variance_fn_ptr_t *vfp,
- int use_mvcost,
- const MV *center_mv,
- MV *best_mv) {
+static int bigdia_search(const MACROBLOCK *x,
+ MV *ref_mv,
+ int search_param,
+ int sad_per_bit,
+ int do_init_search,
+ int *cost_list,
+ const vp9_variance_fn_ptr_t *vfp,
+ int use_mvcost,
+ const MV *center_mv,
+ MV *best_mv) {
// First scale has 4-closest points, the rest have 8 points in diamond
// shape at increasing scales
static const int bigdia_num_candidates[MAX_PATTERN_SCALES] = {
bigdia_num_candidates, bigdia_candidates);
}
-int vp9_square_search(const MACROBLOCK *x,
- MV *ref_mv,
- int search_param,
- int sad_per_bit,
- int do_init_search,
- int *cost_list,
- const vp9_variance_fn_ptr_t *vfp,
- int use_mvcost,
- const MV *center_mv,
- MV *best_mv) {
+static int square_search(const MACROBLOCK *x,
+ MV *ref_mv,
+ int search_param,
+ int sad_per_bit,
+ int do_init_search,
+ int *cost_list,
+ const vp9_variance_fn_ptr_t *vfp,
+ int use_mvcost,
+ const MV *center_mv,
+ MV *best_mv) {
// All scales have 8 closest points in square shape
static const int square_num_candidates[MAX_PATTERN_SCALES] = {
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
square_num_candidates, square_candidates);
}
-int vp9_fast_hex_search(const MACROBLOCK *x,
- MV *ref_mv,
- int search_param,
- int sad_per_bit,
- int do_init_search, // must be zero for fast_hex
- int *cost_list,
- const vp9_variance_fn_ptr_t *vfp,
- int use_mvcost,
- const MV *center_mv,
- MV *best_mv) {
- return vp9_hex_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param),
- sad_per_bit, do_init_search, cost_list, vfp, use_mvcost,
- center_mv, best_mv);
+static int fast_hex_search(const MACROBLOCK *x,
+ MV *ref_mv,
+ int search_param,
+ int sad_per_bit,
+ int do_init_search, // must be zero for fast_hex
+ int *cost_list,
+ const vp9_variance_fn_ptr_t *vfp,
+ int use_mvcost,
+ const MV *center_mv,
+ MV *best_mv) {
+ return hex_search(x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param),
+ sad_per_bit, do_init_search, cost_list, vfp, use_mvcost,
+ center_mv, best_mv);
}
-int vp9_fast_dia_search(const MACROBLOCK *x,
- MV *ref_mv,
- int search_param,
- int sad_per_bit,
- int do_init_search,
- int *cost_list,
- const vp9_variance_fn_ptr_t *vfp,
- int use_mvcost,
- const MV *center_mv,
- MV *best_mv) {
- return vp9_bigdia_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param),
- sad_per_bit, do_init_search, cost_list, vfp,
- use_mvcost, center_mv, best_mv);
+static int fast_dia_search(const MACROBLOCK *x,
+ MV *ref_mv,
+ int search_param,
+ int sad_per_bit,
+ int do_init_search,
+ int *cost_list,
+ const vp9_variance_fn_ptr_t *vfp,
+ int use_mvcost,
+ const MV *center_mv,
+ MV *best_mv) {
+ return bigdia_search(
+ x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param), sad_per_bit,
+ do_init_search, cost_list, vfp, use_mvcost, center_mv, best_mv);
}
#undef CHECK_BETTER
best_sad = fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, ref_mv), in_what->stride) +
mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
- start_row = MAX(-range, x->mv_row_min - ref_mv->row);
- start_col = MAX(-range, x->mv_col_min - ref_mv->col);
- end_row = MIN(range, x->mv_row_max - ref_mv->row);
- end_col = MIN(range, x->mv_col_max - ref_mv->col);
+ start_row = VPXMAX(-range, x->mv_row_min - ref_mv->row);
+ start_col = VPXMAX(-range, x->mv_col_min - ref_mv->col);
+ end_row = VPXMIN(range, x->mv_row_max - ref_mv->row);
+ end_col = VPXMIN(range, x->mv_col_max - ref_mv->col);
for (r = start_row; r <= end_row; ++r) {
for (c = start_col; c <= end_col; c += 4) {
const uint8_t *best_address;
unsigned int bestsad = INT_MAX;
- int best_site = 0;
- int last_site = 0;
+ int best_site = -1;
+ int last_site = -1;
int ref_row;
int ref_col;
// 0 = initial step (MAX_FIRST_STEP) pel
// 1 = (MAX_FIRST_STEP/2) pel,
// 2 = (MAX_FIRST_STEP/4) pel...
- const search_site *ss = &cfg->ss[search_param * cfg->searches_per_step];
- const int tot_steps = (cfg->ss_count / cfg->searches_per_step) - search_param;
+// const search_site *ss = &cfg->ss[search_param * cfg->searches_per_step];
+ const MV *ss_mv = &cfg->ss_mv[search_param * cfg->searches_per_step];
+ const intptr_t *ss_os = &cfg->ss_os[search_param * cfg->searches_per_step];
+ const int tot_steps = cfg->total_steps - search_param;
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride)
+ mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit);
- i = 1;
+ i = 0;
for (step = 0; step < tot_steps; step++) {
int all_in = 1, t;
// All_in is true if every one of the points we are checking are within
// the bounds of the image.
- all_in &= ((best_mv->row + ss[i].mv.row) > x->mv_row_min);
- all_in &= ((best_mv->row + ss[i + 1].mv.row) < x->mv_row_max);
- all_in &= ((best_mv->col + ss[i + 2].mv.col) > x->mv_col_min);
- all_in &= ((best_mv->col + ss[i + 3].mv.col) < x->mv_col_max);
+ all_in &= ((best_mv->row + ss_mv[i].row) > x->mv_row_min);
+ all_in &= ((best_mv->row + ss_mv[i + 1].row) < x->mv_row_max);
+ all_in &= ((best_mv->col + ss_mv[i + 2].col) > x->mv_col_min);
+ all_in &= ((best_mv->col + ss_mv[i + 3].col) < x->mv_col_max);
// If all the pixels are within the bounds we don't check whether the
// search point is valid in this loop, otherwise we check each point
unsigned char const *block_offset[4];
for (t = 0; t < 4; t++)
- block_offset[t] = ss[i + t].offset + best_address;
+ block_offset[t] = ss_os[i + t] + best_address;
fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride,
sad_array);
for (t = 0; t < 4; t++, i++) {
if (sad_array[t] < bestsad) {
- const MV this_mv = {best_mv->row + ss[i].mv.row,
- best_mv->col + ss[i].mv.col};
+ const MV this_mv = {best_mv->row + ss_mv[i].row,
+ best_mv->col + ss_mv[i].col};
sad_array[t] += mvsad_err_cost(x, &this_mv, &fcenter_mv,
sad_per_bit);
if (sad_array[t] < bestsad) {
} else {
for (j = 0; j < cfg->searches_per_step; j++) {
// Trap illegal vectors
- const MV this_mv = {best_mv->row + ss[i].mv.row,
- best_mv->col + ss[i].mv.col};
+ const MV this_mv = {best_mv->row + ss_mv[i].row,
+ best_mv->col + ss_mv[i].col};
if (is_mv_in(x, &this_mv)) {
- const uint8_t *const check_here = ss[i].offset + best_address;
+ const uint8_t *const check_here = ss_os[i] + best_address;
unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here,
in_what_stride);
}
}
if (best_site != last_site) {
- best_mv->row += ss[best_site].mv.row;
- best_mv->col += ss[best_site].mv.col;
- best_address += ss[best_site].offset;
+ best_mv->row += ss_mv[best_site].row;
+ best_mv->col += ss_mv[best_site].col;
+ best_address += ss_os[best_site];
last_site = best_site;
#if defined(NEW_DIAMOND_SEARCH)
while (1) {
- const MV this_mv = {best_mv->row + ss[best_site].mv.row,
- best_mv->col + ss[best_site].mv.col};
+ const MV this_mv = {best_mv->row + ss_mv[best_site].row,
+ best_mv->col + ss_mv[best_site].col};
if (is_mv_in(x, &this_mv)) {
- const uint8_t *const check_here = ss[best_site].offset + best_address;
+ const uint8_t *const check_here = ss_os[best_site] + best_address;
unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here,
in_what_stride);
if (thissad < bestsad) {
thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
if (thissad < bestsad) {
bestsad = thissad;
- best_mv->row += ss[best_site].mv.row;
- best_mv->col += ss[best_site].mv.col;
- best_address += ss[best_site].offset;
+ best_mv->row += ss_mv[best_site].row;
+ best_mv->col += ss_mv[best_site].col;
+ best_address += ss_os[best_site];
continue;
}
}
return best_sad;
}
+// Runs sequence of diamond searches in smaller steps for RD.
/* do_refine: If last step (1-away) of n-step search doesn't pick the center
point as the best match, we will do a final 1-away diamond
refining search */
-int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x,
- MV *mvp_full, int step_param,
- int sadpb, int further_steps, int do_refine,
- int *cost_list,
- const vp9_variance_fn_ptr_t *fn_ptr,
- const MV *ref_mv, MV *dst_mv) {
+static int full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x,
+ MV *mvp_full, int step_param,
+ int sadpb, int further_steps, int do_refine,
+ int *cost_list,
+ const vp9_variance_fn_ptr_t *fn_ptr,
+ const MV *ref_mv, MV *dst_mv) {
MV temp_mv;
int thissme, n, num00 = 0;
int bestsme = cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, &temp_mv,
const MACROBLOCKD *const xd = &x->e_mbd;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
- const int row_min = MAX(ref_mv->row - distance, x->mv_row_min);
- const int row_max = MIN(ref_mv->row + distance, x->mv_row_max);
- const int col_min = MAX(ref_mv->col - distance, x->mv_col_min);
- const int col_max = MIN(ref_mv->col + distance, x->mv_col_max);
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
int best_sad = fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, ref_mv), in_what->stride) +
const MACROBLOCKD *const xd = &x->e_mbd;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
- const int row_min = MAX(ref_mv->row - distance, x->mv_row_min);
- const int row_max = MIN(ref_mv->row + distance, x->mv_row_max);
- const int col_min = MAX(ref_mv->col - distance, x->mv_col_min);
- const int col_max = MIN(ref_mv->col + distance, x->mv_col_max);
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, ref_mv), in_what->stride) +
const MACROBLOCKD *const xd = &x->e_mbd;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
- const int row_min = MAX(ref_mv->row - distance, x->mv_row_min);
- const int row_max = MIN(ref_mv->row + distance, x->mv_row_max);
- const int col_min = MAX(ref_mv->col - distance, x->mv_col_min);
- const int col_max = MIN(ref_mv->col + distance, x->mv_col_max);
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, ref_mv), in_what->stride) +
switch (method) {
case FAST_DIAMOND:
- var = vp9_fast_dia_search(x, mvp_full, step_param, error_per_bit, 0,
- cost_list, fn_ptr, 1, ref_mv, tmp_mv);
+ var = fast_dia_search(x, mvp_full, step_param, error_per_bit, 0,
+ cost_list, fn_ptr, 1, ref_mv, tmp_mv);
break;
case FAST_HEX:
- var = vp9_fast_hex_search(x, mvp_full, step_param, error_per_bit, 0,
- cost_list, fn_ptr, 1, ref_mv, tmp_mv);
+ var = fast_hex_search(x, mvp_full, step_param, error_per_bit, 0,
+ cost_list, fn_ptr, 1, ref_mv, tmp_mv);
break;
case HEX:
- var = vp9_hex_search(x, mvp_full, step_param, error_per_bit, 1,
- cost_list, fn_ptr, 1, ref_mv, tmp_mv);
+ var = hex_search(x, mvp_full, step_param, error_per_bit, 1,
+ cost_list, fn_ptr, 1, ref_mv, tmp_mv);
break;
case SQUARE:
- var = vp9_square_search(x, mvp_full, step_param, error_per_bit, 1,
- cost_list, fn_ptr, 1, ref_mv, tmp_mv);
+ var = square_search(x, mvp_full, step_param, error_per_bit, 1,
+ cost_list, fn_ptr, 1, ref_mv, tmp_mv);
break;
case BIGDIA:
- var = vp9_bigdia_search(x, mvp_full, step_param, error_per_bit, 1,
- cost_list, fn_ptr, 1, ref_mv, tmp_mv);
+ var = bigdia_search(x, mvp_full, step_param, error_per_bit, 1,
+ cost_list, fn_ptr, 1, ref_mv, tmp_mv);
break;
case NSTEP:
- var = vp9_full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit,
- MAX_MVSEARCH_STEPS - 1 - step_param,
- 1, cost_list, fn_ptr, ref_mv, tmp_mv);
+ var = full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit,
+ MAX_MVSEARCH_STEPS - 1 - step_param,
+ 1, cost_list, fn_ptr, ref_mv, tmp_mv);
break;
default:
assert(0 && "Invalid search method.");