1 /*
2 * Copyright (c) 2017, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #ifndef AOM_AV1_COMMON_OBMC_H_
13 #define AOM_AV1_COMMON_OBMC_H_
14
15 typedef void (*overlappable_nb_visitor_t)(MACROBLOCKD *xd, int rel_mi_pos,
16 uint8_t nb_mi_size,
17 MB_MODE_INFO *nb_mi, void *fun_ctxt,
18 const int num_planes);
19
foreach_overlappable_nb_above(const AV1_COMMON * cm,MACROBLOCKD * xd,int mi_col,int nb_max,overlappable_nb_visitor_t fun,void * fun_ctxt)20 static INLINE void foreach_overlappable_nb_above(const AV1_COMMON *cm,
21 MACROBLOCKD *xd, int mi_col,
22 int nb_max,
23 overlappable_nb_visitor_t fun,
24 void *fun_ctxt) {
25 const int num_planes = av1_num_planes(cm);
26 if (!xd->up_available) return;
27
28 int nb_count = 0;
29
30 // prev_row_mi points into the mi array, starting at the beginning of the
31 // previous row.
32 MB_MODE_INFO **prev_row_mi = xd->mi - mi_col - 1 * xd->mi_stride;
33 const int end_col = AOMMIN(mi_col + xd->n4_w, cm->mi_cols);
34 uint8_t mi_step;
35 for (int above_mi_col = mi_col; above_mi_col < end_col && nb_count < nb_max;
36 above_mi_col += mi_step) {
37 MB_MODE_INFO **above_mi = prev_row_mi + above_mi_col;
38 mi_step =
39 AOMMIN(mi_size_wide[above_mi[0]->sb_type], mi_size_wide[BLOCK_64X64]);
40 // If we're considering a block with width 4, it should be treated as
41 // half of a pair of blocks with chroma information in the second. Move
42 // above_mi_col back to the start of the pair if needed, set above_mbmi
43 // to point at the block with chroma information, and set mi_step to 2 to
44 // step over the entire pair at the end of the iteration.
45 if (mi_step == 1) {
46 above_mi_col &= ~1;
47 above_mi = prev_row_mi + above_mi_col + 1;
48 mi_step = 2;
49 }
50 if (is_neighbor_overlappable(*above_mi)) {
51 ++nb_count;
52 fun(xd, above_mi_col - mi_col, AOMMIN(xd->n4_w, mi_step), *above_mi,
53 fun_ctxt, num_planes);
54 }
55 }
56 }
57
foreach_overlappable_nb_left(const AV1_COMMON * cm,MACROBLOCKD * xd,int mi_row,int nb_max,overlappable_nb_visitor_t fun,void * fun_ctxt)58 static INLINE void foreach_overlappable_nb_left(const AV1_COMMON *cm,
59 MACROBLOCKD *xd, int mi_row,
60 int nb_max,
61 overlappable_nb_visitor_t fun,
62 void *fun_ctxt) {
63 const int num_planes = av1_num_planes(cm);
64 if (!xd->left_available) return;
65
66 int nb_count = 0;
67
68 // prev_col_mi points into the mi array, starting at the top of the
69 // previous column
70 MB_MODE_INFO **prev_col_mi = xd->mi - 1 - mi_row * xd->mi_stride;
71 const int end_row = AOMMIN(mi_row + xd->n4_h, cm->mi_rows);
72 uint8_t mi_step;
73 for (int left_mi_row = mi_row; left_mi_row < end_row && nb_count < nb_max;
74 left_mi_row += mi_step) {
75 MB_MODE_INFO **left_mi = prev_col_mi + left_mi_row * xd->mi_stride;
76 mi_step =
77 AOMMIN(mi_size_high[left_mi[0]->sb_type], mi_size_high[BLOCK_64X64]);
78 if (mi_step == 1) {
79 left_mi_row &= ~1;
80 left_mi = prev_col_mi + (left_mi_row + 1) * xd->mi_stride;
81 mi_step = 2;
82 }
83 if (is_neighbor_overlappable(*left_mi)) {
84 ++nb_count;
85 fun(xd, left_mi_row - mi_row, AOMMIN(xd->n4_h, mi_step), *left_mi,
86 fun_ctxt, num_planes);
87 }
88 }
89 }
90
91 #endif // AOM_AV1_COMMON_OBMC_H_
92