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" |
| 16 | #include "av1/common/onyxc_int.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 23 | static INLINE int get_segment_id(const AV1_COMMON *const cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | const uint8_t *segment_ids, BLOCK_SIZE bsize, |
| 25 | int mi_row, int mi_col) { |
| 26 | const int mi_offset = mi_row * cm->mi_cols + mi_col; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 27 | const int bw = mi_size_wide[bsize]; |
| 28 | const int bh = mi_size_high[bsize]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | const int xmis = AOMMIN(cm->mi_cols - mi_col, bw); |
| 30 | const int ymis = AOMMIN(cm->mi_rows - mi_row, bh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | int x, y, segment_id = MAX_SEGMENTS; |
| 32 | |
| 33 | for (y = 0; y < ymis; ++y) |
| 34 | for (x = 0; x < xmis; ++x) |
| 35 | segment_id = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | AOMMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 37 | |
| 38 | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
| 39 | return segment_id; |
| 40 | } |
| 41 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | static INLINE int av1_get_pred_context_seg_id(const MACROBLOCKD *xd) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | const MODE_INFO *const above_mi = xd->above_mi; |
| 44 | const MODE_INFO *const left_mi = xd->left_mi; |
| 45 | const int above_sip = |
| 46 | (above_mi != NULL) ? above_mi->mbmi.seg_id_predicted : 0; |
| 47 | const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0; |
| 48 | |
| 49 | return above_sip + left_sip; |
| 50 | } |
| 51 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 52 | static INLINE aom_prob av1_get_pred_prob_seg_id( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | const struct segmentation_probs *segp, const MACROBLOCKD *xd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 54 | return segp->pred_probs[av1_get_pred_context_seg_id(xd)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 57 | static INLINE int av1_get_skip_context(const MACROBLOCKD *xd) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | const MODE_INFO *const above_mi = xd->above_mi; |
| 59 | const MODE_INFO *const left_mi = xd->left_mi; |
| 60 | const int above_skip = (above_mi != NULL) ? above_mi->mbmi.skip : 0; |
| 61 | const int left_skip = (left_mi != NULL) ? left_mi->mbmi.skip : 0; |
| 62 | return above_skip + left_skip; |
| 63 | } |
| 64 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | static INLINE aom_prob av1_get_skip_prob(const AV1_COMMON *cm, |
| 66 | const MACROBLOCKD *xd) { |
| 67 | return cm->fc->skip_probs[av1_get_skip_context(xd)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | #if CONFIG_DUAL_FILTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | #if CONFIG_EXT_INTRA |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 77 | #if CONFIG_INTRA_INTERP |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 78 | int av1_get_pred_context_intra_interp(const MACROBLOCKD *xd); |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 79 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 80 | #endif // CONFIG_EXT_INTRA |
| 81 | |
hui su | 33567b2 | 2017-04-30 16:40:19 -0700 | [diff] [blame] | 82 | #if CONFIG_PALETTE && CONFIG_PALETTE_DELTA_ENCODING |
| 83 | // Get a list of palette base colors that are used in the above and left blocks, |
| 84 | // referred to as "color cache". The return value is the number of colors in the |
| 85 | // cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache" |
| 86 | // in ascending order. |
| 87 | int av1_get_palette_cache(const MODE_INFO *above_mi, const MODE_INFO *left_mi, |
| 88 | int plane, uint16_t *cache); |
| 89 | #endif // CONFIG_PALETTE && CONFIG_PALETTE_DELTA_ENCODING |
| 90 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | int av1_get_intra_inter_context(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | static INLINE aom_prob av1_get_intra_inter_prob(const AV1_COMMON *cm, |
| 94 | const MACROBLOCKD *xd) { |
| 95 | return cm->fc->intra_inter_prob[av1_get_intra_inter_context(xd)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 98 | int av1_get_reference_mode_context(const AV1_COMMON *cm, const MACROBLOCKD *xd); |
| 99 | |
| 100 | static INLINE aom_prob av1_get_reference_mode_prob(const AV1_COMMON *cm, |
| 101 | const MACROBLOCKD *xd) { |
| 102 | return cm->fc->comp_inter_prob[av1_get_reference_mode_context(cm, xd)]; |
| 103 | } |
Thomas Davies | 860def6 | 2017-06-14 10:00:03 +0100 | [diff] [blame] | 104 | #if CONFIG_NEW_MULTISYMBOL |
| 105 | static INLINE aom_cdf_prob *av1_get_reference_mode_cdf(const AV1_COMMON *cm, |
| 106 | const MACROBLOCKD *xd) { |
| 107 | return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(cm, xd)]; |
| 108 | } |
| 109 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 110 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame^] | 111 | #if CONFIG_EXT_COMP_REFS |
| 112 | int av1_get_comp_reference_type_context(const AV1_COMMON *cm, |
| 113 | const MACROBLOCKD *xd); |
| 114 | |
| 115 | static INLINE aom_prob av1_get_comp_reference_type_prob(const AV1_COMMON *cm, |
| 116 | const MACROBLOCKD *xd) { |
| 117 | return cm->fc |
| 118 | ->comp_ref_type_prob[av1_get_comp_reference_type_context(cm, xd)]; |
| 119 | } |
| 120 | |
| 121 | int av1_get_pred_context_uni_comp_ref_p(const AV1_COMMON *cm, |
| 122 | const MACROBLOCKD *xd); |
| 123 | |
| 124 | static INLINE aom_prob av1_get_pred_prob_uni_comp_ref_p(const AV1_COMMON *cm, |
| 125 | const MACROBLOCKD *xd) { |
| 126 | const int pred_context = av1_get_pred_context_uni_comp_ref_p(cm, xd); |
| 127 | return cm->fc->uni_comp_ref_prob[pred_context][0]; |
| 128 | } |
| 129 | |
| 130 | int av1_get_pred_context_uni_comp_ref_p1(const AV1_COMMON *cm, |
| 131 | const MACROBLOCKD *xd); |
| 132 | |
| 133 | static INLINE aom_prob |
| 134 | av1_get_pred_prob_uni_comp_ref_p1(const AV1_COMMON *cm, const MACROBLOCKD *xd) { |
| 135 | const int pred_context = av1_get_pred_context_uni_comp_ref_p1(cm, xd); |
| 136 | return cm->fc->uni_comp_ref_prob[pred_context][1]; |
| 137 | } |
| 138 | #endif // CONFIG_EXT_COMP_REFS |
| 139 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 140 | int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 141 | const MACROBLOCKD *xd); |
| 142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 143 | static INLINE aom_prob av1_get_pred_prob_comp_ref_p(const AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 144 | const MACROBLOCKD *xd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 145 | const int pred_context = av1_get_pred_context_comp_ref_p(cm, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | return cm->fc->comp_ref_prob[pred_context][0]; |
| 147 | } |
| 148 | |
| 149 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 150 | int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm, |
| 151 | const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 152 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 153 | static INLINE aom_prob av1_get_pred_prob_comp_ref_p1(const AV1_COMMON *cm, |
| 154 | const MACROBLOCKD *xd) { |
| 155 | const int pred_context = av1_get_pred_context_comp_ref_p1(cm, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 156 | return cm->fc->comp_ref_prob[pred_context][1]; |
| 157 | } |
| 158 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 159 | int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm, |
| 160 | const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 162 | static INLINE aom_prob av1_get_pred_prob_comp_ref_p2(const AV1_COMMON *cm, |
| 163 | const MACROBLOCKD *xd) { |
| 164 | const int pred_context = av1_get_pred_context_comp_ref_p2(cm, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | return cm->fc->comp_ref_prob[pred_context][2]; |
| 166 | } |
| 167 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 168 | int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm, |
| 169 | const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 171 | static INLINE aom_prob av1_get_pred_prob_comp_bwdref_p(const AV1_COMMON *cm, |
| 172 | const MACROBLOCKD *xd) { |
| 173 | const int pred_context = av1_get_pred_context_comp_bwdref_p(cm, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 174 | return cm->fc->comp_bwdref_prob[pred_context][0]; |
| 175 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 176 | #endif // CONFIG_EXT_REFS |
| 177 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 178 | int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | static INLINE aom_prob av1_get_pred_prob_single_ref_p1(const AV1_COMMON *cm, |
| 181 | const MACROBLOCKD *xd) { |
| 182 | return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p1(xd)][0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 185 | int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 186 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 187 | static INLINE aom_prob av1_get_pred_prob_single_ref_p2(const AV1_COMMON *cm, |
| 188 | const MACROBLOCKD *xd) { |
| 189 | return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p2(xd)][1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 193 | int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 194 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | static INLINE aom_prob av1_get_pred_prob_single_ref_p3(const AV1_COMMON *cm, |
| 196 | const MACROBLOCKD *xd) { |
| 197 | return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p3(xd)][2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 200 | int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 202 | static INLINE aom_prob av1_get_pred_prob_single_ref_p4(const AV1_COMMON *cm, |
| 203 | const MACROBLOCKD *xd) { |
| 204 | return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p4(xd)][3]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 207 | int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 208 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 209 | static INLINE aom_prob av1_get_pred_prob_single_ref_p5(const AV1_COMMON *cm, |
| 210 | const MACROBLOCKD *xd) { |
| 211 | return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p5(xd)][4]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 212 | } |
| 213 | #endif // CONFIG_EXT_REFS |
| 214 | |
Thomas Davies | 315f578 | 2017-06-14 15:14:55 +0100 | [diff] [blame] | 215 | #if CONFIG_NEW_MULTISYMBOL |
| 216 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p1( |
| 217 | const MACROBLOCKD *xd) { |
| 218 | return xd->tile_ctx |
| 219 | ->single_ref_cdf[av1_get_pred_context_single_ref_p1(xd)][0]; |
| 220 | } |
| 221 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p2( |
| 222 | const MACROBLOCKD *xd) { |
| 223 | return xd->tile_ctx |
| 224 | ->single_ref_cdf[av1_get_pred_context_single_ref_p2(xd)][1]; |
| 225 | } |
| 226 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p3( |
| 227 | const MACROBLOCKD *xd) { |
| 228 | return xd->tile_ctx |
| 229 | ->single_ref_cdf[av1_get_pred_context_single_ref_p3(xd)][2]; |
| 230 | } |
| 231 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p4( |
| 232 | const MACROBLOCKD *xd) { |
| 233 | return xd->tile_ctx |
| 234 | ->single_ref_cdf[av1_get_pred_context_single_ref_p4(xd)][3]; |
| 235 | } |
| 236 | static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p5( |
| 237 | const MACROBLOCKD *xd) { |
| 238 | return xd->tile_ctx |
| 239 | ->single_ref_cdf[av1_get_pred_context_single_ref_p5(xd)][4]; |
| 240 | } |
| 241 | #endif |
| 242 | |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 243 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 244 | int av1_get_inter_mode_context(const MACROBLOCKD *xd); |
| 245 | |
| 246 | static INLINE aom_prob av1_get_inter_mode_prob(const AV1_COMMON *cm, |
| 247 | const MACROBLOCKD *xd) { |
| 248 | return cm->fc->comp_inter_mode_prob[av1_get_inter_mode_context(xd)]; |
| 249 | } |
| 250 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 251 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 252 | // Returns a context number for the given MB prediction signal |
| 253 | // The mode info data structure has a one element border above and to the |
| 254 | // left of the entries corresponding to real blocks. |
| 255 | // The prediction flags in these dummy entries are initialized to 0. |
| 256 | static INLINE int get_tx_size_context(const MACROBLOCKD *xd) { |
| 257 | const int max_tx_size = max_txsize_lookup[xd->mi[0]->mbmi.sb_type]; |
| 258 | const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
| 259 | const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
| 260 | const int has_above = xd->up_available; |
| 261 | const int has_left = xd->left_available; |
| 262 | int above_ctx = (has_above && !above_mbmi->skip) |
| 263 | ? (int)txsize_sqr_map[above_mbmi->tx_size] |
| 264 | : max_tx_size; |
| 265 | int left_ctx = (has_left && !left_mbmi->skip) |
| 266 | ? (int)txsize_sqr_map[left_mbmi->tx_size] |
| 267 | : max_tx_size; |
Jingning Han | 3daa4fd | 2017-01-20 10:33:50 -0800 | [diff] [blame] | 268 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | if (!has_left) left_ctx = above_ctx; |
| 270 | |
| 271 | if (!has_above) above_ctx = left_ctx; |
Timothy B. Terriberry | fe67ed6 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 272 | return (above_ctx + left_ctx) > max_tx_size + TX_SIZE_LUMA_MIN; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | #if CONFIG_VAR_TX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 276 | static void update_tx_counts(AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | MB_MODE_INFO *mbmi, BLOCK_SIZE plane_bsize, |
| 278 | TX_SIZE tx_size, int blk_row, int blk_col, |
| 279 | TX_SIZE max_tx_size, int ctx) { |
| 280 | const struct macroblockd_plane *const pd = &xd->plane[0]; |
| 281 | const BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; |
| 282 | const int tx_row = blk_row >> (1 - pd->subsampling_y); |
| 283 | const int tx_col = blk_col >> (1 - pd->subsampling_x); |
| 284 | const TX_SIZE plane_tx_size = mbmi->inter_tx_size[tx_row][tx_col]; |
Jingning Han | f65b870 | 2016-10-31 12:13:20 -0700 | [diff] [blame] | 285 | const int max_blocks_high = max_block_high(xd, plane_bsize, 0); |
| 286 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 287 | |
| 288 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 289 | |
| 290 | if (tx_size == plane_tx_size) { |
Timothy B. Terriberry | fe0fb1d | 2017-05-18 12:15:16 -0700 | [diff] [blame] | 291 | int depth; |
| 292 | depth = tx_size_to_depth(tx_size); |
| 293 | ++xd->counts->tx_size[max_tx_size - TX_SIZE_CTX_MIN][ctx][depth]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | mbmi->tx_size = tx_size; |
| 295 | } else { |
| 296 | int bsl = b_width_log2_lookup[bsize]; |
| 297 | int i; |
| 298 | |
| 299 | assert(bsl > 0); |
| 300 | --bsl; |
| 301 | |
| 302 | for (i = 0; i < 4; ++i) { |
| 303 | const int offsetr = blk_row + ((i >> 1) << bsl); |
| 304 | const int offsetc = blk_col + ((i & 0x01) << bsl); |
| 305 | |
| 306 | if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 307 | update_tx_counts(cm, xd, mbmi, plane_bsize, (TX_SIZE)(tx_size - 1), |
| 308 | offsetr, offsetc, max_tx_size, ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 313 | static INLINE void inter_block_tx_count_update(AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 314 | MB_MODE_INFO *mbmi, |
| 315 | BLOCK_SIZE plane_bsize, |
| 316 | int ctx) { |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 317 | const int mi_width = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
| 318 | const int mi_height = block_size_high[plane_bsize] >> tx_size_wide_log2[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | TX_SIZE max_tx_size = max_txsize_lookup[plane_bsize]; |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 320 | int bh = tx_size_wide_unit[max_tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 321 | int idx, idy; |
| 322 | |
| 323 | for (idy = 0; idy < mi_height; idy += bh) |
| 324 | for (idx = 0; idx < mi_width; idx += bh) |
| 325 | update_tx_counts(cm, xd, mbmi, plane_bsize, max_tx_size, idy, idx, |
| 326 | max_tx_size, ctx); |
| 327 | } |
| 328 | #endif |
| 329 | |
| 330 | #ifdef __cplusplus |
| 331 | } // extern "C" |
| 332 | #endif |
| 333 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 334 | #endif // AV1_COMMON_PRED_COMMON_H_ |