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 19 matching lines...) Expand all Loading... |
30 const MV *mv) { | 30 const MV *mv) { |
31 return &buf->buf[mv->row * buf->stride + mv->col]; | 31 return &buf->buf[mv->row * buf->stride + mv->col]; |
32 } | 32 } |
33 | 33 |
34 void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv) { | 34 void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv) { |
35 int col_min = (mv->col >> 3) - MAX_FULL_PEL_VAL + (mv->col & 7 ? 1 : 0); | 35 int col_min = (mv->col >> 3) - MAX_FULL_PEL_VAL + (mv->col & 7 ? 1 : 0); |
36 int row_min = (mv->row >> 3) - MAX_FULL_PEL_VAL + (mv->row & 7 ? 1 : 0); | 36 int row_min = (mv->row >> 3) - MAX_FULL_PEL_VAL + (mv->row & 7 ? 1 : 0); |
37 int col_max = (mv->col >> 3) + MAX_FULL_PEL_VAL; | 37 int col_max = (mv->col >> 3) + MAX_FULL_PEL_VAL; |
38 int row_max = (mv->row >> 3) + MAX_FULL_PEL_VAL; | 38 int row_max = (mv->row >> 3) + MAX_FULL_PEL_VAL; |
39 | 39 |
40 col_min = MAX(col_min, (MV_LOW >> 3) + 1); | 40 col_min = VPXMAX(col_min, (MV_LOW >> 3) + 1); |
41 row_min = MAX(row_min, (MV_LOW >> 3) + 1); | 41 row_min = VPXMAX(row_min, (MV_LOW >> 3) + 1); |
42 col_max = MIN(col_max, (MV_UPP >> 3) - 1); | 42 col_max = VPXMIN(col_max, (MV_UPP >> 3) - 1); |
43 row_max = MIN(row_max, (MV_UPP >> 3) - 1); | 43 row_max = VPXMIN(row_max, (MV_UPP >> 3) - 1); |
44 | 44 |
45 // Get intersection of UMV window and valid MV window to reduce # of checks | 45 // Get intersection of UMV window and valid MV window to reduce # of checks |
46 // in diamond search. | 46 // in diamond search. |
47 if (x->mv_col_min < col_min) | 47 if (x->mv_col_min < col_min) |
48 x->mv_col_min = col_min; | 48 x->mv_col_min = col_min; |
49 if (x->mv_col_max > col_max) | 49 if (x->mv_col_max > col_max) |
50 x->mv_col_max = col_max; | 50 x->mv_col_max = col_max; |
51 if (x->mv_row_min < row_min) | 51 if (x->mv_row_min < row_min) |
52 x->mv_row_min = row_min; | 52 x->mv_row_min = row_min; |
53 if (x->mv_row_max > row_max) | 53 if (x->mv_row_max > row_max) |
54 x->mv_row_max = row_max; | 54 x->mv_row_max = row_max; |
55 } | 55 } |
56 | 56 |
57 int vp9_init_search_range(int size) { | 57 int vp9_init_search_range(int size) { |
58 int sr = 0; | 58 int sr = 0; |
59 // Minimum search size no matter what the passed in value. | 59 // Minimum search size no matter what the passed in value. |
60 size = MAX(16, size); | 60 size = VPXMAX(16, size); |
61 | 61 |
62 while ((size << sr) < MAX_FULL_PEL_VAL) | 62 while ((size << sr) < MAX_FULL_PEL_VAL) |
63 sr++; | 63 sr++; |
64 | 64 |
65 sr = MIN(sr, MAX_MVSEARCH_STEPS - 2); | 65 sr = VPXMIN(sr, MAX_MVSEARCH_STEPS - 2); |
66 return sr; | 66 return sr; |
67 } | 67 } |
68 | 68 |
69 static INLINE int mv_cost(const MV *mv, | 69 static INLINE int mv_cost(const MV *mv, |
70 const int *joint_cost, int *const comp_cost[2]) { | 70 const int *joint_cost, int *const comp_cost[2]) { |
71 return joint_cost[vp9_get_mv_joint(mv)] + | 71 return joint_cost[vp9_get_mv_joint(mv)] + |
72 comp_cost[0][mv->row] + comp_cost[1][mv->col]; | 72 comp_cost[0][mv->row] + comp_cost[1][mv->col]; |
73 } | 73 } |
74 | 74 |
75 int vp9_mv_bit_cost(const MV *mv, const MV *ref, | 75 int vp9_mv_bit_cost(const MV *mv, const MV *ref, |
(...skipping 173 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 // TODO(yunqingwang): SECOND_LEVEL_CHECKS_BEST was a rewrote of |
| 260 // SECOND_LEVEL_CHECKS, and SECOND_LEVEL_CHECKS should be rewritten |
| 261 // later in the same way. |
| 262 #define SECOND_LEVEL_CHECKS_BEST \ |
| 263 { \ |
| 264 unsigned int second; \ |
| 265 int br0 = br; \ |
| 266 int bc0 = bc; \ |
| 267 assert(tr == br || tc == bc); \ |
| 268 if (tr == br && tc != bc) { \ |
| 269 kc = bc - tc; \ |
| 270 } else if (tr != br && tc == bc) { \ |
| 271 kr = br - tr; \ |
| 272 } \ |
| 273 CHECK_BETTER(second, br0 + kr, bc0); \ |
| 274 CHECK_BETTER(second, br0, bc0 + kc); \ |
| 275 if (br0 != br || bc0 != bc) { \ |
| 276 CHECK_BETTER(second, br0 + kr, bc0 + kc); \ |
| 277 } \ |
| 278 } |
| 279 |
259 #define SETUP_SUBPEL_SEARCH \ | 280 #define SETUP_SUBPEL_SEARCH \ |
260 const uint8_t *const z = x->plane[0].src.buf; \ | 281 const uint8_t *const z = x->plane[0].src.buf; \ |
261 const int src_stride = x->plane[0].src.stride; \ | 282 const int src_stride = x->plane[0].src.stride; \ |
262 const MACROBLOCKD *xd = &x->e_mbd; \ | 283 const MACROBLOCKD *xd = &x->e_mbd; \ |
263 unsigned int besterr = INT_MAX; \ | 284 unsigned int besterr = INT_MAX; \ |
264 unsigned int sse; \ | 285 unsigned int sse; \ |
265 unsigned int whichdir; \ | 286 unsigned int whichdir; \ |
266 int thismse; \ | 287 int thismse; \ |
267 const unsigned int halfiters = iters_per_step; \ | 288 const unsigned int halfiters = iters_per_step; \ |
268 const unsigned int quarteriters = iters_per_step; \ | 289 const unsigned int quarteriters = iters_per_step; \ |
269 const unsigned int eighthiters = iters_per_step; \ | 290 const unsigned int eighthiters = iters_per_step; \ |
270 const int y_stride = xd->plane[0].pre[0].stride; \ | 291 const int y_stride = xd->plane[0].pre[0].stride; \ |
271 const int offset = bestmv->row * y_stride + bestmv->col; \ | 292 const int offset = bestmv->row * y_stride + bestmv->col; \ |
272 const uint8_t *const y = xd->plane[0].pre[0].buf; \ | 293 const uint8_t *const y = xd->plane[0].pre[0].buf; \ |
273 \ | 294 \ |
274 int rr = ref_mv->row; \ | 295 int rr = ref_mv->row; \ |
275 int rc = ref_mv->col; \ | 296 int rc = ref_mv->col; \ |
276 int br = bestmv->row * 8; \ | 297 int br = bestmv->row * 8; \ |
277 int bc = bestmv->col * 8; \ | 298 int bc = bestmv->col * 8; \ |
278 int hstep = 4; \ | 299 int hstep = 4; \ |
279 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \ | 300 const int minc = VPXMAX(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); \ | 301 const int maxc = VPXMIN(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); \ | 302 const int minr = VPXMAX(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); \ | 303 const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \ |
283 int tr = br; \ | 304 int tr = br; \ |
284 int tc = bc; \ | 305 int tc = bc; \ |
285 \ | 306 \ |
286 bestmv->row *= 8; \ | 307 bestmv->row *= 8; \ |
287 bestmv->col *= 8; | 308 bestmv->col *= 8; |
288 | 309 |
289 static unsigned int setup_center_error(const MACROBLOCKD *xd, | 310 static unsigned int setup_center_error(const MACROBLOCKD *xd, |
290 const MV *bestmv, | 311 const MV *bestmv, |
291 const MV *ref_mv, | 312 const MV *ref_mv, |
292 int error_per_bit, | 313 int error_per_bit, |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 int *distortion, | 650 int *distortion, |
630 unsigned int *sse1, | 651 unsigned int *sse1, |
631 const uint8_t *second_pred, | 652 const uint8_t *second_pred, |
632 int w, int h) { | 653 int w, int h) { |
633 const uint8_t *const z = x->plane[0].src.buf; | 654 const uint8_t *const z = x->plane[0].src.buf; |
634 const uint8_t *const src_address = z; | 655 const uint8_t *const src_address = z; |
635 const int src_stride = x->plane[0].src.stride; | 656 const int src_stride = x->plane[0].src.stride; |
636 const MACROBLOCKD *xd = &x->e_mbd; | 657 const MACROBLOCKD *xd = &x->e_mbd; |
637 unsigned int besterr = INT_MAX; | 658 unsigned int besterr = INT_MAX; |
638 unsigned int sse; | 659 unsigned int sse; |
639 unsigned int whichdir = 0; | |
640 int thismse; | 660 int thismse; |
641 const int y_stride = xd->plane[0].pre[0].stride; | 661 const int y_stride = xd->plane[0].pre[0].stride; |
642 const int offset = bestmv->row * y_stride + bestmv->col; | 662 const int offset = bestmv->row * y_stride + bestmv->col; |
643 const uint8_t *const y = xd->plane[0].pre[0].buf; | 663 const uint8_t *const y = xd->plane[0].pre[0].buf; |
644 | 664 |
645 int rr = ref_mv->row; | 665 int rr = ref_mv->row; |
646 int rc = ref_mv->col; | 666 int rc = ref_mv->col; |
647 int br = bestmv->row * 8; | 667 int br = bestmv->row * 8; |
648 int bc = bestmv->col * 8; | 668 int bc = bestmv->col * 8; |
649 int hstep = 4; | 669 int hstep = 4; |
650 int iter, round = 3 - forced_stop; | 670 int iter, round = 3 - forced_stop; |
651 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); | 671 const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); |
652 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); | 672 const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); |
653 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); | 673 const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); |
654 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); | 674 const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); |
655 int tr = br; | 675 int tr = br; |
656 int tc = bc; | 676 int tc = bc; |
657 const MV *search_step = search_step_table; | 677 const MV *search_step = search_step_table; |
658 int idx, best_idx = -1; | 678 int idx, best_idx = -1; |
659 unsigned int cost_array[5]; | 679 unsigned int cost_array[5]; |
| 680 int kr, kc; |
660 | 681 |
661 if (!(allow_hp && vp9_use_mv_hp(ref_mv))) | 682 if (!(allow_hp && vp9_use_mv_hp(ref_mv))) |
662 if (round == 3) | 683 if (round == 3) |
663 round = 2; | 684 round = 2; |
664 | 685 |
665 bestmv->row *= 8; | 686 bestmv->row *= 8; |
666 bestmv->col *= 8; | 687 bestmv->col *= 8; |
667 | 688 |
668 besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp, | 689 besterr = setup_center_error(xd, bestmv, ref_mv, error_per_bit, vfp, |
669 z, src_stride, y, y_stride, second_pred, | 690 z, src_stride, y, y_stride, second_pred, |
(...skipping 26 matching lines...) Expand all Loading... |
696 besterr = cost_array[idx]; | 717 besterr = cost_array[idx]; |
697 *distortion = thismse; | 718 *distortion = thismse; |
698 *sse1 = sse; | 719 *sse1 = sse; |
699 } | 720 } |
700 } else { | 721 } else { |
701 cost_array[idx] = INT_MAX; | 722 cost_array[idx] = INT_MAX; |
702 } | 723 } |
703 } | 724 } |
704 | 725 |
705 // Check diagonal sub-pixel position | 726 // Check diagonal sub-pixel position |
706 tc = bc + (cost_array[0] < cost_array[1] ? -hstep : hstep); | 727 kc = (cost_array[0] <= cost_array[1] ? -hstep : hstep); |
707 tr = br + (cost_array[2] < cost_array[3] ? -hstep : hstep); | 728 kr = (cost_array[2] <= cost_array[3] ? -hstep : hstep); |
| 729 |
| 730 tc = bc + kc; |
| 731 tr = br + kr; |
708 if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) { | 732 if (tc >= minc && tc <= maxc && tr >= minr && tr <= maxr) { |
709 const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3); | 733 const uint8_t *const pre_address = y + (tr >> 3) * y_stride + (tc >> 3); |
710 MV this_mv = {tr, tc}; | 734 MV this_mv = {tr, tc}; |
711 if (second_pred == NULL) | 735 if (second_pred == NULL) |
712 thismse = vfp->svf(pre_address, y_stride, sp(tc), sp(tr), | 736 thismse = vfp->svf(pre_address, y_stride, sp(tc), sp(tr), |
713 src_address, src_stride, &sse); | 737 src_address, src_stride, &sse); |
714 else | 738 else |
715 thismse = vfp->svaf(pre_address, y_stride, sp(tc), sp(tr), | 739 thismse = vfp->svaf(pre_address, y_stride, sp(tc), sp(tr), |
716 src_address, src_stride, &sse, second_pred); | 740 src_address, src_stride, &sse, second_pred); |
717 cost_array[4] = thismse + | 741 cost_array[4] = thismse + |
(...skipping 10 matching lines...) Expand all Loading... |
728 } | 752 } |
729 | 753 |
730 if (best_idx < 4 && best_idx >= 0) { | 754 if (best_idx < 4 && best_idx >= 0) { |
731 br += search_step[best_idx].row; | 755 br += search_step[best_idx].row; |
732 bc += search_step[best_idx].col; | 756 bc += search_step[best_idx].col; |
733 } else if (best_idx == 4) { | 757 } else if (best_idx == 4) { |
734 br = tr; | 758 br = tr; |
735 bc = tc; | 759 bc = tc; |
736 } | 760 } |
737 | 761 |
738 if (iters_per_step > 1) | 762 if (iters_per_step > 1 && best_idx != -1) |
739 SECOND_LEVEL_CHECKS; | 763 SECOND_LEVEL_CHECKS_BEST; |
740 | 764 |
741 tr = br; | 765 tr = br; |
742 tc = bc; | 766 tc = bc; |
743 | 767 |
744 search_step += 4; | 768 search_step += 4; |
745 hstep >>= 1; | 769 hstep >>= 1; |
746 best_idx = -1; | 770 best_idx = -1; |
747 } | 771 } |
748 | 772 |
749 // Each subsequent iteration checks at least one point in common with | 773 // Each subsequent iteration checks at least one point in common with |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 int vp9_fast_hex_search(const MACROBLOCK *x, | 1493 int vp9_fast_hex_search(const MACROBLOCK *x, |
1470 MV *ref_mv, | 1494 MV *ref_mv, |
1471 int search_param, | 1495 int search_param, |
1472 int sad_per_bit, | 1496 int sad_per_bit, |
1473 int do_init_search, // must be zero for fast_hex | 1497 int do_init_search, // must be zero for fast_hex |
1474 int *cost_list, | 1498 int *cost_list, |
1475 const vp9_variance_fn_ptr_t *vfp, | 1499 const vp9_variance_fn_ptr_t *vfp, |
1476 int use_mvcost, | 1500 int use_mvcost, |
1477 const MV *center_mv, | 1501 const MV *center_mv, |
1478 MV *best_mv) { | 1502 MV *best_mv) { |
1479 return vp9_hex_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), | 1503 return vp9_hex_search(x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param), |
1480 sad_per_bit, do_init_search, cost_list, vfp, use_mvcost, | 1504 sad_per_bit, do_init_search, cost_list, vfp, use_mvcost, |
1481 center_mv, best_mv); | 1505 center_mv, best_mv); |
1482 } | 1506 } |
1483 | 1507 |
1484 int vp9_fast_dia_search(const MACROBLOCK *x, | 1508 int vp9_fast_dia_search(const MACROBLOCK *x, |
1485 MV *ref_mv, | 1509 MV *ref_mv, |
1486 int search_param, | 1510 int search_param, |
1487 int sad_per_bit, | 1511 int sad_per_bit, |
1488 int do_init_search, | 1512 int do_init_search, |
1489 int *cost_list, | 1513 int *cost_list, |
1490 const vp9_variance_fn_ptr_t *vfp, | 1514 const vp9_variance_fn_ptr_t *vfp, |
1491 int use_mvcost, | 1515 int use_mvcost, |
1492 const MV *center_mv, | 1516 const MV *center_mv, |
1493 MV *best_mv) { | 1517 MV *best_mv) { |
1494 return vp9_bigdia_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), | 1518 return vp9_bigdia_search( |
1495 sad_per_bit, do_init_search, cost_list, vfp, | 1519 x, ref_mv, VPXMAX(MAX_MVSEARCH_STEPS - 2, search_param), sad_per_bit, |
1496 use_mvcost, center_mv, best_mv); | 1520 do_init_search, cost_list, vfp, use_mvcost, center_mv, best_mv); |
1497 } | 1521 } |
1498 | 1522 |
1499 #undef CHECK_BETTER | 1523 #undef CHECK_BETTER |
1500 | 1524 |
1501 int vp9_full_range_search_c(const MACROBLOCK *x, | 1525 int vp9_full_range_search_c(const MACROBLOCK *x, |
1502 const search_site_config *cfg, | 1526 const search_site_config *cfg, |
1503 MV *ref_mv, MV *best_mv, | 1527 MV *ref_mv, MV *best_mv, |
1504 int search_param, int sad_per_bit, int *num00, | 1528 int search_param, int sad_per_bit, int *num00, |
1505 const vp9_variance_fn_ptr_t *fn_ptr, | 1529 const vp9_variance_fn_ptr_t *fn_ptr, |
1506 const MV *center_mv) { | 1530 const MV *center_mv) { |
1507 const MACROBLOCKD *const xd = &x->e_mbd; | 1531 const MACROBLOCKD *const xd = &x->e_mbd; |
1508 const struct buf_2d *const what = &x->plane[0].src; | 1532 const struct buf_2d *const what = &x->plane[0].src; |
1509 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 1533 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
1510 const int range = 64; | 1534 const int range = 64; |
1511 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 1535 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
1512 unsigned int best_sad = INT_MAX; | 1536 unsigned int best_sad = INT_MAX; |
1513 int r, c, i; | 1537 int r, c, i; |
1514 int start_col, end_col, start_row, end_row; | 1538 int start_col, end_col, start_row, end_row; |
1515 | 1539 |
1516 // The cfg and search_param parameters are not used in this search variant | 1540 // The cfg and search_param parameters are not used in this search variant |
1517 (void)cfg; | 1541 (void)cfg; |
1518 (void)search_param; | 1542 (void)search_param; |
1519 | 1543 |
1520 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); | 1544 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); |
1521 *best_mv = *ref_mv; | 1545 *best_mv = *ref_mv; |
1522 *num00 = 11; | 1546 *num00 = 11; |
1523 best_sad = fn_ptr->sdf(what->buf, what->stride, | 1547 best_sad = fn_ptr->sdf(what->buf, what->stride, |
1524 get_buf_from_mv(in_what, ref_mv), in_what->stride) + | 1548 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
1525 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 1549 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
1526 start_row = MAX(-range, x->mv_row_min - ref_mv->row); | 1550 start_row = VPXMAX(-range, x->mv_row_min - ref_mv->row); |
1527 start_col = MAX(-range, x->mv_col_min - ref_mv->col); | 1551 start_col = VPXMAX(-range, x->mv_col_min - ref_mv->col); |
1528 end_row = MIN(range, x->mv_row_max - ref_mv->row); | 1552 end_row = VPXMIN(range, x->mv_row_max - ref_mv->row); |
1529 end_col = MIN(range, x->mv_col_max - ref_mv->col); | 1553 end_col = VPXMIN(range, x->mv_col_max - ref_mv->col); |
1530 | 1554 |
1531 for (r = start_row; r <= end_row; ++r) { | 1555 for (r = start_row; r <= end_row; ++r) { |
1532 for (c = start_col; c <= end_col; c += 4) { | 1556 for (c = start_col; c <= end_col; c += 4) { |
1533 if (c + 3 <= end_col) { | 1557 if (c + 3 <= end_col) { |
1534 unsigned int sads[4]; | 1558 unsigned int sads[4]; |
1535 const uint8_t *addrs[4]; | 1559 const uint8_t *addrs[4]; |
1536 for (i = 0; i < 4; ++i) { | 1560 for (i = 0; i < 4; ++i) { |
1537 const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; | 1561 const MV mv = {ref_mv->row + r, ref_mv->col + c + i}; |
1538 addrs[i] = get_buf_from_mv(in_what, &mv); | 1562 addrs[i] = get_buf_from_mv(in_what, &mv); |
1539 } | 1563 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 if (thissad < bestsad) { | 1721 if (thissad < bestsad) { |
1698 bestsad = thissad; | 1722 bestsad = thissad; |
1699 best_mv->row += ss[best_site].mv.row; | 1723 best_mv->row += ss[best_site].mv.row; |
1700 best_mv->col += ss[best_site].mv.col; | 1724 best_mv->col += ss[best_site].mv.col; |
1701 best_address += ss[best_site].offset; | 1725 best_address += ss[best_site].offset; |
1702 continue; | 1726 continue; |
1703 } | 1727 } |
1704 } | 1728 } |
1705 } | 1729 } |
1706 break; | 1730 break; |
1707 }; | 1731 } |
1708 #endif | 1732 #endif |
1709 } else if (best_address == in_what) { | 1733 } else if (best_address == in_what) { |
1710 (*num00)++; | 1734 (*num00)++; |
1711 } | 1735 } |
1712 } | 1736 } |
1713 return bestsad; | 1737 return bestsad; |
1714 } | 1738 } |
1715 | 1739 |
1716 static int vector_match(int16_t *ref, int16_t *src, int bwl) { | 1740 static int vector_match(int16_t *ref, int16_t *src, int bwl) { |
1717 int best_sad = INT_MAX; | 1741 int best_sad = INT_MAX; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 } | 2014 } |
1991 | 2015 |
1992 int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv, | 2016 int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv, |
1993 int sad_per_bit, int distance, | 2017 int sad_per_bit, int distance, |
1994 const vp9_variance_fn_ptr_t *fn_ptr, | 2018 const vp9_variance_fn_ptr_t *fn_ptr, |
1995 const MV *center_mv, MV *best_mv) { | 2019 const MV *center_mv, MV *best_mv) { |
1996 int r, c; | 2020 int r, c; |
1997 const MACROBLOCKD *const xd = &x->e_mbd; | 2021 const MACROBLOCKD *const xd = &x->e_mbd; |
1998 const struct buf_2d *const what = &x->plane[0].src; | 2022 const struct buf_2d *const what = &x->plane[0].src; |
1999 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 2023 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
2000 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); | 2024 const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min); |
2001 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); | 2025 const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max); |
2002 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); | 2026 const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min); |
2003 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); | 2027 const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max); |
2004 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 2028 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
2005 int best_sad = fn_ptr->sdf(what->buf, what->stride, | 2029 int best_sad = fn_ptr->sdf(what->buf, what->stride, |
2006 get_buf_from_mv(in_what, ref_mv), in_what->stride) + | 2030 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
2007 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 2031 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
2008 *best_mv = *ref_mv; | 2032 *best_mv = *ref_mv; |
2009 | 2033 |
2010 for (r = row_min; r < row_max; ++r) { | 2034 for (r = row_min; r < row_max; ++r) { |
2011 for (c = col_min; c < col_max; ++c) { | 2035 for (c = col_min; c < col_max; ++c) { |
2012 const MV mv = {r, c}; | 2036 const MV mv = {r, c}; |
2013 const int sad = fn_ptr->sdf(what->buf, what->stride, | 2037 const int sad = fn_ptr->sdf(what->buf, what->stride, |
2014 get_buf_from_mv(in_what, &mv), in_what->stride) + | 2038 get_buf_from_mv(in_what, &mv), in_what->stride) + |
2015 mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); | 2039 mvsad_err_cost(x, &mv, &fcenter_mv, sad_per_bit); |
2016 if (sad < best_sad) { | 2040 if (sad < best_sad) { |
2017 best_sad = sad; | 2041 best_sad = sad; |
2018 *best_mv = mv; | 2042 *best_mv = mv; |
2019 } | 2043 } |
2020 } | 2044 } |
2021 } | 2045 } |
2022 return best_sad; | 2046 return best_sad; |
2023 } | 2047 } |
2024 | 2048 |
2025 int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, | 2049 int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, |
2026 int sad_per_bit, int distance, | 2050 int sad_per_bit, int distance, |
2027 const vp9_variance_fn_ptr_t *fn_ptr, | 2051 const vp9_variance_fn_ptr_t *fn_ptr, |
2028 const MV *center_mv, MV *best_mv) { | 2052 const MV *center_mv, MV *best_mv) { |
2029 int r; | 2053 int r; |
2030 const MACROBLOCKD *const xd = &x->e_mbd; | 2054 const MACROBLOCKD *const xd = &x->e_mbd; |
2031 const struct buf_2d *const what = &x->plane[0].src; | 2055 const struct buf_2d *const what = &x->plane[0].src; |
2032 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 2056 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
2033 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); | 2057 const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min); |
2034 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); | 2058 const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max); |
2035 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); | 2059 const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min); |
2036 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); | 2060 const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max); |
2037 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 2061 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
2038 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, | 2062 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
2039 get_buf_from_mv(in_what, ref_mv), in_what->stride) + | 2063 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
2040 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 2064 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
2041 *best_mv = *ref_mv; | 2065 *best_mv = *ref_mv; |
2042 | 2066 |
2043 for (r = row_min; r < row_max; ++r) { | 2067 for (r = row_min; r < row_max; ++r) { |
2044 int c = col_min; | 2068 int c = col_min; |
2045 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; | 2069 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; |
2046 | 2070 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 } | 2112 } |
2089 | 2113 |
2090 int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv, | 2114 int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv, |
2091 int sad_per_bit, int distance, | 2115 int sad_per_bit, int distance, |
2092 const vp9_variance_fn_ptr_t *fn_ptr, | 2116 const vp9_variance_fn_ptr_t *fn_ptr, |
2093 const MV *center_mv, MV *best_mv) { | 2117 const MV *center_mv, MV *best_mv) { |
2094 int r; | 2118 int r; |
2095 const MACROBLOCKD *const xd = &x->e_mbd; | 2119 const MACROBLOCKD *const xd = &x->e_mbd; |
2096 const struct buf_2d *const what = &x->plane[0].src; | 2120 const struct buf_2d *const what = &x->plane[0].src; |
2097 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; | 2121 const struct buf_2d *const in_what = &xd->plane[0].pre[0]; |
2098 const int row_min = MAX(ref_mv->row - distance, x->mv_row_min); | 2122 const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min); |
2099 const int row_max = MIN(ref_mv->row + distance, x->mv_row_max); | 2123 const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max); |
2100 const int col_min = MAX(ref_mv->col - distance, x->mv_col_min); | 2124 const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min); |
2101 const int col_max = MIN(ref_mv->col + distance, x->mv_col_max); | 2125 const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max); |
2102 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; | 2126 const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3}; |
2103 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, | 2127 unsigned int best_sad = fn_ptr->sdf(what->buf, what->stride, |
2104 get_buf_from_mv(in_what, ref_mv), in_what->stride) + | 2128 get_buf_from_mv(in_what, ref_mv), in_what->stride) + |
2105 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); | 2129 mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); |
2106 *best_mv = *ref_mv; | 2130 *best_mv = *ref_mv; |
2107 | 2131 |
2108 for (r = row_min; r < row_max; ++r) { | 2132 for (r = row_min; r < row_max; ++r) { |
2109 int c = col_min; | 2133 int c = col_min; |
2110 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; | 2134 const uint8_t *check_here = &in_what->buf[r * in_what->stride + c]; |
2111 | 2135 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2348 break; | 2372 break; |
2349 default: | 2373 default: |
2350 assert(0 && "Invalid search method."); | 2374 assert(0 && "Invalid search method."); |
2351 } | 2375 } |
2352 | 2376 |
2353 if (method != NSTEP && rd && var < var_max) | 2377 if (method != NSTEP && rd && var < var_max) |
2354 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); | 2378 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); |
2355 | 2379 |
2356 return var; | 2380 return var; |
2357 } | 2381 } |
OLD | NEW |