| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ((mvjcost[((r) != rr) * 2 + ((c) != rc)] + \ | 177 ((mvjcost[((r) != rr) * 2 + ((c) != rc)] + \ |
| 178 mvcost[0][((r) - rr)] + mvcost[1][((c) - rc)]) * \ | 178 mvcost[0][((r) - rr)] + mvcost[1][((c) - rc)]) * \ |
| 179 error_per_bit + 4096) >> 13 : 0) | 179 error_per_bit + 4096) >> 13 : 0) |
| 180 | 180 |
| 181 | 181 |
| 182 // convert motion vector component to offset for svf calc | 182 // convert motion vector component to offset for svf calc |
| 183 static INLINE int sp(int x) { | 183 static INLINE int sp(int x) { |
| 184 return (x & 7) << 1; | 184 return (x & 7) << 1; |
| 185 } | 185 } |
| 186 | 186 |
| 187 static INLINE uint8_t *pre(uint8_t *buf, int stride, int r, int c, int offset) { | 187 static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c, |
| 188 int offset) { |
| 188 return &buf[(r >> 3) * stride + (c >> 3) - offset]; | 189 return &buf[(r >> 3) * stride + (c >> 3) - offset]; |
| 189 } | 190 } |
| 190 | 191 |
| 191 /* returns subpixel variance error function */ | 192 /* returns subpixel variance error function */ |
| 192 #define DIST(r, c) \ | 193 #define DIST(r, c) \ |
| 193 vfp->svf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), z, \ | 194 vfp->svf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), z, \ |
| 194 src_stride, &sse) | 195 src_stride, &sse) |
| 195 | 196 |
| 196 /* checks if (r, c) has better score than previous best */ | 197 /* checks if (r, c) has better score than previous best */ |
| 197 #define CHECK_BETTER(v, r, c) \ | 198 #define CHECK_BETTER(v, r, c) \ |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 CHECK_BETTER(second, tr + kr, tc + hstep); \ | 267 CHECK_BETTER(second, tr + kr, tc + hstep); \ |
| 267 break; \ | 268 break; \ |
| 268 case 1: \ | 269 case 1: \ |
| 269 case 3: \ | 270 case 3: \ |
| 270 CHECK_BETTER(second, tr + kr, tc - hstep); \ | 271 CHECK_BETTER(second, tr + kr, tc - hstep); \ |
| 271 break; \ | 272 break; \ |
| 272 } \ | 273 } \ |
| 273 } \ | 274 } \ |
| 274 } | 275 } |
| 275 | 276 |
| 276 int vp9_find_best_sub_pixel_tree(MACROBLOCK *x, | 277 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
| 277 MV *bestmv, const MV *ref_mv, | 278 MV *bestmv, const MV *ref_mv, |
| 278 int allow_hp, | 279 int allow_hp, |
| 279 int error_per_bit, | 280 int error_per_bit, |
| 280 const vp9_variance_fn_ptr_t *vfp, | 281 const vp9_variance_fn_ptr_t *vfp, |
| 281 int forced_stop, | 282 int forced_stop, |
| 282 int iters_per_step, | 283 int iters_per_step, |
| 283 int *mvjcost, int *mvcost[2], | 284 int *mvjcost, int *mvcost[2], |
| 284 int *distortion, | 285 int *distortion, |
| 285 unsigned int *sse1) { | 286 unsigned int *sse1) { |
| 286 uint8_t *z = x->plane[0].src.buf; | 287 const uint8_t *z = x->plane[0].src.buf; |
| 287 const int src_stride = x->plane[0].src.stride; | 288 const int src_stride = x->plane[0].src.stride; |
| 288 MACROBLOCKD *xd = &x->e_mbd; | 289 const MACROBLOCKD *xd = &x->e_mbd; |
| 289 unsigned int besterr = INT_MAX; | 290 unsigned int besterr = INT_MAX; |
| 290 unsigned int sse; | 291 unsigned int sse; |
| 291 unsigned int whichdir; | 292 unsigned int whichdir; |
| 292 int thismse; | 293 int thismse; |
| 293 unsigned int halfiters = iters_per_step; | 294 unsigned int halfiters = iters_per_step; |
| 294 unsigned int quarteriters = iters_per_step; | 295 unsigned int quarteriters = iters_per_step; |
| 295 unsigned int eighthiters = iters_per_step; | 296 unsigned int eighthiters = iters_per_step; |
| 296 | 297 |
| 297 const int y_stride = xd->plane[0].pre[0].stride; | 298 const int y_stride = xd->plane[0].pre[0].stride; |
| 298 const int offset = bestmv->row * y_stride + bestmv->col; | 299 const int offset = bestmv->row * y_stride + bestmv->col; |
| 299 uint8_t *y = xd->plane[0].pre[0].buf + offset; | 300 const uint8_t *y = xd->plane[0].pre[0].buf + offset; |
| 300 | 301 |
| 301 int rr = ref_mv->row; | 302 int rr = ref_mv->row; |
| 302 int rc = ref_mv->col; | 303 int rc = ref_mv->col; |
| 303 int br = bestmv->row * 8; | 304 int br = bestmv->row * 8; |
| 304 int bc = bestmv->col * 8; | 305 int bc = bestmv->col * 8; |
| 305 int hstep = 4; | 306 int hstep = 4; |
| 306 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); | 307 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); |
| 307 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); | 308 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); |
| 308 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); | 309 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); |
| 309 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); | 310 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 342 |
| 342 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) { | 343 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) { |
| 343 hstep >>= 1; | 344 hstep >>= 1; |
| 344 FIRST_LEVEL_CHECKS; | 345 FIRST_LEVEL_CHECKS; |
| 345 if (eighthiters > 1) { | 346 if (eighthiters > 1) { |
| 346 SECOND_LEVEL_CHECKS; | 347 SECOND_LEVEL_CHECKS; |
| 347 } | 348 } |
| 348 tr = br; | 349 tr = br; |
| 349 tc = bc; | 350 tc = bc; |
| 350 } | 351 } |
| 352 // These lines insure static analysis doesn't warn that |
| 353 // tr and tc aren't used after the above point. |
| 354 (void) tr; |
| 355 (void) tc; |
| 351 | 356 |
| 352 bestmv->row = br; | 357 bestmv->row = br; |
| 353 bestmv->col = bc; | 358 bestmv->col = bc; |
| 354 | 359 |
| 355 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || | 360 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || |
| 356 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) | 361 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) |
| 357 return INT_MAX; | 362 return INT_MAX; |
| 358 | 363 |
| 359 return besterr; | 364 return besterr; |
| 360 } | 365 } |
| 361 | 366 |
| 362 #undef DIST | 367 #undef DIST |
| 363 /* returns subpixel variance error function */ | 368 /* returns subpixel variance error function */ |
| 364 #define DIST(r, c) \ | 369 #define DIST(r, c) \ |
| 365 vfp->svaf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), \ | 370 vfp->svaf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), \ |
| 366 z, src_stride, &sse, second_pred) | 371 z, src_stride, &sse, second_pred) |
| 367 | 372 |
| 368 int vp9_find_best_sub_pixel_comp_tree(MACROBLOCK *x, | 373 int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x, |
| 369 MV *bestmv, const MV *ref_mv, | 374 MV *bestmv, const MV *ref_mv, |
| 370 int allow_hp, | 375 int allow_hp, |
| 371 int error_per_bit, | 376 int error_per_bit, |
| 372 const vp9_variance_fn_ptr_t *vfp, | 377 const vp9_variance_fn_ptr_t *vfp, |
| 373 int forced_stop, | 378 int forced_stop, |
| 374 int iters_per_step, | 379 int iters_per_step, |
| 375 int *mvjcost, int *mvcost[2], | 380 int *mvjcost, int *mvcost[2], |
| 376 int *distortion, | 381 int *distortion, |
| 377 unsigned int *sse1, | 382 unsigned int *sse1, |
| 378 const uint8_t *second_pred, | 383 const uint8_t *second_pred, |
| 379 int w, int h) { | 384 int w, int h) { |
| 380 uint8_t *z = x->plane[0].src.buf; | 385 const uint8_t *z = x->plane[0].src.buf; |
| 381 const int src_stride = x->plane[0].src.stride; | 386 const int src_stride = x->plane[0].src.stride; |
| 382 MACROBLOCKD *xd = &x->e_mbd; | 387 const MACROBLOCKD *xd = &x->e_mbd; |
| 383 unsigned int besterr = INT_MAX; | 388 unsigned int besterr = INT_MAX; |
| 384 unsigned int sse; | 389 unsigned int sse; |
| 385 unsigned int whichdir; | 390 unsigned int whichdir; |
| 386 int thismse; | 391 int thismse; |
| 387 unsigned int halfiters = iters_per_step; | 392 unsigned int halfiters = iters_per_step; |
| 388 unsigned int quarteriters = iters_per_step; | 393 unsigned int quarteriters = iters_per_step; |
| 389 unsigned int eighthiters = iters_per_step; | 394 unsigned int eighthiters = iters_per_step; |
| 390 | 395 |
| 391 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); | 396 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); |
| 392 const int y_stride = xd->plane[0].pre[0].stride; | 397 const int y_stride = xd->plane[0].pre[0].stride; |
| 393 const int offset = bestmv->row * y_stride + bestmv->col; | 398 const int offset = bestmv->row * y_stride + bestmv->col; |
| 394 uint8_t *y = xd->plane[0].pre[0].buf + offset; | 399 const uint8_t *y = xd->plane[0].pre[0].buf + offset; |
| 395 | 400 |
| 396 int rr = ref_mv->row; | 401 int rr = ref_mv->row; |
| 397 int rc = ref_mv->col; | 402 int rc = ref_mv->col; |
| 398 int br = bestmv->row * 8; | 403 int br = bestmv->row * 8; |
| 399 int bc = bestmv->col * 8; | 404 int bc = bestmv->col * 8; |
| 400 int hstep = 4; | 405 int hstep = 4; |
| 401 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); | 406 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); |
| 402 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); | 407 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); |
| 403 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); | 408 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); |
| 404 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); | 409 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 449 |
| 445 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) { | 450 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) { |
| 446 hstep >>= 1; | 451 hstep >>= 1; |
| 447 FIRST_LEVEL_CHECKS; | 452 FIRST_LEVEL_CHECKS; |
| 448 if (eighthiters > 1) { | 453 if (eighthiters > 1) { |
| 449 SECOND_LEVEL_CHECKS; | 454 SECOND_LEVEL_CHECKS; |
| 450 } | 455 } |
| 451 tr = br; | 456 tr = br; |
| 452 tc = bc; | 457 tc = bc; |
| 453 } | 458 } |
| 459 // These lines insure static analysis doesn't warn that |
| 460 // tr and tc aren't used after the above point. |
| 461 (void) tr; |
| 462 (void) tc; |
| 463 |
| 454 bestmv->row = br; | 464 bestmv->row = br; |
| 455 bestmv->col = bc; | 465 bestmv->col = bc; |
| 456 | 466 |
| 457 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || | 467 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || |
| 458 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) | 468 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) |
| 459 return INT_MAX; | 469 return INT_MAX; |
| 460 | 470 |
| 461 return besterr; | 471 return besterr; |
| 462 } | 472 } |
| 463 | 473 |
| 464 #undef MVC | 474 #undef MVC |
| 465 #undef PRE | 475 #undef PRE |
| 466 #undef DIST | 476 #undef DIST |
| 467 #undef CHECK_BETTER | 477 #undef CHECK_BETTER |
| 468 #undef SP | |
| 469 | 478 |
| 470 static INLINE int check_bounds(const MACROBLOCK *x, int row, int col, | 479 static INLINE int check_bounds(const MACROBLOCK *x, int row, int col, |
| 471 int range) { | 480 int range) { |
| 472 return ((row - range) >= x->mv_row_min) & | 481 return ((row - range) >= x->mv_row_min) & |
| 473 ((row + range) <= x->mv_row_max) & | 482 ((row + range) <= x->mv_row_max) & |
| 474 ((col - range) >= x->mv_col_min) & | 483 ((col - range) >= x->mv_col_min) & |
| 475 ((col + range) <= x->mv_col_max); | 484 ((col + range) <= x->mv_col_max); |
| 476 } | 485 } |
| 477 | 486 |
| 478 static INLINE int check_point(const MACROBLOCK *x, const MV *mv) { | 487 static INLINE int is_mv_in(const MACROBLOCK *x, const MV *mv) { |
| 479 return (mv->col < x->mv_col_min) | | 488 return (mv->col >= x->mv_col_min) && (mv->col <= x->mv_col_max) && |
| 480 (mv->col > x->mv_col_max) | | 489 (mv->row >= x->mv_row_min) && (mv->row <= x->mv_row_max); |
| 481 (mv->row < x->mv_row_min) | | |
| 482 (mv->row > x->mv_row_max); | |
| 483 } | 490 } |
| 484 | 491 |
| 485 #define CHECK_BETTER \ | 492 #define CHECK_BETTER \ |
| 486 {\ | 493 {\ |
| 487 if (thissad < bestsad)\ | 494 if (thissad < bestsad) {\ |
| 488 {\ | |
| 489 if (use_mvcost) \ | 495 if (use_mvcost) \ |
| 490 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, \ | 496 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, \ |
| 491 mvjsadcost, mvsadcost, \ | 497 mvjsadcost, mvsadcost, sad_per_bit);\ |
| 492 sad_per_bit);\ | 498 if (thissad < bestsad) {\ |
| 493 if (thissad < bestsad)\ | |
| 494 {\ | |
| 495 bestsad = thissad;\ | 499 bestsad = thissad;\ |
| 496 best_site = i;\ | 500 best_site = i;\ |
| 497 }\ | 501 }\ |
| 498 }\ | 502 }\ |
| 499 } | 503 } |
| 500 | 504 |
| 501 #define get_next_chkpts(list, i, n) \ | |
| 502 list[0] = ((i) == 0 ? (n) - 1 : (i) - 1); \ | |
| 503 list[1] = (i); \ | |
| 504 list[2] = ((i) == (n) - 1 ? 0 : (i) + 1); | |
| 505 | |
| 506 #define MAX_PATTERN_SCALES 11 | 505 #define MAX_PATTERN_SCALES 11 |
| 507 #define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale | 506 #define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale |
| 508 #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates | 507 #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates |
| 509 | 508 |
| 510 // Generic pattern search function that searches over multiple scales. | 509 // Generic pattern search function that searches over multiple scales. |
| 511 // Each scale can have a different number of candidates and shape of | 510 // Each scale can have a different number of candidates and shape of |
| 512 // candidates as indicated in the num_candidates and candidates arrays | 511 // candidates as indicated in the num_candidates and candidates arrays |
| 513 // passed into this function | 512 // passed into this function |
| 514 static int vp9_pattern_search(MACROBLOCK *x, | 513 static int vp9_pattern_search(const MACROBLOCK *x, |
| 515 MV *ref_mv, | 514 MV *ref_mv, |
| 516 int search_param, | 515 int search_param, |
| 517 int sad_per_bit, | 516 int sad_per_bit, |
| 518 int do_init_search, | 517 int do_init_search, |
| 519 int do_refine, | 518 int do_refine, |
| 520 const vp9_variance_fn_ptr_t *vfp, | 519 const vp9_variance_fn_ptr_t *vfp, |
| 521 int use_mvcost, | 520 int use_mvcost, |
| 522 const MV *center_mv, MV *best_mv, | 521 const MV *center_mv, MV *best_mv, |
| 523 const int num_candidates[MAX_PATTERN_SCALES], | 522 const int num_candidates[MAX_PATTERN_SCALES], |
| 524 const MV candidates[MAX_PATTERN_SCALES] | 523 const MV candidates[MAX_PATTERN_SCALES] |
| 525 [MAX_PATTERN_CANDIDATES]) { | 524 [MAX_PATTERN_CANDIDATES]) { |
| 526 const MACROBLOCKD* const xd = &x->e_mbd; | 525 const MACROBLOCKD *const xd = &x->e_mbd; |
| 527 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = { | 526 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = { |
| 528 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, | 527 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, |
| 529 }; | 528 }; |
| 530 int i, j, s, t; | 529 int i, j, s, t; |
| 531 uint8_t *what = x->plane[0].src.buf; | 530 const uint8_t *what = x->plane[0].src.buf; |
| 532 int what_stride = x->plane[0].src.stride; | 531 const int what_stride = x->plane[0].src.stride; |
| 533 int in_what_stride = xd->plane[0].pre[0].stride; | 532 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 534 int br, bc; | 533 int br, bc; |
| 535 MV this_mv; | 534 MV this_mv; |
| 536 int bestsad = INT_MAX; | 535 int bestsad = INT_MAX; |
| 537 int thissad; | 536 int thissad; |
| 538 uint8_t *base_offset; | 537 const uint8_t *base_offset; |
| 539 uint8_t *this_offset; | 538 const uint8_t *this_offset; |
| 540 int k = -1; | 539 int k = -1; |
| 541 int best_site = -1; | 540 int best_site = -1; |
| 542 MV fcenter_mv; | 541 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 543 int best_init_s = search_param_to_steps[search_param]; | 542 int best_init_s = search_param_to_steps[search_param]; |
| 544 int *mvjsadcost = x->nmvjointsadcost; | 543 const int *mvjsadcost = x->nmvjointsadcost; |
| 545 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 544 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 546 | 545 |
| 547 fcenter_mv.row = center_mv->row >> 3; | |
| 548 fcenter_mv.col = center_mv->col >> 3; | |
| 549 | |
| 550 // adjust ref_mv to make sure it is within MV range | 546 // adjust ref_mv to make sure it is within MV range |
| 551 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 547 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
| 552 br = ref_mv->row; | 548 br = ref_mv->row; |
| 553 bc = ref_mv->col; | 549 bc = ref_mv->col; |
| 554 | 550 |
| 555 // Work out the start point for the search | 551 // Work out the start point for the search |
| 556 base_offset = (uint8_t *)(xd->plane[0].pre[0].buf); | 552 base_offset = xd->plane[0].pre[0].buf; |
| 557 this_offset = base_offset + (br * in_what_stride) + bc; | 553 this_offset = base_offset + (br * in_what_stride) + bc; |
| 558 this_mv.row = br; | 554 this_mv.row = br; |
| 559 this_mv.col = bc; | 555 this_mv.col = bc; |
| 560 bestsad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 0x7fffffff) | 556 bestsad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 0x7fffffff) |
| 561 + mvsad_err_cost(&this_mv, &fcenter_mv, | 557 + mvsad_err_cost(&this_mv, &fcenter_mv, |
| 562 mvjsadcost, mvsadcost, sad_per_bit); | 558 mvjsadcost, mvsadcost, sad_per_bit); |
| 563 | 559 |
| 564 // Search all possible scales upto the search param around the center point | 560 // Search all possible scales upto the search param around the center point |
| 565 // pick the scale of the point that is best as the starting scale of | 561 // pick the scale of the point that is best as the starting scale of |
| 566 // further steps around it. | 562 // further steps around it. |
| 567 if (do_init_search) { | 563 if (do_init_search) { |
| 568 s = best_init_s; | 564 s = best_init_s; |
| 569 best_init_s = -1; | 565 best_init_s = -1; |
| 570 for (t = 0; t <= s; ++t) { | 566 for (t = 0; t <= s; ++t) { |
| 571 best_site = -1; | 567 best_site = -1; |
| 572 if (check_bounds(x, br, bc, 1 << t)) { | 568 if (check_bounds(x, br, bc, 1 << t)) { |
| 573 for (i = 0; i < num_candidates[t]; i++) { | 569 for (i = 0; i < num_candidates[t]; i++) { |
| 574 this_mv.row = br + candidates[t][i].row; | 570 this_mv.row = br + candidates[t][i].row; |
| 575 this_mv.col = bc + candidates[t][i].col; | 571 this_mv.col = bc + candidates[t][i].col; |
| 576 this_offset = base_offset + (this_mv.row * in_what_stride) + | 572 this_offset = base_offset + (this_mv.row * in_what_stride) + |
| 577 this_mv.col; | 573 this_mv.col; |
| 578 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 574 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 579 bestsad); | 575 bestsad); |
| 580 CHECK_BETTER | 576 CHECK_BETTER |
| 581 } | 577 } |
| 582 } else { | 578 } else { |
| 583 for (i = 0; i < num_candidates[t]; i++) { | 579 for (i = 0; i < num_candidates[t]; i++) { |
| 584 this_mv.row = br + candidates[t][i].row; | 580 this_mv.row = br + candidates[t][i].row; |
| 585 this_mv.col = bc + candidates[t][i].col; | 581 this_mv.col = bc + candidates[t][i].col; |
| 586 if (check_point(x, &this_mv)) | 582 if (!is_mv_in(x, &this_mv)) |
| 587 continue; | 583 continue; |
| 588 this_offset = base_offset + (this_mv.row * in_what_stride) + | 584 this_offset = base_offset + (this_mv.row * in_what_stride) + |
| 589 this_mv.col; | 585 this_mv.col; |
| 590 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 586 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 591 bestsad); | 587 bestsad); |
| 592 CHECK_BETTER | 588 CHECK_BETTER |
| 593 } | 589 } |
| 594 } | 590 } |
| 595 if (best_site == -1) { | 591 if (best_site == -1) { |
| 596 continue; | 592 continue; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 620 this_offset = base_offset + (this_mv.row * in_what_stride) + | 616 this_offset = base_offset + (this_mv.row * in_what_stride) + |
| 621 this_mv.col; | 617 this_mv.col; |
| 622 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 618 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 623 bestsad); | 619 bestsad); |
| 624 CHECK_BETTER | 620 CHECK_BETTER |
| 625 } | 621 } |
| 626 } else { | 622 } else { |
| 627 for (i = 0; i < num_candidates[s]; i++) { | 623 for (i = 0; i < num_candidates[s]; i++) { |
| 628 this_mv.row = br + candidates[s][i].row; | 624 this_mv.row = br + candidates[s][i].row; |
| 629 this_mv.col = bc + candidates[s][i].col; | 625 this_mv.col = bc + candidates[s][i].col; |
| 630 if (check_point(x, &this_mv)) | 626 if (!is_mv_in(x, &this_mv)) |
| 631 continue; | 627 continue; |
| 632 this_offset = base_offset + (this_mv.row * in_what_stride) + | 628 this_offset = base_offset + (this_mv.row * in_what_stride) + |
| 633 this_mv.col; | 629 this_mv.col; |
| 634 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 630 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 635 bestsad); | 631 bestsad); |
| 636 CHECK_BETTER | 632 CHECK_BETTER |
| 637 } | 633 } |
| 638 } | 634 } |
| 639 | 635 |
| 640 if (best_site == -1) { | 636 if (best_site == -1) { |
| 641 continue; | 637 continue; |
| 642 } else { | 638 } else { |
| 643 br += candidates[s][best_site].row; | 639 br += candidates[s][best_site].row; |
| 644 bc += candidates[s][best_site].col; | 640 bc += candidates[s][best_site].col; |
| 645 k = best_site; | 641 k = best_site; |
| 646 } | 642 } |
| 647 } | 643 } |
| 648 | 644 |
| 649 do { | 645 do { |
| 650 int next_chkpts_indices[PATTERN_CANDIDATES_REF]; | 646 int next_chkpts_indices[PATTERN_CANDIDATES_REF]; |
| 651 best_site = -1; | 647 best_site = -1; |
| 652 get_next_chkpts(next_chkpts_indices, k, num_candidates[s]); | 648 next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1; |
| 649 next_chkpts_indices[1] = k; |
| 650 next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1; |
| 651 |
| 653 if (check_bounds(x, br, bc, 1 << s)) { | 652 if (check_bounds(x, br, bc, 1 << s)) { |
| 654 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { | 653 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { |
| 655 this_mv.row = br + candidates[s][next_chkpts_indices[i]].row; | 654 this_mv.row = br + candidates[s][next_chkpts_indices[i]].row; |
| 656 this_mv.col = bc + candidates[s][next_chkpts_indices[i]].col; | 655 this_mv.col = bc + candidates[s][next_chkpts_indices[i]].col; |
| 657 this_offset = base_offset + (this_mv.row * (in_what_stride)) + | 656 this_offset = base_offset + (this_mv.row * (in_what_stride)) + |
| 658 this_mv.col; | 657 this_mv.col; |
| 659 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 658 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 660 bestsad); | 659 bestsad); |
| 661 CHECK_BETTER | 660 CHECK_BETTER |
| 662 } | 661 } |
| 663 } else { | 662 } else { |
| 664 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { | 663 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { |
| 665 this_mv.row = br + candidates[s][next_chkpts_indices[i]].row; | 664 this_mv.row = br + candidates[s][next_chkpts_indices[i]].row; |
| 666 this_mv.col = bc + candidates[s][next_chkpts_indices[i]].col; | 665 this_mv.col = bc + candidates[s][next_chkpts_indices[i]].col; |
| 667 if (check_point(x, &this_mv)) | 666 if (!is_mv_in(x, &this_mv)) |
| 668 continue; | 667 continue; |
| 669 this_offset = base_offset + (this_mv.row * (in_what_stride)) + | 668 this_offset = base_offset + (this_mv.row * (in_what_stride)) + |
| 670 this_mv.col; | 669 this_mv.col; |
| 671 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 670 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 672 bestsad); | 671 bestsad); |
| 673 CHECK_BETTER | 672 CHECK_BETTER |
| 674 } | 673 } |
| 675 } | 674 } |
| 676 | 675 |
| 677 if (best_site != -1) { | 676 if (best_site != -1) { |
| 678 k = next_chkpts_indices[best_site]; | 677 k = next_chkpts_indices[best_site]; |
| 679 br += candidates[s][k].row; | 678 br += candidates[s][k].row; |
| 680 bc += candidates[s][k].col; | 679 bc += candidates[s][k].col; |
| 681 } | 680 } |
| 682 } while (best_site != -1); | 681 } while (best_site != -1); |
| 683 } while (s--); | 682 } while (s--); |
| 684 } | 683 } |
| 685 | 684 |
| 686 // Check 4 1-away neighbors if do_refine is true. | 685 // Check 4 1-away neighbors if do_refine is true. |
| 687 // For most well-designed schemes do_refine will not be necessary. | 686 // For most well-designed schemes do_refine will not be necessary. |
| 688 if (do_refine) { | 687 if (do_refine) { |
| 689 static const MV neighbors[4] = { | 688 static const MV neighbors[4] = { {0, -1}, { -1, 0}, {1, 0}, {0, 1} }; |
| 690 {0, -1}, { -1, 0}, {1, 0}, {0, 1}, | |
| 691 }; | |
| 692 for (j = 0; j < 16; j++) { | 689 for (j = 0; j < 16; j++) { |
| 693 best_site = -1; | 690 best_site = -1; |
| 694 if (check_bounds(x, br, bc, 1)) { | 691 if (check_bounds(x, br, bc, 1)) { |
| 695 for (i = 0; i < 4; i++) { | 692 for (i = 0; i < 4; i++) { |
| 696 this_mv.row = br + neighbors[i].row; | 693 this_mv.row = br + neighbors[i].row; |
| 697 this_mv.col = bc + neighbors[i].col; | 694 this_mv.col = bc + neighbors[i].col; |
| 698 this_offset = base_offset + (this_mv.row * (in_what_stride)) + | 695 this_offset = base_offset + this_mv.row * in_what_stride + |
| 699 this_mv.col; | 696 this_mv.col; |
| 700 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 697 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 701 bestsad); | 698 bestsad); |
| 702 CHECK_BETTER | 699 CHECK_BETTER |
| 703 } | 700 } |
| 704 } else { | 701 } else { |
| 705 for (i = 0; i < 4; i++) { | 702 for (i = 0; i < 4; i++) { |
| 706 this_mv.row = br + neighbors[i].row; | 703 this_mv.row = br + neighbors[i].row; |
| 707 this_mv.col = bc + neighbors[i].col; | 704 this_mv.col = bc + neighbors[i].col; |
| 708 if (check_point(x, &this_mv)) | 705 if (!is_mv_in(x, &this_mv)) |
| 709 continue; | 706 continue; |
| 710 this_offset = base_offset + (this_mv.row * (in_what_stride)) + | 707 this_offset = base_offset + this_mv.row * in_what_stride + |
| 711 this_mv.col; | 708 this_mv.col; |
| 712 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, | 709 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, |
| 713 bestsad); | 710 bestsad); |
| 714 CHECK_BETTER | 711 CHECK_BETTER |
| 715 } | 712 } |
| 716 } | 713 } |
| 717 | 714 |
| 718 if (best_site == -1) { | 715 if (best_site == -1) { |
| 719 break; | 716 break; |
| 720 } else { | 717 } else { |
| 721 br += neighbors[best_site].row; | 718 br += neighbors[best_site].row; |
| 722 bc += neighbors[best_site].col; | 719 bc += neighbors[best_site].col; |
| 723 } | 720 } |
| 724 } | 721 } |
| 725 } | 722 } |
| 726 | 723 |
| 727 best_mv->row = br; | 724 best_mv->row = br; |
| 728 best_mv->col = bc; | 725 best_mv->col = bc; |
| 729 | 726 |
| 730 this_offset = base_offset + (best_mv->row * in_what_stride) + | 727 this_offset = base_offset + (best_mv->row * in_what_stride) + |
| 731 best_mv->col; | 728 best_mv->col; |
| 732 this_mv.row = best_mv->row * 8; | 729 this_mv.row = best_mv->row * 8; |
| 733 this_mv.col = best_mv->col * 8; | 730 this_mv.col = best_mv->col * 8; |
| 734 if (bestsad == INT_MAX) | 731 if (bestsad == INT_MAX) |
| 735 return INT_MAX; | 732 return INT_MAX; |
| 736 | 733 |
| 737 return vfp->vf(what, what_stride, this_offset, in_what_stride, | 734 return vfp->vf(what, what_stride, this_offset, in_what_stride, |
| 738 (unsigned int *)&bestsad) + | 735 (unsigned int *)&bestsad) + |
| 739 use_mvcost ? mv_err_cost(&this_mv, center_mv, | 736 use_mvcost ? mv_err_cost(&this_mv, center_mv, |
| 740 x->nmvjointcost, x->mvcost, x->errorperbit) | 737 x->nmvjointcost, x->mvcost, x->errorperbit) |
| 741 : 0; | 738 : 0; |
| 742 } | 739 } |
| 743 | 740 |
| 744 | 741 |
| 745 int vp9_hex_search(MACROBLOCK *x, | 742 int vp9_hex_search(const MACROBLOCK *x, |
| 746 MV *ref_mv, | 743 MV *ref_mv, |
| 747 int search_param, | 744 int search_param, |
| 748 int sad_per_bit, | 745 int sad_per_bit, |
| 749 int do_init_search, | 746 int do_init_search, |
| 750 const vp9_variance_fn_ptr_t *vfp, | 747 const vp9_variance_fn_ptr_t *vfp, |
| 751 int use_mvcost, | 748 int use_mvcost, |
| 752 const MV *center_mv, MV *best_mv) { | 749 const MV *center_mv, MV *best_mv) { |
| 753 // First scale has 8-closest points, the rest have 6 points in hex shape | 750 // First scale has 8-closest points, the rest have 6 points in hex shape |
| 754 // at increasing scales | 751 // at increasing scales |
| 755 static const int hex_num_candidates[MAX_PATTERN_SCALES] = { | 752 static const int hex_num_candidates[MAX_PATTERN_SCALES] = { |
| 756 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 | 753 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 |
| 757 }; | 754 }; |
| 758 // Note that the largest candidate step at each scale is 2^scale | 755 // Note that the largest candidate step at each scale is 2^scale |
| 759 static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = { | 756 static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = { |
| 760 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}}, | 757 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}}, |
| 761 {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}}, | 758 {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}}, |
| 762 {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}}, | 759 {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}}, |
| 763 {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}}, | 760 {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}}, |
| 764 {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}}, | 761 {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}}, |
| 765 {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}}, | 762 {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}}, |
| 766 {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}}, | 763 {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}}, |
| 767 {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}}, | 764 {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}}, |
| 768 {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}}, | 765 {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}}, |
| 769 {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}}, | 766 {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}}, |
| 770 {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024}, | 767 {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024}, |
| 771 { -1024, 0}}, | 768 { -1024, 0}}, |
| 772 }; | 769 }; |
| 773 return | 770 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, |
| 774 vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, | 771 do_init_search, 0, vfp, use_mvcost, |
| 775 do_init_search, 0, vfp, use_mvcost, | 772 center_mv, best_mv, |
| 776 center_mv, best_mv, | 773 hex_num_candidates, hex_candidates); |
| 777 hex_num_candidates, hex_candidates); | |
| 778 } | 774 } |
| 779 | 775 |
| 780 int vp9_bigdia_search(MACROBLOCK *x, | 776 int vp9_bigdia_search(const MACROBLOCK *x, |
| 781 MV *ref_mv, | 777 MV *ref_mv, |
| 782 int search_param, | 778 int search_param, |
| 783 int sad_per_bit, | 779 int sad_per_bit, |
| 784 int do_init_search, | 780 int do_init_search, |
| 785 const vp9_variance_fn_ptr_t *vfp, | 781 const vp9_variance_fn_ptr_t *vfp, |
| 786 int use_mvcost, | 782 int use_mvcost, |
| 787 const MV *center_mv, | 783 const MV *center_mv, |
| 788 MV *best_mv) { | 784 MV *best_mv) { |
| 789 // First scale has 4-closest points, the rest have 8 points in diamond | 785 // First scale has 4-closest points, the rest have 8 points in diamond |
| 790 // shape at increasing scales | 786 // shape at increasing scales |
| (...skipping 20 matching lines...) Expand all Loading... |
| 811 {-256, 256}, {-512, 0}}, | 807 {-256, 256}, {-512, 0}}, |
| 812 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024}, | 808 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024}, |
| 813 {-512, 512}, {-1024, 0}}, | 809 {-512, 512}, {-1024, 0}}, |
| 814 }; | 810 }; |
| 815 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, | 811 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, |
| 816 do_init_search, 0, vfp, use_mvcost, | 812 do_init_search, 0, vfp, use_mvcost, |
| 817 center_mv, best_mv, | 813 center_mv, best_mv, |
| 818 bigdia_num_candidates, bigdia_candidates); | 814 bigdia_num_candidates, bigdia_candidates); |
| 819 } | 815 } |
| 820 | 816 |
| 821 int vp9_square_search(MACROBLOCK *x, | 817 int vp9_square_search(const MACROBLOCK *x, |
| 822 MV *ref_mv, | 818 MV *ref_mv, |
| 823 int search_param, | 819 int search_param, |
| 824 int sad_per_bit, | 820 int sad_per_bit, |
| 825 int do_init_search, | 821 int do_init_search, |
| 826 const vp9_variance_fn_ptr_t *vfp, | 822 const vp9_variance_fn_ptr_t *vfp, |
| 827 int use_mvcost, | 823 int use_mvcost, |
| 828 const MV *center_mv, | 824 const MV *center_mv, |
| 829 MV *best_mv) { | 825 MV *best_mv) { |
| 830 // All scales have 8 closest points in square shape | 826 // All scales have 8 closest points in square shape |
| 831 static const int square_num_candidates[MAX_PATTERN_SCALES] = { | 827 static const int square_num_candidates[MAX_PATTERN_SCALES] = { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 854 {0, 1024}, {-1024, 1024}, {-1024, 0}}, | 850 {0, 1024}, {-1024, 1024}, {-1024, 0}}, |
| 855 }; | 851 }; |
| 856 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, | 852 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, |
| 857 do_init_search, 0, vfp, use_mvcost, | 853 do_init_search, 0, vfp, use_mvcost, |
| 858 center_mv, best_mv, | 854 center_mv, best_mv, |
| 859 square_num_candidates, square_candidates); | 855 square_num_candidates, square_candidates); |
| 860 }; | 856 }; |
| 861 | 857 |
| 862 #undef CHECK_BETTER | 858 #undef CHECK_BETTER |
| 863 | 859 |
| 864 int vp9_full_range_search_c(MACROBLOCK *x, MV *ref_mv, MV *best_mv, | 860 int vp9_full_range_search_c(const MACROBLOCK *x, MV *ref_mv, MV *best_mv, |
| 865 int search_param, int sad_per_bit, int *num00, | 861 int search_param, int sad_per_bit, int *num00, |
| 866 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost, | 862 const vp9_variance_fn_ptr_t *fn_ptr, |
| 867 int *mvcost[2], const MV *center_mv) { | 863 int *mvjcost, int *mvcost[2], |
| 868 const MACROBLOCKD* const xd = &x->e_mbd; | 864 const MV *center_mv) { |
| 869 uint8_t *what = x->plane[0].src.buf; | 865 const MACROBLOCKD *const xd = &x->e_mbd; |
| 870 int what_stride = x->plane[0].src.stride; | 866 const uint8_t *what = x->plane[0].src.buf; |
| 871 uint8_t *in_what; | 867 const int what_stride = x->plane[0].src.stride; |
| 872 int in_what_stride = xd->plane[0].pre[0].stride; | 868 const uint8_t *in_what; |
| 873 uint8_t *best_address; | 869 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 870 const uint8_t *best_address; |
| 874 | 871 |
| 875 MV this_mv; | 872 MV this_mv; |
| 876 | 873 |
| 877 int bestsad = INT_MAX; | 874 int bestsad = INT_MAX; |
| 878 int ref_row, ref_col; | 875 int ref_row, ref_col; |
| 879 | 876 |
| 880 uint8_t *check_here; | |
| 881 int thissad; | 877 int thissad; |
| 882 MV fcenter_mv; | 878 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 883 | 879 |
| 884 int *mvjsadcost = x->nmvjointsadcost; | 880 const int *mvjsadcost = x->nmvjointsadcost; |
| 885 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 881 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 886 | 882 |
| 887 int tr, tc; | 883 int tr, tc; |
| 888 int best_tr = 0; | 884 int best_tr = 0; |
| 889 int best_tc = 0; | 885 int best_tc = 0; |
| 890 int range = 64; | 886 int range = 64; |
| 891 | 887 |
| 892 int start_col, end_col; | 888 int start_col, end_col; |
| 893 int start_row, end_row; | 889 int start_row, end_row; |
| 894 int i; | 890 int i; |
| 895 | 891 |
| 896 fcenter_mv.row = center_mv->row >> 3; | |
| 897 fcenter_mv.col = center_mv->col >> 3; | |
| 898 | |
| 899 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 892 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
| 900 ref_row = ref_mv->row; | 893 ref_row = ref_mv->row; |
| 901 ref_col = ref_mv->col; | 894 ref_col = ref_mv->col; |
| 902 *num00 = 11; | 895 *num00 = 11; |
| 903 best_mv->row = ref_row; | 896 best_mv->row = ref_row; |
| 904 best_mv->col = ref_col; | 897 best_mv->col = ref_col; |
| 905 | 898 |
| 906 // Work out the start point for the search | 899 // Work out the start point for the search |
| 907 in_what = (uint8_t *)(xd->plane[0].pre[0].buf + | 900 in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; |
| 908 (ref_row * (xd->plane[0].pre[0].stride)) + ref_col); | |
| 909 best_address = in_what; | 901 best_address = in_what; |
| 910 | 902 |
| 911 // Check the starting position | 903 // Check the starting position |
| 912 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) | 904 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) |
| 913 + mvsad_err_cost(best_mv, &fcenter_mv, | 905 + mvsad_err_cost(best_mv, &fcenter_mv, |
| 914 mvjsadcost, mvsadcost, sad_per_bit); | 906 mvjsadcost, mvsadcost, sad_per_bit); |
| 915 | 907 |
| 916 start_row = MAX(-range, x->mv_row_min - ref_row); | 908 start_row = MAX(-range, x->mv_row_min - ref_row); |
| 917 start_col = MAX(-range, x->mv_col_min - ref_col); | 909 start_col = MAX(-range, x->mv_col_min - ref_col); |
| 918 end_row = MIN(range, x->mv_row_max - ref_row); | 910 end_row = MIN(range, x->mv_row_max - ref_row); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 937 mvjsadcost, mvsadcost, sad_per_bit); | 929 mvjsadcost, mvsadcost, sad_per_bit); |
| 938 if (thissad < bestsad) { | 930 if (thissad < bestsad) { |
| 939 bestsad = thissad; | 931 bestsad = thissad; |
| 940 best_tr = tr; | 932 best_tr = tr; |
| 941 best_tc = tc + i; | 933 best_tc = tc + i; |
| 942 } | 934 } |
| 943 } | 935 } |
| 944 } | 936 } |
| 945 } else { | 937 } else { |
| 946 for (i = 0; i < end_col - tc; ++i) { | 938 for (i = 0; i < end_col - tc; ++i) { |
| 947 check_here = in_what + tr * in_what_stride + tc + i; | 939 const uint8_t *check_here = in_what + tr * in_what_stride + tc + i; |
| 948 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, | 940 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, |
| 949 bestsad); | 941 bestsad); |
| 950 | 942 |
| 951 if (thissad < bestsad) { | 943 if (thissad < bestsad) { |
| 952 this_mv.row = ref_row + tr; | 944 this_mv.row = ref_row + tr; |
| 953 this_mv.col = ref_col + tc + i; | 945 this_mv.col = ref_col + tc + i; |
| 954 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 946 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 955 mvjsadcost, mvsadcost, sad_per_bit); | 947 mvjsadcost, mvsadcost, sad_per_bit); |
| 956 | 948 |
| 957 if (thissad < bestsad) { | 949 if (thissad < bestsad) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 973 | 965 |
| 974 if (bestsad == INT_MAX) | 966 if (bestsad == INT_MAX) |
| 975 return INT_MAX; | 967 return INT_MAX; |
| 976 | 968 |
| 977 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, | 969 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, |
| 978 (unsigned int *)(&thissad)) + | 970 (unsigned int *)(&thissad)) + |
| 979 mv_err_cost(&this_mv, center_mv, | 971 mv_err_cost(&this_mv, center_mv, |
| 980 mvjcost, mvcost, x->errorperbit); | 972 mvjcost, mvcost, x->errorperbit); |
| 981 } | 973 } |
| 982 | 974 |
| 983 int vp9_diamond_search_sad_c(MACROBLOCK *x, | 975 int vp9_diamond_search_sad_c(const MACROBLOCK *x, |
| 984 MV *ref_mv, MV *best_mv, | 976 MV *ref_mv, MV *best_mv, |
| 985 int search_param, int sad_per_bit, int *num00, | 977 int search_param, int sad_per_bit, int *num00, |
| 986 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost, | 978 const vp9_variance_fn_ptr_t *fn_ptr, |
| 987 int *mvcost[2], const MV *center_mv) { | 979 int *mvjcost, int *mvcost[2], |
| 980 const MV *center_mv) { |
| 988 int i, j, step; | 981 int i, j, step; |
| 989 | 982 |
| 990 const MACROBLOCKD* const xd = &x->e_mbd; | 983 const MACROBLOCKD *const xd = &x->e_mbd; |
| 991 uint8_t *what = x->plane[0].src.buf; | 984 const uint8_t *what = x->plane[0].src.buf; |
| 992 int what_stride = x->plane[0].src.stride; | 985 const int what_stride = x->plane[0].src.stride; |
| 993 uint8_t *in_what; | 986 const uint8_t *in_what; |
| 994 int in_what_stride = xd->plane[0].pre[0].stride; | 987 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 995 uint8_t *best_address; | 988 const uint8_t *best_address; |
| 996 | 989 |
| 997 int tot_steps; | |
| 998 MV this_mv; | 990 MV this_mv; |
| 999 | 991 |
| 1000 int bestsad = INT_MAX; | 992 int bestsad = INT_MAX; |
| 1001 int best_site = 0; | 993 int best_site = 0; |
| 1002 int last_site = 0; | 994 int last_site = 0; |
| 1003 | 995 |
| 1004 int ref_row, ref_col; | 996 int ref_row, ref_col; |
| 1005 int this_row_offset, this_col_offset; | 997 int this_row_offset, this_col_offset; |
| 1006 search_site *ss; | |
| 1007 | 998 |
| 1008 uint8_t *check_here; | 999 // search_param determines the length of the initial step and hence the number |
| 1000 // of iterations |
| 1001 // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = |
| 1002 // (MAX_FIRST_STEP/4) pel... etc. |
| 1003 const search_site *const ss = &x->ss[search_param * x->searches_per_step]; |
| 1004 const int tot_steps = (x->ss_count / x->searches_per_step) - search_param; |
| 1005 |
| 1009 int thissad; | 1006 int thissad; |
| 1010 MV fcenter_mv; | 1007 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1011 | 1008 |
| 1012 int *mvjsadcost = x->nmvjointsadcost; | 1009 const int *mvjsadcost = x->nmvjointsadcost; |
| 1013 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 1010 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 1014 | 1011 |
| 1015 fcenter_mv.row = center_mv->row >> 3; | |
| 1016 fcenter_mv.col = center_mv->col >> 3; | |
| 1017 | |
| 1018 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 1012 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
| 1019 ref_row = ref_mv->row; | 1013 ref_row = ref_mv->row; |
| 1020 ref_col = ref_mv->col; | 1014 ref_col = ref_mv->col; |
| 1021 *num00 = 0; | 1015 *num00 = 0; |
| 1022 best_mv->row = ref_row; | 1016 best_mv->row = ref_row; |
| 1023 best_mv->col = ref_col; | 1017 best_mv->col = ref_col; |
| 1024 | 1018 |
| 1025 // Work out the start point for the search | 1019 // Work out the start point for the search |
| 1026 in_what = (uint8_t *)(xd->plane[0].pre[0].buf + | 1020 in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; |
| 1027 ref_row * in_what_stride + ref_col); | |
| 1028 best_address = in_what; | 1021 best_address = in_what; |
| 1029 | 1022 |
| 1030 // Check the starting position | 1023 // Check the starting position |
| 1031 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) | 1024 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) |
| 1032 + mvsad_err_cost(best_mv, &fcenter_mv, | 1025 + mvsad_err_cost(best_mv, &fcenter_mv, |
| 1033 mvjsadcost, mvsadcost, sad_per_bit); | 1026 mvjsadcost, mvsadcost, sad_per_bit); |
| 1034 | 1027 |
| 1035 // search_param determines the length of the initial step and hence the number | |
| 1036 // of iterations | |
| 1037 // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = | |
| 1038 // (MAX_FIRST_STEP/4) pel... etc. | |
| 1039 ss = &x->ss[search_param * x->searches_per_step]; | |
| 1040 tot_steps = (x->ss_count / x->searches_per_step) - search_param; | |
| 1041 | |
| 1042 i = 1; | 1028 i = 1; |
| 1043 | 1029 |
| 1044 for (step = 0; step < tot_steps; step++) { | 1030 for (step = 0; step < tot_steps; step++) { |
| 1045 for (j = 0; j < x->searches_per_step; j++) { | 1031 for (j = 0; j < x->searches_per_step; j++) { |
| 1046 // Trap illegal vectors | 1032 // Trap illegal vectors |
| 1047 this_row_offset = best_mv->row + ss[i].mv.row; | 1033 this_row_offset = best_mv->row + ss[i].mv.row; |
| 1048 this_col_offset = best_mv->col + ss[i].mv.col; | 1034 this_col_offset = best_mv->col + ss[i].mv.col; |
| 1049 | 1035 |
| 1050 if ((this_col_offset > x->mv_col_min) && | 1036 if ((this_col_offset > x->mv_col_min) && |
| 1051 (this_col_offset < x->mv_col_max) && | 1037 (this_col_offset < x->mv_col_max) && |
| 1052 (this_row_offset > x->mv_row_min) && | 1038 (this_row_offset > x->mv_row_min) && |
| 1053 (this_row_offset < x->mv_row_max)) { | 1039 (this_row_offset < x->mv_row_max)) { |
| 1054 check_here = ss[i].offset + best_address; | 1040 const uint8_t *const check_here = ss[i].offset + best_address; |
| 1055 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, | 1041 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, |
| 1056 bestsad); | 1042 bestsad); |
| 1057 | 1043 |
| 1058 if (thissad < bestsad) { | 1044 if (thissad < bestsad) { |
| 1059 this_mv.row = this_row_offset; | 1045 this_mv.row = this_row_offset; |
| 1060 this_mv.col = this_col_offset; | 1046 this_mv.col = this_col_offset; |
| 1061 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 1047 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1062 mvjsadcost, mvsadcost, sad_per_bit); | 1048 mvjsadcost, mvsadcost, sad_per_bit); |
| 1063 | 1049 |
| 1064 if (thissad < bestsad) { | 1050 if (thissad < bestsad) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 | 1100 |
| 1115 if (bestsad == INT_MAX) | 1101 if (bestsad == INT_MAX) |
| 1116 return INT_MAX; | 1102 return INT_MAX; |
| 1117 | 1103 |
| 1118 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, | 1104 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, |
| 1119 (unsigned int *)(&thissad)) + | 1105 (unsigned int *)(&thissad)) + |
| 1120 mv_err_cost(&this_mv, center_mv, | 1106 mv_err_cost(&this_mv, center_mv, |
| 1121 mvjcost, mvcost, x->errorperbit); | 1107 mvjcost, mvcost, x->errorperbit); |
| 1122 } | 1108 } |
| 1123 | 1109 |
| 1124 int vp9_diamond_search_sadx4(MACROBLOCK *x, | 1110 int vp9_diamond_search_sadx4(const MACROBLOCK *x, |
| 1125 MV *ref_mv, MV *best_mv, int search_param, | 1111 MV *ref_mv, MV *best_mv, int search_param, |
| 1126 int sad_per_bit, int *num00, | 1112 int sad_per_bit, int *num00, |
| 1127 vp9_variance_fn_ptr_t *fn_ptr, | 1113 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1128 int *mvjcost, int *mvcost[2], | 1114 int *mvjcost, int *mvcost[2], |
| 1129 const MV *center_mv) { | 1115 const MV *center_mv) { |
| 1130 int i, j, step; | 1116 int i, j, step; |
| 1131 | 1117 |
| 1132 const MACROBLOCKD* const xd = &x->e_mbd; | 1118 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1133 uint8_t *what = x->plane[0].src.buf; | 1119 uint8_t *what = x->plane[0].src.buf; |
| 1134 int what_stride = x->plane[0].src.stride; | 1120 const int what_stride = x->plane[0].src.stride; |
| 1135 uint8_t *in_what; | 1121 const uint8_t *in_what; |
| 1136 int in_what_stride = xd->plane[0].pre[0].stride; | 1122 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 1137 uint8_t *best_address; | 1123 const uint8_t *best_address; |
| 1138 | 1124 |
| 1139 int tot_steps; | |
| 1140 MV this_mv; | 1125 MV this_mv; |
| 1141 | 1126 |
| 1142 unsigned int bestsad = INT_MAX; | 1127 unsigned int bestsad = INT_MAX; |
| 1143 int best_site = 0; | 1128 int best_site = 0; |
| 1144 int last_site = 0; | 1129 int last_site = 0; |
| 1145 | 1130 |
| 1146 int ref_row; | 1131 int ref_row; |
| 1147 int ref_col; | 1132 int ref_col; |
| 1148 int this_row_offset; | 1133 int this_row_offset; |
| 1149 int this_col_offset; | 1134 int this_col_offset; |
| 1150 search_site *ss; | |
| 1151 | 1135 |
| 1152 uint8_t *check_here; | 1136 // search_param determines the length of the initial step and hence the number |
| 1137 // of iterations. |
| 1138 // 0 = initial step (MAX_FIRST_STEP) pel |
| 1139 // 1 = (MAX_FIRST_STEP/2) pel, |
| 1140 // 2 = (MAX_FIRST_STEP/4) pel... |
| 1141 const search_site *ss = &x->ss[search_param * x->searches_per_step]; |
| 1142 const int tot_steps = (x->ss_count / x->searches_per_step) - search_param; |
| 1143 |
| 1153 unsigned int thissad; | 1144 unsigned int thissad; |
| 1154 MV fcenter_mv; | 1145 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1155 | 1146 |
| 1156 int *mvjsadcost = x->nmvjointsadcost; | 1147 const int *mvjsadcost = x->nmvjointsadcost; |
| 1157 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 1148 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 1158 | 1149 |
| 1159 fcenter_mv.row = center_mv->row >> 3; | |
| 1160 fcenter_mv.col = center_mv->col >> 3; | |
| 1161 | |
| 1162 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 1150 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
| 1163 ref_row = ref_mv->row; | 1151 ref_row = ref_mv->row; |
| 1164 ref_col = ref_mv->col; | 1152 ref_col = ref_mv->col; |
| 1165 *num00 = 0; | 1153 *num00 = 0; |
| 1166 best_mv->row = ref_row; | 1154 best_mv->row = ref_row; |
| 1167 best_mv->col = ref_col; | 1155 best_mv->col = ref_col; |
| 1168 | 1156 |
| 1169 // Work out the start point for the search | 1157 // Work out the start point for the search |
| 1170 in_what = (uint8_t *)(xd->plane[0].pre[0].buf + | 1158 in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; |
| 1171 ref_row * in_what_stride + ref_col); | |
| 1172 best_address = in_what; | 1159 best_address = in_what; |
| 1173 | 1160 |
| 1174 // Check the starting position | 1161 // Check the starting position |
| 1175 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) | 1162 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) |
| 1176 + mvsad_err_cost(best_mv, &fcenter_mv, | 1163 + mvsad_err_cost(best_mv, &fcenter_mv, |
| 1177 mvjsadcost, mvsadcost, sad_per_bit); | 1164 mvjsadcost, mvsadcost, sad_per_bit); |
| 1178 | 1165 |
| 1179 // search_param determines the length of the initial step and hence the number | |
| 1180 // of iterations. | |
| 1181 // 0 = initial step (MAX_FIRST_STEP) pel | |
| 1182 // 1 = (MAX_FIRST_STEP/2) pel, | |
| 1183 // 2 = (MAX_FIRST_STEP/4) pel... | |
| 1184 ss = &x->ss[search_param * x->searches_per_step]; | |
| 1185 tot_steps = (x->ss_count / x->searches_per_step) - search_param; | |
| 1186 | |
| 1187 i = 1; | 1166 i = 1; |
| 1188 | 1167 |
| 1189 for (step = 0; step < tot_steps; step++) { | 1168 for (step = 0; step < tot_steps; step++) { |
| 1190 int all_in = 1, t; | 1169 int all_in = 1, t; |
| 1191 | 1170 |
| 1192 // All_in is true if every one of the points we are checking are within | 1171 // All_in is true if every one of the points we are checking are within |
| 1193 // the bounds of the image. | 1172 // the bounds of the image. |
| 1194 all_in &= ((best_mv->row + ss[i].mv.row) > x->mv_row_min); | 1173 all_in &= ((best_mv->row + ss[i].mv.row) > x->mv_row_min); |
| 1195 all_in &= ((best_mv->row + ss[i + 1].mv.row) < x->mv_row_max); | 1174 all_in &= ((best_mv->row + ss[i + 1].mv.row) < x->mv_row_max); |
| 1196 all_in &= ((best_mv->col + ss[i + 2].mv.col) > x->mv_col_min); | 1175 all_in &= ((best_mv->col + ss[i + 2].mv.col) > x->mv_col_min); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 } else { | 1207 } else { |
| 1229 for (j = 0; j < x->searches_per_step; j++) { | 1208 for (j = 0; j < x->searches_per_step; j++) { |
| 1230 // Trap illegal vectors | 1209 // Trap illegal vectors |
| 1231 this_row_offset = best_mv->row + ss[i].mv.row; | 1210 this_row_offset = best_mv->row + ss[i].mv.row; |
| 1232 this_col_offset = best_mv->col + ss[i].mv.col; | 1211 this_col_offset = best_mv->col + ss[i].mv.col; |
| 1233 | 1212 |
| 1234 if ((this_col_offset > x->mv_col_min) && | 1213 if ((this_col_offset > x->mv_col_min) && |
| 1235 (this_col_offset < x->mv_col_max) && | 1214 (this_col_offset < x->mv_col_max) && |
| 1236 (this_row_offset > x->mv_row_min) && | 1215 (this_row_offset > x->mv_row_min) && |
| 1237 (this_row_offset < x->mv_row_max)) { | 1216 (this_row_offset < x->mv_row_max)) { |
| 1238 check_here = ss[i].offset + best_address; | 1217 const uint8_t *const check_here = ss[i].offset + best_address; |
| 1239 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, | 1218 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, |
| 1240 bestsad); | 1219 bestsad); |
| 1241 | 1220 |
| 1242 if (thissad < bestsad) { | 1221 if (thissad < bestsad) { |
| 1243 this_mv.row = this_row_offset; | 1222 this_mv.row = this_row_offset; |
| 1244 this_mv.col = this_col_offset; | 1223 this_mv.col = this_col_offset; |
| 1245 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 1224 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1246 mvjsadcost, mvsadcost, sad_per_bit); | 1225 mvjsadcost, mvsadcost, sad_per_bit); |
| 1247 | 1226 |
| 1248 if (thissad < bestsad) { | 1227 if (thissad < bestsad) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 mv_err_cost(&this_mv, center_mv, | 1282 mv_err_cost(&this_mv, center_mv, |
| 1304 mvjcost, mvcost, x->errorperbit); | 1283 mvjcost, mvcost, x->errorperbit); |
| 1305 } | 1284 } |
| 1306 | 1285 |
| 1307 /* do_refine: If last step (1-away) of n-step search doesn't pick the center | 1286 /* do_refine: If last step (1-away) of n-step search doesn't pick the center |
| 1308 point as the best match, we will do a final 1-away diamond | 1287 point as the best match, we will do a final 1-away diamond |
| 1309 refining search */ | 1288 refining search */ |
| 1310 | 1289 |
| 1311 int vp9_full_pixel_diamond(VP9_COMP *cpi, MACROBLOCK *x, | 1290 int vp9_full_pixel_diamond(VP9_COMP *cpi, MACROBLOCK *x, |
| 1312 MV *mvp_full, int step_param, | 1291 MV *mvp_full, int step_param, |
| 1313 int sadpb, int further_steps, | 1292 int sadpb, int further_steps, int do_refine, |
| 1314 int do_refine, vp9_variance_fn_ptr_t *fn_ptr, | 1293 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1315 const MV *ref_mv, int_mv *dst_mv) { | 1294 const MV *ref_mv, MV *dst_mv) { |
| 1316 int_mv temp_mv; | 1295 MV temp_mv; |
| 1317 int thissme, n, num00; | 1296 int thissme, n, num00 = 0; |
| 1318 int bestsme = cpi->diamond_search_sad(x, mvp_full, &temp_mv.as_mv, | 1297 int bestsme = cpi->diamond_search_sad(x, mvp_full, &temp_mv, |
| 1319 step_param, sadpb, &num00, | 1298 step_param, sadpb, &n, |
| 1320 fn_ptr, x->nmvjointcost, | 1299 fn_ptr, x->nmvjointcost, |
| 1321 x->mvcost, ref_mv); | 1300 x->mvcost, ref_mv); |
| 1322 dst_mv->as_int = temp_mv.as_int; | 1301 *dst_mv = temp_mv; |
| 1323 | 1302 |
| 1324 n = num00; | 1303 // If there won't be more n-step search, check to see if refining search is |
| 1325 num00 = 0; | 1304 // needed. |
| 1326 | |
| 1327 /* If there won't be more n-step search, check to see if refining search is | |
| 1328 * needed. */ | |
| 1329 if (n > further_steps) | 1305 if (n > further_steps) |
| 1330 do_refine = 0; | 1306 do_refine = 0; |
| 1331 | 1307 |
| 1332 while (n < further_steps) { | 1308 while (n < further_steps) { |
| 1333 n++; | 1309 ++n; |
| 1334 | 1310 |
| 1335 if (num00) { | 1311 if (num00) { |
| 1336 num00--; | 1312 num00--; |
| 1337 } else { | 1313 } else { |
| 1338 thissme = cpi->diamond_search_sad(x, mvp_full, &temp_mv.as_mv, | 1314 thissme = cpi->diamond_search_sad(x, mvp_full, &temp_mv, |
| 1339 step_param + n, sadpb, &num00, | 1315 step_param + n, sadpb, &num00, |
| 1340 fn_ptr, x->nmvjointcost, x->mvcost, | 1316 fn_ptr, x->nmvjointcost, x->mvcost, |
| 1341 ref_mv); | 1317 ref_mv); |
| 1342 | 1318 |
| 1343 /* check to see if refining search is needed. */ | 1319 // check to see if refining search is needed. |
| 1344 if (num00 > (further_steps - n)) | 1320 if (num00 > further_steps - n) |
| 1345 do_refine = 0; | 1321 do_refine = 0; |
| 1346 | 1322 |
| 1347 if (thissme < bestsme) { | 1323 if (thissme < bestsme) { |
| 1348 bestsme = thissme; | 1324 bestsme = thissme; |
| 1349 dst_mv->as_int = temp_mv.as_int; | 1325 *dst_mv = temp_mv; |
| 1350 } | 1326 } |
| 1351 } | 1327 } |
| 1352 } | 1328 } |
| 1353 | 1329 |
| 1354 /* final 1-away diamond refining search */ | 1330 // final 1-away diamond refining search |
| 1355 if (do_refine == 1) { | 1331 if (do_refine) { |
| 1356 int search_range = 8; | 1332 const int search_range = 8; |
| 1357 int_mv best_mv; | 1333 MV best_mv = *dst_mv; |
| 1358 best_mv.as_int = dst_mv->as_int; | 1334 thissme = cpi->refining_search_sad(x, &best_mv, sadpb, search_range, |
| 1359 thissme = cpi->refining_search_sad(x, &best_mv.as_mv, sadpb, search_range, | |
| 1360 fn_ptr, x->nmvjointcost, x->mvcost, | 1335 fn_ptr, x->nmvjointcost, x->mvcost, |
| 1361 ref_mv); | 1336 ref_mv); |
| 1362 | |
| 1363 if (thissme < bestsme) { | 1337 if (thissme < bestsme) { |
| 1364 bestsme = thissme; | 1338 bestsme = thissme; |
| 1365 dst_mv->as_int = best_mv.as_int; | 1339 *dst_mv = best_mv; |
| 1366 } | 1340 } |
| 1367 } | 1341 } |
| 1342 |
| 1368 return bestsme; | 1343 return bestsme; |
| 1369 } | 1344 } |
| 1370 | 1345 |
| 1371 int vp9_full_search_sad_c(MACROBLOCK *x, MV *ref_mv, | 1346 int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv, |
| 1372 int sad_per_bit, int distance, | 1347 int sad_per_bit, int distance, |
| 1373 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost, | 1348 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1374 int *mvcost[2], | 1349 int *mvjcost, int *mvcost[2], |
| 1375 const MV *center_mv, int n) { | 1350 const MV *center_mv, int block) { |
| 1376 const MACROBLOCKD* const xd = &x->e_mbd; | 1351 int r, c; |
| 1352 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1377 const uint8_t *const what = x->plane[0].src.buf; | 1353 const uint8_t *const what = x->plane[0].src.buf; |
| 1378 const int what_stride = x->plane[0].src.stride; | 1354 const int what_stride = x->plane[0].src.stride; |
| 1379 const uint8_t *const in_what = xd->plane[0].pre[0].buf; | 1355 const uint8_t *const in_what = xd->plane[0].pre[0].buf; |
| 1380 const int in_what_stride = xd->plane[0].pre[0].stride; | 1356 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 1381 const uint8_t *bestaddress; | 1357 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
| 1382 MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv; | 1358 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
| 1383 MV this_mv; | 1359 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
| 1384 int bestsad = INT_MAX; | 1360 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
| 1385 int r, c; | 1361 const int *mvjsadcost = x->nmvjointsadcost; |
| 1386 int thissad; | 1362 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 1387 int ref_row = ref_mv->row; | 1363 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1388 int ref_col = ref_mv->col; | 1364 const uint8_t *best_address = &in_what[ref_mv->row * in_what_stride + |
| 1389 int row_min = ref_row - distance; | 1365 ref_mv->col]; |
| 1390 int row_max = ref_row + distance; | 1366 int best_sad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride, |
| 1391 int col_min = ref_col - distance; | 1367 0x7fffffff) + |
| 1392 int col_max = ref_col + distance; | 1368 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, sad_per_bit); |
| 1393 MV fcenter_mv; | 1369 MV *best_mv = &xd->mi_8x8[0]->bmi[block].as_mv[0].as_mv; |
| 1370 *best_mv = *ref_mv; |
| 1394 | 1371 |
| 1395 int *mvjsadcost = x->nmvjointsadcost; | 1372 for (r = row_min; r < row_max; ++r) { |
| 1396 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 1373 for (c = col_min; c < col_max; ++c) { |
| 1374 const MV this_mv = {r, c}; |
| 1375 const uint8_t *check_here = &in_what[r * in_what_stride + c]; |
| 1376 const int sad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, |
| 1377 best_sad) + |
| 1378 mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1379 mvjsadcost, mvsadcost, sad_per_bit); |
| 1397 | 1380 |
| 1398 fcenter_mv.row = center_mv->row >> 3; | 1381 if (sad < best_sad) { |
| 1399 fcenter_mv.col = center_mv->col >> 3; | 1382 best_sad = sad; |
| 1400 | 1383 *best_mv = this_mv; |
| 1401 // Work out the mid point for the search | 1384 best_address = check_here; |
| 1402 bestaddress = &in_what[ref_row * in_what_stride + ref_col]; | |
| 1403 | |
| 1404 best_mv->row = ref_row; | |
| 1405 best_mv->col = ref_col; | |
| 1406 | |
| 1407 // Baseline value at the centre | |
| 1408 bestsad = fn_ptr->sdf(what, what_stride, bestaddress, | |
| 1409 in_what_stride, 0x7fffffff) | |
| 1410 + mvsad_err_cost(best_mv, &fcenter_mv, | |
| 1411 mvjsadcost, mvsadcost, sad_per_bit); | |
| 1412 | |
| 1413 // Apply further limits to prevent us looking using vectors that stretch | |
| 1414 // beyond the UMV border | |
| 1415 col_min = MAX(col_min, x->mv_col_min); | |
| 1416 col_max = MIN(col_max, x->mv_col_max); | |
| 1417 row_min = MAX(row_min, x->mv_row_min); | |
| 1418 row_max = MIN(row_max, x->mv_row_max); | |
| 1419 | |
| 1420 for (r = row_min; r < row_max; r++) { | |
| 1421 const uint8_t *check_here = &in_what[r * in_what_stride + col_min]; | |
| 1422 this_mv.row = r; | |
| 1423 | |
| 1424 for (c = col_min; c < col_max; c++) { | |
| 1425 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, | |
| 1426 bestsad); | |
| 1427 | |
| 1428 this_mv.col = c; | |
| 1429 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | |
| 1430 mvjsadcost, mvsadcost, sad_per_bit); | |
| 1431 | |
| 1432 if (thissad < bestsad) { | |
| 1433 bestsad = thissad; | |
| 1434 best_mv->row = r; | |
| 1435 best_mv->col = c; | |
| 1436 bestaddress = check_here; | |
| 1437 } | 1385 } |
| 1438 | |
| 1439 check_here++; | |
| 1440 } | 1386 } |
| 1441 } | 1387 } |
| 1442 | 1388 |
| 1443 this_mv.row = best_mv->row * 8; | 1389 if (best_sad < INT_MAX) { |
| 1444 this_mv.col = best_mv->col * 8; | 1390 unsigned int unused; |
| 1445 | 1391 const MV mv = {best_mv->row * 8, best_mv->col * 8}; |
| 1446 if (bestsad < INT_MAX) | 1392 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &unused) |
| 1447 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, | 1393 + mv_err_cost(&mv, center_mv, mvjcost, mvcost, x->errorperbit); |
| 1448 (unsigned int *)(&thissad)) + | 1394 } else { |
| 1449 mv_err_cost(&this_mv, center_mv, | |
| 1450 mvjcost, mvcost, x->errorperbit); | |
| 1451 else | |
| 1452 return INT_MAX; | 1395 return INT_MAX; |
| 1396 } |
| 1453 } | 1397 } |
| 1454 | 1398 |
| 1455 int vp9_full_search_sadx3(MACROBLOCK *x, MV *ref_mv, | 1399 int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, |
| 1456 int sad_per_bit, int distance, | 1400 int sad_per_bit, int distance, |
| 1457 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost, | 1401 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1458 int *mvcost[2], const MV *center_mv, int n) { | 1402 int *mvjcost, int *mvcost[2], |
| 1459 const MACROBLOCKD* const xd = &x->e_mbd; | 1403 const MV *center_mv, int n) { |
| 1404 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1460 const uint8_t *const what = x->plane[0].src.buf; | 1405 const uint8_t *const what = x->plane[0].src.buf; |
| 1461 const int what_stride = x->plane[0].src.stride; | 1406 const int what_stride = x->plane[0].src.stride; |
| 1462 const uint8_t *const in_what = xd->plane[0].pre[0].buf; | 1407 const uint8_t *const in_what = xd->plane[0].pre[0].buf; |
| 1463 const int in_what_stride = xd->plane[0].pre[0].stride; | 1408 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 1464 const uint8_t *bestaddress; | 1409 MV *best_mv = &xd->mi_8x8[0]->bmi[n].as_mv[0].as_mv; |
| 1465 MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv; | |
| 1466 MV this_mv; | 1410 MV this_mv; |
| 1467 unsigned int bestsad = INT_MAX; | 1411 unsigned int bestsad = INT_MAX; |
| 1468 int r, c; | 1412 int r, c; |
| 1469 unsigned int thissad; | 1413 unsigned int thissad; |
| 1470 int ref_row = ref_mv->row; | 1414 int ref_row = ref_mv->row; |
| 1471 int ref_col = ref_mv->col; | 1415 int ref_col = ref_mv->col; |
| 1472 int row_min = ref_row - distance; | 1416 |
| 1473 int row_max = ref_row + distance; | 1417 // Apply further limits to prevent us looking using vectors that stretch |
| 1474 int col_min = ref_col - distance; | 1418 // beyond the UMV border |
| 1475 int col_max = ref_col + distance; | 1419 const int row_min = MAX(ref_row - distance, x->mv_row_min); |
| 1420 const int row_max = MIN(ref_row + distance, x->mv_row_max); |
| 1421 const int col_min = MAX(ref_col - distance, x->mv_col_min); |
| 1422 const int col_max = MIN(ref_col + distance, x->mv_col_max); |
| 1476 unsigned int sad_array[3]; | 1423 unsigned int sad_array[3]; |
| 1477 MV fcenter_mv; | 1424 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1478 int *mvjsadcost = x->nmvjointsadcost; | 1425 const int *mvjsadcost = x->nmvjointsadcost; |
| 1479 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 1426 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 1480 | 1427 |
| 1481 fcenter_mv.row = center_mv->row >> 3; | |
| 1482 fcenter_mv.col = center_mv->col >> 3; | |
| 1483 | |
| 1484 // Work out the mid point for the search | 1428 // Work out the mid point for the search |
| 1485 bestaddress = &in_what[ref_row * in_what_stride + ref_col]; | 1429 const uint8_t *bestaddress = &in_what[ref_row * in_what_stride + ref_col]; |
| 1486 | 1430 |
| 1487 best_mv->row = ref_row; | 1431 best_mv->row = ref_row; |
| 1488 best_mv->col = ref_col; | 1432 best_mv->col = ref_col; |
| 1489 | 1433 |
| 1490 // Baseline value at the centre | 1434 // Baseline value at the centre |
| 1491 bestsad = fn_ptr->sdf(what, what_stride, | 1435 bestsad = fn_ptr->sdf(what, what_stride, |
| 1492 bestaddress, in_what_stride, 0x7fffffff) | 1436 bestaddress, in_what_stride, 0x7fffffff) |
| 1493 + mvsad_err_cost(best_mv, &fcenter_mv, | 1437 + mvsad_err_cost(best_mv, &fcenter_mv, |
| 1494 mvjsadcost, mvsadcost, sad_per_bit); | 1438 mvjsadcost, mvsadcost, sad_per_bit); |
| 1495 | 1439 |
| 1496 // Apply further limits to prevent us looking using vectors that stretch | |
| 1497 // beyond the UMV border | |
| 1498 col_min = MAX(col_min, x->mv_col_min); | |
| 1499 col_max = MIN(col_max, x->mv_col_max); | |
| 1500 row_min = MAX(row_min, x->mv_row_min); | |
| 1501 row_max = MIN(row_max, x->mv_row_max); | |
| 1502 | |
| 1503 for (r = row_min; r < row_max; r++) { | 1440 for (r = row_min; r < row_max; r++) { |
| 1504 const uint8_t *check_here = &in_what[r * in_what_stride + col_min]; | 1441 const uint8_t *check_here = &in_what[r * in_what_stride + col_min]; |
| 1505 this_mv.row = r; | 1442 this_mv.row = r; |
| 1506 c = col_min; | 1443 c = col_min; |
| 1507 | 1444 |
| 1508 while ((c + 2) < col_max && fn_ptr->sdx3f != NULL) { | 1445 while ((c + 2) < col_max && fn_ptr->sdx3f != NULL) { |
| 1509 int i; | 1446 int i; |
| 1510 | 1447 |
| 1511 fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array); | 1448 fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array); |
| 1512 | 1449 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 | 1495 |
| 1559 if (bestsad < INT_MAX) | 1496 if (bestsad < INT_MAX) |
| 1560 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, | 1497 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, |
| 1561 (unsigned int *)(&thissad)) + | 1498 (unsigned int *)(&thissad)) + |
| 1562 mv_err_cost(&this_mv, center_mv, | 1499 mv_err_cost(&this_mv, center_mv, |
| 1563 mvjcost, mvcost, x->errorperbit); | 1500 mvjcost, mvcost, x->errorperbit); |
| 1564 else | 1501 else |
| 1565 return INT_MAX; | 1502 return INT_MAX; |
| 1566 } | 1503 } |
| 1567 | 1504 |
| 1568 int vp9_full_search_sadx8(MACROBLOCK *x, MV *ref_mv, | 1505 int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv, |
| 1569 int sad_per_bit, int distance, | 1506 int sad_per_bit, int distance, |
| 1570 vp9_variance_fn_ptr_t *fn_ptr, | 1507 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1571 int *mvjcost, int *mvcost[2], | 1508 int *mvjcost, int *mvcost[2], |
| 1572 const MV *center_mv, int n) { | 1509 const MV *center_mv, int n) { |
| 1573 const MACROBLOCKD* const xd = &x->e_mbd; | 1510 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1574 const uint8_t *const what = x->plane[0].src.buf; | 1511 const uint8_t *const what = x->plane[0].src.buf; |
| 1575 const int what_stride = x->plane[0].src.stride; | 1512 const int what_stride = x->plane[0].src.stride; |
| 1576 const uint8_t *const in_what = xd->plane[0].pre[0].buf; | 1513 const uint8_t *const in_what = xd->plane[0].pre[0].buf; |
| 1577 const int in_what_stride = xd->plane[0].pre[0].stride; | 1514 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 1578 const uint8_t *bestaddress; | 1515 MV *best_mv = &xd->mi_8x8[0]->bmi[n].as_mv[0].as_mv; |
| 1579 MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv; | |
| 1580 MV this_mv; | 1516 MV this_mv; |
| 1581 unsigned int bestsad = INT_MAX; | 1517 unsigned int bestsad = INT_MAX; |
| 1582 int r, c; | 1518 int r, c; |
| 1583 unsigned int thissad; | 1519 unsigned int thissad; |
| 1584 int ref_row = ref_mv->row; | 1520 int ref_row = ref_mv->row; |
| 1585 int ref_col = ref_mv->col; | 1521 int ref_col = ref_mv->col; |
| 1586 int row_min = ref_row - distance; | 1522 |
| 1587 int row_max = ref_row + distance; | 1523 // Apply further limits to prevent us looking using vectors that stretch |
| 1588 int col_min = ref_col - distance; | 1524 // beyond the UMV border |
| 1589 int col_max = ref_col + distance; | 1525 const int row_min = MAX(ref_row - distance, x->mv_row_min); |
| 1526 const int row_max = MIN(ref_row + distance, x->mv_row_max); |
| 1527 const int col_min = MAX(ref_col - distance, x->mv_col_min); |
| 1528 const int col_max = MIN(ref_col + distance, x->mv_col_max); |
| 1590 DECLARE_ALIGNED_ARRAY(16, uint32_t, sad_array8, 8); | 1529 DECLARE_ALIGNED_ARRAY(16, uint32_t, sad_array8, 8); |
| 1591 unsigned int sad_array[3]; | 1530 unsigned int sad_array[3]; |
| 1592 MV fcenter_mv; | 1531 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1593 | 1532 |
| 1594 int *mvjsadcost = x->nmvjointsadcost; | 1533 const int *mvjsadcost = x->nmvjointsadcost; |
| 1595 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 1534 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 1596 | 1535 |
| 1597 fcenter_mv.row = center_mv->row >> 3; | |
| 1598 fcenter_mv.col = center_mv->col >> 3; | |
| 1599 | |
| 1600 // Work out the mid point for the search | 1536 // Work out the mid point for the search |
| 1601 bestaddress = &in_what[ref_row * in_what_stride + ref_col]; | 1537 const uint8_t *bestaddress = &in_what[ref_row * in_what_stride + ref_col]; |
| 1602 | 1538 |
| 1603 best_mv->row = ref_row; | 1539 best_mv->row = ref_row; |
| 1604 best_mv->col = ref_col; | 1540 best_mv->col = ref_col; |
| 1605 | 1541 |
| 1606 // Baseline value at the center | 1542 // Baseline value at the center |
| 1607 bestsad = fn_ptr->sdf(what, what_stride, | 1543 bestsad = fn_ptr->sdf(what, what_stride, |
| 1608 bestaddress, in_what_stride, 0x7fffffff) | 1544 bestaddress, in_what_stride, 0x7fffffff) |
| 1609 + mvsad_err_cost(best_mv, &fcenter_mv, | 1545 + mvsad_err_cost(best_mv, &fcenter_mv, |
| 1610 mvjsadcost, mvsadcost, sad_per_bit); | 1546 mvjsadcost, mvsadcost, sad_per_bit); |
| 1611 | 1547 |
| 1612 // Apply further limits to prevent us looking using vectors that stretch | |
| 1613 // beyond the UMV border | |
| 1614 col_min = MAX(col_min, x->mv_col_min); | |
| 1615 col_max = MIN(col_max, x->mv_col_max); | |
| 1616 row_min = MAX(row_min, x->mv_row_min); | |
| 1617 row_max = MIN(row_max, x->mv_row_max); | |
| 1618 | |
| 1619 for (r = row_min; r < row_max; r++) { | 1548 for (r = row_min; r < row_max; r++) { |
| 1620 const uint8_t *check_here = &in_what[r * in_what_stride + col_min]; | 1549 const uint8_t *check_here = &in_what[r * in_what_stride + col_min]; |
| 1621 this_mv.row = r; | 1550 this_mv.row = r; |
| 1622 c = col_min; | 1551 c = col_min; |
| 1623 | 1552 |
| 1624 while ((c + 7) < col_max) { | 1553 while ((c + 7) < col_max) { |
| 1625 int i; | 1554 int i; |
| 1626 | 1555 |
| 1627 fn_ptr->sdx8f(what, what_stride, check_here, in_what_stride, sad_array8); | 1556 fn_ptr->sdx8f(what, what_stride, check_here, in_what_stride, sad_array8); |
| 1628 | 1557 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, | 1631 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, |
| 1703 (unsigned int *)(&thissad)) + | 1632 (unsigned int *)(&thissad)) + |
| 1704 mv_err_cost(&this_mv, center_mv, | 1633 mv_err_cost(&this_mv, center_mv, |
| 1705 mvjcost, mvcost, x->errorperbit); | 1634 mvjcost, mvcost, x->errorperbit); |
| 1706 else | 1635 else |
| 1707 return INT_MAX; | 1636 return INT_MAX; |
| 1708 } | 1637 } |
| 1709 | 1638 |
| 1710 int vp9_refining_search_sad_c(const MACROBLOCK *x, | 1639 int vp9_refining_search_sad_c(const MACROBLOCK *x, |
| 1711 MV *ref_mv, int error_per_bit, | 1640 MV *ref_mv, int error_per_bit, |
| 1712 int search_range, vp9_variance_fn_ptr_t *fn_ptr, | 1641 int search_range, |
| 1642 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1713 int *mvjcost, int *mvcost[2], | 1643 int *mvjcost, int *mvcost[2], |
| 1714 const MV *center_mv) { | 1644 const MV *center_mv) { |
| 1715 const MACROBLOCKD *const xd = &x->e_mbd; | 1645 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1716 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 1646 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; |
| 1717 int i, j; | 1647 int i, j; |
| 1718 | 1648 |
| 1719 const int what_stride = x->plane[0].src.stride; | 1649 const int what_stride = x->plane[0].src.stride; |
| 1720 const uint8_t *const what = x->plane[0].src.buf; | 1650 const uint8_t *const what = x->plane[0].src.buf; |
| 1721 const int in_what_stride = xd->plane[0].pre[0].stride; | 1651 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 1722 const uint8_t *const in_what = xd->plane[0].pre[0].buf; | 1652 const uint8_t *const in_what = xd->plane[0].pre[0].buf; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1734 in_what_stride, 0x7fffffff) + | 1664 in_what_stride, 0x7fffffff) + |
| 1735 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); | 1665 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); |
| 1736 | 1666 |
| 1737 for (i = 0; i < search_range; i++) { | 1667 for (i = 0; i < search_range; i++) { |
| 1738 int best_site = -1; | 1668 int best_site = -1; |
| 1739 | 1669 |
| 1740 for (j = 0; j < 4; j++) { | 1670 for (j = 0; j < 4; j++) { |
| 1741 this_mv.row = ref_mv->row + neighbors[j].row; | 1671 this_mv.row = ref_mv->row + neighbors[j].row; |
| 1742 this_mv.col = ref_mv->col + neighbors[j].col; | 1672 this_mv.col = ref_mv->col + neighbors[j].col; |
| 1743 | 1673 |
| 1744 if ((this_mv.col > x->mv_col_min) && | 1674 if (is_mv_in(x, &this_mv)) { |
| 1745 (this_mv.col < x->mv_col_max) && | |
| 1746 (this_mv.row > x->mv_row_min) && | |
| 1747 (this_mv.row < x->mv_row_max)) { | |
| 1748 const uint8_t *check_here = &in_what[this_mv.row * in_what_stride + | 1675 const uint8_t *check_here = &in_what[this_mv.row * in_what_stride + |
| 1749 this_mv.col]; | 1676 this_mv.col]; |
| 1750 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, | 1677 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, |
| 1751 bestsad); | 1678 bestsad); |
| 1752 | 1679 |
| 1753 if (thissad < bestsad) { | 1680 if (thissad < bestsad) { |
| 1754 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 1681 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1755 mvjsadcost, mvsadcost, error_per_bit); | 1682 mvjsadcost, mvsadcost, error_per_bit); |
| 1756 | 1683 |
| 1757 if (thissad < bestsad) { | 1684 if (thissad < bestsad) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1777 if (bestsad < INT_MAX) | 1704 if (bestsad < INT_MAX) |
| 1778 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, | 1705 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, |
| 1779 (unsigned int *)(&thissad)) + | 1706 (unsigned int *)(&thissad)) + |
| 1780 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); | 1707 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); |
| 1781 else | 1708 else |
| 1782 return INT_MAX; | 1709 return INT_MAX; |
| 1783 } | 1710 } |
| 1784 | 1711 |
| 1785 int vp9_refining_search_sadx4(const MACROBLOCK *x, | 1712 int vp9_refining_search_sadx4(const MACROBLOCK *x, |
| 1786 MV *ref_mv, int error_per_bit, | 1713 MV *ref_mv, int error_per_bit, |
| 1787 int search_range, vp9_variance_fn_ptr_t *fn_ptr, | 1714 int search_range, |
| 1715 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1788 int *mvjcost, int *mvcost[2], | 1716 int *mvjcost, int *mvcost[2], |
| 1789 const MV *center_mv) { | 1717 const MV *center_mv) { |
| 1790 const MACROBLOCKD* const xd = &x->e_mbd; | 1718 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1791 MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 1719 MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; |
| 1792 int i, j; | 1720 int i, j; |
| 1793 int this_row_offset, this_col_offset; | 1721 int this_row_offset, this_col_offset; |
| 1794 | 1722 |
| 1795 int what_stride = x->plane[0].src.stride; | 1723 const int what_stride = x->plane[0].src.stride; |
| 1796 int in_what_stride = xd->plane[0].pre[0].stride; | 1724 const int in_what_stride = xd->plane[0].pre[0].stride; |
| 1797 uint8_t *what = x->plane[0].src.buf; | 1725 const uint8_t *what = x->plane[0].src.buf; |
| 1798 uint8_t *best_address = xd->plane[0].pre[0].buf + | 1726 const uint8_t *best_address = xd->plane[0].pre[0].buf + |
| 1799 (ref_mv->row * xd->plane[0].pre[0].stride) + | 1727 (ref_mv->row * xd->plane[0].pre[0].stride) + |
| 1800 ref_mv->col; | 1728 ref_mv->col; |
| 1801 uint8_t *check_here; | |
| 1802 unsigned int thissad; | 1729 unsigned int thissad; |
| 1803 MV this_mv; | 1730 MV this_mv; |
| 1804 unsigned int bestsad = INT_MAX; | 1731 |
| 1805 MV fcenter_mv; | 1732 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
| 1806 | 1733 |
| 1807 const int *mvjsadcost = x->nmvjointsadcost; | 1734 const int *mvjsadcost = x->nmvjointsadcost; |
| 1808 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; | 1735 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; |
| 1809 | 1736 |
| 1810 fcenter_mv.row = center_mv->row >> 3; | 1737 unsigned int bestsad = fn_ptr->sdf(what, what_stride, best_address, |
| 1811 fcenter_mv.col = center_mv->col >> 3; | 1738 in_what_stride, 0x7fffffff) + |
| 1812 | 1739 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); |
| 1813 bestsad = fn_ptr->sdf(what, what_stride, best_address, | |
| 1814 in_what_stride, 0x7fffffff) + | |
| 1815 mvsad_err_cost(ref_mv, &fcenter_mv, | |
| 1816 mvjsadcost, mvsadcost, error_per_bit); | |
| 1817 | 1740 |
| 1818 for (i = 0; i < search_range; i++) { | 1741 for (i = 0; i < search_range; i++) { |
| 1819 int best_site = -1; | 1742 int best_site = -1; |
| 1820 int all_in = ((ref_mv->row - 1) > x->mv_row_min) & | 1743 int all_in = ((ref_mv->row - 1) > x->mv_row_min) & |
| 1821 ((ref_mv->row + 1) < x->mv_row_max) & | 1744 ((ref_mv->row + 1) < x->mv_row_max) & |
| 1822 ((ref_mv->col - 1) > x->mv_col_min) & | 1745 ((ref_mv->col - 1) > x->mv_col_min) & |
| 1823 ((ref_mv->col + 1) < x->mv_col_max); | 1746 ((ref_mv->col + 1) < x->mv_col_max); |
| 1824 | 1747 |
| 1825 if (all_in) { | 1748 if (all_in) { |
| 1826 unsigned int sad_array[4]; | 1749 unsigned int sad_array[4]; |
| 1827 unsigned char const *block_offset[4]; | 1750 uint8_t const *block_offset[4] = { |
| 1828 block_offset[0] = best_address - in_what_stride; | 1751 best_address - in_what_stride, |
| 1829 block_offset[1] = best_address - 1; | 1752 best_address - 1, |
| 1830 block_offset[2] = best_address + 1; | 1753 best_address + 1, |
| 1831 block_offset[3] = best_address + in_what_stride; | 1754 best_address + in_what_stride |
| 1755 }; |
| 1832 | 1756 |
| 1833 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, | 1757 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, |
| 1834 sad_array); | 1758 sad_array); |
| 1835 | 1759 |
| 1836 for (j = 0; j < 4; j++) { | 1760 for (j = 0; j < 4; j++) { |
| 1837 if (sad_array[j] < bestsad) { | 1761 if (sad_array[j] < bestsad) { |
| 1838 this_mv.row = ref_mv->row + neighbors[j].row; | 1762 this_mv.row = ref_mv->row + neighbors[j].row; |
| 1839 this_mv.col = ref_mv->col + neighbors[j].col; | 1763 this_mv.col = ref_mv->col + neighbors[j].col; |
| 1840 sad_array[j] += mvsad_err_cost(&this_mv, &fcenter_mv, | 1764 sad_array[j] += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1841 mvjsadcost, mvsadcost, error_per_bit); | 1765 mvjsadcost, mvsadcost, error_per_bit); |
| 1842 | 1766 |
| 1843 if (sad_array[j] < bestsad) { | 1767 if (sad_array[j] < bestsad) { |
| 1844 bestsad = sad_array[j]; | 1768 bestsad = sad_array[j]; |
| 1845 best_site = j; | 1769 best_site = j; |
| 1846 } | 1770 } |
| 1847 } | 1771 } |
| 1848 } | 1772 } |
| 1849 } else { | 1773 } else { |
| 1850 for (j = 0; j < 4; j++) { | 1774 for (j = 0; j < 4; j++) { |
| 1851 this_row_offset = ref_mv->row + neighbors[j].row; | 1775 this_row_offset = ref_mv->row + neighbors[j].row; |
| 1852 this_col_offset = ref_mv->col + neighbors[j].col; | 1776 this_col_offset = ref_mv->col + neighbors[j].col; |
| 1853 | 1777 |
| 1854 if ((this_col_offset > x->mv_col_min) && | 1778 if ((this_col_offset > x->mv_col_min) && |
| 1855 (this_col_offset < x->mv_col_max) && | 1779 (this_col_offset < x->mv_col_max) && |
| 1856 (this_row_offset > x->mv_row_min) && | 1780 (this_row_offset > x->mv_row_min) && |
| 1857 (this_row_offset < x->mv_row_max)) { | 1781 (this_row_offset < x->mv_row_max)) { |
| 1858 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col + | 1782 const uint8_t *check_here = neighbors[j].row * in_what_stride + |
| 1859 best_address; | 1783 neighbors[j].col + best_address; |
| 1860 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, | 1784 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, |
| 1861 bestsad); | 1785 bestsad); |
| 1862 | 1786 |
| 1863 if (thissad < bestsad) { | 1787 if (thissad < bestsad) { |
| 1864 this_mv.row = this_row_offset; | 1788 this_mv.row = this_row_offset; |
| 1865 this_mv.col = this_col_offset; | 1789 this_mv.col = this_col_offset; |
| 1866 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 1790 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1867 mvjsadcost, mvsadcost, error_per_bit); | 1791 mvjsadcost, mvsadcost, error_per_bit); |
| 1868 | 1792 |
| 1869 if (thissad < bestsad) { | 1793 if (thissad < bestsad) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1894 mv_err_cost(&this_mv, center_mv, | 1818 mv_err_cost(&this_mv, center_mv, |
| 1895 mvjcost, mvcost, x->errorperbit); | 1819 mvjcost, mvcost, x->errorperbit); |
| 1896 else | 1820 else |
| 1897 return INT_MAX; | 1821 return INT_MAX; |
| 1898 } | 1822 } |
| 1899 | 1823 |
| 1900 // This function is called when we do joint motion search in comp_inter_inter | 1824 // This function is called when we do joint motion search in comp_inter_inter |
| 1901 // mode. | 1825 // mode. |
| 1902 int vp9_refining_search_8p_c(const MACROBLOCK *x, | 1826 int vp9_refining_search_8p_c(const MACROBLOCK *x, |
| 1903 MV *ref_mv, int error_per_bit, | 1827 MV *ref_mv, int error_per_bit, |
| 1904 int search_range, vp9_variance_fn_ptr_t *fn_ptr, | 1828 int search_range, |
| 1905 int *mvjcost, int *mvcost[2], const MV *center_mv, | 1829 const vp9_variance_fn_ptr_t *fn_ptr, |
| 1830 int *mvjcost, int *mvcost[2], |
| 1831 const MV *center_mv, |
| 1906 const uint8_t *second_pred, int w, int h) { | 1832 const uint8_t *second_pred, int w, int h) { |
| 1907 const MACROBLOCKD *const xd = &x->e_mbd; | 1833 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1908 const MV neighbors[8] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, | 1834 const MV neighbors[8] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, |
| 1909 {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; | 1835 {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; |
| 1910 int i, j; | 1836 int i, j; |
| 1911 | 1837 |
| 1912 const uint8_t *what = x->plane[0].src.buf; | 1838 const uint8_t *what = x->plane[0].src.buf; |
| 1913 const int what_stride = x->plane[0].src.stride; | 1839 const int what_stride = x->plane[0].src.stride; |
| 1914 const uint8_t *in_what = xd->plane[0].pre[0].buf; | 1840 const uint8_t *in_what = xd->plane[0].pre[0].buf; |
| 1915 const int in_what_stride = xd->plane[0].pre[0].stride; | 1841 const int in_what_stride = xd->plane[0].pre[0].stride; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1928 second_pred, 0x7fffffff) + | 1854 second_pred, 0x7fffffff) + |
| 1929 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); | 1855 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); |
| 1930 | 1856 |
| 1931 for (i = 0; i < search_range; ++i) { | 1857 for (i = 0; i < search_range; ++i) { |
| 1932 int best_site = -1; | 1858 int best_site = -1; |
| 1933 | 1859 |
| 1934 for (j = 0; j < 8; j++) { | 1860 for (j = 0; j < 8; j++) { |
| 1935 this_mv.row = ref_mv->row + neighbors[j].row; | 1861 this_mv.row = ref_mv->row + neighbors[j].row; |
| 1936 this_mv.col = ref_mv->col + neighbors[j].col; | 1862 this_mv.col = ref_mv->col + neighbors[j].col; |
| 1937 | 1863 |
| 1938 if ((this_mv.col > x->mv_col_min) && | 1864 if (is_mv_in(x, &this_mv)) { |
| 1939 (this_mv.col < x->mv_col_max) && | |
| 1940 (this_mv.row > x->mv_row_min) && | |
| 1941 (this_mv.row < x->mv_row_max)) { | |
| 1942 const uint8_t *check_here = &in_what[this_mv.row * in_what_stride + | 1865 const uint8_t *check_here = &in_what[this_mv.row * in_what_stride + |
| 1943 this_mv.col]; | 1866 this_mv.col]; |
| 1944 | 1867 |
| 1945 thissad = fn_ptr->sdaf(what, what_stride, check_here, in_what_stride, | 1868 thissad = fn_ptr->sdaf(what, what_stride, check_here, in_what_stride, |
| 1946 second_pred, bestsad); | 1869 second_pred, bestsad); |
| 1947 if (thissad < bestsad) { | 1870 if (thissad < bestsad) { |
| 1948 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 1871 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
| 1949 mvjsadcost, mvsadcost, error_per_bit); | 1872 mvjsadcost, mvsadcost, error_per_bit); |
| 1950 if (thissad < bestsad) { | 1873 if (thissad < bestsad) { |
| 1951 bestsad = thissad; | 1874 bestsad = thissad; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1971 // FIXME(rbultje, yunqing): add full-pixel averaging variance functions | 1894 // FIXME(rbultje, yunqing): add full-pixel averaging variance functions |
| 1972 // so we don't have to use the subpixel with xoff=0,yoff=0 here. | 1895 // so we don't have to use the subpixel with xoff=0,yoff=0 here. |
| 1973 return fn_ptr->svaf(best_address, in_what_stride, 0, 0, what, what_stride, | 1896 return fn_ptr->svaf(best_address, in_what_stride, 0, 0, what, what_stride, |
| 1974 (unsigned int *)(&thissad), second_pred) + | 1897 (unsigned int *)(&thissad), second_pred) + |
| 1975 mv_err_cost(&this_mv, center_mv, | 1898 mv_err_cost(&this_mv, center_mv, |
| 1976 mvjcost, mvcost, x->errorperbit); | 1899 mvjcost, mvcost, x->errorperbit); |
| 1977 } else { | 1900 } else { |
| 1978 return INT_MAX; | 1901 return INT_MAX; |
| 1979 } | 1902 } |
| 1980 } | 1903 } |
| OLD | NEW |