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