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 AV1_COMMON_OBMC_H_
13 #define AV1_COMMON_OBMC_H_
14 
15 #if CONFIG_MOTION_VAR
16 typedef void (*overlappable_nb_visitor_t)(MACROBLOCKD *xd, int rel_mi_pos,
17                                           uint8_t nb_mi_size, MODE_INFO *nb_mi,
18                                           void *fun_ctxt);
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   if (!xd->up_available) return;
26 
27   int nb_count = 0;
28 
29   // prev_row_mi points into the mi array, starting at the beginning of the
30   // previous row.
31   MODE_INFO **prev_row_mi = xd->mi - mi_col - 1 * xd->mi_stride;
32   const int end_col = AOMMIN(mi_col + xd->n8_w, cm->mi_cols);
33   uint8_t mi_step;
34   for (int above_mi_col = mi_col; above_mi_col < end_col && nb_count < nb_max;
35        above_mi_col += mi_step) {
36     MODE_INFO **above_mi = prev_row_mi + above_mi_col;
37     mi_step = AOMMIN(mi_size_wide[above_mi[0]->mbmi.sb_type],
38                      mi_size_wide[BLOCK_64X64]);
39 #if CONFIG_CHROMA_SUB8X8
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 #endif  // CONFIG_CHROMA_SUB8X8
51     MB_MODE_INFO *above_mbmi = &above_mi[0]->mbmi;
52     if (is_neighbor_overlappable(above_mbmi)) {
53       ++nb_count;
54       fun(xd, above_mi_col - mi_col, AOMMIN(xd->n8_w, mi_step), *above_mi,
55           fun_ctxt);
56     }
57   }
58 }
59 
foreach_overlappable_nb_left(const AV1_COMMON * cm,MACROBLOCKD * xd,int mi_row,int nb_max,overlappable_nb_visitor_t fun,void * fun_ctxt)60 static INLINE void foreach_overlappable_nb_left(const AV1_COMMON *cm,
61                                                 MACROBLOCKD *xd, int mi_row,
62                                                 int nb_max,
63                                                 overlappable_nb_visitor_t fun,
64                                                 void *fun_ctxt) {
65   if (!xd->left_available) return;
66 
67   int nb_count = 0;
68 
69   // prev_col_mi points into the mi array, starting at the top of the
70   // previous column
71   MODE_INFO **prev_col_mi = xd->mi - 1 - mi_row * xd->mi_stride;
72   const int end_row = AOMMIN(mi_row + xd->n8_h, cm->mi_rows);
73   uint8_t mi_step;
74   for (int left_mi_row = mi_row; left_mi_row < end_row && nb_count < nb_max;
75        left_mi_row += mi_step) {
76     MODE_INFO **left_mi = prev_col_mi + left_mi_row * xd->mi_stride;
77     mi_step = AOMMIN(mi_size_high[left_mi[0]->mbmi.sb_type],
78                      mi_size_high[BLOCK_64X64]);
79 #if CONFIG_CHROMA_SUB8X8
80     if (mi_step == 1) {
81       left_mi_row &= ~1;
82       left_mi = prev_col_mi + (left_mi_row + 1) * xd->mi_stride;
83       mi_step = 2;
84     }
85 #endif  // CONFIG_CHROMA_SUB8X8
86     MB_MODE_INFO *left_mbmi = &left_mi[0]->mbmi;
87     if (is_neighbor_overlappable(left_mbmi)) {
88       ++nb_count;
89       fun(xd, left_mi_row - mi_row, AOMMIN(xd->n8_h, mi_step), *left_mi,
90           fun_ctxt);
91     }
92   }
93 }
94 
95 #endif  // CONFIG_MOTION_VAR
96 #endif  // AV1_COMMON_OBMC_H_
97