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_BLOCKD_H_ |
| 13 | #define AV1_COMMON_BLOCKD_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
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 | #include "aom_ports/mem.h" |
| 19 | #include "aom_scale/yv12config.h" |
| 20 | |
| 21 | #include "av1/common/common_data.h" |
| 22 | #include "av1/common/quant_common.h" |
| 23 | #include "av1/common/entropy.h" |
| 24 | #include "av1/common/entropymode.h" |
| 25 | #include "av1/common/mv.h" |
| 26 | #include "av1/common/scale.h" |
| 27 | #include "av1/common/seg_common.h" |
| 28 | #include "av1/common/tile_common.h" |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 29 | #if CONFIG_PVQ |
| 30 | #include "av1/common/pvq.h" |
| 31 | #include "av1/common/pvq_state.h" |
| 32 | #include "av1/decoder/decint.h" |
| 33 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 34 | |
| 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
| 39 | #define MAX_MB_PLANE 3 |
| 40 | |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 41 | #if CONFIG_EXT_INTER |
| 42 | // Should we try rectangular interintra predictions? |
| 43 | #define USE_RECT_INTERINTRA 1 |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame^] | 44 | #if CONFIG_COMPOUND_SEGMENT |
| 45 | #define MAX_SEG_MASK_BITS 3 |
| 46 | |
| 47 | // SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS |
| 48 | typedef enum { |
| 49 | UNIFORM_45 = 0, |
| 50 | UNIFORM_45_INV, |
| 51 | UNIFORM_55, |
| 52 | UNIFORM_55_INV, |
| 53 | SEG_MASK_TYPES, |
| 54 | } SEG_MASK_TYPE; |
| 55 | #endif // CONFIG_COMPOUND_SEGMENT |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 56 | #endif |
| 57 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | typedef enum { |
| 59 | KEY_FRAME = 0, |
| 60 | INTER_FRAME = 1, |
| 61 | FRAME_TYPES, |
| 62 | } FRAME_TYPE; |
| 63 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | static INLINE int is_inter_mode(PREDICTION_MODE mode) { |
| 65 | #if CONFIG_EXT_INTER |
| 66 | return mode >= NEARESTMV && mode <= NEW_NEWMV; |
| 67 | #else |
| 68 | return mode >= NEARESTMV && mode <= NEWMV; |
| 69 | #endif // CONFIG_EXT_INTER |
| 70 | } |
| 71 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 72 | #if CONFIG_PVQ |
| 73 | typedef struct PVQ_INFO { |
| 74 | int theta[PVQ_MAX_PARTITIONS]; |
| 75 | int max_theta[PVQ_MAX_PARTITIONS]; |
| 76 | int qg[PVQ_MAX_PARTITIONS]; |
| 77 | int k[PVQ_MAX_PARTITIONS]; |
Yushin Cho | 48f84db | 2016-11-07 21:20:17 -0800 | [diff] [blame] | 78 | od_coeff y[OD_TXSIZE_MAX * OD_TXSIZE_MAX]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 79 | int nb_bands; |
| 80 | int off[PVQ_MAX_PARTITIONS]; |
| 81 | int size[PVQ_MAX_PARTITIONS]; |
| 82 | int skip_rest; |
| 83 | int skip_dir; |
| 84 | int bs; // log of the block size minus two, |
| 85 | // i.e. equivalent to aom's TX_SIZE |
| 86 | int ac_dc_coded; // block skip info, indicating whether DC/AC is coded. |
| 87 | // bit0: DC coded, bit1 : AC coded (1 means coded) |
| 88 | tran_low_t dq_dc_residue; |
| 89 | } PVQ_INFO; |
| 90 | |
| 91 | typedef struct PVQ_QUEUE { |
| 92 | PVQ_INFO *buf; // buffer for pvq info, stored in encoding order |
| 93 | int curr_pos; // curr position to write PVQ_INFO |
| 94 | int buf_len; // allocated buffer length |
| 95 | int last_pos; // last written position of PVQ_INFO in a tile |
| 96 | } PVQ_QUEUE; |
| 97 | #endif |
| 98 | |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 99 | typedef struct { |
| 100 | uint8_t *plane[MAX_MB_PLANE]; |
| 101 | int stride[MAX_MB_PLANE]; |
| 102 | } BUFFER_SET; |
| 103 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | #if CONFIG_EXT_INTER |
| 105 | static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) { |
| 106 | return mode >= NEARESTMV && mode <= NEWFROMNEARMV; |
| 107 | } |
| 108 | |
| 109 | static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) { |
| 110 | return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV; |
| 111 | } |
| 112 | |
| 113 | static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) { |
| 114 | static PREDICTION_MODE lut[MB_MODE_COUNT] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 115 | MB_MODE_COUNT, // DC_PRED |
| 116 | MB_MODE_COUNT, // V_PRED |
| 117 | MB_MODE_COUNT, // H_PRED |
| 118 | MB_MODE_COUNT, // D45_PRED |
| 119 | MB_MODE_COUNT, // D135_PRED |
| 120 | MB_MODE_COUNT, // D117_PRED |
| 121 | MB_MODE_COUNT, // D153_PRED |
| 122 | MB_MODE_COUNT, // D207_PRED |
| 123 | MB_MODE_COUNT, // D63_PRED |
| 124 | #if CONFIG_ALT_INTRA |
| 125 | MB_MODE_COUNT, // SMOOTH_PRED |
| 126 | #endif // CONFIG_ALT_INTRA |
| 127 | MB_MODE_COUNT, // TM_PRED |
| 128 | MB_MODE_COUNT, // NEARESTMV |
| 129 | MB_MODE_COUNT, // NEARMV |
| 130 | MB_MODE_COUNT, // ZEROMV |
| 131 | MB_MODE_COUNT, // NEWMV |
| 132 | MB_MODE_COUNT, // NEWFROMNEARMV |
| 133 | NEARESTMV, // NEAREST_NEARESTMV |
| 134 | NEARESTMV, // NEAREST_NEARMV |
| 135 | NEARMV, // NEAR_NEARESTMV |
| 136 | NEARMV, // NEAR_NEARMV |
| 137 | NEARESTMV, // NEAREST_NEWMV |
| 138 | NEWMV, // NEW_NEARESTMV |
| 139 | NEARMV, // NEAR_NEWMV |
| 140 | NEWMV, // NEW_NEARMV |
| 141 | ZEROMV, // ZERO_ZEROMV |
| 142 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 143 | }; |
| 144 | assert(is_inter_compound_mode(mode)); |
| 145 | return lut[mode]; |
| 146 | } |
| 147 | |
| 148 | static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) { |
| 149 | static PREDICTION_MODE lut[MB_MODE_COUNT] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 150 | MB_MODE_COUNT, // DC_PRED |
| 151 | MB_MODE_COUNT, // V_PRED |
| 152 | MB_MODE_COUNT, // H_PRED |
| 153 | MB_MODE_COUNT, // D45_PRED |
| 154 | MB_MODE_COUNT, // D135_PRED |
| 155 | MB_MODE_COUNT, // D117_PRED |
| 156 | MB_MODE_COUNT, // D153_PRED |
| 157 | MB_MODE_COUNT, // D207_PRED |
| 158 | MB_MODE_COUNT, // D63_PRED |
| 159 | #if CONFIG_ALT_INTRA |
| 160 | MB_MODE_COUNT, // SMOOTH_PRED |
| 161 | #endif // CONFIG_ALT_INTRA |
| 162 | MB_MODE_COUNT, // TM_PRED |
| 163 | MB_MODE_COUNT, // NEARESTMV |
| 164 | MB_MODE_COUNT, // NEARMV |
| 165 | MB_MODE_COUNT, // ZEROMV |
| 166 | MB_MODE_COUNT, // NEWMV |
| 167 | MB_MODE_COUNT, // NEWFROMNEARMV |
| 168 | NEARESTMV, // NEAREST_NEARESTMV |
| 169 | NEARMV, // NEAREST_NEARMV |
| 170 | NEARESTMV, // NEAR_NEARESTMV |
| 171 | NEARMV, // NEAR_NEARMV |
| 172 | NEWMV, // NEAREST_NEWMV |
| 173 | NEARESTMV, // NEW_NEARESTMV |
| 174 | NEWMV, // NEAR_NEWMV |
| 175 | NEARMV, // NEW_NEARMV |
| 176 | ZEROMV, // ZERO_ZEROMV |
| 177 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 178 | }; |
| 179 | assert(is_inter_compound_mode(mode)); |
| 180 | return lut[mode]; |
| 181 | } |
| 182 | |
| 183 | static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) { |
| 184 | return (mode == NEWMV || mode == NEWFROMNEARMV || mode == NEW_NEWMV || |
| 185 | mode == NEAREST_NEWMV || mode == NEW_NEARESTMV || |
| 186 | mode == NEAR_NEWMV || mode == NEW_NEARMV); |
| 187 | } |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 188 | |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 189 | static INLINE int is_masked_compound_type(COMPOUND_TYPE type) { |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 190 | #if CONFIG_COMPOUND_SEGMENT |
| 191 | return (type == COMPOUND_WEDGE || type == COMPOUND_SEG); |
| 192 | #else |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 193 | return (type == COMPOUND_WEDGE); |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 194 | #endif // CONFIG_COMPOUND_SEGMENT |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 195 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | #else |
| 197 | |
| 198 | static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) { |
| 199 | return (mode == NEWMV); |
| 200 | } |
| 201 | #endif // CONFIG_EXT_INTER |
| 202 | |
| 203 | /* For keyframes, intra block modes are predicted by the (already decoded) |
| 204 | modes for the Y blocks to the left and above us; for interframes, there |
| 205 | is a single probability table. */ |
| 206 | |
| 207 | typedef struct { |
| 208 | PREDICTION_MODE as_mode; |
| 209 | int_mv as_mv[2]; // first, second inter predictor motion vectors |
| 210 | #if CONFIG_REF_MV |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 211 | int_mv pred_mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 212 | #endif |
| 213 | #if CONFIG_EXT_INTER |
| 214 | int_mv ref_mv[2]; |
| 215 | #endif // CONFIG_EXT_INTER |
| 216 | } b_mode_info; |
| 217 | |
| 218 | typedef int8_t MV_REFERENCE_FRAME; |
| 219 | |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 220 | #if CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 221 | typedef struct { |
| 222 | // Number of base colors for Y (0) and UV (1) |
| 223 | uint8_t palette_size[2]; |
| 224 | // Value of base colors for Y, U, and V |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 225 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | uint16_t palette_colors[3 * PALETTE_MAX_SIZE]; |
| 227 | #else |
| 228 | uint8_t palette_colors[3 * PALETTE_MAX_SIZE]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 229 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 230 | // Only used by encoder to store the color index of the top left pixel. |
| 231 | // TODO(huisu): move this to encoder |
| 232 | uint8_t palette_first_color_idx[2]; |
| 233 | } PALETTE_MODE_INFO; |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 234 | #endif // CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 236 | #if CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 237 | typedef struct { |
| 238 | // 1: an ext intra mode is used; 0: otherwise. |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 239 | uint8_t use_filter_intra_mode[PLANE_TYPES]; |
| 240 | FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES]; |
| 241 | } FILTER_INTRA_MODE_INFO; |
| 242 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 243 | |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 244 | #if CONFIG_VAR_TX |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 245 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 246 | #define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE) |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 247 | #endif |
| 248 | #endif |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 249 | |
| 250 | // TODO(angiebird): Merge RD_COST and RD_STATS |
| 251 | typedef struct RD_STATS { |
| 252 | int rate; |
| 253 | int64_t dist; |
| 254 | int64_t sse; |
| 255 | int skip; |
| 256 | #if CONFIG_RD_DEBUG |
| 257 | int txb_coeff_cost[MAX_MB_PLANE]; |
Angie Chiang | 3963d63 | 2016-11-10 18:41:40 -0800 | [diff] [blame] | 258 | #if CONFIG_VAR_TX |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 259 | int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE] |
| 260 | [TXB_COEFF_COST_MAP_SIZE]; |
Angie Chiang | 3963d63 | 2016-11-10 18:41:40 -0800 | [diff] [blame] | 261 | #endif // CONFIG_VAR_TX |
| 262 | #endif // CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 263 | } RD_STATS; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 264 | |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 265 | #if CONFIG_EXT_INTER |
| 266 | typedef struct { |
| 267 | COMPOUND_TYPE type; |
| 268 | int wedge_index; |
| 269 | int wedge_sign; |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 270 | #if CONFIG_COMPOUND_SEGMENT |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame^] | 271 | SEG_MASK_TYPE mask_type; |
| 272 | DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]); |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 273 | #endif // CONFIG_COMPOUND_SEGMENT |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 274 | } INTERINTER_COMPOUND_DATA; |
| 275 | #endif // CONFIG_EXT_INTER |
| 276 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | // This structure now relates to 8x8 block regions. |
| 278 | typedef struct { |
| 279 | // Common for both INTER and INTRA blocks |
| 280 | BLOCK_SIZE sb_type; |
| 281 | PREDICTION_MODE mode; |
| 282 | TX_SIZE tx_size; |
| 283 | #if CONFIG_VAR_TX |
| 284 | // TODO(jingning): This effectively assigned a separate entry for each |
| 285 | // 8x8 block. Apparently it takes much more space than needed. |
| 286 | TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE]; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 287 | TX_SIZE min_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 288 | #endif |
| 289 | int8_t skip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | int8_t segment_id; |
| 291 | #if CONFIG_SUPERTX |
| 292 | // Minimum of all segment IDs under the current supertx block. |
| 293 | int8_t segment_id_supertx; |
| 294 | #endif // CONFIG_SUPERTX |
| 295 | int8_t seg_id_predicted; // valid only when temporal_update is enabled |
| 296 | |
| 297 | // Only for INTRA blocks |
| 298 | PREDICTION_MODE uv_mode; |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 299 | #if CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 300 | PALETTE_MODE_INFO palette_mode_info; |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 301 | #endif // CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 302 | |
| 303 | // Only for INTER blocks |
| 304 | #if CONFIG_DUAL_FILTER |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 305 | InterpFilter interp_filter[4]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 306 | #else |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 307 | InterpFilter interp_filter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 308 | #endif |
| 309 | MV_REFERENCE_FRAME ref_frame[2]; |
| 310 | TX_TYPE tx_type; |
| 311 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 312 | #if CONFIG_FILTER_INTRA |
| 313 | FILTER_INTRA_MODE_INFO filter_intra_mode_info; |
| 314 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | #if CONFIG_EXT_INTRA |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 316 | // The actual prediction angle is the base angle + (angle_delta * step). |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 317 | int8_t angle_delta[2]; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 318 | #if CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | // To-Do (huisu): this may be replaced by interp_filter |
| 320 | INTRA_FILTER intra_filter; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 321 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 322 | #endif // CONFIG_EXT_INTRA |
| 323 | |
| 324 | #if CONFIG_EXT_INTER |
| 325 | INTERINTRA_MODE interintra_mode; |
| 326 | // TODO(debargha): Consolidate these flags |
| 327 | int use_wedge_interintra; |
| 328 | int interintra_wedge_index; |
| 329 | int interintra_wedge_sign; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 330 | INTERINTER_COMPOUND_DATA interinter_compound_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 331 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 332 | MOTION_MODE motion_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 333 | int_mv mv[2]; |
| 334 | int_mv pred_mv[2]; |
| 335 | #if CONFIG_REF_MV |
| 336 | uint8_t ref_mv_idx; |
| 337 | #endif |
| 338 | #if CONFIG_EXT_PARTITION_TYPES |
| 339 | PARTITION_TYPE partition; |
| 340 | #endif |
| 341 | #if CONFIG_NEW_QUANT |
| 342 | int dq_off_index; |
| 343 | int send_dq_bit; |
| 344 | #endif // CONFIG_NEW_QUANT |
| 345 | /* deringing gain *per-superblock* */ |
| 346 | int8_t dering_gain; |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 347 | #if CONFIG_DELTA_Q |
| 348 | int current_q_index; |
| 349 | #endif |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 350 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 351 | RD_STATS rd_stats; |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 352 | int mi_row; |
| 353 | int mi_col; |
| 354 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 355 | #if CONFIG_WARPED_MOTION |
| 356 | int num_proj_ref[2]; |
| 357 | WarpedMotionParams wm_params[2]; |
| 358 | #endif // CONFIG_WARPED_MOTION |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 359 | #if CONFIG_DEBLOCKING_ACROSS_TILES |
| 360 | TILE_BOUNDARY_TYPE tile_boundary_info; |
| 361 | #endif // CONFIG_DEBLOCKING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 362 | } MB_MODE_INFO; |
| 363 | |
| 364 | typedef struct MODE_INFO { |
| 365 | MB_MODE_INFO mbmi; |
| 366 | b_mode_info bmi[4]; |
| 367 | } MODE_INFO; |
| 368 | |
| 369 | static INLINE PREDICTION_MODE get_y_mode(const MODE_INFO *mi, int block) { |
Jingning Han | d7d2047 | 2016-12-14 11:13:48 -0800 | [diff] [blame] | 370 | #if CONFIG_CB4X4 |
| 371 | (void)block; |
| 372 | return mi->mbmi.mode; |
| 373 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | return mi->mbmi.sb_type < BLOCK_8X8 ? mi->bmi[block].as_mode : mi->mbmi.mode; |
Jingning Han | d7d2047 | 2016-12-14 11:13:48 -0800 | [diff] [blame] | 375 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) { |
| 379 | return mbmi->ref_frame[0] > INTRA_FRAME; |
| 380 | } |
| 381 | |
| 382 | static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) { |
| 383 | return mbmi->ref_frame[1] > INTRA_FRAME; |
| 384 | } |
| 385 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 386 | PREDICTION_MODE av1_left_block_mode(const MODE_INFO *cur_mi, |
| 387 | const MODE_INFO *left_mi, int b); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 388 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 389 | PREDICTION_MODE av1_above_block_mode(const MODE_INFO *cur_mi, |
| 390 | const MODE_INFO *above_mi, int b); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 391 | |
| 392 | enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 }; |
| 393 | |
| 394 | struct buf_2d { |
| 395 | uint8_t *buf; |
| 396 | uint8_t *buf0; |
| 397 | int width; |
| 398 | int height; |
| 399 | int stride; |
| 400 | }; |
| 401 | |
| 402 | typedef struct macroblockd_plane { |
| 403 | tran_low_t *dqcoeff; |
| 404 | PLANE_TYPE plane_type; |
| 405 | int subsampling_x; |
| 406 | int subsampling_y; |
| 407 | struct buf_2d dst; |
| 408 | struct buf_2d pre[2]; |
| 409 | ENTROPY_CONTEXT *above_context; |
| 410 | ENTROPY_CONTEXT *left_context; |
| 411 | int16_t seg_dequant[MAX_SEGMENTS][2]; |
| 412 | #if CONFIG_NEW_QUANT |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 413 | dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][QUANT_PROFILES] |
| 414 | [COEF_BANDS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 415 | #endif |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 416 | #if CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 417 | uint8_t *color_index_map; |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 418 | #endif // CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | |
| 420 | // number of 4x4s in current block |
| 421 | uint16_t n4_w, n4_h; |
| 422 | // log2 of n4_w, n4_h |
| 423 | uint8_t n4_wl, n4_hl; |
Jingning Han | c47fe6c | 2016-10-21 16:40:47 -0700 | [diff] [blame] | 424 | // block size in pixels |
| 425 | uint8_t width, height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 426 | |
| 427 | #if CONFIG_AOM_QM |
| 428 | const qm_val_t *seg_iqmatrix[MAX_SEGMENTS][2][TX_SIZES]; |
| 429 | #endif |
| 430 | // encoder |
| 431 | const int16_t *dequant; |
| 432 | #if CONFIG_NEW_QUANT |
| 433 | const dequant_val_type_nuq *dequant_val_nuq[QUANT_PROFILES]; |
| 434 | #endif // CONFIG_NEW_QUANT |
| 435 | #if CONFIG_AOM_QM |
| 436 | const qm_val_t *seg_qmatrix[MAX_SEGMENTS][2][TX_SIZES]; |
| 437 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 438 | |
| 439 | #if CONFIG_PVQ |
| 440 | DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]); |
| 441 | // PVQ: forward transformed predicted image, a reference for PVQ. |
| 442 | tran_low_t *pvq_ref_coeff; |
| 443 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 444 | } MACROBLOCKD_PLANE; |
| 445 | |
Jingning Han | 3468df1 | 2016-12-05 17:53:16 -0800 | [diff] [blame] | 446 | #define BLOCK_OFFSET(x, i) \ |
| 447 | ((x) + (i) * (1 << (tx_size_wide_log2[0] + tx_size_high_log2[0]))) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | |
| 449 | typedef struct RefBuffer { |
| 450 | // TODO(dkovalev): idx is not really required and should be removed, now it |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 451 | // is used in av1_onyxd_if.c |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 452 | int idx; |
| 453 | YV12_BUFFER_CONFIG *buf; |
| 454 | struct scale_factors sf; |
| 455 | } RefBuffer; |
| 456 | |
| 457 | typedef struct macroblockd { |
| 458 | struct macroblockd_plane plane[MAX_MB_PLANE]; |
| 459 | uint8_t bmode_blocks_wl; |
| 460 | uint8_t bmode_blocks_hl; |
| 461 | |
| 462 | FRAME_COUNTS *counts; |
| 463 | TileInfo tile; |
| 464 | |
| 465 | int mi_stride; |
| 466 | |
| 467 | MODE_INFO **mi; |
| 468 | MODE_INFO *left_mi; |
| 469 | MODE_INFO *above_mi; |
| 470 | MB_MODE_INFO *left_mbmi; |
| 471 | MB_MODE_INFO *above_mbmi; |
| 472 | |
| 473 | int up_available; |
| 474 | int left_available; |
| 475 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 476 | const aom_prob (*partition_probs)[PARTITION_TYPES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 477 | |
| 478 | /* Distance of MB away from frame edges */ |
| 479 | int mb_to_left_edge; |
| 480 | int mb_to_right_edge; |
| 481 | int mb_to_top_edge; |
| 482 | int mb_to_bottom_edge; |
| 483 | |
| 484 | FRAME_CONTEXT *fc; |
| 485 | |
| 486 | /* pointers to reference frames */ |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 487 | const RefBuffer *block_refs[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 488 | |
| 489 | /* pointer to current frame */ |
| 490 | const YV12_BUFFER_CONFIG *cur_buf; |
| 491 | |
| 492 | ENTROPY_CONTEXT *above_context[MAX_MB_PLANE]; |
| 493 | ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE]; |
| 494 | |
| 495 | PARTITION_CONTEXT *above_seg_context; |
| 496 | PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE]; |
| 497 | |
| 498 | #if CONFIG_VAR_TX |
| 499 | TXFM_CONTEXT *above_txfm_context; |
| 500 | TXFM_CONTEXT *left_txfm_context; |
| 501 | TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE]; |
| 502 | |
| 503 | TX_SIZE max_tx_size; |
| 504 | #if CONFIG_SUPERTX |
| 505 | TX_SIZE supertx_size; |
| 506 | #endif |
| 507 | #endif |
| 508 | |
Jingning Han | ff6ee6a | 2016-12-07 09:55:21 -0800 | [diff] [blame] | 509 | // block dimension in the unit of mode_info. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | uint8_t n8_w, n8_h; |
| 511 | |
| 512 | #if CONFIG_REF_MV |
| 513 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES]; |
| 514 | CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE]; |
| 515 | uint8_t is_sec_rect; |
| 516 | #endif |
| 517 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 518 | #if CONFIG_PVQ |
| 519 | daala_dec_ctx daala_dec; |
| 520 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 521 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | /* Bit depth: 8, 10, 12 */ |
| 523 | int bd; |
| 524 | #endif |
| 525 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 526 | int qindex[MAX_SEGMENTS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 527 | int lossless[MAX_SEGMENTS]; |
| 528 | int corrupted; |
| 529 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 530 | struct aom_internal_error_info *error_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 531 | #if CONFIG_GLOBAL_MOTION |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 532 | WarpedMotionParams *global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | #endif // CONFIG_GLOBAL_MOTION |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 534 | #if CONFIG_DELTA_Q |
| 535 | int prev_qindex; |
| 536 | int delta_qindex; |
| 537 | int current_qindex; |
| 538 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 539 | } MACROBLOCKD; |
| 540 | |
| 541 | static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize, |
| 542 | PARTITION_TYPE partition) { |
| 543 | if (partition == PARTITION_INVALID) |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 544 | return BLOCK_INVALID; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 545 | else |
| 546 | return subsize_lookup[partition][bsize]; |
| 547 | } |
| 548 | |
| 549 | static const TX_TYPE intra_mode_to_tx_type_context[INTRA_MODES] = { |
| 550 | DCT_DCT, // DC |
| 551 | ADST_DCT, // V |
| 552 | DCT_ADST, // H |
| 553 | DCT_DCT, // D45 |
| 554 | ADST_ADST, // D135 |
| 555 | ADST_DCT, // D117 |
| 556 | DCT_ADST, // D153 |
| 557 | DCT_ADST, // D207 |
| 558 | ADST_DCT, // D63 |
Urvang Joshi | 6be4a54 | 2016-11-03 15:24:05 -0700 | [diff] [blame] | 559 | #if CONFIG_ALT_INTRA |
| 560 | ADST_ADST, // SMOOTH |
| 561 | #endif // CONFIG_ALT_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | ADST_ADST, // TM |
| 563 | }; |
| 564 | |
| 565 | #if CONFIG_SUPERTX |
| 566 | static INLINE int supertx_enabled(const MB_MODE_INFO *mbmi) { |
Jingning Han | 9353124 | 2016-12-20 11:54:36 -0800 | [diff] [blame] | 567 | TX_SIZE max_tx_size = txsize_sqr_map[mbmi->tx_size]; |
| 568 | return tx_size_wide[max_tx_size] > |
| 569 | AOMMIN(block_size_wide[mbmi->sb_type], block_size_high[mbmi->sb_type]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | } |
| 571 | #endif // CONFIG_SUPERTX |
| 572 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | #if CONFIG_EXT_TX |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 574 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 575 | #define ALLOW_INTRA_EXT_TX 1 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | |
| 577 | static const int num_ext_tx_set_inter[EXT_TX_SETS_INTER] = { 1, 16, 12, 2 }; |
| 578 | static const int num_ext_tx_set_intra[EXT_TX_SETS_INTRA] = { 1, 7, 5 }; |
| 579 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 580 | static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter) { |
| 581 | tx_size = txsize_sqr_map[tx_size]; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 582 | #if CONFIG_CB4X4 |
| 583 | (void)bs; |
| 584 | if (tx_size > TX_32X32) return 0; |
| 585 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 586 | if (tx_size > TX_32X32 || bs < BLOCK_8X8) return 0; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 587 | #endif |
Debargha Mukherjee | 3b52b3a | 2016-08-30 15:55:23 -0700 | [diff] [blame] | 588 | if (tx_size == TX_32X32) return is_inter ? 3 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 589 | return (tx_size == TX_16X16 ? 2 : 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 592 | static const int use_intra_ext_tx_for_txsize[EXT_TX_SETS_INTRA] |
| 593 | [EXT_TX_SIZES] = { |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 594 | #if CONFIG_CB4X4 |
| 595 | { 1, 1, 1, 1, 1 }, // unused |
| 596 | { 0, 1, 1, 0, 0 }, |
| 597 | { 0, 0, 0, 1, 0 }, |
| 598 | #else |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 599 | { 1, 1, 1, 1 }, // unused |
| 600 | { 1, 1, 0, 0 }, |
| 601 | { 0, 0, 1, 0 }, |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 602 | #endif // CONFIG_CB4X4 |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 603 | }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 604 | |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 605 | static const int use_inter_ext_tx_for_txsize[EXT_TX_SETS_INTER] |
| 606 | [EXT_TX_SIZES] = { |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 607 | #if CONFIG_CB4X4 |
| 608 | { 1, 1, 1, 1, 1 }, // unused |
| 609 | { 0, 1, 1, 0, 0 }, |
| 610 | { 0, 0, 0, 1, 0 }, |
| 611 | { 0, 0, 0, 0, 1 }, |
| 612 | #else |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 613 | { 1, 1, 1, 1 }, // unused |
| 614 | { 1, 1, 0, 0 }, |
| 615 | { 0, 0, 1, 0 }, |
| 616 | { 0, 0, 0, 1 }, |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 617 | #endif // CONFIG_CB4X4 |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 618 | }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 619 | |
| 620 | // Transform types used in each intra set |
| 621 | static const int ext_tx_used_intra[EXT_TX_SETS_INTRA][TX_TYPES] = { |
| 622 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 623 | { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 }, |
| 624 | { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, |
| 625 | }; |
| 626 | |
| 627 | // Transform types used in each inter set |
| 628 | static const int ext_tx_used_inter[EXT_TX_SETS_INTER][TX_TYPES] = { |
| 629 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 630 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 631 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, |
| 632 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, |
| 633 | }; |
| 634 | |
| 635 | // 1D Transforms used in inter set, this needs to be changed if |
| 636 | // ext_tx_used_inter is changed |
| 637 | static const int ext_tx_used_inter_1D[EXT_TX_SETS_INTER][TX_TYPES_1D] = { |
| 638 | { 1, 0, 0, 0 }, { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, |
| 639 | }; |
| 640 | |
| 641 | static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, |
| 642 | int is_inter) { |
| 643 | const int set = get_ext_tx_set(tx_size, bs, is_inter); |
| 644 | return is_inter ? num_ext_tx_set_inter[set] : num_ext_tx_set_intra[set]; |
| 645 | } |
| 646 | |
| 647 | #if CONFIG_RECT_TX |
| 648 | static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) { |
| 649 | static const char LUT[BLOCK_SIZES] = { |
| 650 | 0, // BLOCK_4X4 |
| 651 | 1, // BLOCK_4X8 |
| 652 | 1, // BLOCK_8X4 |
| 653 | 0, // BLOCK_8X8 |
| 654 | 1, // BLOCK_8X16 |
| 655 | 1, // BLOCK_16X8 |
| 656 | 0, // BLOCK_16X16 |
| 657 | 1, // BLOCK_16X32 |
| 658 | 1, // BLOCK_32X16 |
| 659 | 0, // BLOCK_32X32 |
| 660 | 0, // BLOCK_32X64 |
| 661 | 0, // BLOCK_64X32 |
| 662 | 0, // BLOCK_64X64 |
| 663 | #if CONFIG_EXT_PARTITION |
| 664 | 0, // BLOCK_64X128 |
| 665 | 0, // BLOCK_128X64 |
| 666 | 0, // BLOCK_128X128 |
| 667 | #endif // CONFIG_EXT_PARTITION |
| 668 | }; |
| 669 | |
| 670 | return LUT[bsize]; |
| 671 | } |
| 672 | |
Yue Chen | 49587a7 | 2016-09-28 17:09:47 -0700 | [diff] [blame] | 673 | static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd, |
| 674 | const MB_MODE_INFO *mbmi) { |
| 675 | return is_inter_block(mbmi) && is_rect_tx_allowed_bsize(mbmi->sb_type) && |
| 676 | !xd->lossless[mbmi->segment_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; } |
| 680 | #endif // CONFIG_RECT_TX |
| 681 | #endif // CONFIG_EXT_TX |
| 682 | |
| 683 | static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode, |
| 684 | int is_inter) { |
| 685 | const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 686 | #if CONFIG_VAR_TX |
| 687 | const TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize]; |
| 688 | |
Jingning Han | 4be1a4d | 2017-01-06 10:59:20 -0800 | [diff] [blame] | 689 | #if CONFIG_CB4X4 |
| 690 | if (!is_inter || bsize == BLOCK_4X4) |
| 691 | return AOMMIN(max_txsize_lookup[bsize], largest_tx_size); |
| 692 | #else |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 693 | if (!is_inter || bsize < BLOCK_8X8) |
| 694 | return AOMMIN(max_txsize_lookup[bsize], largest_tx_size); |
Jingning Han | 4be1a4d | 2017-01-06 10:59:20 -0800 | [diff] [blame] | 695 | #endif |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 696 | |
| 697 | if (txsize_sqr_map[max_tx_size] <= largest_tx_size) |
| 698 | return max_tx_size; |
| 699 | else |
| 700 | return largest_tx_size; |
| 701 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 703 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 704 | |
| 705 | #if CONFIG_EXT_TX && CONFIG_RECT_TX |
| 706 | if (!is_inter) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 707 | return AOMMIN(max_tx_size, largest_tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 708 | } else { |
| 709 | const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize]; |
| 710 | if (txsize_sqr_up_map[max_rect_tx_size] <= largest_tx_size) { |
| 711 | return max_rect_tx_size; |
| 712 | } else { |
| 713 | return largest_tx_size; |
| 714 | } |
| 715 | } |
| 716 | #else |
| 717 | (void)is_inter; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 718 | return AOMMIN(max_tx_size, largest_tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 719 | #endif // CONFIG_EXT_TX && CONFIG_RECT_TX |
| 720 | } |
| 721 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 722 | #if CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 723 | static const TX_TYPE filter_intra_mode_to_tx_type_lookup[FILTER_INTRA_MODES] = { |
| 724 | DCT_DCT, // FILTER_DC |
| 725 | ADST_DCT, // FILTER_V |
| 726 | DCT_ADST, // FILTER_H |
| 727 | DCT_DCT, // FILTER_D45 |
| 728 | ADST_ADST, // FILTER_D135 |
| 729 | ADST_DCT, // FILTER_D117 |
| 730 | DCT_ADST, // FILTER_D153 |
| 731 | DCT_ADST, // FILTER_D207 |
| 732 | ADST_DCT, // FILTER_D63 |
| 733 | ADST_ADST, // FILTER_TM |
| 734 | }; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 735 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 736 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 737 | #if CONFIG_EXT_INTRA |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 738 | #define MAX_ANGLE_DELTA_UV 2 |
| 739 | #define ANGLE_STEP_UV 4 |
| 740 | |
| 741 | static const uint8_t av1_angle_step_y[TX_SIZES] = { |
| 742 | 0, 4, 3, 3, |
| 743 | }; |
| 744 | static const uint8_t av1_max_angle_delta_y[TX_SIZES] = { |
| 745 | 0, 2, 3, 3, |
| 746 | }; |
| 747 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 748 | extern const int16_t dr_intra_derivative[90]; |
| 749 | static const uint8_t mode_to_angle_map[INTRA_MODES] = { |
| 750 | 0, 90, 180, 45, 135, 111, 157, 203, 67, 0, |
| 751 | }; |
| 752 | |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 753 | static INLINE int av1_get_angle_step(BLOCK_SIZE sb_type, int plane) { |
| 754 | const TX_SIZE max_tx_size = max_txsize_lookup[sb_type]; |
| 755 | return plane ? ANGLE_STEP_UV : av1_angle_step_y[max_tx_size]; |
| 756 | } |
| 757 | |
| 758 | static INLINE int av1_get_max_angle_delta(BLOCK_SIZE sb_type, int plane) { |
| 759 | const TX_SIZE max_tx_size = max_txsize_lookup[sb_type]; |
| 760 | return plane ? MAX_ANGLE_DELTA_UV : av1_max_angle_delta_y[max_tx_size]; |
| 761 | } |
| 762 | |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 763 | #if CONFIG_INTRA_INTERP |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 764 | // Returns whether filter selection is needed for a given |
| 765 | // intra prediction angle. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 766 | int av1_is_intra_filter_switchable(int angle); |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 767 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 768 | #endif // CONFIG_EXT_INTRA |
| 769 | |
| 770 | #if CONFIG_EXT_TILE |
| 771 | #define FIXED_TX_TYPE 1 |
| 772 | #else |
| 773 | #define FIXED_TX_TYPE 0 |
| 774 | #endif |
| 775 | |
| 776 | static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type, |
| 777 | const MACROBLOCKD *xd, int block_idx, |
| 778 | TX_SIZE tx_size) { |
| 779 | const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 780 | |
| 781 | if (is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y || |
| 782 | xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32) |
| 783 | return DCT_DCT; |
| 784 | |
| 785 | return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y |
| 786 | ? get_y_mode(xd->mi[0], block_idx) |
| 787 | : mbmi->uv_mode]; |
| 788 | } |
| 789 | |
| 790 | static INLINE TX_TYPE get_tx_type(PLANE_TYPE plane_type, const MACROBLOCKD *xd, |
| 791 | int block_idx, TX_SIZE tx_size) { |
| 792 | const MODE_INFO *const mi = xd->mi[0]; |
| 793 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 794 | |
| 795 | if (FIXED_TX_TYPE) |
| 796 | return get_default_tx_type(plane_type, xd, block_idx, tx_size); |
| 797 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 798 | #if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 799 | if (!is_inter_block(mbmi)) { |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 800 | #if CONFIG_FILTER_INTRA |
| 801 | const int use_filter_intra_mode_info = |
| 802 | mbmi->filter_intra_mode_info.use_filter_intra_mode[plane_type]; |
| 803 | const FILTER_INTRA_MODE filter_intra_mode = |
| 804 | mbmi->filter_intra_mode_info.filter_intra_mode[plane_type]; |
| 805 | #endif // CONFIG_FILTER_INTRA |
| 806 | #if CONFIG_EXT_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 807 | const PREDICTION_MODE mode = (plane_type == PLANE_TYPE_Y) |
| 808 | ? get_y_mode(mi, block_idx) |
| 809 | : mbmi->uv_mode; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 810 | #endif // CONFIG_EXT_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 811 | |
| 812 | if (xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32) return DCT_DCT; |
| 813 | |
| 814 | #if CONFIG_EXT_TX |
| 815 | #if ALLOW_INTRA_EXT_TX |
| 816 | if (mbmi->sb_type >= BLOCK_8X8 && plane_type == PLANE_TYPE_Y) |
| 817 | return mbmi->tx_type; |
| 818 | #endif // ALLOW_INTRA_EXT_TX |
| 819 | #endif // CONFIG_EXT_TX |
| 820 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 821 | #if CONFIG_FILTER_INTRA |
| 822 | if (use_filter_intra_mode_info) |
| 823 | return filter_intra_mode_to_tx_type_lookup[filter_intra_mode]; |
| 824 | #endif // CONFIG_FILTER_INTRA |
| 825 | #if CONFIG_EXT_INTRA |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 826 | #if CONFIG_ALT_INTRA |
| 827 | if (mode == SMOOTH_PRED) return ADST_ADST; |
| 828 | #endif // CONFIG_ALT_INTRA |
| 829 | if (mode == DC_PRED) return DCT_DCT; |
| 830 | if (mode == TM_PRED) return ADST_ADST; |
| 831 | { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 832 | int angle = mode_to_angle_map[mode]; |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 833 | const int angle_step = av1_get_angle_step(mbmi->sb_type, (int)plane_type); |
| 834 | assert(mode == D45_PRED || mode == D63_PRED || mode == D117_PRED || |
| 835 | mode == D135_PRED || mode == D153_PRED || mode == D207_PRED || |
| 836 | mode == V_PRED || mode == H_PRED); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 837 | if (mbmi->sb_type >= BLOCK_8X8) |
hui su | 45dc597 | 2016-12-08 17:42:50 -0800 | [diff] [blame] | 838 | angle += mbmi->angle_delta[plane_type] * angle_step; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 839 | assert(angle > 0 && angle < 270); |
| 840 | if (angle == 135) |
| 841 | return ADST_ADST; |
| 842 | else if (angle < 45 || angle > 225) |
| 843 | return DCT_DCT; |
| 844 | else if (angle < 135) |
| 845 | return ADST_DCT; |
| 846 | else |
| 847 | return DCT_ADST; |
| 848 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | #endif // CONFIG_EXT_INTRA |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 850 | } |
| 851 | #endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 852 | |
| 853 | #if CONFIG_EXT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 854 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 || |
| 855 | (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi))) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 856 | return DCT_DCT; |
Jingning Han | 8260d8b | 2016-12-28 13:48:43 -0800 | [diff] [blame] | 857 | if (mbmi->sb_type >= BLOCK_8X8 || CONFIG_CB4X4) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 858 | if (plane_type == PLANE_TYPE_Y) { |
| 859 | #if !ALLOW_INTRA_EXT_TX |
| 860 | if (is_inter_block(mbmi)) |
| 861 | #endif // ALLOW_INTRA_EXT_TX |
| 862 | return mbmi->tx_type; |
| 863 | } |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 864 | |
| 865 | if (is_inter_block(mbmi)) { |
| 866 | // UV Inter only |
| 867 | #if CONFIG_CB4X4 |
| 868 | if (tx_size < TX_4X4) return DCT_DCT; |
| 869 | #endif |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 870 | return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 871 | ? DCT_DCT |
| 872 | : mbmi->tx_type; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 873 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Jingning Han | 8260d8b | 2016-12-28 13:48:43 -0800 | [diff] [blame] | 876 | #if CONFIG_CB4X4 |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 877 | if (tx_size < TX_4X4) |
| 878 | return DCT_DCT; |
| 879 | else |
| 880 | return intra_mode_to_tx_type_context[mbmi->uv_mode]; |
Jingning Han | 8260d8b | 2016-12-28 13:48:43 -0800 | [diff] [blame] | 881 | #endif |
| 882 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | // Sub8x8-Inter/Intra OR UV-Intra |
| 884 | if (is_inter_block(mbmi)) // Sub8x8-Inter |
| 885 | return DCT_DCT; |
| 886 | else // Sub8x8 Intra OR UV-Intra |
| 887 | return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y |
| 888 | ? get_y_mode(mi, block_idx) |
| 889 | : mbmi->uv_mode]; |
| 890 | #else // CONFIG_EXT_TX |
| 891 | (void)block_idx; |
| 892 | if (plane_type != PLANE_TYPE_Y || xd->lossless[mbmi->segment_id] || |
| 893 | txsize_sqr_map[tx_size] >= TX_32X32) |
| 894 | return DCT_DCT; |
| 895 | return mbmi->tx_type; |
| 896 | #endif // CONFIG_EXT_TX |
| 897 | } |
| 898 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 899 | void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 900 | |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 901 | static INLINE int tx_size_to_depth(const TX_SIZE tx_size) { |
| 902 | return (int)(tx_size - TX_4X4); |
| 903 | } |
| 904 | |
| 905 | static INLINE TX_SIZE depth_to_tx_size(const int depth) { |
| 906 | return (TX_SIZE)(depth + TX_4X4); |
| 907 | } |
| 908 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 909 | static INLINE TX_SIZE get_uv_tx_size(const MB_MODE_INFO *mbmi, |
| 910 | const struct macroblockd_plane *pd) { |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 911 | TX_SIZE uv_txsize; |
Jingning Han | 9353124 | 2016-12-20 11:54:36 -0800 | [diff] [blame] | 912 | #if CONFIG_CB4X4 |
| 913 | assert(mbmi->tx_size > TX_2X2); |
| 914 | #endif |
| 915 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | #if CONFIG_SUPERTX |
| 917 | if (supertx_enabled(mbmi)) |
| 918 | return uvsupertx_size_lookup[txsize_sqr_map[mbmi->tx_size]] |
| 919 | [pd->subsampling_x][pd->subsampling_y]; |
| 920 | #endif // CONFIG_SUPERTX |
Jingning Han | cabd989 | 2016-12-01 12:28:42 -0800 | [diff] [blame] | 921 | |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 922 | uv_txsize = uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x] |
| 923 | [pd->subsampling_y]; |
| 924 | assert(uv_txsize != TX_INVALID); |
| 925 | return uv_txsize; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static INLINE BLOCK_SIZE |
| 929 | get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) { |
| 930 | return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y]; |
| 931 | } |
| 932 | |
| 933 | static INLINE void reset_skip_context(MACROBLOCKD *xd, BLOCK_SIZE bsize) { |
| 934 | int i; |
| 935 | for (i = 0; i < MAX_MB_PLANE; i++) { |
| 936 | struct macroblockd_plane *const pd = &xd->plane[i]; |
| 937 | const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
Jingning Han | b49004d | 2016-12-05 09:37:29 -0800 | [diff] [blame] | 938 | const int txs_wide = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
| 939 | const int txs_high = block_size_high[plane_bsize] >> tx_size_high_log2[0]; |
| 940 | memset(pd->above_context, 0, sizeof(ENTROPY_CONTEXT) * txs_wide); |
| 941 | memset(pd->left_context, 0, sizeof(ENTROPY_CONTEXT) * txs_high); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
| 945 | typedef void (*foreach_transformed_block_visitor)(int plane, int block, |
| 946 | int blk_row, int blk_col, |
| 947 | BLOCK_SIZE plane_bsize, |
| 948 | TX_SIZE tx_size, void *arg); |
| 949 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 950 | void av1_foreach_transformed_block_in_plane( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane, |
| 952 | foreach_transformed_block_visitor visit, void *arg); |
| 953 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 954 | void av1_foreach_transformed_block(const MACROBLOCKD *const xd, |
| 955 | BLOCK_SIZE bsize, |
| 956 | foreach_transformed_block_visitor visit, |
| 957 | void *arg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 958 | |
iole moccagatta | f25a4cf | 2016-11-11 23:57:57 -0800 | [diff] [blame] | 959 | #if CONFIG_COEF_INTERLEAVE |
| 960 | static INLINE int get_max_4x4_size(int num_4x4, int mb_to_edge, |
| 961 | int subsampling) { |
| 962 | return num_4x4 + (mb_to_edge >= 0 ? 0 : mb_to_edge >> (5 + subsampling)); |
| 963 | } |
| 964 | |
| 965 | void av1_foreach_transformed_block_interleave( |
| 966 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, |
| 967 | foreach_transformed_block_visitor visit, void *arg); |
| 968 | #endif |
| 969 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 970 | void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, |
Jingning Han | eee4315 | 2016-12-05 09:58:45 -0800 | [diff] [blame] | 971 | int plane, TX_SIZE tx_size, int has_eob, int aoff, |
| 972 | int loff); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 973 | |
| 974 | #if CONFIG_EXT_INTER |
| 975 | static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) { |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 976 | #if !USE_RECT_INTERINTRA |
| 977 | if (block_size_wide[bsize] != block_size_high[bsize]) return 0; |
| 978 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 979 | // TODO(debargha): Should this be bsize < BLOCK_LARGEST? |
| 980 | return (bsize >= BLOCK_8X8) && (bsize < BLOCK_64X64); |
| 981 | } |
| 982 | |
| 983 | static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) { |
| 984 | return (mode >= NEARESTMV) && (mode <= NEWMV); |
| 985 | } |
| 986 | |
| 987 | static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) { |
| 988 | return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME); |
| 989 | } |
| 990 | |
| 991 | static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) { |
| 992 | return is_interintra_allowed_bsize(mbmi->sb_type) && |
| 993 | is_interintra_allowed_mode(mbmi->mode) && |
| 994 | is_interintra_allowed_ref(mbmi->ref_frame); |
| 995 | } |
| 996 | |
| 997 | static INLINE int is_interintra_allowed_bsize_group(const int group) { |
| 998 | int i; |
| 999 | for (i = 0; i < BLOCK_SIZES; i++) { |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 1000 | if (size_group_lookup[i] == group && |
| 1001 | is_interintra_allowed_bsize((BLOCK_SIZE)i)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1002 | return 1; |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 1003 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1004 | } |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) { |
| 1009 | return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi); |
| 1010 | } |
| 1011 | #endif // CONFIG_EXT_INTER |
| 1012 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1013 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 1014 | static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) { |
| 1015 | return (bsize >= BLOCK_8X8); |
| 1016 | } |
| 1017 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1018 | static INLINE MOTION_MODE motion_mode_allowed(const MB_MODE_INFO *mbmi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1019 | #if CONFIG_EXT_INTER |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1020 | if (is_motion_variation_allowed_bsize(mbmi->sb_type) && |
| 1021 | is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1022 | #else |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1023 | if (is_motion_variation_allowed_bsize(mbmi->sb_type) && |
| 1024 | is_inter_mode(mbmi->mode)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1025 | #endif // CONFIG_EXT_INTER |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1026 | #if CONFIG_WARPED_MOTION |
| 1027 | if (!has_second_ref(mbmi) && mbmi->num_proj_ref[0] >= 3) |
| 1028 | return WARPED_CAUSAL; |
| 1029 | else |
| 1030 | #endif // CONFIG_WARPED_MOTION |
| 1031 | #if CONFIG_MOTION_VAR |
| 1032 | return OBMC_CAUSAL; |
| 1033 | #else |
| 1034 | return SIMPLE_TRANSLATION; |
| 1035 | #endif // CONFIG_MOTION_VAR |
| 1036 | } else { |
| 1037 | return SIMPLE_TRANSLATION; |
| 1038 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1041 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1042 | static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) { |
| 1043 | return (is_inter_block(mbmi)); |
| 1044 | } |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1045 | #endif // CONFIG_MOTION_VAR |
| 1046 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1047 | |
| 1048 | #ifdef __cplusplus |
| 1049 | } // extern "C" |
| 1050 | #endif |
| 1051 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1052 | #endif // AV1_COMMON_BLOCKD_H_ |