Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Yaowu Xu | 2dcefd9 | 2015-08-13 09:25:39 -0700 | [diff] [blame] | 11 | #ifndef VP10_COMMON_PRED_COMMON_H_ |
| 12 | #define VP10_COMMON_PRED_COMMON_H_ |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 13 | |
Jingning Han | 54d66ef | 2015-08-06 21:14:07 -0700 | [diff] [blame] | 14 | #include "vp10/common/blockd.h" |
| 15 | #include "vp10/common/onyxc_int.h" |
Johann | c5f1191 | 2015-08-31 14:36:35 -0700 | [diff] [blame] | 16 | #include "vpx_dsp/vpx_dsp_common.h" |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 22 | static INLINE int get_segment_id(const VP10_COMMON *cm, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 23 | const uint8_t *segment_ids, |
| 24 | BLOCK_SIZE bsize, int mi_row, int mi_col) { |
| 25 | const int mi_offset = mi_row * cm->mi_cols + mi_col; |
| 26 | const int bw = num_8x8_blocks_wide_lookup[bsize]; |
| 27 | const int bh = num_8x8_blocks_high_lookup[bsize]; |
James Zern | 5e16d39 | 2015-08-17 18:19:22 -0700 | [diff] [blame] | 28 | const int xmis = VPXMIN(cm->mi_cols - mi_col, bw); |
| 29 | const int ymis = VPXMIN(cm->mi_rows - mi_row, bh); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 30 | int x, y, segment_id = MAX_SEGMENTS; |
| 31 | |
| 32 | for (y = 0; y < ymis; ++y) |
| 33 | for (x = 0; x < xmis; ++x) |
James Zern | 5e16d39 | 2015-08-17 18:19:22 -0700 | [diff] [blame] | 34 | segment_id = |
| 35 | VPXMIN(segment_id, segment_ids[mi_offset + y * cm->mi_cols + x]); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 36 | |
| 37 | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
| 38 | return segment_id; |
| 39 | } |
| 40 | |
| 41 | static INLINE int vp10_get_pred_context_seg_id(const MACROBLOCKD *xd) { |
| 42 | const MODE_INFO *const above_mi = xd->above_mi; |
| 43 | const MODE_INFO *const left_mi = xd->left_mi; |
| 44 | const int above_sip = (above_mi != NULL) ? |
| 45 | above_mi->mbmi.seg_id_predicted : 0; |
| 46 | const int left_sip = (left_mi != NULL) ? left_mi->mbmi.seg_id_predicted : 0; |
| 47 | |
| 48 | return above_sip + left_sip; |
| 49 | } |
| 50 | |
Ronald S. Bultje | 6e5a116 | 2015-10-13 14:06:28 -0400 | [diff] [blame] | 51 | static INLINE vpx_prob vp10_get_pred_prob_seg_id( |
| 52 | const struct segmentation_probs *segp, const MACROBLOCKD *xd) { |
| 53 | return segp->pred_probs[vp10_get_pred_context_seg_id(xd)]; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static INLINE int vp10_get_skip_context(const MACROBLOCKD *xd) { |
| 57 | const MODE_INFO *const above_mi = xd->above_mi; |
| 58 | const MODE_INFO *const left_mi = xd->left_mi; |
| 59 | const int above_skip = (above_mi != NULL) ? above_mi->mbmi.skip : 0; |
| 60 | const int left_skip = (left_mi != NULL) ? left_mi->mbmi.skip : 0; |
| 61 | return above_skip + left_skip; |
| 62 | } |
| 63 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 64 | static INLINE vpx_prob vp10_get_skip_prob(const VP10_COMMON *cm, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 65 | const MACROBLOCKD *xd) { |
| 66 | return cm->fc->skip_probs[vp10_get_skip_context(xd)]; |
| 67 | } |
| 68 | |
| 69 | int vp10_get_pred_context_switchable_interp(const MACROBLOCKD *xd); |
| 70 | |
hui su | 3b1c766 | 2016-01-12 16:38:58 -0800 | [diff] [blame] | 71 | #if CONFIG_EXT_INTRA |
| 72 | int vp10_get_pred_context_intra_interp(const MACROBLOCKD *xd); |
| 73 | #endif // CONFIG_EXT_INTRA |
| 74 | |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 75 | int vp10_get_intra_inter_context(const MACROBLOCKD *xd); |
| 76 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 77 | static INLINE vpx_prob vp10_get_intra_inter_prob(const VP10_COMMON *cm, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 78 | const MACROBLOCKD *xd) { |
| 79 | return cm->fc->intra_inter_prob[vp10_get_intra_inter_context(xd)]; |
| 80 | } |
| 81 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 82 | int vp10_get_reference_mode_context(const VP10_COMMON *cm, |
| 83 | const MACROBLOCKD *xd); |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 84 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 85 | static INLINE vpx_prob vp10_get_reference_mode_prob(const VP10_COMMON *cm, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 86 | const MACROBLOCKD *xd) { |
| 87 | return cm->fc->comp_inter_prob[vp10_get_reference_mode_context(cm, xd)]; |
| 88 | } |
| 89 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 90 | int vp10_get_pred_context_comp_ref_p(const VP10_COMMON *cm, |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 91 | const MACROBLOCKD *xd); |
| 92 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 93 | static INLINE vpx_prob vp10_get_pred_prob_comp_ref_p(const VP10_COMMON *cm, |
Zoe Liu | 3ec1601 | 2015-11-12 02:12:17 -0800 | [diff] [blame] | 94 | const MACROBLOCKD *xd) { |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 95 | const int pred_context = vp10_get_pred_context_comp_ref_p(cm, xd); |
Zoe Liu | 3ec1601 | 2015-11-12 02:12:17 -0800 | [diff] [blame] | 96 | return cm->fc->comp_ref_prob[pred_context][0]; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Zoe Liu | 3ec1601 | 2015-11-12 02:12:17 -0800 | [diff] [blame] | 99 | #if CONFIG_EXT_REFS |
| 100 | int vp10_get_pred_context_comp_ref_p1(const VP10_COMMON *cm, |
| 101 | const MACROBLOCKD *xd); |
| 102 | |
| 103 | static INLINE vpx_prob vp10_get_pred_prob_comp_ref_p1(const VP10_COMMON *cm, |
| 104 | const MACROBLOCKD *xd) { |
| 105 | const int pred_context = vp10_get_pred_context_comp_ref_p1(cm, xd); |
| 106 | return cm->fc->comp_ref_prob[pred_context][1]; |
| 107 | } |
| 108 | |
| 109 | int vp10_get_pred_context_comp_ref_p2(const VP10_COMMON *cm, |
| 110 | const MACROBLOCKD *xd); |
| 111 | |
| 112 | static INLINE vpx_prob vp10_get_pred_prob_comp_ref_p2(const VP10_COMMON *cm, |
| 113 | const MACROBLOCKD *xd) { |
| 114 | const int pred_context = vp10_get_pred_context_comp_ref_p2(cm, xd); |
| 115 | return cm->fc->comp_ref_prob[pred_context][2]; |
| 116 | } |
| 117 | |
| 118 | int vp10_get_pred_context_comp_ref_p3(const VP10_COMMON *cm, |
| 119 | const MACROBLOCKD *xd); |
| 120 | |
| 121 | static INLINE vpx_prob vp10_get_pred_prob_comp_ref_p3(const VP10_COMMON *cm, |
| 122 | const MACROBLOCKD *xd) { |
| 123 | const int pred_context = vp10_get_pred_context_comp_ref_p3(cm, xd); |
| 124 | return cm->fc->comp_ref_prob[pred_context][3]; |
| 125 | } |
| 126 | #endif // CONFIG_EXT_REFS |
| 127 | |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 128 | int vp10_get_pred_context_single_ref_p1(const MACROBLOCKD *xd); |
| 129 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 130 | static INLINE vpx_prob vp10_get_pred_prob_single_ref_p1(const VP10_COMMON *cm, |
Zoe Liu | 3ec1601 | 2015-11-12 02:12:17 -0800 | [diff] [blame] | 131 | const MACROBLOCKD *xd) { |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 132 | return cm->fc->single_ref_prob[vp10_get_pred_context_single_ref_p1(xd)][0]; |
| 133 | } |
| 134 | |
| 135 | int vp10_get_pred_context_single_ref_p2(const MACROBLOCKD *xd); |
| 136 | |
Yaowu Xu | fc7cbd1 | 2015-08-13 09:36:53 -0700 | [diff] [blame] | 137 | static INLINE vpx_prob vp10_get_pred_prob_single_ref_p2(const VP10_COMMON *cm, |
Zoe Liu | 3ec1601 | 2015-11-12 02:12:17 -0800 | [diff] [blame] | 138 | const MACROBLOCKD *xd) { |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 139 | return cm->fc->single_ref_prob[vp10_get_pred_context_single_ref_p2(xd)][1]; |
| 140 | } |
| 141 | |
Zoe Liu | 3ec1601 | 2015-11-12 02:12:17 -0800 | [diff] [blame] | 142 | #if CONFIG_EXT_REFS |
| 143 | int vp10_get_pred_context_single_ref_p3(const MACROBLOCKD *xd); |
| 144 | |
| 145 | static INLINE vpx_prob vp10_get_pred_prob_single_ref_p3(const VP10_COMMON *cm, |
| 146 | const MACROBLOCKD *xd) { |
| 147 | return cm->fc->single_ref_prob[vp10_get_pred_context_single_ref_p3(xd)][2]; |
| 148 | } |
| 149 | |
| 150 | int vp10_get_pred_context_single_ref_p4(const MACROBLOCKD *xd); |
| 151 | |
| 152 | static INLINE vpx_prob vp10_get_pred_prob_single_ref_p4(const VP10_COMMON *cm, |
| 153 | const MACROBLOCKD *xd) { |
| 154 | return cm->fc->single_ref_prob[vp10_get_pred_context_single_ref_p4(xd)][3]; |
| 155 | } |
| 156 | |
| 157 | int vp10_get_pred_context_single_ref_p5(const MACROBLOCKD *xd); |
| 158 | |
| 159 | static INLINE vpx_prob vp10_get_pred_prob_single_ref_p5(const VP10_COMMON *cm, |
| 160 | const MACROBLOCKD *xd) { |
| 161 | return cm->fc->single_ref_prob[vp10_get_pred_context_single_ref_p5(xd)][4]; |
| 162 | } |
| 163 | #endif // CONFIG_EXT_REFS |
| 164 | |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 165 | // Returns a context number for the given MB prediction signal |
| 166 | // The mode info data structure has a one element border above and to the |
| 167 | // left of the entries corresponding to real blocks. |
| 168 | // The prediction flags in these dummy entries are initialized to 0. |
| 169 | static INLINE int get_tx_size_context(const MACROBLOCKD *xd) { |
| 170 | const int max_tx_size = max_txsize_lookup[xd->mi[0]->mbmi.sb_type]; |
| 171 | const MB_MODE_INFO *const above_mbmi = xd->above_mbmi; |
| 172 | const MB_MODE_INFO *const left_mbmi = xd->left_mbmi; |
| 173 | const int has_above = xd->up_available; |
| 174 | const int has_left = xd->left_available; |
| 175 | int above_ctx = (has_above && !above_mbmi->skip) ? (int)above_mbmi->tx_size |
| 176 | : max_tx_size; |
| 177 | int left_ctx = (has_left && !left_mbmi->skip) ? (int)left_mbmi->tx_size |
| 178 | : max_tx_size; |
| 179 | if (!has_left) |
| 180 | left_ctx = above_ctx; |
| 181 | |
| 182 | if (!has_above) |
| 183 | above_ctx = left_ctx; |
| 184 | |
| 185 | return (above_ctx + left_ctx) > max_tx_size; |
| 186 | } |
| 187 | |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 188 | #if CONFIG_VAR_TX |
| 189 | static void update_tx_counts(VP10_COMMON *cm, MACROBLOCKD *xd, |
| 190 | MB_MODE_INFO *mbmi, BLOCK_SIZE plane_bsize, |
| 191 | TX_SIZE tx_size, int blk_row, int blk_col, |
hui su | 954e560 | 2016-03-07 15:25:50 -0800 | [diff] [blame] | 192 | TX_SIZE max_tx_size, int ctx) { |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 193 | const struct macroblockd_plane *const pd = &xd->plane[0]; |
| 194 | const BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; |
Geza Lore | efe7d4e | 2016-03-16 18:03:57 +0000 | [diff] [blame] | 195 | const int tx_row = blk_row >> (1 - pd->subsampling_y); |
| 196 | const int tx_col = blk_col >> (1 - pd->subsampling_x); |
| 197 | const TX_SIZE plane_tx_size = mbmi->inter_tx_size[tx_row][tx_col]; |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 198 | int max_blocks_high = num_4x4_blocks_high_lookup[plane_bsize]; |
| 199 | int max_blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 200 | |
| 201 | if (xd->mb_to_bottom_edge < 0) |
| 202 | max_blocks_high += xd->mb_to_bottom_edge >> (5 + pd->subsampling_y); |
| 203 | if (xd->mb_to_right_edge < 0) |
| 204 | max_blocks_wide += xd->mb_to_right_edge >> (5 + pd->subsampling_x); |
| 205 | |
| 206 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) |
| 207 | return; |
| 208 | |
| 209 | if (tx_size == plane_tx_size) { |
hui su | 954e560 | 2016-03-07 15:25:50 -0800 | [diff] [blame] | 210 | ++xd->counts->tx_size[max_tx_size - TX_8X8][ctx][tx_size]; |
Jingning Han | 3a27961 | 2015-10-12 19:20:58 -0700 | [diff] [blame] | 211 | mbmi->tx_size = tx_size; |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 212 | } else { |
| 213 | int bsl = b_width_log2_lookup[bsize]; |
| 214 | int i; |
| 215 | |
| 216 | assert(bsl > 0); |
| 217 | --bsl; |
| 218 | |
| 219 | for (i = 0; i < 4; ++i) { |
| 220 | const int offsetr = blk_row + ((i >> 1) << bsl); |
| 221 | const int offsetc = blk_col + ((i & 0x01) << bsl); |
| 222 | |
| 223 | if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) |
| 224 | continue; |
| 225 | update_tx_counts(cm, xd, mbmi, plane_bsize, |
hui su | 954e560 | 2016-03-07 15:25:50 -0800 | [diff] [blame] | 226 | tx_size - 1, offsetr, offsetc, max_tx_size, ctx); |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | static INLINE void inter_block_tx_count_update(VP10_COMMON *cm, |
| 232 | MACROBLOCKD *xd, |
| 233 | MB_MODE_INFO *mbmi, |
| 234 | BLOCK_SIZE plane_bsize, |
hui su | 954e560 | 2016-03-07 15:25:50 -0800 | [diff] [blame] | 235 | int ctx) { |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 236 | const int mi_width = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 237 | const int mi_height = num_4x4_blocks_high_lookup[plane_bsize]; |
| 238 | TX_SIZE max_tx_size = max_txsize_lookup[plane_bsize]; |
| 239 | BLOCK_SIZE txb_size = txsize_to_bsize[max_tx_size]; |
| 240 | int bh = num_4x4_blocks_wide_lookup[txb_size]; |
| 241 | int idx, idy; |
| 242 | |
| 243 | for (idy = 0; idy < mi_height; idy += bh) |
| 244 | for (idx = 0; idx < mi_width; idx += bh) |
| 245 | update_tx_counts(cm, xd, mbmi, plane_bsize, max_tx_size, idy, idx, |
hui su | 954e560 | 2016-03-07 15:25:50 -0800 | [diff] [blame] | 246 | max_tx_size, ctx); |
Jingning Han | 2cdc127 | 2015-10-09 09:57:42 -0700 | [diff] [blame] | 247 | } |
| 248 | #endif |
| 249 | |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 250 | #ifdef __cplusplus |
| 251 | } // extern "C" |
| 252 | #endif |
| 253 | |
Yaowu Xu | 2dcefd9 | 2015-08-13 09:25:39 -0700 | [diff] [blame] | 254 | #endif // VP10_COMMON_PRED_COMMON_H_ |