Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_mcomp.c

Issue 592203002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mbgraph.c ('k') | source/libvpx/vp9/encoder/vp9_picklpf.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (sad_list && 313 if (sad_list &&
314 sad_list[0] != INT_MAX && sad_list[1] != INT_MAX && 314 sad_list[0] != INT_MAX && sad_list[1] != INT_MAX &&
315 sad_list[2] != INT_MAX && sad_list[3] != INT_MAX && 315 sad_list[2] != INT_MAX && sad_list[3] != INT_MAX &&
316 sad_list[4] != INT_MAX) { 316 sad_list[4] != INT_MAX) {
317 unsigned int left, right, up, down, diag; 317 unsigned int left, right, up, down, diag;
318 whichdir = (sad_list[1] < sad_list[3] ? 0 : 1) + 318 whichdir = (sad_list[1] < sad_list[3] ? 0 : 1) +
319 (sad_list[2] < sad_list[4] ? 0 : 2); 319 (sad_list[2] < sad_list[4] ? 0 : 2);
320 switch (whichdir) { 320 switch (whichdir) {
321 case 0: 321 case 0:
322 CHECK_BETTER(left, tr, tc - hstep); 322 CHECK_BETTER(left, tr, tc - hstep);
323 CHECK_BETTER(down, 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(down, tr + hstep, tc);
329 CHECK_BETTER(diag, tr + hstep, tc + hstep);
330 break;
331 case 2:
332 CHECK_BETTER(left, tr, tc - hstep);
323 CHECK_BETTER(up, tr - hstep, tc); 333 CHECK_BETTER(up, tr - hstep, tc);
324 CHECK_BETTER(diag, tr - hstep, tc - hstep); 334 CHECK_BETTER(diag, tr - hstep, tc - hstep);
325 break; 335 break;
326 case 1: 336 case 3:
327 CHECK_BETTER(right, tr, tc + hstep); 337 CHECK_BETTER(right, tr, tc + hstep);
328 CHECK_BETTER(up, tr - hstep, tc); 338 CHECK_BETTER(up, tr - hstep, tc);
329 CHECK_BETTER(diag, tr - hstep, tc + hstep); 339 CHECK_BETTER(diag, tr - hstep, tc + hstep);
330 break; 340 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 } 341 }
342 } else { 342 } else {
343 FIRST_LEVEL_CHECKS; 343 FIRST_LEVEL_CHECKS;
344 if (halfiters > 1) { 344 if (halfiters > 1) {
345 SECOND_LEVEL_CHECKS; 345 SECOND_LEVEL_CHECKS;
346 } 346 }
347 } 347 }
348 348
349 tr = br; 349 tr = br;
350 tc = bc; 350 tc = bc;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 br += candidates[s][k].row; 641 br += candidates[s][k].row;
642 bc += candidates[s][k].col; 642 bc += candidates[s][k].col;
643 } 643 }
644 } while (best_site != -1); 644 } while (best_site != -1);
645 } while (s--); 645 } while (s--);
646 } 646 }
647 647
648 // Returns the one-away integer pel sad values around the best as follows: 648 // Returns the one-away integer pel sad values around the best as follows:
649 // sad_list[0]: sad at the best integer pel 649 // sad_list[0]: sad at the best integer pel
650 // sad_list[1]: sad at delta {0, -1} (left) from the best integer pel 650 // sad_list[1]: sad at delta {0, -1} (left) from the best integer pel
651 // sad_list[2]: sad at delta {-1, 0} (top) from the best integer pel 651 // sad_list[2]: sad at delta { 1, 0} (bottom) from the best integer pel
652 // sad_list[3]: sad at delta { 0, 1} (right) from the best integer pel 652 // sad_list[3]: sad at delta { 0, 1} (right) from the best integer pel
653 // sad_list[4]: sad at delta { 1, 0} (bottom) from the best integer pel 653 // sad_list[4]: sad at delta {-1, 0} (top) from the best integer pel
654 if (sad_list) { 654 if (sad_list) {
655 static const MV neighbors[4] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; 655 static const MV neighbors[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
656 sad_list[0] = bestsad; 656 sad_list[0] = bestsad;
657 if (check_bounds(x, br, bc, 1)) { 657 if (check_bounds(x, br, bc, 1)) {
658 for (i = 0; i < 4; i++) { 658 for (i = 0; i < 4; i++) {
659 const MV this_mv = {br + neighbors[i].row, 659 const MV this_mv = {br + neighbors[i].row,
660 bc + neighbors[i].col}; 660 bc + neighbors[i].col};
661 sad_list[i + 1] = vfp->sdf(what->buf, what->stride, 661 sad_list[i + 1] = vfp->sdf(what->buf, what->stride,
662 get_buf_from_mv(in_what, &this_mv), 662 get_buf_from_mv(in_what, &this_mv),
663 in_what->stride); 663 in_what->stride) +
664 (use_mvcost ?
665 mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit) :
666 0);
664 } 667 }
665 } else { 668 } else {
666 for (i = 0; i < 4; i++) { 669 for (i = 0; i < 4; i++) {
667 const MV this_mv = {br + neighbors[i].row, 670 const MV this_mv = {br + neighbors[i].row,
668 bc + neighbors[i].col}; 671 bc + neighbors[i].col};
669 if (!is_mv_in(x, &this_mv)) 672 if (!is_mv_in(x, &this_mv))
670 sad_list[i + 1] = INT_MAX; 673 sad_list[i + 1] = INT_MAX;
671 else 674 else
672 sad_list[i + 1] = vfp->sdf(what->buf, what->stride, 675 sad_list[i + 1] = vfp->sdf(what->buf, what->stride,
673 get_buf_from_mv(in_what, &this_mv), 676 get_buf_from_mv(in_what, &this_mv),
677 in_what->stride) +
678 (use_mvcost ?
679 mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit) :
680 0);
681 }
682 }
683 }
684 best_mv->row = br;
685 best_mv->col = bc;
686 return bestsad;
687 }
688
689 // A specialized function where the smallest scale search candidates
690 // are 4 1-away neighbors, and sad_list is non-null
691 // TODO(debargha): Merge this function with the one above. Also remove
692 // use_mvcost option since it is always 1, to save unnecessary branches.
693 static int vp9_pattern_search_sad(const MACROBLOCK *x,
694 MV *ref_mv,
695 int search_param,
696 int sad_per_bit,
697 int do_init_search,
698 int *sad_list,
699 const vp9_variance_fn_ptr_t *vfp,
700 int use_mvcost,
701 const MV *center_mv,
702 MV *best_mv,
703 const int num_candidates[MAX_PATTERN_SCALES],
704 const MV candidates[MAX_PATTERN_SCALES]
705 [MAX_PATTERN_CANDIDATES]) {
706 const MACROBLOCKD *const xd = &x->e_mbd;
707 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = {
708 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
709 };
710 int i, s, t;
711 const struct buf_2d *const what = &x->plane[0].src;
712 const struct buf_2d *const in_what = &xd->plane[0].pre[0];
713 int br, bc;
714 int bestsad = INT_MAX;
715 int thissad;
716 int k = -1;
717 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
718 int best_init_s = search_param_to_steps[search_param];
719 // adjust ref_mv to make sure it is within MV range
720 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
721 br = ref_mv->row;
722 bc = ref_mv->col;
723 if (sad_list != NULL) {
724 sad_list[0] = sad_list[1] = sad_list[2] = sad_list[3] = sad_list[4] =
725 INT_MAX;
726 }
727
728 // Work out the start point for the search
729 bestsad = vfp->sdf(what->buf, what->stride,
730 get_buf_from_mv(in_what, ref_mv), in_what->stride) +
731 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit);
732
733 // Search all possible scales upto the search param around the center point
734 // pick the scale of the point that is best as the starting scale of
735 // further steps around it.
736 if (do_init_search) {
737 s = best_init_s;
738 best_init_s = -1;
739 for (t = 0; t <= s; ++t) {
740 int best_site = -1;
741 if (check_bounds(x, br, bc, 1 << t)) {
742 for (i = 0; i < num_candidates[t]; i++) {
743 const MV this_mv = {br + candidates[t][i].row,
744 bc + candidates[t][i].col};
745 thissad = vfp->sdf(what->buf, what->stride,
746 get_buf_from_mv(in_what, &this_mv),
747 in_what->stride);
748 CHECK_BETTER
749 }
750 } else {
751 for (i = 0; i < num_candidates[t]; i++) {
752 const MV this_mv = {br + candidates[t][i].row,
753 bc + candidates[t][i].col};
754 if (!is_mv_in(x, &this_mv))
755 continue;
756 thissad = vfp->sdf(what->buf, what->stride,
757 get_buf_from_mv(in_what, &this_mv),
758 in_what->stride);
759 CHECK_BETTER
760 }
761 }
762 if (best_site == -1) {
763 continue;
764 } else {
765 best_init_s = t;
766 k = best_site;
767 }
768 }
769 if (best_init_s != -1) {
770 br += candidates[best_init_s][k].row;
771 bc += candidates[best_init_s][k].col;
772 }
773 }
774
775 // If the center point is still the best, just skip this and move to
776 // the refinement step.
777 if (best_init_s != -1) {
778 int do_sad = (num_candidates[0] == 4 && sad_list != NULL);
779 int best_site = -1;
780 s = best_init_s;
781
782 for (; s >= do_sad; s--) {
783 if (!do_init_search || s != best_init_s) {
784 if (check_bounds(x, br, bc, 1 << s)) {
785 for (i = 0; i < num_candidates[s]; i++) {
786 const MV this_mv = {br + candidates[s][i].row,
787 bc + candidates[s][i].col};
788 thissad = vfp->sdf(what->buf, what->stride,
789 get_buf_from_mv(in_what, &this_mv),
790 in_what->stride);
791 CHECK_BETTER
792 }
793 } else {
794 for (i = 0; i < num_candidates[s]; i++) {
795 const MV this_mv = {br + candidates[s][i].row,
796 bc + candidates[s][i].col};
797 if (!is_mv_in(x, &this_mv))
798 continue;
799 thissad = vfp->sdf(what->buf, what->stride,
800 get_buf_from_mv(in_what, &this_mv),
801 in_what->stride);
802 CHECK_BETTER
803 }
804 }
805
806 if (best_site == -1) {
807 continue;
808 } else {
809 br += candidates[s][best_site].row;
810 bc += candidates[s][best_site].col;
811 k = best_site;
812 }
813 }
814
815 do {
816 int next_chkpts_indices[PATTERN_CANDIDATES_REF];
817 best_site = -1;
818 next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1;
819 next_chkpts_indices[1] = k;
820 next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
821
822 if (check_bounds(x, br, bc, 1 << s)) {
823 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
824 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
825 bc + candidates[s][next_chkpts_indices[i]].col};
826 thissad = vfp->sdf(what->buf, what->stride,
827 get_buf_from_mv(in_what, &this_mv),
828 in_what->stride);
829 CHECK_BETTER
830 }
831 } else {
832 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
833 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
834 bc + candidates[s][next_chkpts_indices[i]].col};
835 if (!is_mv_in(x, &this_mv))
836 continue;
837 thissad = vfp->sdf(what->buf, what->stride,
838 get_buf_from_mv(in_what, &this_mv),
839 in_what->stride);
840 CHECK_BETTER
841 }
842 }
843
844 if (best_site != -1) {
845 k = next_chkpts_indices[best_site];
846 br += candidates[s][k].row;
847 bc += candidates[s][k].col;
848 }
849 } while (best_site != -1);
850 }
851
852 // Note: If we enter the if below, then sad_list must be non-NULL.
853 if (s == 0) {
854 sad_list[0] = bestsad;
855 if (!do_init_search || s != best_init_s) {
856 if (check_bounds(x, br, bc, 1 << s)) {
857 for (i = 0; i < num_candidates[s]; i++) {
858 const MV this_mv = {br + candidates[s][i].row,
859 bc + candidates[s][i].col};
860 sad_list[i + 1] =
861 thissad = vfp->sdf(what->buf, what->stride,
862 get_buf_from_mv(in_what, &this_mv),
863 in_what->stride);
864 CHECK_BETTER
865 }
866 } else {
867 for (i = 0; i < num_candidates[s]; i++) {
868 const MV this_mv = {br + candidates[s][i].row,
869 bc + candidates[s][i].col};
870 if (!is_mv_in(x, &this_mv))
871 continue;
872 sad_list[i + 1] =
873 thissad = vfp->sdf(what->buf, what->stride,
874 get_buf_from_mv(in_what, &this_mv),
875 in_what->stride);
876 CHECK_BETTER
877 }
878 }
879
880 if (best_site != -1) {
881 br += candidates[s][best_site].row;
882 bc += candidates[s][best_site].col;
883 k = best_site;
884 }
885 }
886 while (best_site != -1) {
887 int next_chkpts_indices[PATTERN_CANDIDATES_REF];
888 best_site = -1;
889 next_chkpts_indices[0] = (k == 0) ? num_candidates[s] - 1 : k - 1;
890 next_chkpts_indices[1] = k;
891 next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
892 sad_list[1] = sad_list[2] = sad_list[3] = sad_list[4] = INT_MAX;
893 sad_list[((k + 2) % 4) + 1] = sad_list[0];
894 sad_list[0] = bestsad;
895
896 if (check_bounds(x, br, bc, 1 << s)) {
897 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
898 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
899 bc + candidates[s][next_chkpts_indices[i]].col};
900 sad_list[next_chkpts_indices[i] + 1] =
901 thissad = vfp->sdf(what->buf, what->stride,
902 get_buf_from_mv(in_what, &this_mv),
903 in_what->stride);
904 CHECK_BETTER
905 }
906 } else {
907 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
908 const MV this_mv = {br + candidates[s][next_chkpts_indices[i]].row,
909 bc + candidates[s][next_chkpts_indices[i]].col};
910 if (!is_mv_in(x, &this_mv)) {
911 sad_list[next_chkpts_indices[i] + 1] = INT_MAX;
912 continue;
913 }
914 sad_list[next_chkpts_indices[i] + 1] =
915 thissad = vfp->sdf(what->buf, what->stride,
916 get_buf_from_mv(in_what, &this_mv),
917 in_what->stride);
918 CHECK_BETTER
919 }
920 }
921
922 if (best_site != -1) {
923 k = next_chkpts_indices[best_site];
924 br += candidates[s][k].row;
925 bc += candidates[s][k].col;
926 }
927 }
928 }
929 }
930
931 // Returns the one-away integer pel sad values around the best as follows:
932 // sad_list[0]: sad at the best integer pel
933 // sad_list[1]: sad at delta {0, -1} (left) from the best integer pel
934 // sad_list[2]: sad at delta { 1, 0} (bottom) from the best integer pel
935 // sad_list[3]: sad at delta { 0, 1} (right) from the best integer pel
936 // sad_list[4]: sad at delta {-1, 0} (top) from the best integer pel
937 if (sad_list) {
938 static const MV neighbors[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
939 if (sad_list[0] == INT_MAX) {
940 sad_list[0] = bestsad;
941 if (check_bounds(x, br, bc, 1)) {
942 for (i = 0; i < 4; i++) {
943 const MV this_mv = {br + neighbors[i].row,
944 bc + neighbors[i].col};
945 sad_list[i + 1] = vfp->sdf(what->buf, what->stride,
946 get_buf_from_mv(in_what, &this_mv),
674 in_what->stride); 947 in_what->stride);
948 }
949 } else {
950 for (i = 0; i < 4; i++) {
951 const MV this_mv = {br + neighbors[i].row,
952 bc + neighbors[i].col};
953 if (!is_mv_in(x, &this_mv))
954 sad_list[i + 1] = INT_MAX;
955 else
956 sad_list[i + 1] = vfp->sdf(what->buf, what->stride,
957 get_buf_from_mv(in_what, &this_mv),
958 in_what->stride);
959 }
960 }
961 } else {
962 if (use_mvcost) {
963 for (i = 0; i < 4; i++) {
964 const MV this_mv = {br + neighbors[i].row,
965 bc + neighbors[i].col};
966 if (sad_list[i + 1] != INT_MAX) {
967 sad_list[i + 1] +=
968 mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit);
969 }
970 }
675 } 971 }
676 } 972 }
677 } 973 }
678 best_mv->row = br; 974 best_mv->row = br;
679 best_mv->col = bc; 975 best_mv->col = bc;
680 return bestsad; 976 return bestsad;
681 } 977 }
682 978
683 int vp9_get_mvpred_var(const MACROBLOCK *x, 979 int vp9_get_mvpred_var(const MACROBLOCK *x,
684 const MV *best_mv, const MV *center_mv, 980 const MV *best_mv, const MV *center_mv,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 {-32, 32}, {-64, 0}}, 1073 {-32, 32}, {-64, 0}},
778 {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128}, 1074 {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128},
779 {-64, 64}, {-128, 0}}, 1075 {-64, 64}, {-128, 0}},
780 {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256}, 1076 {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256},
781 {-128, 128}, {-256, 0}}, 1077 {-128, 128}, {-256, 0}},
782 {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512}, 1078 {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512},
783 {-256, 256}, {-512, 0}}, 1079 {-256, 256}, {-512, 0}},
784 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024}, 1080 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024},
785 {-512, 512}, {-1024, 0}}, 1081 {-512, 512}, {-1024, 0}},
786 }; 1082 };
787 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, 1083 return vp9_pattern_search_sad(x, ref_mv, search_param, sad_per_bit,
788 do_init_search, sad_list, vfp, use_mvcost, 1084 do_init_search, sad_list, vfp, use_mvcost,
789 center_mv, best_mv, 1085 center_mv, best_mv,
790 bigdia_num_candidates, bigdia_candidates); 1086 bigdia_num_candidates, bigdia_candidates);
791 } 1087 }
792 1088
793 int vp9_square_search(const MACROBLOCK *x, 1089 int vp9_square_search(const MACROBLOCK *x,
794 MV *ref_mv, 1090 MV *ref_mv,
795 int search_param, 1091 int search_param,
796 int sad_per_bit, 1092 int sad_per_bit,
797 int do_init_search, 1093 int do_init_search,
798 int *sad_list, 1094 int *sad_list,
799 const vp9_variance_fn_ptr_t *vfp, 1095 const vp9_variance_fn_ptr_t *vfp,
800 int use_mvcost, 1096 int use_mvcost,
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 break; 1796 break;
1501 default: 1797 default:
1502 assert(!"Invalid search method."); 1798 assert(!"Invalid search method.");
1503 } 1799 }
1504 1800
1505 if (method != NSTEP && rd && var < var_max) 1801 if (method != NSTEP && rd && var < var_max)
1506 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); 1802 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1);
1507 1803
1508 return var; 1804 return var;
1509 } 1805 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mbgraph.c ('k') | source/libvpx/vp9/encoder/vp9_picklpf.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698