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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 CHECK_BETTER(second, tr + kr, tc + hstep); \ | 249 CHECK_BETTER(second, tr + kr, tc + hstep); \ |
250 break; \ | 250 break; \ |
251 case 1: \ | 251 case 1: \ |
252 case 3: \ | 252 case 3: \ |
253 CHECK_BETTER(second, tr + kr, tc - hstep); \ | 253 CHECK_BETTER(second, tr + kr, tc - hstep); \ |
254 break; \ | 254 break; \ |
255 } \ | 255 } \ |
256 } \ | 256 } \ |
257 } | 257 } |
258 | 258 |
| 259 #define SETUP_SUBPEL_SEARCH \ |
| 260 const uint8_t *const z = x->plane[0].src.buf; \ |
| 261 const int src_stride = x->plane[0].src.stride; \ |
| 262 const MACROBLOCKD *xd = &x->e_mbd; \ |
| 263 unsigned int besterr = INT_MAX; \ |
| 264 unsigned int sse; \ |
| 265 unsigned int whichdir; \ |
| 266 int thismse; \ |
| 267 const unsigned int halfiters = iters_per_step; \ |
| 268 const unsigned int quarteriters = iters_per_step; \ |
| 269 const unsigned int eighthiters = iters_per_step; \ |
| 270 const int y_stride = xd->plane[0].pre[0].stride; \ |
| 271 const int offset = bestmv->row * y_stride + bestmv->col; \ |
| 272 const uint8_t *const y = xd->plane[0].pre[0].buf; \ |
| 273 \ |
| 274 int rr = ref_mv->row; \ |
| 275 int rc = ref_mv->col; \ |
| 276 int br = bestmv->row * 8; \ |
| 277 int bc = bestmv->col * 8; \ |
| 278 int hstep = 4; \ |
| 279 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \ |
| 280 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); \ |
| 281 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); \ |
| 282 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \ |
| 283 int tr = br; \ |
| 284 int tc = bc; \ |
| 285 \ |
| 286 bestmv->row *= 8; \ |
| 287 bestmv->col *= 8; \ |
| 288 if (second_pred != NULL) { \ |
| 289 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); \ |
| 290 vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); \ |
| 291 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1); \ |
| 292 } else { \ |
| 293 besterr = vfp->vf(y + offset, y_stride, z, src_stride, sse1); \ |
| 294 } \ |
| 295 *distortion = besterr; \ |
| 296 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); |
| 297 |
| 298 int vp9_find_best_sub_pixel_tree_pruned(const MACROBLOCK *x, |
| 299 MV *bestmv, const MV *ref_mv, |
| 300 int allow_hp, |
| 301 int error_per_bit, |
| 302 const vp9_variance_fn_ptr_t *vfp, |
| 303 int forced_stop, |
| 304 int iters_per_step, |
| 305 int *sad_list, |
| 306 int *mvjcost, int *mvcost[2], |
| 307 int *distortion, |
| 308 unsigned int *sse1, |
| 309 const uint8_t *second_pred, |
| 310 int w, int h) { |
| 311 SETUP_SUBPEL_SEARCH; |
| 312 |
| 313 if (sad_list && |
| 314 sad_list[0] != INT_MAX && sad_list[1] != INT_MAX && |
| 315 sad_list[2] != INT_MAX && sad_list[3] != INT_MAX && |
| 316 sad_list[4] != INT_MAX) { |
| 317 unsigned int left, right, up, down, diag; |
| 318 whichdir = (sad_list[1] < sad_list[3] ? 0 : 1) + |
| 319 (sad_list[2] < sad_list[4] ? 0 : 2); |
| 320 switch (whichdir) { |
| 321 case 0: |
| 322 CHECK_BETTER(left, tr, tc - hstep); |
| 323 CHECK_BETTER(up, tr - hstep, tc); |
| 324 CHECK_BETTER(diag, tr - hstep, tc - hstep); |
| 325 break; |
| 326 case 1: |
| 327 CHECK_BETTER(right, tr, tc + hstep); |
| 328 CHECK_BETTER(up, tr - hstep, tc); |
| 329 CHECK_BETTER(diag, tr - hstep, tc + hstep); |
| 330 break; |
| 331 case 2: |
| 332 CHECK_BETTER(left, tr, tc - hstep); |
| 333 CHECK_BETTER(down, tr + hstep, tc); |
| 334 CHECK_BETTER(diag, tr + hstep, tc - hstep); |
| 335 break; |
| 336 case 3: |
| 337 CHECK_BETTER(right, tr, tc + hstep); |
| 338 CHECK_BETTER(down, tr + hstep, tc); |
| 339 CHECK_BETTER(diag, tr + hstep, tc + hstep); |
| 340 break; |
| 341 } |
| 342 } else { |
| 343 FIRST_LEVEL_CHECKS; |
| 344 if (halfiters > 1) { |
| 345 SECOND_LEVEL_CHECKS; |
| 346 } |
| 347 } |
| 348 |
| 349 tr = br; |
| 350 tc = bc; |
| 351 |
| 352 // Each subsequent iteration checks at least one point in common with |
| 353 // the last iteration could be 2 ( if diag selected) 1/4 pel |
| 354 |
| 355 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only |
| 356 if (forced_stop != 2) { |
| 357 hstep >>= 1; |
| 358 FIRST_LEVEL_CHECKS; |
| 359 if (quarteriters > 1) { |
| 360 SECOND_LEVEL_CHECKS; |
| 361 } |
| 362 tr = br; |
| 363 tc = bc; |
| 364 } |
| 365 |
| 366 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) { |
| 367 hstep >>= 1; |
| 368 FIRST_LEVEL_CHECKS; |
| 369 if (eighthiters > 1) { |
| 370 SECOND_LEVEL_CHECKS; |
| 371 } |
| 372 tr = br; |
| 373 tc = bc; |
| 374 } |
| 375 // These lines insure static analysis doesn't warn that |
| 376 // tr and tc aren't used after the above point. |
| 377 (void) tr; |
| 378 (void) tc; |
| 379 |
| 380 bestmv->row = br; |
| 381 bestmv->col = bc; |
| 382 |
| 383 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || |
| 384 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) |
| 385 return INT_MAX; |
| 386 |
| 387 return besterr; |
| 388 } |
| 389 |
259 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, | 390 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, |
260 MV *bestmv, const MV *ref_mv, | 391 MV *bestmv, const MV *ref_mv, |
261 int allow_hp, | 392 int allow_hp, |
262 int error_per_bit, | 393 int error_per_bit, |
263 const vp9_variance_fn_ptr_t *vfp, | 394 const vp9_variance_fn_ptr_t *vfp, |
264 int forced_stop, | 395 int forced_stop, |
265 int iters_per_step, | 396 int iters_per_step, |
| 397 int *sad_list, |
266 int *mvjcost, int *mvcost[2], | 398 int *mvjcost, int *mvcost[2], |
267 int *distortion, | 399 int *distortion, |
268 unsigned int *sse1, | 400 unsigned int *sse1, |
269 const uint8_t *second_pred, | 401 const uint8_t *second_pred, |
270 int w, int h) { | 402 int w, int h) { |
271 const uint8_t *const z = x->plane[0].src.buf; | 403 SETUP_SUBPEL_SEARCH; |
272 const int src_stride = x->plane[0].src.stride; | 404 (void) sad_list; // to silence compiler warning |
273 const MACROBLOCKD *xd = &x->e_mbd; | |
274 unsigned int besterr = INT_MAX; | |
275 unsigned int sse; | |
276 unsigned int whichdir; | |
277 int thismse; | |
278 const unsigned int halfiters = iters_per_step; | |
279 const unsigned int quarteriters = iters_per_step; | |
280 const unsigned int eighthiters = iters_per_step; | |
281 | |
282 const int y_stride = xd->plane[0].pre[0].stride; | |
283 const int offset = bestmv->row * y_stride + bestmv->col; | |
284 const uint8_t *const y = xd->plane[0].pre[0].buf; | |
285 | |
286 int rr = ref_mv->row; | |
287 int rc = ref_mv->col; | |
288 int br = bestmv->row * 8; | |
289 int bc = bestmv->col * 8; | |
290 int hstep = 4; | |
291 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); | |
292 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); | |
293 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); | |
294 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); | |
295 | |
296 int tr = br; | |
297 int tc = bc; | |
298 | |
299 // central mv | |
300 bestmv->row *= 8; | |
301 bestmv->col *= 8; | |
302 | |
303 // calculate central point error | |
304 // TODO(yunqingwang): central pointer error was already calculated in full- | |
305 // pixel search, and can be passed in this function. | |
306 if (second_pred != NULL) { | |
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 } | |
313 *distortion = besterr; | |
314 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); | |
315 | 405 |
316 // Each subsequent iteration checks at least one point in | 406 // Each subsequent iteration checks at least one point in |
317 // common with the last iteration could be 2 ( if diag selected) | 407 // common with the last iteration could be 2 ( if diag selected) |
318 // 1/2 pel | 408 // 1/2 pel |
319 FIRST_LEVEL_CHECKS; | 409 FIRST_LEVEL_CHECKS; |
320 if (halfiters > 1) { | 410 if (halfiters > 1) { |
321 SECOND_LEVEL_CHECKS; | 411 SECOND_LEVEL_CHECKS; |
322 } | 412 } |
323 tr = br; | 413 tr = br; |
324 tc = bc; | 414 tc = bc; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 481 } |
392 | 482 |
393 #define MAX_PATTERN_SCALES 11 | 483 #define MAX_PATTERN_SCALES 11 |
394 #define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale | 484 #define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale |
395 #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates | 485 #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates |
396 | 486 |
397 // Generic pattern search function that searches over multiple scales. | 487 // Generic pattern search function that searches over multiple scales. |
398 // Each scale can have a different number of candidates and shape of | 488 // Each scale can have a different number of candidates and shape of |
399 // candidates as indicated in the num_candidates and candidates arrays | 489 // candidates as indicated in the num_candidates and candidates arrays |
400 // passed into this function | 490 // passed into this function |
| 491 // |
401 static int vp9_pattern_search(const MACROBLOCK *x, | 492 static int vp9_pattern_search(const MACROBLOCK *x, |
402 MV *ref_mv, | 493 MV *ref_mv, |
403 int search_param, | 494 int search_param, |
404 int sad_per_bit, | 495 int sad_per_bit, |
405 int do_init_search, int do_refine, | 496 int do_init_search, |
| 497 int *sad_list, |
406 const vp9_variance_fn_ptr_t *vfp, | 498 const vp9_variance_fn_ptr_t *vfp, |
407 int use_mvcost, | 499 int use_mvcost, |
408 const MV *center_mv, MV *best_mv, | 500 const MV *center_mv, |
| 501 MV *best_mv, |
409 const int num_candidates[MAX_PATTERN_SCALES], | 502 const int num_candidates[MAX_PATTERN_SCALES], |
410 const MV candidates[MAX_PATTERN_SCALES] | 503 const MV candidates[MAX_PATTERN_SCALES] |
411 [MAX_PATTERN_CANDIDATES]) { | 504 [MAX_PATTERN_CANDIDATES]) { |
412 const MACROBLOCKD *const xd = &x->e_mbd; | 505 const MACROBLOCKD *const xd = &x->e_mbd; |
413 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = { | 506 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = { |
414 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, | 507 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, |
415 }; | 508 }; |
416 int i, j, s, t; | 509 int i, s, t; |
417 const struct buf_2d *const what = &x->plane[0].src; | 510 const struct buf_2d *const what = &x->plane[0].src; |
418 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 511 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
419 int br, bc; | 512 int br, bc; |
420 int bestsad = INT_MAX; | 513 int bestsad = INT_MAX; |
421 int thissad; | 514 int thissad; |
422 int k = -1; | 515 int k = -1; |
423 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 516 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
424 int best_init_s = search_param_to_steps[search_param]; | 517 int best_init_s = search_param_to_steps[search_param]; |
425 // adjust ref_mv to make sure it is within MV range | 518 // adjust ref_mv to make sure it is within MV range |
426 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 519 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 638 |
546 if (best_site != -1) { | 639 if (best_site != -1) { |
547 k = next_chkpts_indices[best_site]; | 640 k = next_chkpts_indices[best_site]; |
548 br += candidates[s][k].row; | 641 br += candidates[s][k].row; |
549 bc += candidates[s][k].col; | 642 bc += candidates[s][k].col; |
550 } | 643 } |
551 } while (best_site != -1); | 644 } while (best_site != -1); |
552 } while (s--); | 645 } while (s--); |
553 } | 646 } |
554 | 647 |
555 // Check 4 1-away neighbors if do_refine is true. | 648 // Returns the one-away integer pel sad values around the best as follows: |
556 // For most well-designed schemes do_refine will not be necessary. | 649 // sad_list[0]: sad at the best integer pel |
557 if (do_refine) { | 650 // sad_list[1]: sad at delta {0, -1} (left) from the best integer pel |
558 static const MV neighbors[4] = {{0, -1}, { -1, 0}, {1, 0}, {0, 1}}; | 651 // sad_list[2]: sad at delta {-1, 0} (top) from the best integer pel |
559 | 652 // sad_list[3]: sad at delta { 0, 1} (right) from the best integer pel |
560 for (j = 0; j < 16; j++) { | 653 // sad_list[4]: sad at delta { 1, 0} (bottom) from the best integer pel |
561 int best_site = -1; | 654 if (sad_list) { |
562 if (check_bounds(x, br, bc, 1)) { | 655 static const MV neighbors[4] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; |
563 for (i = 0; i < 4; i++) { | 656 sad_list[0] = bestsad; |
564 const MV this_mv = {br + neighbors[i].row, | 657 if (check_bounds(x, br, bc, 1)) { |
565 bc + neighbors[i].col}; | 658 for (i = 0; i < 4; i++) { |
566 thissad = vfp->sdf(what->buf, what->stride, | 659 const MV this_mv = {br + neighbors[i].row, |
567 get_buf_from_mv(in_what, &this_mv), | 660 bc + neighbors[i].col}; |
568 in_what->stride); | 661 sad_list[i + 1] = vfp->sdf(what->buf, what->stride, |
569 CHECK_BETTER | 662 get_buf_from_mv(in_what, &this_mv), |
570 } | 663 in_what->stride); |
571 } else { | |
572 for (i = 0; i < 4; i++) { | |
573 const MV this_mv = {br + neighbors[i].row, | |
574 bc + neighbors[i].col}; | |
575 if (!is_mv_in(x, &this_mv)) | |
576 continue; | |
577 thissad = vfp->sdf(what->buf, what->stride, | |
578 get_buf_from_mv(in_what, &this_mv), | |
579 in_what->stride); | |
580 CHECK_BETTER | |
581 } | |
582 } | 664 } |
583 | 665 } else { |
584 if (best_site == -1) { | 666 for (i = 0; i < 4; i++) { |
585 break; | 667 const MV this_mv = {br + neighbors[i].row, |
586 } else { | 668 bc + neighbors[i].col}; |
587 br += neighbors[best_site].row; | 669 if (!is_mv_in(x, &this_mv)) |
588 bc += neighbors[best_site].col; | 670 sad_list[i + 1] = INT_MAX; |
| 671 else |
| 672 sad_list[i + 1] = vfp->sdf(what->buf, what->stride, |
| 673 get_buf_from_mv(in_what, &this_mv), |
| 674 in_what->stride); |
589 } | 675 } |
590 } | 676 } |
591 } | 677 } |
592 | |
593 best_mv->row = br; | 678 best_mv->row = br; |
594 best_mv->col = bc; | 679 best_mv->col = bc; |
595 | |
596 return bestsad; | 680 return bestsad; |
597 } | 681 } |
598 | 682 |
599 int vp9_get_mvpred_var(const MACROBLOCK *x, | 683 int vp9_get_mvpred_var(const MACROBLOCK *x, |
600 const MV *best_mv, const MV *center_mv, | 684 const MV *best_mv, const MV *center_mv, |
601 const vp9_variance_fn_ptr_t *vfp, | 685 const vp9_variance_fn_ptr_t *vfp, |
602 int use_mvcost) { | 686 int use_mvcost) { |
603 const MACROBLOCKD *const xd = &x->e_mbd; | 687 const MACROBLOCKD *const xd = &x->e_mbd; |
604 const struct buf_2d *const what = &x->plane[0].src; | 688 const struct buf_2d *const what = &x->plane[0].src; |
605 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 689 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
(...skipping 21 matching lines...) Expand all Loading... |
627 what->buf, what->stride, &unused, second_pred) + | 711 what->buf, what->stride, &unused, second_pred) + |
628 (use_mvcost ? mv_err_cost(&mv, center_mv, x->nmvjointcost, | 712 (use_mvcost ? mv_err_cost(&mv, center_mv, x->nmvjointcost, |
629 x->mvcost, x->errorperbit) : 0); | 713 x->mvcost, x->errorperbit) : 0); |
630 } | 714 } |
631 | 715 |
632 int vp9_hex_search(const MACROBLOCK *x, | 716 int vp9_hex_search(const MACROBLOCK *x, |
633 MV *ref_mv, | 717 MV *ref_mv, |
634 int search_param, | 718 int search_param, |
635 int sad_per_bit, | 719 int sad_per_bit, |
636 int do_init_search, | 720 int do_init_search, |
| 721 int *sad_list, |
637 const vp9_variance_fn_ptr_t *vfp, | 722 const vp9_variance_fn_ptr_t *vfp, |
638 int use_mvcost, | 723 int use_mvcost, |
639 const MV *center_mv, MV *best_mv) { | 724 const MV *center_mv, MV *best_mv) { |
640 // First scale has 8-closest points, the rest have 6 points in hex shape | 725 // First scale has 8-closest points, the rest have 6 points in hex shape |
641 // at increasing scales | 726 // at increasing scales |
642 static const int hex_num_candidates[MAX_PATTERN_SCALES] = { | 727 static const int hex_num_candidates[MAX_PATTERN_SCALES] = { |
643 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 | 728 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 |
644 }; | 729 }; |
645 // Note that the largest candidate step at each scale is 2^scale | 730 // Note that the largest candidate step at each scale is 2^scale |
646 static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = { | 731 static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = { |
647 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}}, | 732 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}}, |
648 {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}}, | 733 {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}}, |
649 {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}}, | 734 {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}}, |
650 {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}}, | 735 {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}}, |
651 {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}}, | 736 {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}}, |
652 {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}}, | 737 {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}}, |
653 {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}}, | 738 {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}}, |
654 {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}}, | 739 {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}}, |
655 {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}}, | 740 {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}}, |
656 {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}}, | 741 {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}}, |
657 {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024}, | 742 {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024}, |
658 { -1024, 0}}, | 743 { -1024, 0}}, |
659 }; | 744 }; |
660 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, | 745 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, |
661 do_init_search, 0, vfp, use_mvcost, | 746 do_init_search, sad_list, vfp, use_mvcost, |
662 center_mv, best_mv, | 747 center_mv, best_mv, |
663 hex_num_candidates, hex_candidates); | 748 hex_num_candidates, hex_candidates); |
664 } | 749 } |
665 | 750 |
666 int vp9_bigdia_search(const MACROBLOCK *x, | 751 int vp9_bigdia_search(const MACROBLOCK *x, |
667 MV *ref_mv, | 752 MV *ref_mv, |
668 int search_param, | 753 int search_param, |
669 int sad_per_bit, | 754 int sad_per_bit, |
670 int do_init_search, | 755 int do_init_search, |
| 756 int *sad_list, |
671 const vp9_variance_fn_ptr_t *vfp, | 757 const vp9_variance_fn_ptr_t *vfp, |
672 int use_mvcost, | 758 int use_mvcost, |
673 const MV *center_mv, | 759 const MV *center_mv, |
674 MV *best_mv) { | 760 MV *best_mv) { |
675 // First scale has 4-closest points, the rest have 8 points in diamond | 761 // First scale has 4-closest points, the rest have 8 points in diamond |
676 // shape at increasing scales | 762 // shape at increasing scales |
677 static const int bigdia_num_candidates[MAX_PATTERN_SCALES] = { | 763 static const int bigdia_num_candidates[MAX_PATTERN_SCALES] = { |
678 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | 764 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
679 }; | 765 }; |
680 // Note that the largest candidate step at each scale is 2^scale | 766 // Note that the largest candidate step at each scale is 2^scale |
(...skipping 11 matching lines...) Expand all Loading... |
692 {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128}, | 778 {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128}, |
693 {-64, 64}, {-128, 0}}, | 779 {-64, 64}, {-128, 0}}, |
694 {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256}, | 780 {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256}, |
695 {-128, 128}, {-256, 0}}, | 781 {-128, 128}, {-256, 0}}, |
696 {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512}, | 782 {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512}, |
697 {-256, 256}, {-512, 0}}, | 783 {-256, 256}, {-512, 0}}, |
698 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024}, | 784 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024}, |
699 {-512, 512}, {-1024, 0}}, | 785 {-512, 512}, {-1024, 0}}, |
700 }; | 786 }; |
701 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, | 787 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, |
702 do_init_search, 0, vfp, use_mvcost, | 788 do_init_search, sad_list, vfp, use_mvcost, |
703 center_mv, best_mv, | 789 center_mv, best_mv, |
704 bigdia_num_candidates, bigdia_candidates); | 790 bigdia_num_candidates, bigdia_candidates); |
705 } | 791 } |
706 | 792 |
707 int vp9_square_search(const MACROBLOCK *x, | 793 int vp9_square_search(const MACROBLOCK *x, |
708 MV *ref_mv, | 794 MV *ref_mv, |
709 int search_param, | 795 int search_param, |
710 int sad_per_bit, | 796 int sad_per_bit, |
711 int do_init_search, | 797 int do_init_search, |
| 798 int *sad_list, |
712 const vp9_variance_fn_ptr_t *vfp, | 799 const vp9_variance_fn_ptr_t *vfp, |
713 int use_mvcost, | 800 int use_mvcost, |
714 const MV *center_mv, | 801 const MV *center_mv, |
715 MV *best_mv) { | 802 MV *best_mv) { |
716 // All scales have 8 closest points in square shape | 803 // All scales have 8 closest points in square shape |
717 static const int square_num_candidates[MAX_PATTERN_SCALES] = { | 804 static const int square_num_candidates[MAX_PATTERN_SCALES] = { |
718 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | 805 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
719 }; | 806 }; |
720 // Note that the largest candidate step at each scale is 2^scale | 807 // Note that the largest candidate step at each scale is 2^scale |
721 static const MV square_candidates[MAX_PATTERN_SCALES] | 808 static const MV square_candidates[MAX_PATTERN_SCALES] |
(...skipping 11 matching lines...) Expand all Loading... |
733 {{-128, -128}, {0, -128}, {128, -128}, {128, 0}, {128, 128}, {0, 128}, | 820 {{-128, -128}, {0, -128}, {128, -128}, {128, 0}, {128, 128}, {0, 128}, |
734 {-128, 128}, {-128, 0}}, | 821 {-128, 128}, {-128, 0}}, |
735 {{-256, -256}, {0, -256}, {256, -256}, {256, 0}, {256, 256}, {0, 256}, | 822 {{-256, -256}, {0, -256}, {256, -256}, {256, 0}, {256, 256}, {0, 256}, |
736 {-256, 256}, {-256, 0}}, | 823 {-256, 256}, {-256, 0}}, |
737 {{-512, -512}, {0, -512}, {512, -512}, {512, 0}, {512, 512}, {0, 512}, | 824 {{-512, -512}, {0, -512}, {512, -512}, {512, 0}, {512, 512}, {0, 512}, |
738 {-512, 512}, {-512, 0}}, | 825 {-512, 512}, {-512, 0}}, |
739 {{-1024, -1024}, {0, -1024}, {1024, -1024}, {1024, 0}, {1024, 1024}, | 826 {{-1024, -1024}, {0, -1024}, {1024, -1024}, {1024, 0}, {1024, 1024}, |
740 {0, 1024}, {-1024, 1024}, {-1024, 0}}, | 827 {0, 1024}, {-1024, 1024}, {-1024, 0}}, |
741 }; | 828 }; |
742 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, | 829 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, |
743 do_init_search, 0, vfp, use_mvcost, | 830 do_init_search, sad_list, vfp, use_mvcost, |
744 center_mv, best_mv, | 831 center_mv, best_mv, |
745 square_num_candidates, square_candidates); | 832 square_num_candidates, square_candidates); |
746 } | 833 } |
747 | 834 |
748 int vp9_fast_hex_search(const MACROBLOCK *x, | 835 int vp9_fast_hex_search(const MACROBLOCK *x, |
749 MV *ref_mv, | 836 MV *ref_mv, |
750 int search_param, | 837 int search_param, |
751 int sad_per_bit, | 838 int sad_per_bit, |
752 int do_init_search, // must be zero for fast_hex | 839 int do_init_search, // must be zero for fast_hex |
| 840 int *sad_list, |
753 const vp9_variance_fn_ptr_t *vfp, | 841 const vp9_variance_fn_ptr_t *vfp, |
754 int use_mvcost, | 842 int use_mvcost, |
755 const MV *center_mv, | 843 const MV *center_mv, |
756 MV *best_mv) { | 844 MV *best_mv) { |
757 return vp9_hex_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), | 845 return vp9_hex_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), |
758 sad_per_bit, do_init_search, vfp, use_mvcost, | 846 sad_per_bit, do_init_search, sad_list, vfp, use_mvcost, |
759 center_mv, best_mv); | 847 center_mv, best_mv); |
760 } | 848 } |
761 | 849 |
762 int vp9_fast_dia_search(const MACROBLOCK *x, | 850 int vp9_fast_dia_search(const MACROBLOCK *x, |
763 MV *ref_mv, | 851 MV *ref_mv, |
764 int search_param, | 852 int search_param, |
765 int sad_per_bit, | 853 int sad_per_bit, |
766 int do_init_search, | 854 int do_init_search, |
| 855 int *sad_list, |
767 const vp9_variance_fn_ptr_t *vfp, | 856 const vp9_variance_fn_ptr_t *vfp, |
768 int use_mvcost, | 857 int use_mvcost, |
769 const MV *center_mv, | 858 const MV *center_mv, |
770 MV *best_mv) { | 859 MV *best_mv) { |
771 return vp9_bigdia_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), | 860 return vp9_bigdia_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), |
772 sad_per_bit, do_init_search, vfp, use_mvcost, | 861 sad_per_bit, do_init_search, sad_list, vfp, |
773 center_mv, best_mv); | 862 use_mvcost, center_mv, best_mv); |
774 } | 863 } |
775 | 864 |
776 #undef CHECK_BETTER | 865 #undef CHECK_BETTER |
777 | 866 |
778 int vp9_full_range_search_c(const MACROBLOCK *x, | 867 int vp9_full_range_search_c(const MACROBLOCK *x, |
779 const search_site_config *cfg, | 868 const search_site_config *cfg, |
780 MV *ref_mv, MV *best_mv, | 869 MV *ref_mv, MV *best_mv, |
781 int search_param, int sad_per_bit, int *num00, | 870 int search_param, int sad_per_bit, int *num00, |
782 const vp9_variance_fn_ptr_t *fn_ptr, | 871 const vp9_variance_fn_ptr_t *fn_ptr, |
783 const MV *center_mv) { | 872 const MV *center_mv) { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 ref_mv->row += neighbors[best_site].row; | 1450 ref_mv->row += neighbors[best_site].row; |
1362 ref_mv->col += neighbors[best_site].col; | 1451 ref_mv->col += neighbors[best_site].col; |
1363 } | 1452 } |
1364 } | 1453 } |
1365 return best_sad; | 1454 return best_sad; |
1366 } | 1455 } |
1367 | 1456 |
1368 int vp9_full_pixel_search(VP9_COMP *cpi, MACROBLOCK *x, | 1457 int vp9_full_pixel_search(VP9_COMP *cpi, MACROBLOCK *x, |
1369 BLOCK_SIZE bsize, MV *mvp_full, | 1458 BLOCK_SIZE bsize, MV *mvp_full, |
1370 int step_param, int error_per_bit, | 1459 int step_param, int error_per_bit, |
| 1460 int *sad_list, |
1371 const MV *ref_mv, MV *tmp_mv, | 1461 const MV *ref_mv, MV *tmp_mv, |
1372 int var_max, int rd) { | 1462 int var_max, int rd) { |
1373 const SPEED_FEATURES *const sf = &cpi->sf; | 1463 const SPEED_FEATURES *const sf = &cpi->sf; |
1374 const SEARCH_METHODS method = sf->mv.search_method; | 1464 const SEARCH_METHODS method = sf->mv.search_method; |
1375 vp9_variance_fn_ptr_t *fn_ptr = &cpi->fn_ptr[bsize]; | 1465 vp9_variance_fn_ptr_t *fn_ptr = &cpi->fn_ptr[bsize]; |
1376 int var = 0; | 1466 int var = 0; |
| 1467 if (sad_list) { |
| 1468 sad_list[0] = INT_MAX; |
| 1469 sad_list[1] = INT_MAX; |
| 1470 sad_list[2] = INT_MAX; |
| 1471 sad_list[3] = INT_MAX; |
| 1472 sad_list[4] = INT_MAX; |
| 1473 } |
1377 | 1474 |
1378 switch (method) { | 1475 switch (method) { |
1379 case FAST_DIAMOND: | 1476 case FAST_DIAMOND: |
1380 var = vp9_fast_dia_search(x, mvp_full, step_param, error_per_bit, 0, | 1477 var = vp9_fast_dia_search(x, mvp_full, step_param, error_per_bit, 0, |
1381 fn_ptr, 1, ref_mv, tmp_mv); | 1478 sad_list, fn_ptr, 1, ref_mv, tmp_mv); |
1382 break; | 1479 break; |
1383 case FAST_HEX: | 1480 case FAST_HEX: |
1384 var = vp9_fast_hex_search(x, mvp_full, step_param, error_per_bit, 0, | 1481 var = vp9_fast_hex_search(x, mvp_full, step_param, error_per_bit, 0, |
1385 fn_ptr, 1, ref_mv, tmp_mv); | 1482 sad_list, fn_ptr, 1, ref_mv, tmp_mv); |
1386 break; | 1483 break; |
1387 case HEX: | 1484 case HEX: |
1388 var = vp9_hex_search(x, mvp_full, step_param, error_per_bit, 1, | 1485 var = vp9_hex_search(x, mvp_full, step_param, error_per_bit, 1, |
1389 fn_ptr, 1, ref_mv, tmp_mv); | 1486 sad_list, fn_ptr, 1, ref_mv, tmp_mv); |
1390 break; | 1487 break; |
1391 case SQUARE: | 1488 case SQUARE: |
1392 var = vp9_square_search(x, mvp_full, step_param, error_per_bit, 1, | 1489 var = vp9_square_search(x, mvp_full, step_param, error_per_bit, 1, |
1393 fn_ptr, 1, ref_mv, tmp_mv); | 1490 sad_list, fn_ptr, 1, ref_mv, tmp_mv); |
1394 break; | 1491 break; |
1395 case BIGDIA: | 1492 case BIGDIA: |
1396 var = vp9_bigdia_search(x, mvp_full, step_param, error_per_bit, 1, | 1493 var = vp9_bigdia_search(x, mvp_full, step_param, error_per_bit, 1, |
1397 fn_ptr, 1, ref_mv, tmp_mv); | 1494 sad_list, fn_ptr, 1, ref_mv, tmp_mv); |
1398 break; | 1495 break; |
1399 case NSTEP: | 1496 case NSTEP: |
1400 var = vp9_full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit, | 1497 var = vp9_full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit, |
1401 MAX_MVSEARCH_STEPS - 1 - step_param, | 1498 MAX_MVSEARCH_STEPS - 1 - step_param, |
1402 1, fn_ptr, ref_mv, tmp_mv); | 1499 1, fn_ptr, ref_mv, tmp_mv); |
1403 break; | 1500 break; |
1404 default: | 1501 default: |
1405 assert(!"Invalid search method."); | 1502 assert(!"Invalid search method."); |
1406 } | 1503 } |
1407 | 1504 |
1408 if (method != NSTEP && rd && var < var_max) | 1505 if (method != NSTEP && rd && var < var_max) |
1409 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); | 1506 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); |
1410 | 1507 |
1411 return var; | 1508 return var; |
1412 } | 1509 } |
OLD | NEW |