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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 int vp9_init_search_range(const SPEED_FEATURES *sf, int size) { | 54 int vp9_init_search_range(const SPEED_FEATURES *sf, int size) { |
55 int sr = 0; | 55 int sr = 0; |
56 | 56 |
57 // Minimum search size no matter what the passed in value. | 57 // Minimum search size no matter what the passed in value. |
58 size = MAX(16, size); | 58 size = MAX(16, size); |
59 | 59 |
60 while ((size << sr) < MAX_FULL_PEL_VAL) | 60 while ((size << sr) < MAX_FULL_PEL_VAL) |
61 sr++; | 61 sr++; |
62 | 62 |
63 sr += sf->reduce_first_step_size; | 63 sr += sf->mv.reduce_first_step_size; |
64 sr = MIN(sr, (sf->max_step_search_steps - 2)); | 64 sr = MIN(sr, (sf->mv.max_step_search_steps - 2)); |
65 return sr; | 65 return sr; |
66 } | 66 } |
67 | 67 |
68 static INLINE int mv_cost(const MV *mv, | 68 static INLINE int mv_cost(const MV *mv, |
69 const int *joint_cost, int *const comp_cost[2]) { | 69 const int *joint_cost, int *const comp_cost[2]) { |
70 return joint_cost[vp9_get_mv_joint(mv)] + | 70 return joint_cost[vp9_get_mv_joint(mv)] + |
71 comp_cost[0][mv->row] + comp_cost[1][mv->col]; | 71 comp_cost[0][mv->row] + comp_cost[1][mv->col]; |
72 } | 72 } |
73 | 73 |
74 int vp9_mv_bit_cost(const MV *mv, const MV *ref, | 74 int vp9_mv_bit_cost(const MV *mv, const MV *ref, |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 int k = -1; | 517 int k = -1; |
518 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 518 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
519 int best_init_s = search_param_to_steps[search_param]; | 519 int best_init_s = search_param_to_steps[search_param]; |
520 // adjust ref_mv to make sure it is within MV range | 520 // adjust ref_mv to make sure it is within MV range |
521 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 521 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
522 br = ref_mv->row; | 522 br = ref_mv->row; |
523 bc = ref_mv->col; | 523 bc = ref_mv->col; |
524 | 524 |
525 // Work out the start point for the search | 525 // Work out the start point for the search |
526 bestsad = vfp->sdf(what->buf, what->stride, | 526 bestsad = vfp->sdf(what->buf, what->stride, |
527 get_buf_from_mv(in_what, ref_mv), in_what->stride, | 527 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
528 0x7fffffff) + mvsad_err_cost(x, ref_mv, &fcenter_mv, | 528 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
529 sad_per_bit); | |
530 | 529 |
531 // Search all possible scales upto the search param around the center point | 530 // Search all possible scales upto the search param around the center point |
532 // pick the scale of the point that is best as the starting scale of | 531 // pick the scale of the point that is best as the starting scale of |
533 // further steps around it. | 532 // further steps around it. |
534 if (do_init_search) { | 533 if (do_init_search) { |
535 s = best_init_s; | 534 s = best_init_s; |
536 best_init_s = -1; | 535 best_init_s = -1; |
537 for (t = 0; t <= s; ++t) { | 536 for (t = 0; t <= s; ++t) { |
538 int best_site = -1; | 537 int best_site = -1; |
539 if (check_bounds(x, br, bc, 1 << t)) { | 538 if (check_bounds(x, br, bc, 1 << t)) { |
540 for (i = 0; i < num_candidates[t]; i++) { | 539 for (i = 0; i < num_candidates[t]; i++) { |
541 const MV this_mv = {br + candidates[t][i].row, | 540 const MV this_mv = {br + candidates[t][i].row, |
542 bc + candidates[t][i].col}; | 541 bc + candidates[t][i].col}; |
543 thissad = vfp->sdf(what->buf, what->stride, | 542 thissad = vfp->sdf(what->buf, what->stride, |
544 get_buf_from_mv(in_what, &this_mv), | 543 get_buf_from_mv(in_what, &this_mv), |
545 in_what->stride, bestsad); | 544 in_what->stride); |
546 CHECK_BETTER | 545 CHECK_BETTER |
547 } | 546 } |
548 } else { | 547 } else { |
549 for (i = 0; i < num_candidates[t]; i++) { | 548 for (i = 0; i < num_candidates[t]; i++) { |
550 const MV this_mv = {br + candidates[t][i].row, | 549 const MV this_mv = {br + candidates[t][i].row, |
551 bc + candidates[t][i].col}; | 550 bc + candidates[t][i].col}; |
552 if (!is_mv_in(x, &this_mv)) | 551 if (!is_mv_in(x, &this_mv)) |
553 continue; | 552 continue; |
554 thissad = vfp->sdf(what->buf, what->stride, | 553 thissad = vfp->sdf(what->buf, what->stride, |
555 get_buf_from_mv(in_what, &this_mv), | 554 get_buf_from_mv(in_what, &this_mv), |
556 in_what->stride, bestsad); | 555 in_what->stride); |
557 CHECK_BETTER | 556 CHECK_BETTER |
558 } | 557 } |
559 } | 558 } |
560 if (best_site == -1) { | 559 if (best_site == -1) { |
561 continue; | 560 continue; |
562 } else { | 561 } else { |
563 best_init_s = t; | 562 best_init_s = t; |
564 k = best_site; | 563 k = best_site; |
565 } | 564 } |
566 } | 565 } |
(...skipping 11 matching lines...) Expand all Loading... |
578 | 577 |
579 do { | 578 do { |
580 // No need to search all 6 points the 1st time if initial search was used | 579 // No need to search all 6 points the 1st time if initial search was used |
581 if (!do_init_search || s != best_init_s) { | 580 if (!do_init_search || s != best_init_s) { |
582 if (check_bounds(x, br, bc, 1 << s)) { | 581 if (check_bounds(x, br, bc, 1 << s)) { |
583 for (i = 0; i < num_candidates[s]; i++) { | 582 for (i = 0; i < num_candidates[s]; i++) { |
584 const MV this_mv = {br + candidates[s][i].row, | 583 const MV this_mv = {br + candidates[s][i].row, |
585 bc + candidates[s][i].col}; | 584 bc + candidates[s][i].col}; |
586 thissad = vfp->sdf(what->buf, what->stride, | 585 thissad = vfp->sdf(what->buf, what->stride, |
587 get_buf_from_mv(in_what, &this_mv), | 586 get_buf_from_mv(in_what, &this_mv), |
588 in_what->stride, bestsad); | 587 in_what->stride); |
589 CHECK_BETTER | 588 CHECK_BETTER |
590 } | 589 } |
591 } else { | 590 } else { |
592 for (i = 0; i < num_candidates[s]; i++) { | 591 for (i = 0; i < num_candidates[s]; i++) { |
593 const MV this_mv = {br + candidates[s][i].row, | 592 const MV this_mv = {br + candidates[s][i].row, |
594 bc + candidates[s][i].col}; | 593 bc + candidates[s][i].col}; |
595 if (!is_mv_in(x, &this_mv)) | 594 if (!is_mv_in(x, &this_mv)) |
596 continue; | 595 continue; |
597 thissad = vfp->sdf(what->buf, what->stride, | 596 thissad = vfp->sdf(what->buf, what->stride, |
598 get_buf_from_mv(in_what, &this_mv), | 597 get_buf_from_mv(in_what, &this_mv), |
599 in_what->stride, bestsad); | 598 in_what->stride); |
600 CHECK_BETTER | 599 CHECK_BETTER |
601 } | 600 } |
602 } | 601 } |
603 | 602 |
604 if (best_site == -1) { | 603 if (best_site == -1) { |
605 continue; | 604 continue; |
606 } else { | 605 } else { |
607 br += candidates[s][best_site].row; | 606 br += candidates[s][best_site].row; |
608 bc += candidates[s][best_site].col; | 607 bc += candidates[s][best_site].col; |
609 k = best_site; | 608 k = best_site; |
610 } | 609 } |
611 } | 610 } |
612 | 611 |
613 do { | 612 do { |
614 int next_chkpts_indices[PATTERN_CANDIDATES_REF]; | 613 int next_chkpts_indices[PATTERN_CANDIDATES_REF]; |
615 best_site = -1; | 614 best_site = -1; |
616 next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1; | 615 next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1; |
617 next_chkpts_indices[1] = k; | 616 next_chkpts_indices[1] = k; |
618 next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1; | 617 next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1; |
619 | 618 |
620 if (check_bounds(x, br, bc, 1 << s)) { | 619 if (check_bounds(x, br, bc, 1 << s)) { |
621 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { | 620 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { |
622 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row, | 621 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row, |
623 bc + candidates[s][next_chkpts_indices[i]].col}; | 622 bc + candidates[s][next_chkpts_indices[i]].col}; |
624 thissad = vfp->sdf(what->buf, what->stride, | 623 thissad = vfp->sdf(what->buf, what->stride, |
625 get_buf_from_mv(in_what, &this_mv), | 624 get_buf_from_mv(in_what, &this_mv), |
626 in_what->stride, bestsad); | 625 in_what->stride); |
627 CHECK_BETTER | 626 CHECK_BETTER |
628 } | 627 } |
629 } else { | 628 } else { |
630 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { | 629 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { |
631 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row, | 630 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row, |
632 bc + candidates[s][next_chkpts_indices[i]].col}; | 631 bc + candidates[s][next_chkpts_indices[i]].col}; |
633 if (!is_mv_in(x, &this_mv)) | 632 if (!is_mv_in(x, &this_mv)) |
634 continue; | 633 continue; |
635 thissad = vfp->sdf(what->buf, what->stride, | 634 thissad = vfp->sdf(what->buf, what->stride, |
636 get_buf_from_mv(in_what, &this_mv), | 635 get_buf_from_mv(in_what, &this_mv), |
637 in_what->stride, bestsad); | 636 in_what->stride); |
638 CHECK_BETTER | 637 CHECK_BETTER |
639 } | 638 } |
640 } | 639 } |
641 | 640 |
642 if (best_site != -1) { | 641 if (best_site != -1) { |
643 k = next_chkpts_indices[best_site]; | 642 k = next_chkpts_indices[best_site]; |
644 br += candidates[s][k].row; | 643 br += candidates[s][k].row; |
645 bc += candidates[s][k].col; | 644 bc += candidates[s][k].col; |
646 } | 645 } |
647 } while (best_site != -1); | 646 } while (best_site != -1); |
648 } while (s--); | 647 } while (s--); |
649 } | 648 } |
650 | 649 |
651 // Check 4 1-away neighbors if do_refine is true. | 650 // Check 4 1-away neighbors if do_refine is true. |
652 // For most well-designed schemes do_refine will not be necessary. | 651 // For most well-designed schemes do_refine will not be necessary. |
653 if (do_refine) { | 652 if (do_refine) { |
654 static const MV neighbors[4] = {{0, -1}, { -1, 0}, {1, 0}, {0, 1}}; | 653 static const MV neighbors[4] = {{0, -1}, { -1, 0}, {1, 0}, {0, 1}}; |
655 | 654 |
656 for (j = 0; j < 16; j++) { | 655 for (j = 0; j < 16; j++) { |
657 int best_site = -1; | 656 int best_site = -1; |
658 if (check_bounds(x, br, bc, 1)) { | 657 if (check_bounds(x, br, bc, 1)) { |
659 for (i = 0; i < 4; i++) { | 658 for (i = 0; i < 4; i++) { |
660 const MV this_mv = {br + neighbors[i].row, | 659 const MV this_mv = {br + neighbors[i].row, |
661 bc + neighbors[i].col}; | 660 bc + neighbors[i].col}; |
662 thissad = vfp->sdf(what->buf, what->stride, | 661 thissad = vfp->sdf(what->buf, what->stride, |
663 get_buf_from_mv(in_what, &this_mv), | 662 get_buf_from_mv(in_what, &this_mv), |
664 in_what->stride, bestsad); | 663 in_what->stride); |
665 CHECK_BETTER | 664 CHECK_BETTER |
666 } | 665 } |
667 } else { | 666 } else { |
668 for (i = 0; i < 4; i++) { | 667 for (i = 0; i < 4; i++) { |
669 const MV this_mv = {br + neighbors[i].row, | 668 const MV this_mv = {br + neighbors[i].row, |
670 bc + neighbors[i].col}; | 669 bc + neighbors[i].col}; |
671 if (!is_mv_in(x, &this_mv)) | 670 if (!is_mv_in(x, &this_mv)) |
672 continue; | 671 continue; |
673 thissad = vfp->sdf(what->buf, what->stride, | 672 thissad = vfp->sdf(what->buf, what->stride, |
674 get_buf_from_mv(in_what, &this_mv), | 673 get_buf_from_mv(in_what, &this_mv), |
675 in_what->stride, bestsad); | 674 in_what->stride); |
676 CHECK_BETTER | 675 CHECK_BETTER |
677 } | 676 } |
678 } | 677 } |
679 | 678 |
680 if (best_site == -1) { | 679 if (best_site == -1) { |
681 break; | 680 break; |
682 } else { | 681 } else { |
683 br += neighbors[best_site].row; | 682 br += neighbors[best_site].row; |
684 bc += neighbors[best_site].col; | 683 bc += neighbors[best_site].col; |
685 } | 684 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 int start_col, end_col, start_row, end_row; | 886 int start_col, end_col, start_row, end_row; |
888 | 887 |
889 // The cfg and search_param parameters are not used in this search variant | 888 // The cfg and search_param parameters are not used in this search variant |
890 (void)cfg; | 889 (void)cfg; |
891 (void)search_param; | 890 (void)search_param; |
892 | 891 |
893 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); |
894 *best_mv = *ref_mv; | 893 *best_mv = *ref_mv; |
895 *num00 = 11; | 894 *num00 = 11; |
896 best_sad = fn_ptr->sdf(what->buf, what->stride, | 895 best_sad = fn_ptr->sdf(what->buf, what->stride, |
897 get_buf_from_mv(in_what, ref_mv), in_what->stride, | 896 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
898 0x7fffffff) + | |
899 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 897 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
900 start_row = MAX(-range, x->mv_row_min - ref_mv->row); | 898 start_row = MAX(-range, x->mv_row_min - ref_mv->row); |
901 start_col = MAX(-range, x->mv_col_min - ref_mv->col); | 899 start_col = MAX(-range, x->mv_col_min - ref_mv->col); |
902 end_row = MIN(range, x->mv_row_max - ref_mv->row); | 900 end_row = MIN(range, x->mv_row_max - ref_mv->row); |
903 end_col = MIN(range, x->mv_col_max - ref_mv->col); | 901 end_col = MIN(range, x->mv_col_max - ref_mv->col); |
904 | 902 |
905 for (r = start_row; r <= end_row; ++r) { | 903 for (r = start_row; r <= end_row; ++r) { |
906 for (c = start_col; c <= end_col; c += 4) { | 904 for (c = start_col; c <= end_col; c += 4) { |
907 if (c + 3 <= end_col) { | 905 if (c + 3 <= end_col) { |
908 unsigned int sads[4]; | 906 unsigned int sads[4]; |
(...skipping 13 matching lines...) Expand all Loading... |
922 if (sad < best_sad) { | 920 if (sad < best_sad) { |
923 best_sad = sad; | 921 best_sad = sad; |
924 *best_mv = mv; | 922 *best_mv = mv; |
925 } | 923 } |
926 } | 924 } |
927 } | 925 } |
928 } else { | 926 } else { |
929 for (i = 0; i < end_col - c; ++i) { | 927 for (i = 0; i < end_col - c; ++i) { |
930 const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; | 928 const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; |
931 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, | 929 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, |
932 get_buf_from_mv(in_what, &mv), in_what->stride, best_sad); | 930 get_buf_from_mv(in_what, &mv), in_what->stride); |
933 if (sad < best_sad) { | 931 if (sad < best_sad) { |
934 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | 932 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); |
935 if (sad < best_sad) { | 933 if (sad < best_sad) { |
936 best_sad = sad; | 934 best_sad = sad; |
937 *best_mv = mv; | 935 *best_mv = mv; |
938 } | 936 } |
939 } | 937 } |
940 } | 938 } |
941 } | 939 } |
942 } | 940 } |
(...skipping 25 matching lines...) Expand all Loading... |
968 int i, j, step; | 966 int i, j, step; |
969 | 967 |
970 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 968 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
971 in_what_ref = get_buf_from_mv(in_what, ref_mv); | 969 in_what_ref = get_buf_from_mv(in_what, ref_mv); |
972 best_address = in_what_ref; | 970 best_address = in_what_ref; |
973 *num00 = 0; | 971 *num00 = 0; |
974 *best_mv = *ref_mv; | 972 *best_mv = *ref_mv; |
975 | 973 |
976 // Check the starting position | 974 // Check the starting position |
977 best_sad = fn_ptr->sdf(what->buf, what->stride, | 975 best_sad = fn_ptr->sdf(what->buf, what->stride, |
978 best_address, in_what->stride, 0x7fffffff) + | 976 best_address, in_what->stride) + |
979 mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); | 977 mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); |
980 | 978 |
981 i = 1; | 979 i = 1; |
982 | 980 |
983 for (step = 0; step < tot_steps; step++) { | 981 for (step = 0; step < tot_steps; step++) { |
984 for (j = 0; j < cfg->searches_per_step; j++) { | 982 for (j = 0; j < cfg->searches_per_step; j++) { |
985 const MV mv = {best_mv->row + ss[i].mv.row, | 983 const MV mv = {best_mv->row + ss[i].mv.row, |
986 best_mv->col + ss[i].mv.col}; | 984 best_mv->col + ss[i].mv.col}; |
987 if (is_mv_in(x, &mv)) { | 985 if (is_mv_in(x, &mv)) { |
988 int sad = fn_ptr->sdf(what->buf, what->stride, | 986 int sad = fn_ptr->sdf(what->buf, what->stride, |
989 best_address + ss[i].offset, in_what->stride, | 987 best_address + ss[i].offset, in_what->stride); |
990 best_sad); | |
991 if (sad < best_sad) { | 988 if (sad < best_sad) { |
992 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | 989 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); |
993 if (sad < best_sad) { | 990 if (sad < best_sad) { |
994 best_sad = sad; | 991 best_sad = sad; |
995 best_site = i; | 992 best_site = i; |
996 } | 993 } |
997 } | 994 } |
998 } | 995 } |
999 | 996 |
1000 i++; | 997 i++; |
1001 } | 998 } |
1002 | 999 |
1003 if (best_site != last_site) { | 1000 if (best_site != last_site) { |
1004 best_mv->row += ss[best_site].mv.row; | 1001 best_mv->row += ss[best_site].mv.row; |
1005 best_mv->col += ss[best_site].mv.col; | 1002 best_mv->col += ss[best_site].mv.col; |
1006 best_address += ss[best_site].offset; | 1003 best_address += ss[best_site].offset; |
1007 last_site = best_site; | 1004 last_site = best_site; |
1008 #if defined(NEW_DIAMOND_SEARCH) | 1005 #if defined(NEW_DIAMOND_SEARCH) |
1009 while (1) { | 1006 while (1) { |
1010 const MV this_mv = {best_mv->row + ss[best_site].mv.row, | 1007 const MV this_mv = {best_mv->row + ss[best_site].mv.row, |
1011 best_mv->col + ss[best_site].mv.col}; | 1008 best_mv->col + ss[best_site].mv.col}; |
1012 if (is_mv_in(x, &this_mv)) { | 1009 if (is_mv_in(x, &this_mv)) { |
1013 int sad = fn_ptr->sdf(what->buf, what->stride, | 1010 int sad = fn_ptr->sdf(what->buf, what->stride, |
1014 best_address + ss[best_site].offset, | 1011 best_address + ss[best_site].offset, |
1015 in_what->stride, best_sad); | 1012 in_what->stride); |
1016 if (sad < best_sad) { | 1013 if (sad < best_sad) { |
1017 sad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); | 1014 sad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); |
1018 if (sad < best_sad) { | 1015 if (sad < best_sad) { |
1019 best_sad = sad; | 1016 best_sad = sad; |
1020 best_mv->row += ss[best_site].mv.row; | 1017 best_mv->row += ss[best_site].mv.row; |
1021 best_mv->col += ss[best_site].mv.col; | 1018 best_mv->col += ss[best_site].mv.col; |
1022 best_address += ss[best_site].offset; | 1019 best_address += ss[best_site].offset; |
1023 continue; | 1020 continue; |
1024 } | 1021 } |
1025 } | 1022 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 ref_col = ref_mv->col; | 1067 ref_col = ref_mv->col; |
1071 *num00 = 0; | 1068 *num00 = 0; |
1072 best_mv->row = ref_row; | 1069 best_mv->row = ref_row; |
1073 best_mv->col = ref_col; | 1070 best_mv->col = ref_col; |
1074 | 1071 |
1075 // Work out the start point for the search | 1072 // Work out the start point for the search |
1076 in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; | 1073 in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; |
1077 best_address = in_what; | 1074 best_address = in_what; |
1078 | 1075 |
1079 // Check the starting position | 1076 // Check the starting position |
1080 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) | 1077 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride) |
1081 + mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); | 1078 + mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); |
1082 | 1079 |
1083 i = 1; | 1080 i = 1; |
1084 | 1081 |
1085 for (step = 0; step < tot_steps; step++) { | 1082 for (step = 0; step < tot_steps; step++) { |
1086 int all_in = 1, t; | 1083 int all_in = 1, t; |
1087 | 1084 |
1088 // All_in is true if every one of the points we are checking are within | 1085 // All_in is true if every one of the points we are checking are within |
1089 // the bounds of the image. | 1086 // the bounds of the image. |
1090 all_in &= ((best_mv->row + ss[i].mv.row) > x->mv_row_min); | 1087 all_in &= ((best_mv->row + ss[i].mv.row) > x->mv_row_min); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 } | 1119 } |
1123 } else { | 1120 } else { |
1124 for (j = 0; j < cfg->searches_per_step; j++) { | 1121 for (j = 0; j < cfg->searches_per_step; j++) { |
1125 // Trap illegal vectors | 1122 // Trap illegal vectors |
1126 const MV this_mv = {best_mv->row + ss[i].mv.row, | 1123 const MV this_mv = {best_mv->row + ss[i].mv.row, |
1127 best_mv->col + ss[i].mv.col}; | 1124 best_mv->col + ss[i].mv.col}; |
1128 | 1125 |
1129 if (is_mv_in(x, &this_mv)) { | 1126 if (is_mv_in(x, &this_mv)) { |
1130 const uint8_t *const check_here = ss[i].offset + best_address; | 1127 const uint8_t *const check_here = ss[i].offset + best_address; |
1131 unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here, | 1128 unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here, |
1132 in_what_stride, bestsad); | 1129 in_what_stride); |
1133 | 1130 |
1134 if (thissad < bestsad) { | 1131 if (thissad < bestsad) { |
1135 thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); | 1132 thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); |
1136 if (thissad < bestsad) { | 1133 if (thissad < bestsad) { |
1137 bestsad = thissad; | 1134 bestsad = thissad; |
1138 best_site = i; | 1135 best_site = i; |
1139 } | 1136 } |
1140 } | 1137 } |
1141 } | 1138 } |
1142 i++; | 1139 i++; |
1143 } | 1140 } |
1144 } | 1141 } |
1145 if (best_site != last_site) { | 1142 if (best_site != last_site) { |
1146 best_mv->row += ss[best_site].mv.row; | 1143 best_mv->row += ss[best_site].mv.row; |
1147 best_mv->col += ss[best_site].mv.col; | 1144 best_mv->col += ss[best_site].mv.col; |
1148 best_address += ss[best_site].offset; | 1145 best_address += ss[best_site].offset; |
1149 last_site = best_site; | 1146 last_site = best_site; |
1150 #if defined(NEW_DIAMOND_SEARCH) | 1147 #if defined(NEW_DIAMOND_SEARCH) |
1151 while (1) { | 1148 while (1) { |
1152 const MV this_mv = {best_mv->row + ss[best_site].mv.row, | 1149 const MV this_mv = {best_mv->row + ss[best_site].mv.row, |
1153 best_mv->col + ss[best_site].mv.col}; | 1150 best_mv->col + ss[best_site].mv.col}; |
1154 if (is_mv_in(x, &this_mv)) { | 1151 if (is_mv_in(x, &this_mv)) { |
1155 const uint8_t *const check_here = ss[best_site].offset + best_address; | 1152 const uint8_t *const check_here = ss[best_site].offset + best_address; |
1156 unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here, | 1153 unsigned int thissad = fn_ptr->sdf(what, what_stride, check_here, |
1157 in_what_stride, bestsad); | 1154 in_what_stride); |
1158 if (thissad < bestsad) { | 1155 if (thissad < bestsad) { |
1159 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 1156 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, |
1160 mvjsadcost, mvsadcost, sad_per_bit); | 1157 mvjsadcost, mvsadcost, sad_per_bit); |
1161 if (thissad < bestsad) { | 1158 if (thissad < bestsad) { |
1162 bestsad = thissad; | 1159 bestsad = thissad; |
1163 best_mv->row += ss[best_site].mv.row; | 1160 best_mv->row += ss[best_site].mv.row; |
1164 best_mv->col += ss[best_site].mv.col; | 1161 best_mv->col += ss[best_site].mv.col; |
1165 best_address += ss[best_site].offset; | 1162 best_address += ss[best_site].offset; |
1166 continue; | 1163 continue; |
1167 } | 1164 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 int r, c; | 1243 int r, c; |
1247 const MACROBLOCKD *const xd = &x->e_mbd; | 1244 const MACROBLOCKD *const xd = &x->e_mbd; |
1248 const struct buf_2d *const what = &x->plane[0].src; | 1245 const struct buf_2d *const what = &x->plane[0].src; |
1249 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1246 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1250 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); | 1247 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
1251 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); | 1248 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
1252 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); | 1249 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
1253 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); | 1250 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
1254 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1251 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1255 int best_sad = fn_ptr->sdf(what->buf, what->stride, | 1252 int best_sad = fn_ptr->sdf(what->buf, what->stride, |
1256 get_buf_from_mv(in_what, ref_mv), in_what->stride, 0x7fffffff) + | 1253 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
1257 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 1254 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
1258 *best_mv = *ref_mv; | 1255 *best_mv = *ref_mv; |
1259 | 1256 |
1260 for (r = row_min; r < row_max; ++r) { | 1257 for (r = row_min; r < row_max; ++r) { |
1261 for (c = col_min; c < col_max; ++c) { | 1258 for (c = col_min; c < col_max; ++c) { |
1262 const MV mv = {r, c}; | 1259 const MV mv = {r, c}; |
1263 const int sad = fn_ptr->sdf(what->buf, what->stride, | 1260 const int sad = fn_ptr->sdf(what->buf, what->stride, |
1264 get_buf_from_mv(in_what, &mv), in_what->stride, best_sad) + | 1261 get_buf_from_mv(in_what, &mv), in_what->stride) + |
1265 mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | 1262 mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); |
1266 if (sad < best_sad) { | 1263 if (sad < best_sad) { |
1267 best_sad = sad; | 1264 best_sad = sad; |
1268 *best_mv = mv; | 1265 *best_mv = mv; |
1269 } | 1266 } |
1270 } | 1267 } |
1271 } | 1268 } |
1272 return best_sad; | 1269 return best_sad; |
1273 } | 1270 } |
1274 | 1271 |
1275 int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, | 1272 int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, |
1276 int sad_per_bit, int distance, | 1273 int sad_per_bit, int distance, |
1277 const vp9_variance_fn_ptr_t *fn_ptr, | 1274 const vp9_variance_fn_ptr_t *fn_ptr, |
1278 const MV *center_mv, MV *best_mv) { | 1275 const MV *center_mv, MV *best_mv) { |
1279 int r; | 1276 int r; |
1280 const MACROBLOCKD *const xd = &x->e_mbd; | 1277 const MACROBLOCKD *const xd = &x->e_mbd; |
1281 const struct buf_2d *const what = &x->plane[0].src; | 1278 const struct buf_2d *const what = &x->plane[0].src; |
1282 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1279 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1283 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); | 1280 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
1284 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); | 1281 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
1285 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); | 1282 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
1286 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); | 1283 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
1287 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1284 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1288 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, | 1285 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
1289 get_buf_from_mv(in_what, ref_mv), in_what->stride, 0x7fffffff) + | 1286 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
1290 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 1287 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
1291 *best_mv = *ref_mv; | 1288 *best_mv = *ref_mv; |
1292 | 1289 |
1293 for (r = row_min; r < row_max; ++r) { | 1290 for (r = row_min; r < row_max; ++r) { |
1294 int c = col_min; | 1291 int c = col_min; |
1295 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; | 1292 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; |
1296 | 1293 |
1297 if (fn_ptr->sdx3f != NULL) { | 1294 if (fn_ptr->sdx3f != NULL) { |
1298 while ((c + 2) < col_max) { | 1295 while ((c + 2) < col_max) { |
1299 int i; | 1296 int i; |
(...skipping 13 matching lines...) Expand all Loading... |
1313 } | 1310 } |
1314 } | 1311 } |
1315 ++check_here; | 1312 ++check_here; |
1316 ++c; | 1313 ++c; |
1317 } | 1314 } |
1318 } | 1315 } |
1319 } | 1316 } |
1320 | 1317 |
1321 while (c < col_max) { | 1318 while (c < col_max) { |
1322 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, | 1319 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, |
1323 check_here, in_what->stride, best_sad); | 1320 check_here, in_what->stride); |
1324 if (sad < best_sad) { | 1321 if (sad < best_sad) { |
1325 const MV mv = {r, c}; | 1322 const MV mv = {r, c}; |
1326 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | 1323 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); |
1327 if (sad < best_sad) { | 1324 if (sad < best_sad) { |
1328 best_sad = sad; | 1325 best_sad = sad; |
1329 *best_mv = mv; | 1326 *best_mv = mv; |
1330 } | 1327 } |
1331 } | 1328 } |
1332 ++check_here; | 1329 ++check_here; |
1333 ++c; | 1330 ++c; |
(...skipping 10 matching lines...) Expand all Loading... |
1344 int r; | 1341 int r; |
1345 const MACROBLOCKD *const xd = &x->e_mbd; | 1342 const MACROBLOCKD *const xd = &x->e_mbd; |
1346 const struct buf_2d *const what = &x->plane[0].src; | 1343 const struct buf_2d *const what = &x->plane[0].src; |
1347 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1344 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1348 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); | 1345 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); |
1349 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); | 1346 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); |
1350 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); | 1347 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); |
1351 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); | 1348 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); |
1352 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1349 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1353 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, | 1350 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
1354 get_buf_from_mv(in_what, ref_mv), in_what->stride, 0x7fffffff) + | 1351 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
1355 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 1352 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
1356 *best_mv = *ref_mv; | 1353 *best_mv = *ref_mv; |
1357 | 1354 |
1358 for (r = row_min; r < row_max; ++r) { | 1355 for (r = row_min; r < row_max; ++r) { |
1359 int c = col_min; | 1356 int c = col_min; |
1360 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; | 1357 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; |
1361 | 1358 |
1362 if (fn_ptr->sdx8f != NULL) { | 1359 if (fn_ptr->sdx8f != NULL) { |
1363 while ((c + 7) < col_max) { | 1360 while ((c + 7) < col_max) { |
1364 int i; | 1361 int i; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 } | 1399 } |
1403 } | 1400 } |
1404 ++check_here; | 1401 ++check_here; |
1405 ++c; | 1402 ++c; |
1406 } | 1403 } |
1407 } | 1404 } |
1408 } | 1405 } |
1409 | 1406 |
1410 while (c < col_max) { | 1407 while (c < col_max) { |
1411 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, | 1408 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, |
1412 check_here, in_what->stride, best_sad); | 1409 check_here, in_what->stride); |
1413 if (sad < best_sad) { | 1410 if (sad < best_sad) { |
1414 const MV mv = {r, c}; | 1411 const MV mv = {r, c}; |
1415 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | 1412 sad += mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); |
1416 if (sad < best_sad) { | 1413 if (sad < best_sad) { |
1417 best_sad = sad; | 1414 best_sad = sad; |
1418 *best_mv = mv; | 1415 *best_mv = mv; |
1419 } | 1416 } |
1420 } | 1417 } |
1421 ++check_here; | 1418 ++check_here; |
1422 ++c; | 1419 ++c; |
1423 } | 1420 } |
1424 } | 1421 } |
1425 | 1422 |
1426 return best_sad; | 1423 return best_sad; |
1427 } | 1424 } |
1428 | 1425 |
1429 int vp9_refining_search_sad_c(const MACROBLOCK *x, | 1426 int vp9_refining_search_sad_c(const MACROBLOCK *x, |
1430 MV *ref_mv, int error_per_bit, | 1427 MV *ref_mv, int error_per_bit, |
1431 int search_range, | 1428 int search_range, |
1432 const vp9_variance_fn_ptr_t *fn_ptr, | 1429 const vp9_variance_fn_ptr_t *fn_ptr, |
1433 const MV *center_mv) { | 1430 const MV *center_mv) { |
1434 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 1431 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; |
1435 const MACROBLOCKD *const xd = &x->e_mbd; | 1432 const MACROBLOCKD *const xd = &x->e_mbd; |
1436 const struct buf_2d *const what = &x->plane[0].src; | 1433 const struct buf_2d *const what = &x->plane[0].src; |
1437 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1434 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1438 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1435 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1439 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, | 1436 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
1440 get_buf_from_mv(in_what, ref_mv), | 1437 get_buf_from_mv(in_what, ref_mv), |
1441 in_what->stride, 0x7fffffff) + | 1438 in_what->stride) + |
1442 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); | 1439 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); |
1443 int i, j; | 1440 int i, j; |
1444 | 1441 |
1445 for (i = 0; i < search_range; i++) { | 1442 for (i = 0; i < search_range; i++) { |
1446 int best_site = -1; | 1443 int best_site = -1; |
1447 | 1444 |
1448 for (j = 0; j < 4; j++) { | 1445 for (j = 0; j < 4; j++) { |
1449 const MV mv = {ref_mv->row + neighbors[j].row, | 1446 const MV mv = {ref_mv->row + neighbors[j].row, |
1450 ref_mv->col + neighbors[j].col}; | 1447 ref_mv->col + neighbors[j].col}; |
1451 if (is_mv_in(x, &mv)) { | 1448 if (is_mv_in(x, &mv)) { |
1452 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, | 1449 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, |
1453 get_buf_from_mv(in_what, &mv), in_what->stride, best_sad); | 1450 get_buf_from_mv(in_what, &mv), in_what->stride); |
1454 if (sad < best_sad) { | 1451 if (sad < best_sad) { |
1455 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); | 1452 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); |
1456 if (sad < best_sad) { | 1453 if (sad < best_sad) { |
1457 best_sad = sad; | 1454 best_sad = sad; |
1458 best_site = j; | 1455 best_site = j; |
1459 } | 1456 } |
1460 } | 1457 } |
1461 } | 1458 } |
1462 } | 1459 } |
1463 | 1460 |
(...skipping 12 matching lines...) Expand all Loading... |
1476 int search_range, | 1473 int search_range, |
1477 const vp9_variance_fn_ptr_t *fn_ptr, | 1474 const vp9_variance_fn_ptr_t *fn_ptr, |
1478 const MV *center_mv) { | 1475 const MV *center_mv) { |
1479 const MACROBLOCKD *const xd = &x->e_mbd; | 1476 const MACROBLOCKD *const xd = &x->e_mbd; |
1480 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 1477 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; |
1481 const struct buf_2d *const what = &x->plane[0].src; | 1478 const struct buf_2d *const what = &x->plane[0].src; |
1482 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1479 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1483 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1480 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1484 const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv); | 1481 const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv); |
1485 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address, | 1482 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address, |
1486 in_what->stride, 0x7fffffff) + | 1483 in_what->stride) + |
1487 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); | 1484 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); |
1488 int i, j; | 1485 int i, j; |
1489 | 1486 |
1490 for (i = 0; i < search_range; i++) { | 1487 for (i = 0; i < search_range; i++) { |
1491 int best_site = -1; | 1488 int best_site = -1; |
1492 const int all_in = ((ref_mv->row - 1) > x->mv_row_min) & | 1489 const int all_in = ((ref_mv->row - 1) > x->mv_row_min) & |
1493 ((ref_mv->row + 1) < x->mv_row_max) & | 1490 ((ref_mv->row + 1) < x->mv_row_max) & |
1494 ((ref_mv->col - 1) > x->mv_col_min) & | 1491 ((ref_mv->col - 1) > x->mv_col_min) & |
1495 ((ref_mv->col + 1) < x->mv_col_max); | 1492 ((ref_mv->col + 1) < x->mv_col_max); |
1496 | 1493 |
(...skipping 20 matching lines...) Expand all Loading... |
1517 } | 1514 } |
1518 } | 1515 } |
1519 } else { | 1516 } else { |
1520 for (j = 0; j < 4; ++j) { | 1517 for (j = 0; j < 4; ++j) { |
1521 const MV mv = {ref_mv->row + neighbors[j].row, | 1518 const MV mv = {ref_mv->row + neighbors[j].row, |
1522 ref_mv->col + neighbors[j].col}; | 1519 ref_mv->col + neighbors[j].col}; |
1523 | 1520 |
1524 if (is_mv_in(x, &mv)) { | 1521 if (is_mv_in(x, &mv)) { |
1525 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, | 1522 unsigned int sad = fn_ptr->sdf(what->buf, what->stride, |
1526 get_buf_from_mv(in_what, &mv), | 1523 get_buf_from_mv(in_what, &mv), |
1527 in_what->stride, best_sad); | 1524 in_what->stride); |
1528 if (sad < best_sad) { | 1525 if (sad < best_sad) { |
1529 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); | 1526 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); |
1530 if (sad < best_sad) { | 1527 if (sad < best_sad) { |
1531 best_sad = sad; | 1528 best_sad = sad; |
1532 best_site = j; | 1529 best_site = j; |
1533 } | 1530 } |
1534 } | 1531 } |
1535 } | 1532 } |
1536 } | 1533 } |
1537 } | 1534 } |
(...skipping 18 matching lines...) Expand all Loading... |
1556 const vp9_variance_fn_ptr_t *fn_ptr, | 1553 const vp9_variance_fn_ptr_t *fn_ptr, |
1557 const MV *center_mv, | 1554 const MV *center_mv, |
1558 const uint8_t *second_pred) { | 1555 const uint8_t *second_pred) { |
1559 const MV neighbors[8] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, | 1556 const MV neighbors[8] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, |
1560 {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; | 1557 {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; |
1561 const MACROBLOCKD *const xd = &x->e_mbd; | 1558 const MACROBLOCKD *const xd = &x->e_mbd; |
1562 const struct buf_2d *const what = &x->plane[0].src; | 1559 const struct buf_2d *const what = &x->plane[0].src; |
1563 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1560 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1564 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1561 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1565 unsigned int best_sad = fn_ptr->sdaf(what->buf, what->stride, | 1562 unsigned int best_sad = fn_ptr->sdaf(what->buf, what->stride, |
1566 get_buf_from_mv(in_what, ref_mv), in_what->stride, | 1563 get_buf_from_mv(in_what, ref_mv), in_what->stride, second_pred) + |
1567 second_pred, 0x7fffffff) + | |
1568 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); | 1564 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); |
1569 int i, j; | 1565 int i, j; |
1570 | 1566 |
1571 for (i = 0; i < search_range; ++i) { | 1567 for (i = 0; i < search_range; ++i) { |
1572 int best_site = -1; | 1568 int best_site = -1; |
1573 | 1569 |
1574 for (j = 0; j < 8; ++j) { | 1570 for (j = 0; j < 8; ++j) { |
1575 const MV mv = {ref_mv->row + neighbors[j].row, | 1571 const MV mv = {ref_mv->row + neighbors[j].row, |
1576 ref_mv->col + neighbors[j].col}; | 1572 ref_mv->col + neighbors[j].col}; |
1577 | 1573 |
1578 if (is_mv_in(x, &mv)) { | 1574 if (is_mv_in(x, &mv)) { |
1579 unsigned int sad = fn_ptr->sdaf(what->buf, what->stride, | 1575 unsigned int sad = fn_ptr->sdaf(what->buf, what->stride, |
1580 get_buf_from_mv(in_what, &mv), in_what->stride, | 1576 get_buf_from_mv(in_what, &mv), in_what->stride, second_pred); |
1581 second_pred, best_sad); | |
1582 if (sad < best_sad) { | 1577 if (sad < best_sad) { |
1583 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); | 1578 sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); |
1584 if (sad < best_sad) { | 1579 if (sad < best_sad) { |
1585 best_sad = sad; | 1580 best_sad = sad; |
1586 best_site = j; | 1581 best_site = j; |
1587 } | 1582 } |
1588 } | 1583 } |
1589 } | 1584 } |
1590 } | 1585 } |
1591 | 1586 |
1592 if (best_site == -1) { | 1587 if (best_site == -1) { |
1593 break; | 1588 break; |
1594 } else { | 1589 } else { |
1595 ref_mv->row += neighbors[best_site].row; | 1590 ref_mv->row += neighbors[best_site].row; |
1596 ref_mv->col += neighbors[best_site].col; | 1591 ref_mv->col += neighbors[best_site].col; |
1597 } | 1592 } |
1598 } | 1593 } |
1599 return best_sad; | 1594 return best_sad; |
1600 } | 1595 } |
| 1596 |
| 1597 int vp9_full_pixel_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 1598 BLOCK_SIZE bsize, MV *mvp_full, |
| 1599 int step_param, int error_per_bit, |
| 1600 const MV *ref_mv, MV *tmp_mv, |
| 1601 int var_max, int rd) { |
| 1602 const SPEED_FEATURES *const sf = &cpi->sf; |
| 1603 const SEARCH_METHODS method = sf->mv.search_method; |
| 1604 vp9_variance_fn_ptr_t *fn_ptr = &cpi->fn_ptr[bsize]; |
| 1605 int var = 0; |
| 1606 |
| 1607 switch (method) { |
| 1608 case FAST_DIAMOND: |
| 1609 var = vp9_fast_dia_search(x, mvp_full, step_param, error_per_bit, 0, |
| 1610 fn_ptr, 1, ref_mv, tmp_mv); |
| 1611 break; |
| 1612 case FAST_HEX: |
| 1613 var = vp9_fast_hex_search(x, mvp_full, step_param, error_per_bit, 0, |
| 1614 fn_ptr, 1, ref_mv, tmp_mv); |
| 1615 break; |
| 1616 case HEX: |
| 1617 var = vp9_hex_search(x, mvp_full, step_param, error_per_bit, 1, |
| 1618 fn_ptr, 1, ref_mv, tmp_mv); |
| 1619 break; |
| 1620 case SQUARE: |
| 1621 var = vp9_square_search(x, mvp_full, step_param, error_per_bit, 1, |
| 1622 fn_ptr, 1, ref_mv, tmp_mv); |
| 1623 break; |
| 1624 case BIGDIA: |
| 1625 var = vp9_bigdia_search(x, mvp_full, step_param, error_per_bit, 1, |
| 1626 fn_ptr, 1, ref_mv, tmp_mv); |
| 1627 break; |
| 1628 case NSTEP: |
| 1629 var = vp9_full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit, |
| 1630 (sf->mv.max_step_search_steps - 1) - |
| 1631 step_param, |
| 1632 1, fn_ptr, ref_mv, tmp_mv); |
| 1633 break; |
| 1634 default: |
| 1635 assert(!"Invalid search method."); |
| 1636 } |
| 1637 |
| 1638 if (method != NSTEP && rd && var < var_max) |
| 1639 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); |
| 1640 |
| 1641 return var; |
| 1642 } |
OLD | NEW |