Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_PRED_COMMON_H_ |
| 13 | #define AV1_COMMON_PRED_COMMON_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include "av1/common/blockd.h" |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 16 | #include "av1/common/mvref_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "av1/common/onyxc_int.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 24 | static INLINE int get_segment_id(const AV1_COMMON *const cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | const uint8_t *segment_ids, BLOCK_SIZE bsize, |
| 26 | int mi_row, int mi_col) { |
| 27 | const int mi_offset = mi_row * cm->mi_cols + mi_col; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 28 | const int bw = mi_size_wide[bsize]; |
| 29 | const int bh = mi_size_high[bsize]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 30 | const int xmis = AOMMIN(cm->mi_cols - mi_col, bw); |
| 31 | const int ymis = AOMMIN(cm->mi_rows - mi_row, bh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 32 | int x, y, segment_id = MAX_SEGMENTS; |
| 33 | |
| 34 | for (y = 0; y < ymis; ++y) |
| 35 | for (x = 0; x < xmis; ++x) |
| 36 | segment_id = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 37 | AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | |
| 39 | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
| 40 | return segment_id; |
| 41 | } |
| 42 | |
Hui Su | cff20b9 | 2018-03-13 15:35:52 -0700 | [diff] [blame] | 43 | static INLINE int av1_get_spatial_seg_pred(const AV1_COMMON *const cm, |
| 44 | const MACROBLOCKD *const xd, |
| 45 | int mi_row, int mi_col, |
| 46 | int *cdf_index) { |
| 47 | int prev_ul = -1; // top left segment_id |
| 48 | int prev_l = -1; // left segment_id |
| 49 | int prev_u = -1; // top segment_id |
| 50 | if ((xd->up_available) && (xd->left_available)) { |
| 51 | prev_ul = get_segment_id(cm, cm->current_frame_seg_map, BLOCK_4X4, |
| 52 | mi_row - 1, mi_col - 1); |
| 53 | } |
| 54 | if (xd->up_available) { |
| 55 | prev_u = get_segment_id(cm, cm->current_frame_seg_map, BLOCK_4X4, |
| 56 | mi_row - 1, mi_col - 0); |
| 57 | } |
| 58 | if (xd->left_available) { |
| 59 | prev_l = get_segment_id(cm, cm->current_frame_seg_map, BLOCK_4X4, |
| 60 | mi_row - 0, mi_col - 1); |
| 61 | } |
| 62 | |
| 63 | // Pick CDF index based on number of matching/out-of-bounds segment IDs. |
David Barker | a56736c | 2018-03-20 17:13:15 +0000 | [diff] [blame] | 64 | if (prev_ul < 0 || prev_u < 0 || prev_l < 0) /* Edge case */ |
| 65 | *cdf_index = 0; |
| 66 | else if ((prev_ul == prev_u) && (prev_ul == prev_l)) |
Hui Su | cff20b9 | 2018-03-13 15:35:52 -0700 | [diff] [blame] | 67 | *cdf_index = 2; |
| 68 | else if ((prev_ul == prev_u) || (prev_ul == prev_l) || (prev_u == prev_l)) |
| 69 | *cdf_index = 1; |
David Barker | a56736c | 2018-03-20 17:13:15 +0000 | [diff] [blame] | 70 | else |
| 71 | *cdf_index = 0; |
Hui Su | cff20b9 | 2018-03-13 15:35:52 -0700 | [diff] [blame] | 72 | |
| 73 | // If 2 or more are identical returns that as predictor, otherwise prev_l. |
| 74 | if (prev_u == -1) // edge case |
| 75 | return prev_l == -1 ? 0 : prev_l; |
| 76 | if (prev_l == -1) // edge case |
| 77 | return prev_u; |
| 78 | return (prev_ul == prev_u) ? prev_u : prev_l; |
| 79 | } |
Hui Su | cff20b9 | 2018-03-13 15:35:52 -0700 | [diff] [blame] | 80 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | static INLINE int av1_get_pred_context_seg_id(const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 82 | const MB_MODE_INFO *const above_mi = xd->above_mbmi; |
| 83 | const MB_MODE_INFO *const left_mi = xd->left_mbmi; |
| 84 | const int above_sip = (above_mi != NULL) ? above_mi->seg_id_predicted : 0; |
| 85 | const int left_sip = (left_mi != NULL) ? left_mi->seg_id_predicted : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 86 | |
| 87 | return above_sip + left_sip; |
| 88 | } |
| 89 | |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 90 | static INLINE int get_comp_index_context(const AV1_COMMON *cm, |
| 91 | const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 92 | MB_MODE_INFO *mbmi = xd->mi[0]; |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 93 | int bck_idx = cm->frame_refs[mbmi->ref_frame[0] - LAST_FRAME].idx; |
| 94 | int fwd_idx = cm->frame_refs[mbmi->ref_frame[1] - LAST_FRAME].idx; |
| 95 | int bck_frame_index = 0, fwd_frame_index = 0; |
| 96 | int cur_frame_index = cm->cur_frame->cur_frame_offset; |
| 97 | |
| 98 | if (bck_idx >= 0) |
| 99 | bck_frame_index = cm->buffer_pool->frame_bufs[bck_idx].cur_frame_offset; |
| 100 | |
| 101 | if (fwd_idx >= 0) |
| 102 | fwd_frame_index = cm->buffer_pool->frame_bufs[fwd_idx].cur_frame_offset; |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 103 | int fwd = abs(get_relative_dist(cm, fwd_frame_index, cur_frame_index)); |
| 104 | int bck = abs(get_relative_dist(cm, cur_frame_index, bck_frame_index)); |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 105 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 106 | const MB_MODE_INFO *const above_mi = xd->above_mbmi; |
| 107 | const MB_MODE_INFO *const left_mi = xd->left_mbmi; |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 108 | |
| 109 | int above_ctx = 0, left_ctx = 0; |
Cheng Chen | c87b340 | 2017-11-03 16:02:41 -0700 | [diff] [blame] | 110 | const int offset = (fwd == bck); |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 111 | |
| 112 | if (above_mi) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 113 | if (has_second_ref(above_mi)) |
| 114 | above_ctx = above_mi->compound_idx; |
| 115 | else if (above_mi->ref_frame[0] == ALTREF_FRAME) |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 116 | above_ctx = 1; |
| 117 | } |
| 118 | |
| 119 | if (left_mi) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 120 | if (has_second_ref(left_mi)) |
| 121 | left_ctx = left_mi->compound_idx; |
| 122 | else if (left_mi->ref_frame[0] == ALTREF_FRAME) |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 123 | left_ctx = 1; |
| 124 | } |
| 125 | |
| 126 | return above_ctx + left_ctx + 3 * offset; |
| 127 | } |
Cheng Chen | 33a13d9 | 2017-11-28 16:49:59 -0800 | [diff] [blame] | 128 | |
| 129 | static INLINE int get_comp_group_idx_context(const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 130 | const MB_MODE_INFO *const above_mi = xd->above_mbmi; |
| 131 | const MB_MODE_INFO *const left_mi = xd->left_mbmi; |
Cheng Chen | 33a13d9 | 2017-11-28 16:49:59 -0800 | [diff] [blame] | 132 | int above_ctx = 0, left_ctx = 0; |
| 133 | |
| 134 | if (above_mi) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 135 | if (has_second_ref(above_mi)) |
| 136 | above_ctx = above_mi->comp_group_idx; |
| 137 | else if (above_mi->ref_frame[0] == ALTREF_FRAME) |
Cheng Chen | 5a88172 | 2017-11-30 17:05:10 -0800 | [diff] [blame] | 138 | above_ctx = 3; |
Cheng Chen | 33a13d9 | 2017-11-28 16:49:59 -0800 | [diff] [blame] | 139 | } |
| 140 | if (left_mi) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 141 | if (has_second_ref(left_mi)) |
| 142 | left_ctx = left_mi->comp_group_idx; |
| 143 | else if (left_mi->ref_frame[0] == ALTREF_FRAME) |
Cheng Chen | 5a88172 | 2017-11-30 17:05:10 -0800 | [diff] [blame] | 144 | left_ctx = 3; |
Cheng Chen | 33a13d9 | 2017-11-28 16:49:59 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Jingning Han | 0c3eb5a | 2018-03-26 15:29:12 -0700 | [diff] [blame] | 147 | return AOMMIN(5, above_ctx + left_ctx); |
Cheng Chen | 33a13d9 | 2017-11-28 16:49:59 -0800 | [diff] [blame] | 148 | } |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 149 | |
Thomas Davies | 0002135 | 2017-07-11 16:07:55 +0100 | [diff] [blame] | 150 | static INLINE aom_cdf_prob *av1_get_pred_cdf_seg_id( |
| 151 | struct segmentation_probs *segp, const MACROBLOCKD *xd) { |
| 152 | return segp->pred_cdf[av1_get_pred_context_seg_id(xd)]; |
| 153 | } |
Thomas Davies | 0002135 | 2017-07-11 16:07:55 +0100 | [diff] [blame] | 154 | |
Zoe Liu | f704a1c | 2017-10-02 16:55:59 -0700 | [diff] [blame] | 155 | static INLINE int av1_get_skip_mode_context(const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 156 | const MB_MODE_INFO *const above_mi = xd->above_mbmi; |
| 157 | const MB_MODE_INFO *const left_mi = xd->left_mbmi; |
| 158 | const int above_skip_mode = above_mi ? above_mi->skip_mode : 0; |
| 159 | const int left_skip_mode = left_mi ? left_mi->skip_mode : 0; |
Zoe Liu | f704a1c | 2017-10-02 16:55:59 -0700 | [diff] [blame] | 160 | return above_skip_mode + left_skip_mode; |
| 161 | } |
Zoe Liu | f704a1c | 2017-10-02 16:55:59 -0700 | [diff] [blame] | 162 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 163 | static INLINE int av1_get_skip_context(const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 164 | const MB_MODE_INFO *const above_mi = xd->above_mbmi; |
| 165 | const MB_MODE_INFO *const left_mi = xd->left_mbmi; |
| 166 | const int above_skip = above_mi ? above_mi->skip : 0; |
| 167 | const int left_skip = left_mi ? left_mi->skip : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 168 | return above_skip + left_skip; |
| 169 | } |
| 170 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 171 | int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 173 | // Get a list of palette base colors that are used in the above and left blocks, |
| 174 | // referred to as "color cache". The return value is the number of colors in the |
| 175 | // cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache" |
| 176 | // in ascending order. |
Hui Su | 3748bc2 | 2017-08-23 11:30:41 -0700 | [diff] [blame] | 177 | int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane, |
| 178 | uint16_t *cache); |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 179 | |
Hui Su | c1f411b | 2017-12-19 15:58:28 -0800 | [diff] [blame] | 180 | static INLINE int av1_get_palette_bsize_ctx(BLOCK_SIZE bsize) { |
Hui Su | 476f0b5 | 2018-04-16 15:51:44 -0700 | [diff] [blame] | 181 | return num_pels_log2_lookup[bsize] - num_pels_log2_lookup[BLOCK_8X8]; |
Hui Su | c1f411b | 2017-12-19 15:58:28 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Hui Su | db68555 | 2018-01-12 16:38:33 -0800 | [diff] [blame] | 184 | static INLINE int av1_get_palette_mode_ctx(const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 185 | const MB_MODE_INFO *const above_mi = xd->above_mbmi; |
| 186 | const MB_MODE_INFO *const left_mi = xd->left_mbmi; |
Hui Su | db68555 | 2018-01-12 16:38:33 -0800 | [diff] [blame] | 187 | int ctx = 0; |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 188 | if (above_mi) ctx += (above_mi->palette_mode_info.palette_size[0] > 0); |
| 189 | if (left_mi) ctx += (left_mi->palette_mode_info.palette_size[0] > 0); |
Hui Su | db68555 | 2018-01-12 16:38:33 -0800 | [diff] [blame] | 190 | return ctx; |
| 191 | } |
| 192 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 193 | int av1_get_intra_inter_context(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 194 | |
Yaowu Xu | 6567c4a | 2018-03-19 21:39:31 -0700 | [diff] [blame] | 195 | int av1_get_reference_mode_context(const MACROBLOCKD *xd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | |
Yaowu Xu | 6567c4a | 2018-03-19 21:39:31 -0700 | [diff] [blame] | 197 | static INLINE aom_cdf_prob *av1_get_reference_mode_cdf(const MACROBLOCKD *xd) { |
| 198 | return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(xd)]; |
Thomas Davies | 860def6 | 2017-06-14 10:00:03 +0100 | [diff] [blame] | 199 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 200 | |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 201 | int av1_get_comp_reference_type_context(const MACROBLOCKD *xd); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 202 | |
Zoe Liu | 4917295 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 203 | // == Uni-directional contexts == |
| 204 | |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 205 | int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 206 | |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 207 | int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 208 | |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 209 | int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd); |
| 210 | |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 211 | static INLINE aom_cdf_prob *av1_get_comp_reference_type_cdf( |
| 212 | const MACROBLOCKD *xd) { |
| 213 | const int pred_context = av1_get_comp_reference_type_context(xd); |
| 214 | return xd->tile_ctx->comp_ref_type_cdf[pred_context]; |
| 215 | } |
| 216 | |
| 217 | static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p( |
| 218 | const MACROBLOCKD *xd) { |
| 219 | const int pred_context = av1_get_pred_context_uni_comp_ref_p(xd); |
| 220 | return xd->tile_ctx->uni_comp_ref_cdf[pred_context][0]; |
| 221 | } |
| 222 | |
| 223 | static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p1( |
| 224 | const MACROBLOCKD *xd) { |
| 225 | const int pred_context = av1_get_pred_context_uni_comp_ref_p1(xd); |
| 226 | return xd->tile_ctx->uni_comp_ref_cdf[pred_context][1]; |
| 227 | } |
| 228 | |
| 229 | static INLINE aom_cdf_prob *av1_get_pred_cdf_uni_comp_ref_p2( |
| 230 | const MACROBLOCKD *xd) { |
| 231 | const int pred_context = av1_get_pred_context_uni_comp_ref_p2(xd); |
| 232 | return xd->tile_ctx->uni_comp_ref_cdf[pred_context][2]; |
| 233 | } |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 234 | |
Zoe Liu | 4917295 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 235 | // == Bi-directional contexts == |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 236 | |
Zoe Liu | 4917295 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 237 | int av1_get_pred_context_comp_ref_p(const MACROBLOCKD *xd); |
| 238 | |
| 239 | int av1_get_pred_context_comp_ref_p1(const MACROBLOCKD *xd); |
| 240 | |
| 241 | int av1_get_pred_context_comp_ref_p2(const MACROBLOCKD *xd); |
| 242 | |
| 243 | int av1_get_pred_context_comp_bwdref_p(const MACROBLOCKD *xd); |
| 244 | |
| 245 | int av1_get_pred_context_comp_bwdref_p1(const MACROBLOCKD *xd); |
| 246 | |
| 247 | static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p(const MACROBLOCKD *xd) { |
| 248 | const int pred_context = av1_get_pred_context_comp_ref_p(xd); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 249 | return xd->tile_ctx->comp_ref_cdf[pred_context][0]; |
| 250 | } |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 251 | |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 252 | static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p1( |
Zoe Liu | 4917295 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 253 | const MACROBLOCKD *xd) { |
| 254 | const int pred_context = av1_get_pred_context_comp_ref_p1(xd); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 255 | return xd->tile_ctx->comp_ref_cdf[pred_context][1]; |
| 256 | } |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 257 | |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 258 | static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_ref_p2( |
Zoe Liu | 4917295 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 259 | const MACROBLOCKD *xd) { |
| 260 | const int pred_context = av1_get_pred_context_comp_ref_p2(xd); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 261 | return xd->tile_ctx->comp_ref_cdf[pred_context][2]; |
| 262 | } |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 263 | |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 264 | static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p( |
Zoe Liu | d15afb2 | 2018-02-08 17:10:51 -0800 | [diff] [blame] | 265 | const MACROBLOCKD *xd) { |
| 266 | const int pred_context = av1_get_pred_context_comp_bwdref_p(xd); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 267 | return xd->tile_ctx->comp_bwdref_cdf[pred_context][0]; |
| 268 | } |
Zoe Liu | 97ad058 | 2017-02-09 10:51:00 -0800 | [diff] [blame] | 269 | |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 270 | static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p1( |
Zoe Liu | d15afb2 | 2018-02-08 17:10:51 -0800 | [diff] [blame] | 271 | const MACROBLOCKD *xd) { |
| 272 | const int pred_context = av1_get_pred_context_comp_bwdref_p1(xd); |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 273 | return xd->tile_ctx->comp_bwdref_cdf[pred_context][1]; |
| 274 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 275 | |
Zoe Liu | 4917295 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 276 | // == Single contexts == |
| 277 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 278 | int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 280 | int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 282 | int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 284 | int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 286 | int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 287 | |
Zoe Liu | 97ad058 | 2017-02-09 10:51:00 -0800 | [diff] [blame] | 288 | int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd); |
| 289 | |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 290 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p1( |
Zoe Liu | 50097b7 | 2018-02-09 10:35:43 -0800 | [diff] [blame] | 291 | const MACROBLOCKD *xd) { |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 292 | return xd->tile_ctx |
| 293 | ->single_ref_cdf[av1_get_pred_context_single_ref_p1(xd)][0]; |
| 294 | } |
| 295 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p2( |
Zoe Liu | 50097b7 | 2018-02-09 10:35:43 -0800 | [diff] [blame] | 296 | const MACROBLOCKD *xd) { |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 297 | return xd->tile_ctx |
| 298 | ->single_ref_cdf[av1_get_pred_context_single_ref_p2(xd)][1]; |
| 299 | } |
| 300 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p3( |
Zoe Liu | 50097b7 | 2018-02-09 10:35:43 -0800 | [diff] [blame] | 301 | const MACROBLOCKD *xd) { |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 302 | return xd->tile_ctx |
| 303 | ->single_ref_cdf[av1_get_pred_context_single_ref_p3(xd)][2]; |
| 304 | } |
| 305 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p4( |
Zoe Liu | 50097b7 | 2018-02-09 10:35:43 -0800 | [diff] [blame] | 306 | const MACROBLOCKD *xd) { |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 307 | return xd->tile_ctx |
| 308 | ->single_ref_cdf[av1_get_pred_context_single_ref_p4(xd)][3]; |
| 309 | } |
| 310 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p5( |
Zoe Liu | 50097b7 | 2018-02-09 10:35:43 -0800 | [diff] [blame] | 311 | const MACROBLOCKD *xd) { |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 312 | return xd->tile_ctx |
| 313 | ->single_ref_cdf[av1_get_pred_context_single_ref_p5(xd)][4]; |
| 314 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 315 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p6( |
Zoe Liu | 50097b7 | 2018-02-09 10:35:43 -0800 | [diff] [blame] | 316 | const MACROBLOCKD *xd) { |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 317 | return xd->tile_ctx |
| 318 | ->single_ref_cdf[av1_get_pred_context_single_ref_p6(xd)][5]; |
| 319 | } |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 320 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 321 | // Returns a context number for the given MB prediction signal |
| 322 | // The mode info data structure has a one element border above and to the |
| 323 | // left of the entries corresponding to real blocks. |
| 324 | // The prediction flags in these dummy entries are initialized to 0. |
Yaowu Xu | 25ff26a | 2018-02-26 11:20:10 -0800 | [diff] [blame] | 325 | static INLINE int get_tx_size_context(const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 326 | const MB_MODE_INFO *mbmi = xd->mi[0]; |
Jingning Han | 0238457 | 2018-02-21 11:28:59 -0800 | [diff] [blame] | 327 | const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
| 328 | const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
Jingning Han | d26fde2 | 2018-02-21 09:24:37 -0800 | [diff] [blame] | 329 | const TX_SIZE max_tx_size = max_txsize_rect_lookup[mbmi->sb_type]; |
Yue Chen | ee9c4d9 | 2018-01-11 00:50:09 -0800 | [diff] [blame] | 330 | const int max_tx_wide = tx_size_wide[max_tx_size]; |
| 331 | const int max_tx_high = tx_size_high[max_tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 332 | const int has_above = xd->up_available; |
| 333 | const int has_left = xd->left_available; |
Jingning Han | 3daa4fd | 2017-01-20 10:33:50 -0800 | [diff] [blame] | 334 | |
Jingning Han | 0238457 | 2018-02-21 11:28:59 -0800 | [diff] [blame] | 335 | int above = xd->above_txfm_context[0] >= max_tx_wide; |
| 336 | int left = xd->left_txfm_context[0] >= max_tx_high; |
| 337 | |
| 338 | if (has_above) |
| 339 | if (is_inter_block(above_mbmi)) |
| 340 | above = block_size_wide[above_mbmi->sb_type] >= max_tx_wide; |
| 341 | |
| 342 | if (has_left) |
| 343 | if (is_inter_block(left_mbmi)) |
| 344 | left = block_size_high[left_mbmi->sb_type] >= max_tx_high; |
| 345 | |
| 346 | if (has_above && has_left) |
| 347 | return (above + left); |
| 348 | else if (has_above) |
| 349 | return above; |
| 350 | else if (has_left) |
| 351 | return left; |
| 352 | else |
| 353 | return 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 356 | #ifdef __cplusplus |
| 357 | } // extern "C" |
| 358 | #endif |
| 359 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 360 | #endif // AV1_COMMON_PRED_COMMON_H_ |