| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 if (x->mv_col_min < col_min) | 44 if (x->mv_col_min < col_min) |
| 45 x->mv_col_min = col_min; | 45 x->mv_col_min = col_min; |
| 46 if (x->mv_col_max > col_max) | 46 if (x->mv_col_max > col_max) |
| 47 x->mv_col_max = col_max; | 47 x->mv_col_max = col_max; |
| 48 if (x->mv_row_min < row_min) | 48 if (x->mv_row_min < row_min) |
| 49 x->mv_row_min = row_min; | 49 x->mv_row_min = row_min; |
| 50 if (x->mv_row_max > row_max) | 50 if (x->mv_row_max > row_max) |
| 51 x->mv_row_max = row_max; | 51 x->mv_row_max = row_max; |
| 52 } | 52 } |
| 53 | 53 |
| 54 int vp9_init_search_range(const SPEED_FEATURES *sf, int size) { | 54 int vp9_init_search_range(int size) { |
| 55 int sr = 0; | 55 int sr = 0; |
| 56 | |
| 57 // Minimum search size no matter what the passed in value. | 56 // Minimum search size no matter what the passed in value. |
| 58 size = MAX(16, size); | 57 size = MAX(16, size); |
| 59 | 58 |
| 60 while ((size << sr) < MAX_FULL_PEL_VAL) | 59 while ((size << sr) < MAX_FULL_PEL_VAL) |
| 61 sr++; | 60 sr++; |
| 62 | 61 |
| 63 sr = MIN(sr, MAX_MVSEARCH_STEPS - 2); | 62 sr = MIN(sr, MAX_MVSEARCH_STEPS - 2); |
| 64 return sr; | 63 return sr; |
| 65 } | 64 } |
| 66 | 65 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 164 |
| 166 // convert motion vector component to offset for svf calc | 165 // convert motion vector component to offset for svf calc |
| 167 static INLINE int sp(int x) { | 166 static INLINE int sp(int x) { |
| 168 return (x & 7) << 1; | 167 return (x & 7) << 1; |
| 169 } | 168 } |
| 170 | 169 |
| 171 static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { | 170 static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { |
| 172 return &buf[(r >> 3) * stride + (c >> 3)]; | 171 return &buf[(r >> 3) * stride + (c >> 3)]; |
| 173 } | 172 } |
| 174 | 173 |
| 175 /* returns subpixel variance error function */ | |
| 176 #define DIST(r, c) \ | |
| 177 vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \ | |
| 178 src_stride, &sse) | |
| 179 | |
| 180 /* checks if (r, c) has better score than previous best */ | 174 /* checks if (r, c) has better score than previous best */ |
| 181 #define CHECK_BETTER(v, r, c) \ | 175 #define CHECK_BETTER(v, r, c) \ |
| 182 if (c >= minc && c <= maxc && r >= minr && r <= maxr) { \ | 176 if (c >= minc && c <= maxc && r >= minr && r <= maxr) { \ |
| 183 thismse = (DIST(r, c)); \ | 177 if (second_pred == NULL) \ |
| 178 thismse = vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \ |
| 179 src_stride, &sse); \ |
| 180 else \ |
| 181 thismse = vfp->svaf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), \ |
| 182 z, src_stride, &sse, second_pred); \ |
| 184 if ((v = MVC(r, c) + thismse) < besterr) { \ | 183 if ((v = MVC(r, c) + thismse) < besterr) { \ |
| 185 besterr = v; \ | 184 besterr = v; \ |
| 186 br = r; \ | 185 br = r; \ |
| 187 bc = c; \ | 186 bc = c; \ |
| 188 *distortion = thismse; \ | 187 *distortion = thismse; \ |
| 189 *sse1 = sse; \ | 188 *sse1 = sse; \ |
| 190 } \ | 189 } \ |
| 191 } else { \ | 190 } else { \ |
| 192 v = INT_MAX; \ | 191 v = INT_MAX; \ |
| 193 } | 192 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 258 |
| 260 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, | 259 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
| 261 MV *bestmv, const MV *ref_mv, | 260 MV *bestmv, const MV *ref_mv, |
| 262 int allow_hp, | 261 int allow_hp, |
| 263 int error_per_bit, | 262 int error_per_bit, |
| 264 const vp9_variance_fn_ptr_t *vfp, | 263 const vp9_variance_fn_ptr_t *vfp, |
| 265 int forced_stop, | 264 int forced_stop, |
| 266 int iters_per_step, | 265 int iters_per_step, |
| 267 int *mvjcost, int *mvcost[2], | 266 int *mvjcost, int *mvcost[2], |
| 268 int *distortion, | 267 int *distortion, |
| 269 unsigned int *sse1) { | 268 unsigned int *sse1, |
| 269 const uint8_t *second_pred, |
| 270 int w, int h) { |
| 270 const uint8_t *const z = x->plane[0].src.buf; | 271 const uint8_t *const z = x->plane[0].src.buf; |
| 271 const int src_stride = x->plane[0].src.stride; | 272 const int src_stride = x->plane[0].src.stride; |
| 272 const MACROBLOCKD *xd = &x->e_mbd; | 273 const MACROBLOCKD *xd = &x->e_mbd; |
| 273 unsigned int besterr = INT_MAX; | 274 unsigned int besterr = INT_MAX; |
| 274 unsigned int sse; | 275 unsigned int sse; |
| 275 unsigned int whichdir; | 276 unsigned int whichdir; |
| 276 int thismse; | 277 int thismse; |
| 277 unsigned int halfiters = iters_per_step; | |
| 278 unsigned int quarteriters = iters_per_step; | |
| 279 unsigned int eighthiters = iters_per_step; | |
| 280 | |
| 281 const int y_stride = xd->plane[0].pre[0].stride; | |
| 282 const int offset = bestmv->row * y_stride + bestmv->col; | |
| 283 const uint8_t *const y = xd->plane[0].pre[0].buf; | |
| 284 | |
| 285 int rr = ref_mv->row; | |
| 286 int rc = ref_mv->col; | |
| 287 int br = bestmv->row * 8; | |
| 288 int bc = bestmv->col * 8; | |
| 289 int hstep = 4; | |
| 290 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); | |
| 291 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); | |
| 292 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); | |
| 293 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); | |
| 294 | |
| 295 int tr = br; | |
| 296 int tc = bc; | |
| 297 | |
| 298 // central mv | |
| 299 bestmv->row *= 8; | |
| 300 bestmv->col *= 8; | |
| 301 | |
| 302 // calculate central point error | |
| 303 besterr = vfp->vf(y + offset, y_stride, z, src_stride, sse1); | |
| 304 *distortion = besterr; | |
| 305 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); | |
| 306 | |
| 307 // 1/2 pel | |
| 308 FIRST_LEVEL_CHECKS; | |
| 309 if (halfiters > 1) { | |
| 310 SECOND_LEVEL_CHECKS; | |
| 311 } | |
| 312 tr = br; | |
| 313 tc = bc; | |
| 314 | |
| 315 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only | |
| 316 if (forced_stop != 2) { | |
| 317 hstep >>= 1; | |
| 318 FIRST_LEVEL_CHECKS; | |
| 319 if (quarteriters > 1) { | |
| 320 SECOND_LEVEL_CHECKS; | |
| 321 } | |
| 322 tr = br; | |
| 323 tc = bc; | |
| 324 } | |
| 325 | |
| 326 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) { | |
| 327 hstep >>= 1; | |
| 328 FIRST_LEVEL_CHECKS; | |
| 329 if (eighthiters > 1) { | |
| 330 SECOND_LEVEL_CHECKS; | |
| 331 } | |
| 332 tr = br; | |
| 333 tc = bc; | |
| 334 } | |
| 335 // These lines insure static analysis doesn't warn that | |
| 336 // tr and tc aren't used after the above point. | |
| 337 (void) tr; | |
| 338 (void) tc; | |
| 339 | |
| 340 bestmv->row = br; | |
| 341 bestmv->col = bc; | |
| 342 | |
| 343 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || | |
| 344 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) | |
| 345 return INT_MAX; | |
| 346 | |
| 347 return besterr; | |
| 348 } | |
| 349 | |
| 350 #undef DIST | |
| 351 /* returns subpixel variance error function */ | |
| 352 #define DIST(r, c) \ | |
| 353 vfp->svaf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), \ | |
| 354 z, src_stride, &sse, second_pred) | |
| 355 | |
| 356 int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x, | |
| 357 MV *bestmv, const MV *ref_mv, | |
| 358 int allow_hp, | |
| 359 int error_per_bit, | |
| 360 const vp9_variance_fn_ptr_t *vfp, | |
| 361 int forced_stop, | |
| 362 int iters_per_step, | |
| 363 int *mvjcost, int *mvcost[2], | |
| 364 int *distortion, | |
| 365 unsigned int *sse1, | |
| 366 const uint8_t *second_pred, | |
| 367 int w, int h) { | |
| 368 const uint8_t *const z = x->plane[0].src.buf; | |
| 369 const int src_stride = x->plane[0].src.stride; | |
| 370 const MACROBLOCKD *xd = &x->e_mbd; | |
| 371 unsigned int besterr = INT_MAX; | |
| 372 unsigned int sse; | |
| 373 unsigned int whichdir; | |
| 374 int thismse; | |
| 375 const unsigned int halfiters = iters_per_step; | 278 const unsigned int halfiters = iters_per_step; |
| 376 const unsigned int quarteriters = iters_per_step; | 279 const unsigned int quarteriters = iters_per_step; |
| 377 const unsigned int eighthiters = iters_per_step; | 280 const unsigned int eighthiters = iters_per_step; |
| 378 | 281 |
| 379 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); | |
| 380 const int y_stride = xd->plane[0].pre[0].stride; | 282 const int y_stride = xd->plane[0].pre[0].stride; |
| 381 const int offset = bestmv->row * y_stride + bestmv->col; | 283 const int offset = bestmv->row * y_stride + bestmv->col; |
| 382 const uint8_t *const y = xd->plane[0].pre[0].buf; | 284 const uint8_t *const y = xd->plane[0].pre[0].buf; |
| 383 | 285 |
| 384 int rr = ref_mv->row; | 286 int rr = ref_mv->row; |
| 385 int rc = ref_mv->col; | 287 int rc = ref_mv->col; |
| 386 int br = bestmv->row * 8; | 288 int br = bestmv->row * 8; |
| 387 int bc = bestmv->col * 8; | 289 int bc = bestmv->col * 8; |
| 388 int hstep = 4; | 290 int hstep = 4; |
| 389 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); | 291 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); |
| 390 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); | 292 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); |
| 391 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); | 293 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); |
| 392 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); | 294 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); |
| 393 | 295 |
| 394 int tr = br; | 296 int tr = br; |
| 395 int tc = bc; | 297 int tc = bc; |
| 396 | 298 |
| 397 // central mv | 299 // central mv |
| 398 bestmv->row *= 8; | 300 bestmv->row *= 8; |
| 399 bestmv->col *= 8; | 301 bestmv->col *= 8; |
| 400 | 302 |
| 401 // calculate central point error | 303 // calculate central point error |
| 402 // TODO(yunqingwang): central pointer error was already calculated in full- | 304 // TODO(yunqingwang): central pointer error was already calculated in full- |
| 403 // pixel search, and can be passed in this function. | 305 // pixel search, and can be passed in this function. |
| 404 vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); | 306 if (second_pred != NULL) { |
| 405 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1); | 307 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); |
| 308 vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); |
| 309 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1); |
| 310 } else { |
| 311 besterr = vfp->vf(y + offset, y_stride, z, src_stride, sse1); |
| 312 } |
| 406 *distortion = besterr; | 313 *distortion = besterr; |
| 407 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); | 314 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); |
| 408 | 315 |
| 409 // Each subsequent iteration checks at least one point in | 316 // Each subsequent iteration checks at least one point in |
| 410 // common with the last iteration could be 2 ( if diag selected) | 317 // common with the last iteration could be 2 ( if diag selected) |
| 411 // 1/2 pel | 318 // 1/2 pel |
| 412 FIRST_LEVEL_CHECKS; | 319 FIRST_LEVEL_CHECKS; |
| 413 if (halfiters > 1) { | 320 if (halfiters > 1) { |
| 414 SECOND_LEVEL_CHECKS; | 321 SECOND_LEVEL_CHECKS; |
| 415 } | 322 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 356 |
| 450 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || | 357 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || |
| 451 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) | 358 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) |
| 452 return INT_MAX; | 359 return INT_MAX; |
| 453 | 360 |
| 454 return besterr; | 361 return besterr; |
| 455 } | 362 } |
| 456 | 363 |
| 457 #undef MVC | 364 #undef MVC |
| 458 #undef PRE | 365 #undef PRE |
| 459 #undef DIST | |
| 460 #undef CHECK_BETTER | 366 #undef CHECK_BETTER |
| 461 | 367 |
| 462 static INLINE int check_bounds(const MACROBLOCK *x, int row, int col, | 368 static INLINE int check_bounds(const MACROBLOCK *x, int row, int col, |
| 463 int range) { | 369 int range) { |
| 464 return ((row - range) >= x->mv_row_min) & | 370 return ((row - range) >= x->mv_row_min) & |
| 465 ((row + range) <= x->mv_row_max) & | 371 ((row + range) <= x->mv_row_max) & |
| 466 ((col - range) >= x->mv_col_min) & | 372 ((col - range) >= x->mv_col_min) & |
| 467 ((col + range) <= x->mv_col_max); | 373 ((col + range) <= x->mv_col_max); |
| 468 } | 374 } |
| 469 | 375 |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 } | 843 } |
| 938 } | 844 } |
| 939 } | 845 } |
| 940 } | 846 } |
| 941 | 847 |
| 942 return best_sad; | 848 return best_sad; |
| 943 } | 849 } |
| 944 | 850 |
| 945 int vp9_diamond_search_sad_c(const MACROBLOCK *x, | 851 int vp9_diamond_search_sad_c(const MACROBLOCK *x, |
| 946 const search_site_config *cfg, | 852 const search_site_config *cfg, |
| 947 MV *ref_mv, MV *best_mv, | |
| 948 int search_param, int sad_per_bit, int *num00, | |
| 949 const vp9_variance_fn_ptr_t *fn_ptr, | |
| 950 const MV *center_mv) { | |
| 951 const MACROBLOCKD *const xd = &x->e_mbd; | |
| 952 const struct buf_2d *const what = &x->plane[0].src; | |
| 953 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | |
| 954 // search_param determines the length of the initial step and hence the number | |
| 955 // of iterations | |
| 956 // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = | |
| 957 // (MAX_FIRST_STEP/4) pel... etc. | |
| 958 const search_site *const ss = &cfg->ss[search_param * cfg->searches_per_step]; | |
| 959 const int tot_steps = (cfg->ss_count / cfg->searches_per_step) - search_param; | |
| 960 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | |
| 961 const uint8_t *best_address, *in_what_ref; | |
| 962 int best_sad = INT_MAX; | |
| 963 int best_site = 0; | |
| 964 int last_site = 0; | |
| 965 int i, j, step; | |
| 966 | |
| 967 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | |
| 968 in_what_ref = get_buf_from_mv(in_what, ref_mv); | |
| 969 best_address = in_what_ref; | |
| 970 *num00 = 0; | |
| 971 *best_mv = *ref_mv; | |
| 972 | |
| 973 // Check the starting position | |
| 974 best_sad = fn_ptr->sdf(what->buf, what->stride, | |
| 975 best_address, in_what->stride) + | |
| 976 mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); | |
| 977 | |
| 978 i = 1; | |
| 979 | |
| 980 for (step = 0; step < tot_steps; step++) { | |
| 981 for (j = 0; j < cfg->searches_per_step; j++) { | |
| 982 const MV mv = {best_mv->row + ss[i].mv.row, | |
| 983 best_mv->col + ss[i].mv.col}; | |
| 984 if (is_mv_in(x, &mv)) { | |
| 985 int sad = fn_ptr->sdf(what->buf, what->stride, | |
| 986 best_address + ss[i].offset, in_what->stride); | |
| 987 if (sad < best_sad) { | |
| 988 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | |
| 989 if (sad < best_sad) { | |
| 990 best_sad = sad; | |
| 991 best_site = i; | |
| 992 } | |
| 993 } | |
| 994 } | |
| 995 | |
| 996 i++; | |
| 997 } | |
| 998 | |
| 999 if (best_site != last_site) { | |
| 1000 best_mv->row += ss[best_site].mv.row; | |
| 1001 best_mv->col += ss[best_site].mv.col; | |
| 1002 best_address += ss[best_site].offset; | |
| 1003 last_site = best_site; | |
| 1004 #if defined(NEW_DIAMOND_SEARCH) | |
| 1005 while (1) { | |
| 1006 const MV this_mv = {best_mv->row + ss[best_site].mv.row, | |
| 1007 best_mv->col + ss[best_site].mv.col}; | |
| 1008 if (is_mv_in(x, &this_mv)) { | |
| 1009 int sad = fn_ptr->sdf(what->buf, what->stride, | |
| 1010 best_address + ss[best_site].offset, | |
| 1011 in_what->stride); | |
| 1012 if (sad < best_sad) { | |
| 1013 sad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); | |
| 1014 if (sad < best_sad) { | |
| 1015 best_sad = sad; | |
| 1016 best_mv->row += ss[best_site].mv.row; | |
| 1017 best_mv->col += ss[best_site].mv.col; | |
| 1018 best_address += ss[best_site].offset; | |
| 1019 continue; | |
| 1020 } | |
| 1021 } | |
| 1022 } | |
| 1023 break; | |
| 1024 }; | |
| 1025 #endif | |
| 1026 } else if (best_address == in_what_ref) { | |
| 1027 (*num00)++; | |
| 1028 } | |
| 1029 } | |
| 1030 return best_sad; | |
| 1031 } | |
| 1032 | |
| 1033 int vp9_diamond_search_sadx4(const MACROBLOCK *x, | |
| 1034 const search_site_config *cfg, | |
| 1035 MV *ref_mv, MV *best_mv, int search_param, | 853 MV *ref_mv, MV *best_mv, int search_param, |
| 1036 int sad_per_bit, int *num00, | 854 int sad_per_bit, int *num00, |
| 1037 const vp9_variance_fn_ptr_t *fn_ptr, | 855 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1038 const MV *center_mv) { | 856 const MV *center_mv) { |
| 1039 int i, j, step; | 857 int i, j, step; |
| 1040 | 858 |
| 1041 const MACROBLOCKD *const xd = &x->e_mbd; | 859 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1042 uint8_t *what = x->plane[0].src.buf; | 860 uint8_t *what = x->plane[0].src.buf; |
| 1043 const int what_stride = x->plane[0].src.stride; | 861 const int what_stride = x->plane[0].src.stride; |
| 1044 const uint8_t *in_what; | 862 const uint8_t *in_what; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 last_site = best_site; | 963 last_site = best_site; |
| 1146 #if defined(NEW_DIAMOND_SEARCH) | 964 #if defined(NEW_DIAMOND_SEARCH) |
| 1147 while (1) { | 965 while (1) { |
| 1148 const MV this_mv = {best_mv->row + ss[best_site].mv.row, | 966 const MV this_mv = {best_mv->row + ss[best_site].mv.row, |
| 1149 best_mv->col + ss[best_site].mv.col}; | 967 best_mv->col + ss[best_site].mv.col}; |
| 1150 if (is_mv_in(x, &this_mv)) { | 968 if (is_mv_in(x, &this_mv)) { |
| 1151 const uint8_t *const check_here = ss[best_site].offset + best_address; | 969 const uint8_t *const check_here = ss[best_site].offset + best_address; |
| 1152 unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here, | 970 unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here, |
| 1153 in_what_stride); | 971 in_what_stride); |
| 1154 if (thissad < bestsad) { | 972 if (thissad < bestsad) { |
| 1155 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 973 thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); |
| 1156 mvjsadcost, mvsadcost, sad_per_bit); | |
| 1157 if (thissad < bestsad) { | 974 if (thissad < bestsad) { |
| 1158 bestsad = thissad; | 975 bestsad = thissad; |
| 1159 best_mv->row += ss[best_site].mv.row; | 976 best_mv->row += ss[best_site].mv.row; |
| 1160 best_mv->col += ss[best_site].mv.col; | 977 best_mv->col += ss[best_site].mv.col; |
| 1161 best_address += ss[best_site].offset; | 978 best_address += ss[best_site].offset; |
| 1162 continue; | 979 continue; |
| 1163 } | 980 } |
| 1164 } | 981 } |
| 1165 } | 982 } |
| 1166 break; | 983 break; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 } | 1237 } |
| 1421 | 1238 |
| 1422 return best_sad; | 1239 return best_sad; |
| 1423 } | 1240 } |
| 1424 | 1241 |
| 1425 int vp9_refining_search_sad_c(const MACROBLOCK *x, | 1242 int vp9_refining_search_sad_c(const MACROBLOCK *x, |
| 1426 MV *ref_mv, int error_per_bit, | 1243 MV *ref_mv, int error_per_bit, |
| 1427 int search_range, | 1244 int search_range, |
| 1428 const vp9_variance_fn_ptr_t *fn_ptr, | 1245 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1429 const MV *center_mv) { | 1246 const MV *center_mv) { |
| 1430 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; | |
| 1431 const MACROBLOCKD *const xd = &x->e_mbd; | |
| 1432 const struct buf_2d *const what = &x->plane[0].src; | |
| 1433 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | |
| 1434 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | |
| 1435 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, | |
| 1436 get_buf_from_mv(in_what, ref_mv), | |
| 1437 in_what->stride) + | |
| 1438 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); | |
| 1439 int i, j; | |
| 1440 | |
| 1441 for (i = 0; i < search_range; i++) { | |
| 1442 int best_site = -1; | |
| 1443 | |
| 1444 for (j = 0; j < 4; j++) { | |
| 1445 const MV mv = {ref_mv->row + neighbors[j].row, | |
| 1446 ref_mv->col + neighbors[j].col}; | |
| 1447 if (is_mv_in(x, &mv)) { | |
| 1448 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, | |
| 1449 get_buf_from_mv(in_what, &mv), in_what->stride); | |
| 1450 if (sad < best_sad) { | |
| 1451 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); | |
| 1452 if (sad < best_sad) { | |
| 1453 best_sad = sad; | |
| 1454 best_site = j; | |
| 1455 } | |
| 1456 } | |
| 1457 } | |
| 1458 } | |
| 1459 | |
| 1460 if (best_site == -1) { | |
| 1461 break; | |
| 1462 } else { | |
| 1463 ref_mv->row += neighbors[best_site].row; | |
| 1464 ref_mv->col += neighbors[best_site].col; | |
| 1465 } | |
| 1466 } | |
| 1467 return best_sad; | |
| 1468 } | |
| 1469 | |
| 1470 int vp9_refining_search_sadx4(const MACROBLOCK *x, | |
| 1471 MV *ref_mv, int error_per_bit, | |
| 1472 int search_range, | |
| 1473 const vp9_variance_fn_ptr_t *fn_ptr, | |
| 1474 const MV *center_mv) { | |
| 1475 const MACROBLOCKD *const xd = &x->e_mbd; | 1247 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1476 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 1248 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; |
| 1477 const struct buf_2d *const what = &x->plane[0].src; | 1249 const struct buf_2d *const what = &x->plane[0].src; |
| 1478 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1250 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
| 1479 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1251 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1480 const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv); | 1252 const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv); |
| 1481 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address, | 1253 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address, |
| 1482 in_what->stride) + | 1254 in_what->stride) + |
| 1483 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); | 1255 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); |
| 1484 int i, j; | 1256 int i, j; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 break; | 1403 break; |
| 1632 default: | 1404 default: |
| 1633 assert(!"Invalid search method."); | 1405 assert(!"Invalid search method."); |
| 1634 } | 1406 } |
| 1635 | 1407 |
| 1636 if (method != NSTEP && rd && var < var_max) | 1408 if (method != NSTEP && rd && var < var_max) |
| 1637 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); | 1409 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); |
| 1638 | 1410 |
| 1639 return var; | 1411 return var; |
| 1640 } | 1412 } |
| OLD | NEW |