Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 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 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_COMMON_OBMC_H_ |
| 13 | #define AOM_AV1_COMMON_OBMC_H_ |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 14 | |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 15 | typedef void (*overlappable_nb_visitor_t)(MACROBLOCKD *xd, int rel_mi_row, |
| 16 | int rel_mi_col, uint8_t op_mi_size, |
| 17 | int dir, MB_MODE_INFO *nb_mi, |
| 18 | void *fun_ctxt, const int num_planes); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 19 | |
| 20 | static INLINE void foreach_overlappable_nb_above(const AV1_COMMON *cm, |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 21 | MACROBLOCKD *xd, int nb_max, |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 22 | overlappable_nb_visitor_t fun, |
| 23 | void *fun_ctxt) { |
| 24 | if (!xd->up_available) return; |
| 25 | |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 26 | const int num_planes = av1_num_planes(cm); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 27 | int nb_count = 0; |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 28 | const int mi_col = xd->mi_col; |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 29 | // prev_row_mi points into the mi array, starting at the beginning of the |
| 30 | // previous row. |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 31 | MB_MODE_INFO **prev_row_mi = xd->mi - mi_col - 1 * xd->mi_stride; |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 32 | const int end_col = AOMMIN(mi_col + xd->width, cm->mi_params.mi_cols); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 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) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 36 | MB_MODE_INFO **above_mi = prev_row_mi + above_mi_col; |
| 37 | mi_step = |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 38 | AOMMIN(mi_size_wide[above_mi[0]->bsize], mi_size_wide[BLOCK_64X64]); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 39 | // If we're considering a block with width 4, it should be treated as |
| 40 | // half of a pair of blocks with chroma information in the second. Move |
| 41 | // above_mi_col back to the start of the pair if needed, set above_mbmi |
| 42 | // to point at the block with chroma information, and set mi_step to 2 to |
| 43 | // step over the entire pair at the end of the iteration. |
| 44 | if (mi_step == 1) { |
| 45 | above_mi_col &= ~1; |
| 46 | above_mi = prev_row_mi + above_mi_col + 1; |
| 47 | mi_step = 2; |
| 48 | } |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 49 | if (is_neighbor_overlappable(*above_mi)) { |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 50 | ++nb_count; |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 51 | fun(xd, 0, above_mi_col - mi_col, AOMMIN(xd->width, mi_step), 0, |
| 52 | *above_mi, fun_ctxt, num_planes); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static INLINE void foreach_overlappable_nb_left(const AV1_COMMON *cm, |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 58 | MACROBLOCKD *xd, int nb_max, |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 59 | overlappable_nb_visitor_t fun, |
| 60 | void *fun_ctxt) { |
| 61 | if (!xd->left_available) return; |
| 62 | |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 63 | const int num_planes = av1_num_planes(cm); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 64 | int nb_count = 0; |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 65 | // prev_col_mi points into the mi array, starting at the top of the |
| 66 | // previous column |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 67 | const int mi_row = xd->mi_row; |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 68 | MB_MODE_INFO **prev_col_mi = xd->mi - 1 - mi_row * xd->mi_stride; |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 69 | const int end_row = AOMMIN(mi_row + xd->height, cm->mi_params.mi_rows); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 70 | uint8_t mi_step; |
| 71 | for (int left_mi_row = mi_row; left_mi_row < end_row && nb_count < nb_max; |
| 72 | left_mi_row += mi_step) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 73 | MB_MODE_INFO **left_mi = prev_col_mi + left_mi_row * xd->mi_stride; |
| 74 | mi_step = |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 75 | AOMMIN(mi_size_high[left_mi[0]->bsize], mi_size_high[BLOCK_64X64]); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 76 | if (mi_step == 1) { |
| 77 | left_mi_row &= ~1; |
| 78 | left_mi = prev_col_mi + (left_mi_row + 1) * xd->mi_stride; |
| 79 | mi_step = 2; |
| 80 | } |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 81 | if (is_neighbor_overlappable(*left_mi)) { |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 82 | ++nb_count; |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 83 | fun(xd, left_mi_row - mi_row, 0, AOMMIN(xd->height, mi_step), 1, *left_mi, |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 84 | fun_ctxt, num_planes); |
Rupert Swarbrick | c0cea7f | 2017-08-22 14:06:56 +0100 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 89 | #endif // AOM_AV1_COMMON_OBMC_H_ |