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

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

Issue 756673003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years 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_mcomp.h ('k') | source/libvpx/vp9/encoder/vp9_pickmode.h » ('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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 bestmv->row = br; 583 bestmv->row = br;
584 bestmv->col = bc; 584 bestmv->col = bc;
585 585
586 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || 586 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
587 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) 587 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
588 return INT_MAX; 588 return INT_MAX;
589 589
590 return besterr; 590 return besterr;
591 } 591 }
592 592
593 const MV search_step_table[12] = {
594 // left, right, up, down
595 {0, -4}, {0, 4}, {-4, 0}, {4, 0},
596 {0, -2}, {0, 2}, {-2, 0}, {2, 0},
597 {0, -1}, {0, 1}, {-1, 0}, {1, 0}
598 };
599
593 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, 600 int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x,
594 MV *bestmv, const MV *ref_mv, 601 MV *bestmv, const MV *ref_mv,
595 int allow_hp, 602 int allow_hp,
596 int error_per_bit, 603 int error_per_bit,
597 const vp9_variance_fn_ptr_t *vfp, 604 const vp9_variance_fn_ptr_t *vfp,
598 int forced_stop, 605 int forced_stop,
599 int iters_per_step, 606 int iters_per_step,
600 int *cost_list, 607 int *cost_list,
601 int *mvjcost, int *mvcost[2], 608 int *mvjcost, int *mvcost[2],
602 int *distortion, 609 int *distortion,
603 unsigned int *sse1, 610 unsigned int *sse1,
604 const uint8_t *second_pred, 611 const uint8_t *second_pred,
605 int w, int h) { 612 int w, int h) {
606 SETUP_SUBPEL_SEARCH; 613 const uint8_t *const z = x->plane[0].src.buf;
607 SETUP_CENTER_ERROR; 614 const uint8_t *const src_address = z;
615 const int src_stride = x->plane[0].src.stride;
616 const MACROBLOCKD *xd = &x->e_mbd;
617 unsigned int besterr = INT_MAX;
618 unsigned int sse;
619 unsigned int whichdir = 0;
620 int thismse;
621 const int y_stride = xd->plane[0].pre[0].stride;
622 const int offset = bestmv->row * y_stride + bestmv->col;
623 const uint8_t *const y = xd->plane[0].pre[0].buf;
624
625 int rr = ref_mv->row;
626 int rc = ref_mv->col;
627 int br = bestmv->row * 8;
628 int bc = bestmv->col * 8;
629 int hstep = 4;
630 int iter, round = 3 - forced_stop;
631 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
632 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
633 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
634 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
635 int tr = br;
636 int tc = bc;
637 const MV *search_step = search_step_table;
638 int idx, best_idx = -1;
639 unsigned int cost_array[5];
640
641 if (!(allow_hp && vp9_use_mv_hp(ref_mv)))
642 if (round == 3)
643 round = 2;
644
645 bestmv->row *= 8;
646 bestmv->col *= 8;
647
648 if (second_pred != NULL) {
649 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64);
650 vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride);
651 besterr = vfp->vf(comp_pred, w, src_address, src_stride, sse1);
652 } else {
653 besterr = vfp->vf(y + offset, y_stride, src_address, src_stride, sse1);
654 }
655 *distortion = besterr;
656 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
657
608 (void) cost_list; // to silence compiler warning 658 (void) cost_list; // to silence compiler warning
609 659
610 // Each subsequent iteration checks at least one point in 660 for (iter = 0; iter < round; ++iter) {
611 // common with the last iteration could be 2 ( if diag selected) 661 // Check vertical and horizontal sub-pixel positions.
612 // 1/2 pel 662 for (idx = 0; idx < 4; ++idx) {
613 FIRST_LEVEL_CHECKS; 663 tr = br + search_step[idx].row;
614 if (halfiters > 1) { 664 tc = bc + search_step[idx].col;
615 SECOND_LEVEL_CHECKS; 665 if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) {
666 const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3);
667 int row_offset = (tr & 0x07) << 1;
668 int col_offset = (tc & 0x07) << 1;
669 MV this_mv;
670 this_mv.row = tr;
671 this_mv.col = tc;
672 if (second_pred == NULL)
673 thismse = vfp->svf(pre_address, y_stride, col_offset, row_offset,
674 src_address, src_stride, &sse);
675 else
676 thismse = vfp->svaf(pre_address, y_stride, col_offset, row_offset,
677 src_address, src_stride, &sse, second_pred);
678 cost_array[idx] = thismse +
679 mv_err_cost(&this_mv, ref_mv, mvjcost, mvcost, error_per_bit);
680
681 if (cost_array[idx] < besterr) {
682 best_idx = idx;
683 besterr = cost_array[idx];
684 *distortion = thismse;
685 *sse1 = sse;
686 }
687 } else {
688 cost_array[idx] = INT_MAX;
689 }
690 }
691
692 // Check diagonal sub-pixel position
693 tc = bc + (cost_array[0] < cost_array[1] ? -hstep : hstep);
694 tr = br + (cost_array[2] < cost_array[3] ? -hstep : hstep);
695 if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) {
696 const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3);
697 int row_offset = (tr & 0x07) << 1;
698 int col_offset = (tc & 0x07) << 1;
699 MV this_mv = {tr, tc};
700 if (second_pred == NULL)
701 thismse = vfp->svf(pre_address, y_stride, col_offset, row_offset,
702 src_address, src_stride, &sse);
703 else
704 thismse = vfp->svaf(pre_address, y_stride, col_offset, row_offset,
705 src_address, src_stride, &sse, second_pred);
706 cost_array[4] = thismse +
707 mv_err_cost(&this_mv, ref_mv, mvjcost, mvcost, error_per_bit);
708
709 if (cost_array[4] < besterr) {
710 best_idx = 4;
711 besterr = cost_array[4];
712 *distortion = thismse;
713 *sse1 = sse;
714 }
715 } else {
716 cost_array[idx] = INT_MAX;
717 }
718
719 if (best_idx < 4 && best_idx >= 0) {
720 br += search_step[best_idx].row;
721 bc += search_step[best_idx].col;
722 } else if (best_idx == 4) {
723 br = tr;
724 bc = tc;
725 }
726
727 if (iters_per_step > 1)
728 SECOND_LEVEL_CHECKS;
729
730 tr = br;
731 tc = bc;
732
733 search_step += 4;
734 hstep >>= 1;
735 best_idx = -1;
616 } 736 }
617 tr = br;
618 tc = bc;
619 737
620 // Each subsequent iteration checks at least one point in common with 738 // Each subsequent iteration checks at least one point in common with
621 // the last iteration could be 2 ( if diag selected) 1/4 pel 739 // the last iteration could be 2 ( if diag selected) 1/4 pel
622 740
623 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only
624 if (forced_stop != 2) {
625 hstep >>= 1;
626 FIRST_LEVEL_CHECKS;
627 if (quarteriters > 1) {
628 SECOND_LEVEL_CHECKS;
629 }
630 tr = br;
631 tc = bc;
632 }
633
634 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) {
635 hstep >>= 1;
636 FIRST_LEVEL_CHECKS;
637 if (eighthiters > 1) {
638 SECOND_LEVEL_CHECKS;
639 }
640 tr = br;
641 tc = bc;
642 }
643 // These lines insure static analysis doesn't warn that 741 // These lines insure static analysis doesn't warn that
644 // tr and tc aren't used after the above point. 742 // tr and tc aren't used after the above point.
645 (void) tr; 743 (void) tr;
646 (void) tc; 744 (void) tc;
647 745
648 bestmv->row = br; 746 bestmv->row = br;
649 bestmv->col = bc; 747 bestmv->col = bc;
650 748
651 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || 749 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
652 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) 750 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 bestsme = thissme; 1745 bestsme = thissme;
1648 *dst_mv = temp_mv; 1746 *dst_mv = temp_mv;
1649 } 1747 }
1650 } 1748 }
1651 } 1749 }
1652 1750
1653 // final 1-away diamond refining search 1751 // final 1-away diamond refining search
1654 if (do_refine) { 1752 if (do_refine) {
1655 const int search_range = 8; 1753 const int search_range = 8;
1656 MV best_mv = *dst_mv; 1754 MV best_mv = *dst_mv;
1657 thissme = cpi->refining_search_sad(x, &best_mv, sadpb, search_range, 1755 thissme = vp9_refining_search_sad(x, &best_mv, sadpb, search_range,
1658 fn_ptr, ref_mv); 1756 fn_ptr, ref_mv);
1659 if (thissme < INT_MAX) 1757 if (thissme < INT_MAX)
1660 thissme = vp9_get_mvpred_var(x, &best_mv, ref_mv, fn_ptr, 1); 1758 thissme = vp9_get_mvpred_var(x, &best_mv, ref_mv, fn_ptr, 1);
1661 if (thissme < bestsme) { 1759 if (thissme < bestsme) {
1662 bestsme = thissme; 1760 bestsme = thissme;
1663 *dst_mv = best_mv; 1761 *dst_mv = best_mv;
1664 } 1762 }
1665 } 1763 }
1666 1764
1667 // Return cost list. 1765 // Return cost list.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 } 1949 }
1852 } 1950 }
1853 ++check_here; 1951 ++check_here;
1854 ++c; 1952 ++c;
1855 } 1953 }
1856 } 1954 }
1857 1955
1858 return best_sad; 1956 return best_sad;
1859 } 1957 }
1860 1958
1861 int vp9_refining_search_sad_c(const MACROBLOCK *x, 1959 int vp9_refining_search_sad(const MACROBLOCK *x,
1862 MV *ref_mv, int error_per_bit, 1960 MV *ref_mv, int error_per_bit,
1863 int search_range, 1961 int search_range,
1864 const vp9_variance_fn_ptr_t *fn_ptr, 1962 const vp9_variance_fn_ptr_t *fn_ptr,
1865 const MV *center_mv) { 1963 const MV *center_mv) {
1866 const MACROBLOCKD *const xd = &x->e_mbd; 1964 const MACROBLOCKD *const xd = &x->e_mbd;
1867 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; 1965 const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
1868 const struct buf_2d *const what = &x->plane[0].src; 1966 const struct buf_2d *const what = &x->plane[0].src;
1869 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; 1967 const struct buf_2d *const in_what = &xd->plane[0].pre[0];
1870 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; 1968 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};
1871 const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv); 1969 const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv);
1872 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address, 1970 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, best_address,
1873 in_what->stride) + 1971 in_what->stride) +
1874 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); 1972 mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit);
1875 int i, j; 1973 int i, j;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 break; 2128 break;
2031 default: 2129 default:
2032 assert(!"Invalid search method."); 2130 assert(!"Invalid search method.");
2033 } 2131 }
2034 2132
2035 if (method != NSTEP && rd && var < var_max) 2133 if (method != NSTEP && rd && var < var_max)
2036 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); 2134 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1);
2037 2135
2038 return var; 2136 return var;
2039 } 2137 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.h ('k') | source/libvpx/vp9/encoder/vp9_pickmode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698