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 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
Jingning Han | 69d2101 | 2017-05-14 16:51:27 -0700 | [diff] [blame] | 38 | #if (CONFIG_CHROMA_SUB8X8 || CONFIG_CHROMA_2X2) |
| 39 | #define SUB8X8_COMP_REF 0 |
| 40 | #else |
| 41 | #define SUB8X8_COMP_REF 1 |
| 42 | #endif |
Jingning Han | c41a549 | 2017-02-24 11:18:52 -0800 | [diff] [blame] | 43 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | #define MAX_MB_PLANE 3 |
| 45 | |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 46 | #if CONFIG_EXT_INTER |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 47 | |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 48 | #if CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 49 | // Set COMPOUND_SEGMENT_TYPE to one of the three |
| 50 | // 0: Uniform |
| 51 | // 1: Difference weighted |
| 52 | #define COMPOUND_SEGMENT_TYPE 1 |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 53 | #define MAX_SEG_MASK_BITS 1 |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 54 | |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 55 | // SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS |
| 56 | typedef enum { |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 57 | #if COMPOUND_SEGMENT_TYPE == 0 |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 58 | UNIFORM_45 = 0, |
| 59 | UNIFORM_45_INV, |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 60 | #elif COMPOUND_SEGMENT_TYPE == 1 |
Sarah Parker | 7bb84f3 | 2017-05-09 15:17:46 -0700 | [diff] [blame] | 61 | DIFFWTD_38 = 0, |
| 62 | DIFFWTD_38_INV, |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 63 | #endif // COMPOUND_SEGMENT_TYPE |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 64 | SEG_MASK_TYPES, |
| 65 | } SEG_MASK_TYPE; |
| 66 | |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 67 | #endif // CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 68 | #endif // CONFIG_EXT_INTER |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 69 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | typedef enum { |
| 71 | KEY_FRAME = 0, |
| 72 | INTER_FRAME = 1, |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 73 | #if CONFIG_OBU |
| 74 | INTRA_ONLY_FRAME = 2, // replaces intra-only |
| 75 | S_FRAME = 3, |
| 76 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | FRAME_TYPES, |
| 78 | } FRAME_TYPE; |
| 79 | |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 80 | static INLINE int is_comp_ref_allowed(BLOCK_SIZE bsize) { |
| 81 | (void)bsize; |
| 82 | #if SUB8X8_COMP_REF |
| 83 | return 1; |
| 84 | #else |
| 85 | return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
| 86 | #endif // SUB8X8_COMP_REF |
| 87 | } |
| 88 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | static INLINE int is_inter_mode(PREDICTION_MODE mode) { |
| 90 | #if CONFIG_EXT_INTER |
| 91 | return mode >= NEARESTMV && mode <= NEW_NEWMV; |
| 92 | #else |
| 93 | return mode >= NEARESTMV && mode <= NEWMV; |
| 94 | #endif // CONFIG_EXT_INTER |
| 95 | } |
| 96 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 97 | #if CONFIG_PVQ |
| 98 | typedef struct PVQ_INFO { |
| 99 | int theta[PVQ_MAX_PARTITIONS]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 100 | int qg[PVQ_MAX_PARTITIONS]; |
| 101 | int k[PVQ_MAX_PARTITIONS]; |
Yushin Cho | 48f84db | 2016-11-07 21:20:17 -0800 | [diff] [blame] | 102 | od_coeff y[OD_TXSIZE_MAX * OD_TXSIZE_MAX]; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 103 | int nb_bands; |
| 104 | int off[PVQ_MAX_PARTITIONS]; |
| 105 | int size[PVQ_MAX_PARTITIONS]; |
| 106 | int skip_rest; |
| 107 | int skip_dir; |
ltrudeau | e1c0929 | 2017-01-20 15:42:13 -0500 | [diff] [blame] | 108 | int bs; // log of the block size minus two, |
| 109 | // i.e. equivalent to aom's TX_SIZE |
| 110 | // Block skip info, indicating whether DC/AC, is coded. |
| 111 | PVQ_SKIP_TYPE ac_dc_coded; // bit0: DC coded, bit1 : AC coded (1 means coded) |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 112 | tran_low_t dq_dc_residue; |
| 113 | } PVQ_INFO; |
| 114 | |
| 115 | typedef struct PVQ_QUEUE { |
| 116 | PVQ_INFO *buf; // buffer for pvq info, stored in encoding order |
| 117 | int curr_pos; // curr position to write PVQ_INFO |
| 118 | int buf_len; // allocated buffer length |
| 119 | int last_pos; // last written position of PVQ_INFO in a tile |
| 120 | } PVQ_QUEUE; |
| 121 | #endif |
| 122 | |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 123 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 124 | typedef struct superblock_mi_boundaries { |
| 125 | int mi_row_begin; |
| 126 | int mi_col_begin; |
| 127 | int mi_row_end; |
| 128 | int mi_col_end; |
| 129 | } SB_MI_BD; |
| 130 | |
Wei-Ting Lin | b586de8 | 2017-08-03 15:17:38 -0700 | [diff] [blame] | 131 | typedef struct { int16_t KERNEL[4][MAX_SB_SIZE][MAX_SB_SIZE]; } NCOBMC_KERNELS; |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 132 | #endif |
| 133 | |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 134 | typedef struct { |
| 135 | uint8_t *plane[MAX_MB_PLANE]; |
| 136 | int stride[MAX_MB_PLANE]; |
| 137 | } BUFFER_SET; |
| 138 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 139 | #if CONFIG_EXT_INTER |
| 140 | static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) { |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 141 | return mode >= NEARESTMV && mode <= NEWMV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 142 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 143 | static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) { |
| 144 | return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV; |
| 145 | } |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 146 | #if CONFIG_COMPOUND_SINGLEREF |
| 147 | static INLINE int is_inter_singleref_comp_mode(PREDICTION_MODE mode) { |
| 148 | return mode >= SR_NEAREST_NEARMV && mode <= SR_NEW_NEWMV; |
| 149 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 150 | static INLINE int is_inter_anyref_comp_mode(PREDICTION_MODE mode) { |
| 151 | return is_inter_compound_mode(mode) || is_inter_singleref_comp_mode(mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 152 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 153 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 154 | |
| 155 | static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) { |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 156 | static PREDICTION_MODE lut[] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 157 | MB_MODE_COUNT, // DC_PRED |
| 158 | MB_MODE_COUNT, // V_PRED |
| 159 | MB_MODE_COUNT, // H_PRED |
| 160 | MB_MODE_COUNT, // D45_PRED |
| 161 | MB_MODE_COUNT, // D135_PRED |
| 162 | MB_MODE_COUNT, // D117_PRED |
| 163 | MB_MODE_COUNT, // D153_PRED |
| 164 | MB_MODE_COUNT, // D207_PRED |
| 165 | MB_MODE_COUNT, // D63_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 166 | MB_MODE_COUNT, // SMOOTH_PRED |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 167 | #if CONFIG_SMOOTH_HV |
| 168 | MB_MODE_COUNT, // SMOOTH_V_PRED |
| 169 | MB_MODE_COUNT, // SMOOTH_H_PRED |
| 170 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 171 | MB_MODE_COUNT, // TM_PRED |
| 172 | MB_MODE_COUNT, // NEARESTMV |
| 173 | MB_MODE_COUNT, // NEARMV |
| 174 | MB_MODE_COUNT, // ZEROMV |
| 175 | MB_MODE_COUNT, // NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 176 | #if CONFIG_COMPOUND_SINGLEREF |
| 177 | NEARESTMV, // SR_NEAREST_NEARMV |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 178 | // NEARESTMV, // SR_NEAREST_NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 179 | NEARMV, // SR_NEAR_NEWMV |
| 180 | ZEROMV, // SR_ZERO_NEWMV |
| 181 | NEWMV, // SR_NEW_NEWMV |
| 182 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 183 | NEARESTMV, // NEAREST_NEARESTMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 184 | NEARMV, // NEAR_NEARMV |
| 185 | NEARESTMV, // NEAREST_NEWMV |
| 186 | NEWMV, // NEW_NEARESTMV |
| 187 | NEARMV, // NEAR_NEWMV |
| 188 | NEWMV, // NEW_NEARMV |
| 189 | ZEROMV, // ZERO_ZEROMV |
| 190 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 191 | }; |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 192 | assert(NELEMENTS(lut) == MB_MODE_COUNT); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 193 | #if CONFIG_COMPOUND_SINGLEREF |
| 194 | assert(is_inter_anyref_comp_mode(mode)); |
| 195 | #else // !CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | assert(is_inter_compound_mode(mode)); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 197 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 198 | return lut[mode]; |
| 199 | } |
| 200 | |
| 201 | static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) { |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 202 | static PREDICTION_MODE lut[] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 203 | MB_MODE_COUNT, // DC_PRED |
| 204 | MB_MODE_COUNT, // V_PRED |
| 205 | MB_MODE_COUNT, // H_PRED |
| 206 | MB_MODE_COUNT, // D45_PRED |
| 207 | MB_MODE_COUNT, // D135_PRED |
| 208 | MB_MODE_COUNT, // D117_PRED |
| 209 | MB_MODE_COUNT, // D153_PRED |
| 210 | MB_MODE_COUNT, // D207_PRED |
| 211 | MB_MODE_COUNT, // D63_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 212 | MB_MODE_COUNT, // SMOOTH_PRED |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 213 | #if CONFIG_SMOOTH_HV |
| 214 | MB_MODE_COUNT, // SMOOTH_V_PRED |
| 215 | MB_MODE_COUNT, // SMOOTH_H_PRED |
| 216 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 217 | MB_MODE_COUNT, // TM_PRED |
| 218 | MB_MODE_COUNT, // NEARESTMV |
| 219 | MB_MODE_COUNT, // NEARMV |
| 220 | MB_MODE_COUNT, // ZEROMV |
| 221 | MB_MODE_COUNT, // NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 222 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 223 | NEARMV, // SR_NEAREST_NEARMV |
| 224 | // NEWMV, // SR_NEAREST_NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 225 | NEWMV, // SR_NEAR_NEWMV |
| 226 | NEWMV, // SR_ZERO_NEWMV |
| 227 | NEWMV, // SR_NEW_NEWMV |
| 228 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 229 | NEARESTMV, // NEAREST_NEARESTMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 230 | NEARMV, // NEAR_NEARMV |
| 231 | NEWMV, // NEAREST_NEWMV |
| 232 | NEARESTMV, // NEW_NEARESTMV |
| 233 | NEWMV, // NEAR_NEWMV |
| 234 | NEARMV, // NEW_NEARMV |
| 235 | ZEROMV, // ZERO_ZEROMV |
| 236 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 237 | }; |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 238 | assert(NELEMENTS(lut) == MB_MODE_COUNT); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 239 | #if CONFIG_COMPOUND_SINGLEREF |
| 240 | assert(is_inter_anyref_comp_mode(mode)); |
| 241 | #else // !CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 242 | assert(is_inter_compound_mode(mode)); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 243 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 244 | return lut[mode]; |
| 245 | } |
| 246 | |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 247 | static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) { |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 248 | return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV || |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 249 | #if CONFIG_COMPOUND_SINGLEREF |
| 250 | mode == SR_NEAREST_NEARMV || mode == SR_NEAR_NEWMV || |
| 251 | #endif // CONFIG_COMPOUND_SINGLEREF |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 252 | mode == NEW_NEARMV); |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 255 | static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) { |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 256 | return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV || |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 257 | #if CONFIG_COMPOUND_SINGLEREF |
| 258 | /* mode == SR_NEAREST_NEWMV || */ mode == SR_NEAR_NEWMV || |
| 259 | mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV || |
| 260 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 261 | mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 262 | } |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 263 | |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 264 | static INLINE int use_masked_motion_search(COMPOUND_TYPE type) { |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 265 | #if CONFIG_WEDGE |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 266 | return (type == COMPOUND_WEDGE); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 267 | #else |
| 268 | (void)type; |
| 269 | return 0; |
| 270 | #endif |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 273 | static INLINE int is_masked_compound_type(COMPOUND_TYPE type) { |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 274 | #if CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 275 | return (type == COMPOUND_WEDGE || type == COMPOUND_SEG); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 276 | #elif !CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 277 | return (type == COMPOUND_WEDGE); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 278 | #elif CONFIG_COMPOUND_SEGMENT && !CONFIG_WEDGE |
| 279 | return (type == COMPOUND_SEG); |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 280 | #endif // CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 281 | (void)type; |
| 282 | return 0; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 283 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 284 | |
| 285 | #else // !CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 286 | |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 287 | static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) { |
| 288 | return (mode == NEARMV); |
| 289 | } |
| 290 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) { |
| 292 | return (mode == NEWMV); |
| 293 | } |
| 294 | #endif // CONFIG_EXT_INTER |
| 295 | |
| 296 | /* For keyframes, intra block modes are predicted by the (already decoded) |
| 297 | modes for the Y blocks to the left and above us; for interframes, there |
| 298 | is a single probability table. */ |
| 299 | |
| 300 | typedef struct { |
| 301 | PREDICTION_MODE as_mode; |
| 302 | int_mv as_mv[2]; // first, second inter predictor motion vectors |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 303 | int_mv pred_mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | #if CONFIG_EXT_INTER |
| 305 | int_mv ref_mv[2]; |
| 306 | #endif // CONFIG_EXT_INTER |
| 307 | } b_mode_info; |
| 308 | |
| 309 | typedef int8_t MV_REFERENCE_FRAME; |
| 310 | |
| 311 | typedef struct { |
| 312 | // Number of base colors for Y (0) and UV (1) |
| 313 | uint8_t palette_size[2]; |
hui su | fa4ff85 | 2017-05-15 12:20:50 -0700 | [diff] [blame] | 314 | // Value of base colors for Y, U, and V |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | uint16_t palette_colors[3 * PALETTE_MAX_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 316 | } PALETTE_MODE_INFO; |
| 317 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 318 | #if CONFIG_FILTER_INTRA |
Yue Chen | 8d8638a | 2017-02-21 13:28:16 +0800 | [diff] [blame] | 319 | #define USE_3TAP_INTRA_FILTER 1 // 0: 4-tap; 1: 3-tap |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 320 | typedef struct { |
| 321 | // 1: an ext intra mode is used; 0: otherwise. |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 322 | uint8_t use_filter_intra_mode[PLANE_TYPES]; |
| 323 | FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES]; |
| 324 | } FILTER_INTRA_MODE_INFO; |
| 325 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 326 | |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 327 | #if CONFIG_VAR_TX |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 328 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 329 | #define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE) |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 330 | #endif |
| 331 | #endif |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 332 | |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 333 | typedef struct RD_STATS { |
| 334 | int rate; |
| 335 | int64_t dist; |
Angie Chiang | 7bbd3b1 | 2017-04-26 11:06:09 -0700 | [diff] [blame] | 336 | // Please be careful of using rdcost, it's not guaranteed to be set all the |
| 337 | // time. |
| 338 | // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In |
| 339 | // these functions, make sure rdcost is always up-to-date according to |
| 340 | // rate/dist. |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 341 | int64_t rdcost; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 342 | int64_t sse; |
Angie Chiang | 7bbd3b1 | 2017-04-26 11:06:09 -0700 | [diff] [blame] | 343 | int skip; // sse should equal to dist when skip == 1 |
Jingning Han | 3bce754 | 2017-07-25 10:53:57 -0700 | [diff] [blame] | 344 | int64_t ref_rdcost; |
| 345 | int zero_rate; |
Jingning Han | 1a7f0a8 | 2017-07-27 09:48:05 -0700 | [diff] [blame] | 346 | uint8_t invalid_rate; |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 347 | #if CONFIG_DIST_8X8 && CONFIG_CB4X4 |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 348 | int64_t dist_y; |
| 349 | #endif |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 350 | #if CONFIG_RD_DEBUG |
| 351 | int txb_coeff_cost[MAX_MB_PLANE]; |
Angie Chiang | 3963d63 | 2016-11-10 18:41:40 -0800 | [diff] [blame] | 352 | #if CONFIG_VAR_TX |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 353 | int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE] |
| 354 | [TXB_COEFF_COST_MAP_SIZE]; |
Angie Chiang | 3963d63 | 2016-11-10 18:41:40 -0800 | [diff] [blame] | 355 | #endif // CONFIG_VAR_TX |
| 356 | #endif // CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 357 | } RD_STATS; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 358 | |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 359 | #if CONFIG_EXT_INTER |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 360 | // This struct is used to group function args that are commonly |
| 361 | // sent together in functions related to interinter compound modes |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 362 | typedef struct { |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 363 | #if CONFIG_WEDGE |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 364 | int wedge_index; |
| 365 | int wedge_sign; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 366 | #endif // CONFIG_WEDGE |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 367 | #if CONFIG_COMPOUND_SEGMENT |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 368 | SEG_MASK_TYPE mask_type; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 369 | uint8_t *seg_mask; |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 370 | #endif // CONFIG_COMPOUND_SEGMENT |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 371 | COMPOUND_TYPE interinter_compound_type; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 372 | } INTERINTER_COMPOUND_DATA; |
| 373 | #endif // CONFIG_EXT_INTER |
| 374 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 375 | // This structure now relates to 8x8 block regions. |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 376 | typedef struct MB_MODE_INFO { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | // Common for both INTER and INTRA blocks |
| 378 | BLOCK_SIZE sb_type; |
| 379 | PREDICTION_MODE mode; |
| 380 | TX_SIZE tx_size; |
| 381 | #if CONFIG_VAR_TX |
| 382 | // TODO(jingning): This effectively assigned a separate entry for each |
| 383 | // 8x8 block. Apparently it takes much more space than needed. |
| 384 | TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE]; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 385 | TX_SIZE min_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | #endif |
| 387 | int8_t skip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 388 | int8_t segment_id; |
| 389 | #if CONFIG_SUPERTX |
| 390 | // Minimum of all segment IDs under the current supertx block. |
| 391 | int8_t segment_id_supertx; |
| 392 | #endif // CONFIG_SUPERTX |
| 393 | int8_t seg_id_predicted; // valid only when temporal_update is enabled |
| 394 | |
Sarah Parker | c5ccd4c | 2017-08-03 11:27:50 -0700 | [diff] [blame] | 395 | #if CONFIG_MRC_TX |
| 396 | int valid_mrc_mask; |
| 397 | #endif // CONFIG_MRC_TX |
| 398 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 399 | // Only for INTRA blocks |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 400 | UV_PREDICTION_MODE uv_mode; |
Urvang Joshi | c6300aa | 2017-06-01 14:46:23 -0700 | [diff] [blame] | 401 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | PALETTE_MODE_INFO palette_mode_info; |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 403 | #if CONFIG_INTRABC |
| 404 | uint8_t use_intrabc; |
| 405 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 406 | |
| 407 | // Only for INTER blocks |
| 408 | #if CONFIG_DUAL_FILTER |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 409 | InterpFilter interp_filter[4]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 410 | #else |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 411 | InterpFilter interp_filter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 412 | #endif |
| 413 | MV_REFERENCE_FRAME ref_frame[2]; |
| 414 | TX_TYPE tx_type; |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 415 | #if CONFIG_TXK_SEL |
Angie Chiang | 808d859 | 2017-04-06 18:36:55 -0700 | [diff] [blame] | 416 | TX_TYPE txk_type[MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)]; |
| 417 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 418 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 419 | #if CONFIG_FILTER_INTRA |
| 420 | FILTER_INTRA_MODE_INFO filter_intra_mode_info; |
| 421 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 422 | #if CONFIG_EXT_INTRA |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 423 | // The actual prediction angle is the base angle + (angle_delta * step). |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 424 | int8_t angle_delta[2]; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 425 | #if CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 426 | // To-Do (huisu): this may be replaced by interp_filter |
| 427 | INTRA_FILTER intra_filter; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 428 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 429 | #endif // CONFIG_EXT_INTRA |
| 430 | |
| 431 | #if CONFIG_EXT_INTER |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 432 | #if CONFIG_INTERINTRA |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 433 | // interintra members |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 434 | INTERINTRA_MODE interintra_mode; |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 435 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | // TODO(debargha): Consolidate these flags |
| 437 | int use_wedge_interintra; |
| 438 | int interintra_wedge_index; |
| 439 | int interintra_wedge_sign; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 440 | // interinter members |
| 441 | COMPOUND_TYPE interinter_compound_type; |
| 442 | #if CONFIG_WEDGE |
| 443 | int wedge_index; |
| 444 | int wedge_sign; |
| 445 | #endif // CONFIG_WEDGE |
| 446 | #if CONFIG_COMPOUND_SEGMENT |
| 447 | SEG_MASK_TYPE mask_type; |
| 448 | #endif // CONFIG_COMPOUND_SEGMENT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 449 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 450 | MOTION_MODE motion_mode; |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 451 | #if CONFIG_MOTION_VAR |
| 452 | int overlappable_neighbors[2]; |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 453 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 454 | // Applying different weighting kernels in ncobmc |
| 455 | // In current implementation, interpolation modes only defined for squared |
| 456 | // blocks. A rectangular block is divided into two squared blocks and each |
| 457 | // squared block has an interpolation mode. |
| 458 | NCOBMC_MODE ncobmc_mode[2]; |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 459 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 460 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 461 | int_mv mv[2]; |
| 462 | int_mv pred_mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 463 | uint8_t ref_mv_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 464 | #if CONFIG_EXT_PARTITION_TYPES |
| 465 | PARTITION_TYPE partition; |
| 466 | #endif |
| 467 | #if CONFIG_NEW_QUANT |
| 468 | int dq_off_index; |
| 469 | int send_dq_bit; |
| 470 | #endif // CONFIG_NEW_QUANT |
| 471 | /* deringing gain *per-superblock* */ |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 472 | int8_t cdef_strength; |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 473 | #if CONFIG_DELTA_Q |
| 474 | int current_q_index; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 475 | #if CONFIG_EXT_DELTA_Q |
| 476 | int current_delta_lf_from_base; |
| 477 | #endif |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 478 | #endif |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 479 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 480 | RD_STATS rd_stats; |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 481 | int mi_row; |
| 482 | int mi_col; |
| 483 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 484 | #if CONFIG_WARPED_MOTION |
| 485 | int num_proj_ref[2]; |
| 486 | WarpedMotionParams wm_params[2]; |
| 487 | #endif // CONFIG_WARPED_MOTION |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 488 | |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 489 | #if CONFIG_CFL |
| 490 | // Index of the alpha Cb and alpha Cr combination |
Luc Trudeau | a9bd85f | 2017-05-11 14:37:56 -0400 | [diff] [blame] | 491 | int cfl_alpha_idx; |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 492 | // Joint sign of alpha Cb and alpha Cr |
| 493 | int cfl_alpha_signs; |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 494 | #endif |
| 495 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 496 | BOUNDARY_TYPE boundary_info; |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 497 | #if CONFIG_LPF_SB |
| 498 | uint8_t filt_lvl; |
| 499 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 500 | } MB_MODE_INFO; |
| 501 | |
| 502 | typedef struct MODE_INFO { |
| 503 | MB_MODE_INFO mbmi; |
| 504 | b_mode_info bmi[4]; |
| 505 | } MODE_INFO; |
| 506 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 507 | #if CONFIG_INTRABC |
| 508 | static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) { |
| 509 | return mbmi->use_intrabc; |
| 510 | } |
| 511 | #endif |
| 512 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 513 | 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] | 514 | #if CONFIG_CB4X4 |
| 515 | (void)block; |
| 516 | return mi->mbmi.mode; |
| 517 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | 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] | 519 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 522 | #if CONFIG_CFL |
| 523 | static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) { |
| 524 | static const PREDICTION_MODE uv2y[UV_INTRA_MODES] = { |
Urvang Joshi | 93b543a | 2017-06-01 17:32:41 -0700 | [diff] [blame] | 525 | DC_PRED, // UV_DC_PRED |
| 526 | V_PRED, // UV_V_PRED |
| 527 | H_PRED, // UV_H_PRED |
| 528 | D45_PRED, // UV_D45_PRED |
| 529 | D135_PRED, // UV_D135_PRED |
| 530 | D117_PRED, // UV_D117_PRED |
| 531 | D153_PRED, // UV_D153_PRED |
| 532 | D207_PRED, // UV_D207_PRED |
| 533 | D63_PRED, // UV_D63_PRED |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 534 | SMOOTH_PRED, // UV_SMOOTH_PRED |
| 535 | #if CONFIG_SMOOTH_HV |
| 536 | SMOOTH_V_PRED, // UV_SMOOTH_V_PRED |
| 537 | SMOOTH_H_PRED, // UV_SMOOTH_H_PRED |
| 538 | #endif // CONFIG_SMOOTH_HV |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 539 | TM_PRED, // UV_TM_PRED |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 540 | DC_PRED, // CFL_PRED |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 541 | }; |
| 542 | return uv2y[mode]; |
| 543 | } |
| 544 | #else |
| 545 | static INLINE PREDICTION_MODE get_uv_mode(PREDICTION_MODE mode) { return mode; } |
| 546 | #endif // CONFIG_CFL |
| 547 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 548 | static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) { |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 549 | #if CONFIG_INTRABC |
| 550 | if (is_intrabc_block(mbmi)) return 1; |
| 551 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 552 | return mbmi->ref_frame[0] > INTRA_FRAME; |
| 553 | } |
| 554 | |
| 555 | static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) { |
| 556 | return mbmi->ref_frame[1] > INTRA_FRAME; |
| 557 | } |
| 558 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 559 | #if CONFIG_EXT_COMP_REFS |
| 560 | static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) { |
| 561 | return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^ |
| 562 | (mbmi->ref_frame[1] >= BWDREF_FRAME))); |
| 563 | } |
| 564 | |
| 565 | static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) { |
| 566 | static const MV_REFERENCE_FRAME lut[] = { |
| 567 | LAST_FRAME, // LAST_LAST2_FRAMES, |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 568 | LAST_FRAME, // LAST_LAST3_FRAMES, |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 569 | LAST_FRAME, // LAST_GOLDEN_FRAMES, |
| 570 | BWDREF_FRAME, // BWDREF_ALTREF_FRAMES, |
| 571 | }; |
| 572 | assert(NELEMENTS(lut) == UNIDIR_COMP_REFS); |
| 573 | return lut[ref_idx]; |
| 574 | } |
| 575 | |
| 576 | static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) { |
| 577 | static const MV_REFERENCE_FRAME lut[] = { |
| 578 | LAST2_FRAME, // LAST_LAST2_FRAMES, |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 579 | LAST3_FRAME, // LAST_LAST3_FRAMES, |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 580 | GOLDEN_FRAME, // LAST_GOLDEN_FRAMES, |
| 581 | ALTREF_FRAME, // BWDREF_ALTREF_FRAMES, |
| 582 | }; |
| 583 | assert(NELEMENTS(lut) == UNIDIR_COMP_REFS); |
| 584 | return lut[ref_idx]; |
| 585 | } |
| 586 | #endif // CONFIG_EXT_COMP_REFS |
| 587 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 588 | PREDICTION_MODE av1_left_block_mode(const MODE_INFO *cur_mi, |
| 589 | const MODE_INFO *left_mi, int b); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 590 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 591 | PREDICTION_MODE av1_above_block_mode(const MODE_INFO *cur_mi, |
| 592 | const MODE_INFO *above_mi, int b); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 593 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 594 | #if CONFIG_GLOBAL_MOTION |
| 595 | static INLINE int is_global_mv_block(const MODE_INFO *mi, int block, |
| 596 | TransformationType type) { |
| 597 | PREDICTION_MODE mode = get_y_mode(mi, block); |
| 598 | #if GLOBAL_SUB8X8_USED |
| 599 | const int block_size_allowed = 1; |
| 600 | #else |
| 601 | const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
Debargha Mukherjee | c17a443 | 2017-08-28 22:22:45 -0700 | [diff] [blame] | 602 | const int block_size_allowed = |
| 603 | AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 604 | #endif // GLOBAL_SUB8X8_USED |
| 605 | #if CONFIG_EXT_INTER |
| 606 | return (mode == ZEROMV || mode == ZERO_ZEROMV) && type > TRANSLATION && |
| 607 | block_size_allowed; |
| 608 | #else |
| 609 | return mode == ZEROMV && type > TRANSLATION && block_size_allowed; |
| 610 | #endif // CONFIG_EXT_INTER |
| 611 | } |
| 612 | #endif // CONFIG_GLOBAL_MOTION |
| 613 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 614 | enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 }; |
| 615 | |
| 616 | struct buf_2d { |
| 617 | uint8_t *buf; |
| 618 | uint8_t *buf0; |
| 619 | int width; |
| 620 | int height; |
| 621 | int stride; |
| 622 | }; |
| 623 | |
| 624 | typedef struct macroblockd_plane { |
| 625 | tran_low_t *dqcoeff; |
| 626 | PLANE_TYPE plane_type; |
| 627 | int subsampling_x; |
| 628 | int subsampling_y; |
| 629 | struct buf_2d dst; |
| 630 | struct buf_2d pre[2]; |
| 631 | ENTROPY_CONTEXT *above_context; |
| 632 | ENTROPY_CONTEXT *left_context; |
| 633 | int16_t seg_dequant[MAX_SEGMENTS][2]; |
| 634 | #if CONFIG_NEW_QUANT |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 635 | dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][QUANT_PROFILES] |
| 636 | [COEF_BANDS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 637 | #endif |
| 638 | uint8_t *color_index_map; |
| 639 | |
| 640 | // number of 4x4s in current block |
| 641 | uint16_t n4_w, n4_h; |
| 642 | // log2 of n4_w, n4_h |
| 643 | uint8_t n4_wl, n4_hl; |
Jingning Han | c47fe6c | 2016-10-21 16:40:47 -0700 | [diff] [blame] | 644 | // block size in pixels |
| 645 | uint8_t width, height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 646 | |
| 647 | #if CONFIG_AOM_QM |
Sarah Parker | 172f3c1 | 2017-09-08 14:23:36 -0700 | [diff] [blame] | 648 | qm_val_t *seg_iqmatrix[MAX_SEGMENTS][2][TX_SIZES_ALL]; |
| 649 | qm_val_t *seg_qmatrix[MAX_SEGMENTS][2][TX_SIZES_ALL]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 650 | #endif |
| 651 | // encoder |
| 652 | const int16_t *dequant; |
| 653 | #if CONFIG_NEW_QUANT |
| 654 | const dequant_val_type_nuq *dequant_val_nuq[QUANT_PROFILES]; |
| 655 | #endif // CONFIG_NEW_QUANT |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 656 | |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 657 | #if CONFIG_PVQ || CONFIG_DIST_8X8 |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 658 | DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]); |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 659 | #endif |
| 660 | #if CONFIG_PVQ |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 661 | // PVQ: forward transformed predicted image, a reference for PVQ. |
| 662 | tran_low_t *pvq_ref_coeff; |
| 663 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 664 | } MACROBLOCKD_PLANE; |
| 665 | |
Jingning Han | 3468df1 | 2016-12-05 17:53:16 -0800 | [diff] [blame] | 666 | #define BLOCK_OFFSET(x, i) \ |
| 667 | ((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] | 668 | |
| 669 | typedef struct RefBuffer { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 670 | int idx; |
| 671 | YV12_BUFFER_CONFIG *buf; |
| 672 | struct scale_factors sf; |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 673 | #if CONFIG_VAR_REFS |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 674 | int is_valid; |
| 675 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | } RefBuffer; |
| 677 | |
Yi Luo | 2ab63cb | 2017-05-11 16:44:22 -0700 | [diff] [blame] | 678 | #if CONFIG_ADAPT_SCAN |
| 679 | typedef int16_t EobThresholdMD[TX_TYPES][EOB_THRESHOLD_NUM]; |
| 680 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 681 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 682 | #if CONFIG_LOOP_RESTORATION |
| 683 | typedef struct { |
| 684 | DECLARE_ALIGNED(16, InterpKernel, vfilter); |
| 685 | DECLARE_ALIGNED(16, InterpKernel, hfilter); |
| 686 | } WienerInfo; |
| 687 | |
| 688 | typedef struct { |
| 689 | int ep; |
| 690 | int xqd[2]; |
| 691 | } SgrprojInfo; |
| 692 | #endif // CONFIG_LOOP_RESTORATION |
| 693 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 694 | #if CONFIG_CFL |
Luc Trudeau | 03b7e7d | 2017-09-19 13:20:52 -0400 | [diff] [blame] | 695 | #if CONFIG_CHROMA_SUB8X8 && CONFIG_DEBUG |
| 696 | #define CFL_SUB8X8_VAL_MI_SIZE (4) |
| 697 | #define CFL_SUB8X8_VAL_MI_SQUARE \ |
| 698 | (CFL_SUB8X8_VAL_MI_SIZE * CFL_SUB8X8_VAL_MI_SIZE) |
| 699 | #endif // CONFIG_CHROMA_SUB8X8 && CONFIG_DEBUG |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 700 | typedef struct cfl_ctx { |
| 701 | // Pixel buffer containing the luma pixels used as prediction for chroma |
| 702 | // TODO(ltrudeau) Convert to uint16 for HBD support |
| 703 | uint8_t y_pix[MAX_SB_SQUARE]; |
| 704 | |
| 705 | // Pixel buffer containing the downsampled luma pixels used as prediction for |
| 706 | // chroma |
| 707 | // TODO(ltrudeau) Convert to uint16 for HBD support |
| 708 | uint8_t y_down_pix[MAX_SB_SQUARE]; |
| 709 | |
| 710 | // Height and width of the luma prediction block currently in the pixel buffer |
| 711 | int y_height, y_width; |
| 712 | |
| 713 | // Height and width of the chroma prediction block currently associated with |
| 714 | // this context |
| 715 | int uv_height, uv_width; |
| 716 | |
| 717 | // Transform level averages of the luma reconstructed values over the entire |
| 718 | // prediction unit |
| 719 | // Fixed point y_averages is Q12.3: |
| 720 | // * Worst case division is 1/1024 |
| 721 | // * Max error will be 1/16th. |
| 722 | // Note: 3 is chosen so that y_averages fits in 15 bits when 12 bit input is |
| 723 | // used |
Luc Trudeau | f1cf717 | 2017-09-19 13:32:05 -0400 | [diff] [blame] | 724 | int y_averages_q3[MAX_NUM_TXB_SQUARE]; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 725 | int y_averages_stride; |
| 726 | |
| 727 | int are_parameters_computed; |
| 728 | |
| 729 | // Chroma subsampling |
| 730 | int subsampling_x, subsampling_y; |
| 731 | |
| 732 | // Block level DC_PRED for each chromatic plane |
| 733 | int dc_pred[CFL_PRED_PLANES]; |
| 734 | |
| 735 | int mi_row, mi_col; |
| 736 | |
| 737 | // Whether the reconstructed luma pixels need to be stored |
| 738 | int store_y; |
| 739 | |
| 740 | #if CONFIG_CB4X4 |
| 741 | int is_chroma_reference; |
| 742 | #if CONFIG_CHROMA_SUB8X8 && CONFIG_DEBUG |
| 743 | // The prediction used for sub8x8 blocks originates from multiple luma blocks, |
| 744 | // this array is used to validate that cfl_store() is called only once for |
| 745 | // each luma block |
Luc Trudeau | 03b7e7d | 2017-09-19 13:20:52 -0400 | [diff] [blame] | 746 | uint8_t sub8x8_val[CFL_SUB8X8_VAL_MI_SQUARE]; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 747 | #endif // CONFIG_CHROMA_SUB8X8 && CONFIG_DEBUG |
| 748 | #endif // CONFIG_CB4X4 |
| 749 | } CFL_CTX; |
| 750 | #endif // CONFIG_CFL |
| 751 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | typedef struct macroblockd { |
| 753 | struct macroblockd_plane plane[MAX_MB_PLANE]; |
| 754 | uint8_t bmode_blocks_wl; |
| 755 | uint8_t bmode_blocks_hl; |
| 756 | |
| 757 | FRAME_COUNTS *counts; |
| 758 | TileInfo tile; |
| 759 | |
| 760 | int mi_stride; |
| 761 | |
| 762 | MODE_INFO **mi; |
| 763 | MODE_INFO *left_mi; |
| 764 | MODE_INFO *above_mi; |
| 765 | MB_MODE_INFO *left_mbmi; |
| 766 | MB_MODE_INFO *above_mbmi; |
| 767 | |
| 768 | int up_available; |
| 769 | int left_available; |
Jingning Han | 3da18d6 | 2017-05-02 12:43:58 -0700 | [diff] [blame] | 770 | #if CONFIG_CHROMA_SUB8X8 |
| 771 | int chroma_up_available; |
| 772 | int chroma_left_available; |
| 773 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 774 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 775 | const aom_prob (*partition_probs)[PARTITION_TYPES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 776 | |
Rupert Swarbrick | 57486c5 | 2017-08-14 10:53:49 +0100 | [diff] [blame] | 777 | /* Distance of MB away from frame edges in subpixels (1/8th pixel) */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | int mb_to_left_edge; |
| 779 | int mb_to_right_edge; |
| 780 | int mb_to_top_edge; |
| 781 | int mb_to_bottom_edge; |
| 782 | |
| 783 | FRAME_CONTEXT *fc; |
| 784 | |
| 785 | /* pointers to reference frames */ |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 786 | const RefBuffer *block_refs[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 787 | |
| 788 | /* pointer to current frame */ |
| 789 | const YV12_BUFFER_CONFIG *cur_buf; |
| 790 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 791 | #if CONFIG_INTRABC |
| 792 | /* Scale of the current frame with respect to itself */ |
| 793 | struct scale_factors sf_identity; |
| 794 | #endif |
| 795 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 796 | ENTROPY_CONTEXT *above_context[MAX_MB_PLANE]; |
| 797 | ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE]; |
| 798 | |
| 799 | PARTITION_CONTEXT *above_seg_context; |
| 800 | PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE]; |
| 801 | |
| 802 | #if CONFIG_VAR_TX |
| 803 | TXFM_CONTEXT *above_txfm_context; |
| 804 | TXFM_CONTEXT *left_txfm_context; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 805 | TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | |
| 807 | TX_SIZE max_tx_size; |
| 808 | #if CONFIG_SUPERTX |
| 809 | TX_SIZE supertx_size; |
| 810 | #endif |
| 811 | #endif |
| 812 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 813 | #if CONFIG_LOOP_RESTORATION |
| 814 | WienerInfo wiener_info[MAX_MB_PLANE]; |
| 815 | SgrprojInfo sgrproj_info[MAX_MB_PLANE]; |
| 816 | #endif // CONFIG_LOOP_RESTORATION |
| 817 | |
Jingning Han | ff6ee6a | 2016-12-07 09:55:21 -0800 | [diff] [blame] | 818 | // block dimension in the unit of mode_info. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 819 | uint8_t n8_w, n8_h; |
| 820 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 821 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES]; |
| 822 | CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE]; |
| 823 | uint8_t is_sec_rect; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 825 | #if CONFIG_PVQ |
| 826 | daala_dec_ctx daala_dec; |
| 827 | #endif |
Thomas Davies | f77d4ad | 2017-01-10 18:55:42 +0000 | [diff] [blame] | 828 | FRAME_CONTEXT *tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 829 | /* Bit depth: 8, 10, 12 */ |
| 830 | int bd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 831 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 832 | int qindex[MAX_SEGMENTS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | int lossless[MAX_SEGMENTS]; |
| 834 | int corrupted; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 835 | #if CONFIG_AMVR |
| 836 | int cur_frame_mv_precision_level; |
| 837 | // same with that in AV1_COMMON |
| 838 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 839 | struct aom_internal_error_info *error_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 840 | #if CONFIG_GLOBAL_MOTION |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 841 | WarpedMotionParams *global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 842 | #endif // CONFIG_GLOBAL_MOTION |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 843 | #if CONFIG_DELTA_Q |
| 844 | int prev_qindex; |
| 845 | int delta_qindex; |
| 846 | int current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 847 | #if CONFIG_EXT_DELTA_Q |
| 848 | // Since actual frame level loop filtering level value is not available |
| 849 | // at the beginning of the tile (only available during actual filtering) |
| 850 | // at encoder side.we record the delta_lf (against the frame level loop |
| 851 | // filtering level) and code the delta between previous superblock's delta |
| 852 | // lf and current delta lf. It is equivalent to the delta between previous |
| 853 | // superblock's actual lf and current lf. |
| 854 | int prev_delta_lf_from_base; |
| 855 | int current_delta_lf_from_base; |
| 856 | #endif |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 857 | #endif |
Yi Luo | f8e87b4 | 2017-04-14 17:20:27 -0700 | [diff] [blame] | 858 | #if CONFIG_ADAPT_SCAN |
| 859 | const EobThresholdMD *eob_threshold_md; |
| 860 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 861 | |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 862 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SEGMENT |
| 863 | DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]); |
| 864 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SEGMENT |
| 865 | |
Sarah Parker | 5c6744b | 2017-08-25 17:27:45 -0700 | [diff] [blame] | 866 | #if CONFIG_MRC_TX |
| 867 | uint8_t *mrc_mask; |
| 868 | #endif // CONFIG_MRC_TX |
| 869 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 870 | #if CONFIG_CFL |
| 871 | CFL_CTX *cfl; |
| 872 | #endif |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 873 | |
| 874 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 875 | uint8_t *ncobmc_pred_buf[MAX_MB_PLANE]; |
| 876 | int ncobmc_pred_buf_stride[MAX_MB_PLANE]; |
| 877 | SB_MI_BD sb_mi_bd; |
| 878 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 879 | } MACROBLOCKD; |
| 880 | |
Yi Luo | 5128109 | 2017-06-26 16:36:15 -0700 | [diff] [blame] | 881 | static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) { |
| 882 | return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0; |
| 883 | } |
| 884 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 885 | static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize, |
| 886 | PARTITION_TYPE partition) { |
| 887 | if (partition == PARTITION_INVALID) |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 888 | return BLOCK_INVALID; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 889 | else |
| 890 | return subsize_lookup[partition][bsize]; |
| 891 | } |
| 892 | |
| 893 | static const TX_TYPE intra_mode_to_tx_type_context[INTRA_MODES] = { |
| 894 | DCT_DCT, // DC |
| 895 | ADST_DCT, // V |
| 896 | DCT_ADST, // H |
| 897 | DCT_DCT, // D45 |
| 898 | ADST_ADST, // D135 |
| 899 | ADST_DCT, // D117 |
| 900 | DCT_ADST, // D153 |
| 901 | DCT_ADST, // D207 |
| 902 | ADST_DCT, // D63 |
Urvang Joshi | 6be4a54 | 2016-11-03 15:24:05 -0700 | [diff] [blame] | 903 | ADST_ADST, // SMOOTH |
Urvang Joshi | e6ca8e8 | 2017-03-15 14:57:41 -0700 | [diff] [blame] | 904 | #if CONFIG_SMOOTH_HV |
| 905 | ADST_DCT, // SMOOTH_V |
| 906 | DCT_ADST, // SMOOTH_H |
| 907 | #endif // CONFIG_SMOOTH_HV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 908 | ADST_ADST, // TM |
| 909 | }; |
| 910 | |
| 911 | #if CONFIG_SUPERTX |
| 912 | static INLINE int supertx_enabled(const MB_MODE_INFO *mbmi) { |
Jingning Han | 9353124 | 2016-12-20 11:54:36 -0800 | [diff] [blame] | 913 | TX_SIZE max_tx_size = txsize_sqr_map[mbmi->tx_size]; |
| 914 | return tx_size_wide[max_tx_size] > |
| 915 | 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] | 916 | } |
| 917 | #endif // CONFIG_SUPERTX |
| 918 | |
Jingning Han | b83e64b | 2017-03-01 14:52:04 -0800 | [diff] [blame] | 919 | #define USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 1 |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 920 | |
Sarah Parker | 076437f | 2017-03-14 17:39:53 -0700 | [diff] [blame] | 921 | #if CONFIG_RECT_TX |
Sarah Parker | 076437f | 2017-03-14 17:39:53 -0700 | [diff] [blame] | 922 | static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; } |
| 923 | #endif // CONFIG_RECT_TX |
| 924 | |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 925 | #if CONFIG_MRC_TX |
| 926 | #define USE_MRC_INTRA 0 |
| 927 | #define USE_MRC_INTER 1 |
Sarah Parker | 99e7daa | 2017-08-29 10:30:13 -0700 | [diff] [blame] | 928 | #define SIGNAL_MRC_MASK_INTRA (USE_MRC_INTRA && 0) |
| 929 | #define SIGNAL_MRC_MASK_INTER (USE_MRC_INTER && 1) |
| 930 | #define SIGNAL_ANY_MRC_MASK (SIGNAL_MRC_MASK_INTRA || SIGNAL_MRC_MASK_INTER) |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 931 | #endif // CONFIG_MRC_TX |
| 932 | |
Jingning Han | b83e64b | 2017-03-01 14:52:04 -0800 | [diff] [blame] | 933 | #if CONFIG_EXT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | #define ALLOW_INTRA_EXT_TX 1 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 935 | |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 936 | // Number of transform types in each set type |
| 937 | static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = { |
| 938 | 1, 2, |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 939 | #if CONFIG_MRC_TX |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 940 | 2, 3, |
| 941 | #endif // CONFIG_MRC_TX |
| 942 | 5, 7, 12, 16, |
| 943 | }; |
| 944 | |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 945 | static const int av1_ext_tx_set_idx_to_type[2][AOMMAX(EXT_TX_SETS_INTRA, |
| 946 | EXT_TX_SETS_INTER)] = { |
| 947 | { |
| 948 | // Intra |
| 949 | EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 950 | #if CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 951 | EXT_TX_SET_MRC_DCT, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 952 | #endif // CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 953 | }, |
| 954 | { |
| 955 | // Inter |
| 956 | EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT, |
| 957 | EXT_TX_SET_DCT_IDTX, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 958 | #if CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 959 | EXT_TX_SET_MRC_DCT_IDTX, |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 960 | #endif // CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 961 | } |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 962 | }; |
| 963 | |
| 964 | static const int use_intra_ext_tx_for_txsize[EXT_TX_SETS_INTRA][EXT_TX_SIZES] = |
| 965 | { |
| 966 | #if CONFIG_CHROMA_2X2 |
| 967 | { 1, 1, 1, 1, 1 }, // unused |
| 968 | { 0, 1, 1, 0, 0 }, |
| 969 | { 0, 0, 0, 1, 0 }, |
| 970 | #if CONFIG_MRC_TX |
| 971 | { 0, 0, 0, 0, 1 }, |
| 972 | #endif // CONFIG_MRC_TX |
| 973 | #else // CONFIG_CHROMA_2X2 |
| 974 | { 1, 1, 1, 1 }, // unused |
| 975 | { 1, 1, 0, 0 }, |
| 976 | { 0, 0, 1, 0 }, |
| 977 | #if CONFIG_MRC_TX |
| 978 | { 0, 0, 0, 1 }, |
| 979 | #endif // CONFIG_MRC_TX |
| 980 | #endif // CONFIG_CHROMA_2X2 |
| 981 | }; |
| 982 | |
| 983 | static const int use_inter_ext_tx_for_txsize[EXT_TX_SETS_INTER][EXT_TX_SIZES] = |
| 984 | { |
| 985 | #if CONFIG_CHROMA_2X2 |
| 986 | { 1, 1, 1, 1, 1 }, // unused |
| 987 | { 0, 1, 1, 0, 0 }, { 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 1 }, |
| 988 | #if CONFIG_MRC_TX |
| 989 | { 0, 0, 0, 0, 1 }, |
| 990 | #endif // CONFIG_MRC_TX |
| 991 | #else // CONFIG_CHROMA_2X2 |
| 992 | { 1, 1, 1, 1 }, // unused |
| 993 | { 1, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 }, |
| 994 | #if CONFIG_MRC_TX |
| 995 | { 0, 0, 0, 1 }, |
| 996 | #endif // CONFIG_MRC_TX |
| 997 | #endif // CONFIG_CHROMA_2X2 |
| 998 | }; |
| 999 | |
| 1000 | // 1D Transforms used in inter set, this needs to be changed if |
| 1001 | // ext_tx_used_inter is changed |
| 1002 | static const int ext_tx_used_inter_1D[EXT_TX_SETS_INTER][TX_TYPES_1D] = { |
| 1003 | { 1, 0, 0, 0 }, { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, |
| 1004 | #if CONFIG_MRC_TX |
| 1005 | { 1, 0, 0, 1 }, |
| 1006 | #endif // CONFIG_MRC_TX |
| 1007 | }; |
| 1008 | |
| 1009 | #if CONFIG_MRC_TX |
| 1010 | static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = { |
| 1011 | { |
| 1012 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1013 | }, |
| 1014 | { |
| 1015 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, |
| 1016 | }, |
| 1017 | { |
| 1018 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
| 1019 | }, |
| 1020 | { |
| 1021 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, |
| 1022 | }, |
| 1023 | { |
| 1024 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, |
| 1025 | }, |
| 1026 | { |
| 1027 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, |
| 1028 | }, |
| 1029 | { |
| 1030 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, |
| 1031 | }, |
| 1032 | { |
| 1033 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, |
| 1034 | }, |
| 1035 | }; |
| 1036 | #else // CONFIG_MRC_TX |
| 1037 | static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = { |
| 1038 | { |
| 1039 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1040 | }, |
| 1041 | { |
| 1042 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
| 1043 | }, |
| 1044 | { |
| 1045 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
| 1046 | }, |
| 1047 | { |
| 1048 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, |
| 1049 | }, |
| 1050 | { |
| 1051 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, |
| 1052 | }, |
| 1053 | { |
| 1054 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 1055 | }, |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1056 | }; |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1057 | #endif // CONFIG_MRC_TX |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1058 | |
| 1059 | static INLINE TxSetType get_ext_tx_set_type(TX_SIZE tx_size, BLOCK_SIZE bs, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 1060 | int is_inter, int use_reduced_set) { |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1061 | const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size]; |
| 1062 | const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size]; |
Debargha Mukherjee | 094c943 | 2017-02-22 10:31:25 -0800 | [diff] [blame] | 1063 | #if CONFIG_CB4X4 && USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1064 | (void)bs; |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1065 | if (tx_size_sqr > TX_32X32) return EXT_TX_SET_DCTONLY; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1066 | #else |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1067 | if (tx_size_sqr > TX_32X32 || bs < BLOCK_8X8) return EXT_TX_SET_DCTONLY; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1068 | #endif |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 1069 | if (use_reduced_set) |
| 1070 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX; |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1071 | #if CONFIG_MRC_TX |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 1072 | if (tx_size == TX_32X32) { |
| 1073 | if (is_inter && USE_MRC_INTER) |
| 1074 | return EXT_TX_SET_MRC_DCT_IDTX; |
| 1075 | else if (!is_inter && USE_MRC_INTRA) |
| 1076 | return EXT_TX_SET_MRC_DCT; |
| 1077 | } |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1078 | #endif // CONFIG_MRC_TX |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1079 | if (tx_size_sqr_up == TX_32X32) |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1080 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY; |
| 1081 | if (is_inter) |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1082 | return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT |
| 1083 | : EXT_TX_SET_ALL16); |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1084 | else |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1085 | return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT4_IDTX |
| 1086 | : EXT_TX_SET_DTT4_IDTX_1DDCT); |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1087 | } |
| 1088 | |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 1089 | // Maps tx set types to the indices. |
| 1090 | static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = { |
| 1091 | { |
| 1092 | // Intra |
| 1093 | 0, -1, |
| 1094 | #if CONFIG_MRC_TX |
| 1095 | 3, -1, |
| 1096 | #endif // CONFIG_MRC_TX |
| 1097 | 2, 1, -1, -1, |
| 1098 | }, |
| 1099 | { |
| 1100 | // Inter |
| 1101 | 0, 3, |
| 1102 | #if CONFIG_MRC_TX |
| 1103 | -1, 4, |
| 1104 | #endif // CONFIG_MRC_TX |
| 1105 | -1, -1, 2, 1, |
| 1106 | }, |
| 1107 | }; |
| 1108 | |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1109 | static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 1110 | int use_reduced_set) { |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 1111 | const TxSetType set_type = |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 1112 | get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set); |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame^] | 1113 | return ext_tx_set_index[is_inter][set_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 1116 | static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 1117 | int use_reduced_set) { |
| 1118 | const int set_type = |
| 1119 | get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set); |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 1120 | return av1_num_ext_tx_set[set_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | #if CONFIG_RECT_TX |
| 1124 | static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1125 | static const char LUT[BLOCK_SIZES_ALL] = { |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1126 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | f4e097b | 2017-01-20 09:23:58 -0800 | [diff] [blame] | 1127 | 0, // BLOCK_2X2 |
| 1128 | 0, // BLOCK_2X4 |
| 1129 | 0, // BLOCK_4X2 |
| 1130 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1131 | 0, // BLOCK_4X4 |
| 1132 | 1, // BLOCK_4X8 |
| 1133 | 1, // BLOCK_8X4 |
| 1134 | 0, // BLOCK_8X8 |
| 1135 | 1, // BLOCK_8X16 |
| 1136 | 1, // BLOCK_16X8 |
| 1137 | 0, // BLOCK_16X16 |
| 1138 | 1, // BLOCK_16X32 |
| 1139 | 1, // BLOCK_32X16 |
| 1140 | 0, // BLOCK_32X32 |
| 1141 | 0, // BLOCK_32X64 |
| 1142 | 0, // BLOCK_64X32 |
| 1143 | 0, // BLOCK_64X64 |
| 1144 | #if CONFIG_EXT_PARTITION |
| 1145 | 0, // BLOCK_64X128 |
| 1146 | 0, // BLOCK_128X64 |
| 1147 | 0, // BLOCK_128X128 |
| 1148 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1149 | 0, // BLOCK_4X16 |
| 1150 | 0, // BLOCK_16X4 |
| 1151 | 0, // BLOCK_8X32 |
| 1152 | 0, // BLOCK_32X8 |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1153 | 0, // BLOCK_16X64 |
| 1154 | 0, // BLOCK_64X16 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1155 | }; |
| 1156 | |
| 1157 | return LUT[bsize]; |
| 1158 | } |
| 1159 | |
Yue Chen | 49587a7 | 2016-09-28 17:09:47 -0700 | [diff] [blame] | 1160 | static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd, |
| 1161 | const MB_MODE_INFO *mbmi) { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1162 | return is_rect_tx_allowed_bsize(mbmi->sb_type) && |
Yue Chen | 49587a7 | 2016-09-28 17:09:47 -0700 | [diff] [blame] | 1163 | !xd->lossless[mbmi->segment_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1164 | } |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 1165 | #endif // CONFIG_RECT_TX |
| 1166 | #endif // CONFIG_EXT_TX |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1167 | |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 1168 | #if CONFIG_RECT_TX_EXT && (CONFIG_EXT_TX || CONFIG_VAR_TX) |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1169 | static INLINE int is_quarter_tx_allowed_bsize(BLOCK_SIZE bsize) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1170 | static const char LUT_QTTX[BLOCK_SIZES_ALL] = { |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1171 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1172 | 0, // BLOCK_2X2 |
| 1173 | 0, // BLOCK_2X4 |
| 1174 | 0, // BLOCK_4X2 |
| 1175 | #endif |
| 1176 | 0, // BLOCK_4X4 |
| 1177 | 0, // BLOCK_4X8 |
| 1178 | 0, // BLOCK_8X4 |
| 1179 | 0, // BLOCK_8X8 |
| 1180 | 1, // BLOCK_8X16 |
| 1181 | 1, // BLOCK_16X8 |
| 1182 | 0, // BLOCK_16X16 |
| 1183 | 0, // BLOCK_16X32 |
| 1184 | 0, // BLOCK_32X16 |
| 1185 | 0, // BLOCK_32X32 |
| 1186 | 0, // BLOCK_32X64 |
| 1187 | 0, // BLOCK_64X32 |
| 1188 | 0, // BLOCK_64X64 |
| 1189 | #if CONFIG_EXT_PARTITION |
| 1190 | 0, // BLOCK_64X128 |
| 1191 | 0, // BLOCK_128X64 |
| 1192 | 0, // BLOCK_128X128 |
| 1193 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1194 | 0, // BLOCK_4X16 |
| 1195 | 0, // BLOCK_16X4 |
| 1196 | 0, // BLOCK_8X32 |
| 1197 | 0, // BLOCK_32X8 |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1198 | 0, // BLOCK_16X64 |
| 1199 | 0, // BLOCK_64X16 |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1200 | }; |
| 1201 | |
| 1202 | return LUT_QTTX[bsize]; |
| 1203 | } |
| 1204 | |
| 1205 | static INLINE int is_quarter_tx_allowed(const MACROBLOCKD *xd, |
| 1206 | const MB_MODE_INFO *mbmi, |
| 1207 | int is_inter) { |
| 1208 | return is_quarter_tx_allowed_bsize(mbmi->sb_type) && is_inter && |
| 1209 | !xd->lossless[mbmi->segment_id]; |
| 1210 | } |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 1211 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1212 | |
| 1213 | static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode, |
| 1214 | int is_inter) { |
| 1215 | const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; |
Debargha Mukherjee | 428bbb2 | 2017-03-17 07:30:24 -0700 | [diff] [blame] | 1216 | #if (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1217 | const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize]; |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 1218 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1219 | const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; |
Debargha Mukherjee | 428bbb2 | 2017-03-17 07:30:24 -0700 | [diff] [blame] | 1220 | #endif // (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1221 | (void)is_inter; |
Debargha Mukherjee | 428bbb2 | 2017-03-17 07:30:24 -0700 | [diff] [blame] | 1222 | #if CONFIG_VAR_TX && CONFIG_RECT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1223 | #if CONFIG_CB4X4 |
| 1224 | if (bsize == BLOCK_4X4) |
| 1225 | return AOMMIN(max_txsize_lookup[bsize], largest_tx_size); |
| 1226 | #else |
| 1227 | if (bsize < BLOCK_8X8) |
| 1228 | return AOMMIN(max_txsize_lookup[bsize], largest_tx_size); |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 1229 | #endif |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1230 | if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size) |
| 1231 | return max_rect_tx_size; |
| 1232 | else |
| 1233 | return largest_tx_size; |
| 1234 | #elif CONFIG_EXT_TX && CONFIG_RECT_TX |
| 1235 | if (txsize_sqr_up_map[max_rect_tx_size] <= largest_tx_size) { |
| 1236 | return max_rect_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1237 | } else { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1238 | return largest_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1239 | } |
| 1240 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1241 | return AOMMIN(max_tx_size, largest_tx_size); |
Debargha Mukherjee | 428bbb2 | 2017-03-17 07:30:24 -0700 | [diff] [blame] | 1242 | #endif // CONFIG_VAR_TX && CONFIG_RECT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1245 | #if CONFIG_EXT_INTRA |
hui su | 0a6731f | 2017-04-26 15:23:47 -0700 | [diff] [blame] | 1246 | #define MAX_ANGLE_DELTA 3 |
| 1247 | #define ANGLE_STEP 3 |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1248 | extern const int16_t dr_intra_derivative[90]; |
hui su | 02c7974 | 2017-05-16 17:19:04 -0700 | [diff] [blame] | 1249 | static const uint8_t mode_to_angle_map[] = { |
Urvang Joshi | 93b543a | 2017-06-01 17:32:41 -0700 | [diff] [blame] | 1250 | 0, 90, 180, 45, 135, 111, 157, 203, 67, 0, 0, |
hui su | 02c7974 | 2017-05-16 17:19:04 -0700 | [diff] [blame] | 1251 | #if CONFIG_SMOOTH_HV |
| 1252 | 0, 0, |
| 1253 | #endif // CONFIG_SMOOTH_HV |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1254 | }; |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 1255 | #if CONFIG_INTRA_INTERP |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1256 | // Returns whether filter selection is needed for a given |
| 1257 | // intra prediction angle. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1258 | int av1_is_intra_filter_switchable(int angle); |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 1259 | #endif // CONFIG_INTRA_INTERP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1260 | #endif // CONFIG_EXT_INTRA |
| 1261 | |
Monty Montgomery | cb55dad | 2017-07-11 16:59:52 -0400 | [diff] [blame] | 1262 | #if CONFIG_DCT_ONLY |
| 1263 | #define FIXED_TX_TYPE 1 |
| 1264 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1265 | #define FIXED_TX_TYPE 0 |
Monty Montgomery | cb55dad | 2017-07-11 16:59:52 -0400 | [diff] [blame] | 1266 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1267 | |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1268 | // Converts block_index for given transform size to index of the block in raster |
| 1269 | // order. |
| 1270 | static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size, |
| 1271 | int block_idx) { |
| 1272 | // For transform size 4x8, the possible block_idx values are 0 & 2, because |
| 1273 | // block_idx values are incremented in steps of size 'tx_width_unit x |
| 1274 | // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to |
| 1275 | // block number 1 in raster order, inside an 8x8 MI block. |
| 1276 | // For any other transform size, the two indices are equivalent. |
| 1277 | return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx; |
| 1278 | } |
| 1279 | |
| 1280 | // Inverse of above function. |
| 1281 | // Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now. |
| 1282 | static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size, |
| 1283 | int raster_order) { |
| 1284 | assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4); |
| 1285 | // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4. |
| 1286 | return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0; |
| 1287 | } |
| 1288 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1289 | static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type, |
| 1290 | const MACROBLOCKD *xd, int block_idx, |
| 1291 | TX_SIZE tx_size) { |
| 1292 | const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 1293 | |
Monty Montgomery | cb55dad | 2017-07-11 16:59:52 -0400 | [diff] [blame] | 1294 | if (CONFIG_DCT_ONLY || is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1295 | xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32) |
| 1296 | return DCT_DCT; |
| 1297 | |
| 1298 | return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y |
| 1299 | ? get_y_mode(xd->mi[0], block_idx) |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1300 | : get_uv_mode(mbmi->uv_mode)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1303 | static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type, |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1304 | const MACROBLOCKD *xd, int blk_row, |
| 1305 | int blk_col, int block, TX_SIZE tx_size) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1306 | const MODE_INFO *const mi = xd->mi[0]; |
| 1307 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1308 | (void)blk_row; |
| 1309 | (void)blk_col; |
Alex Converse | daa15e4 | 2017-05-02 14:27:16 -0700 | [diff] [blame] | 1310 | #if CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL) |
| 1311 | // TODO(aconverse@google.com): Handle INTRABC + EXT_TX + TXK_SEL |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1312 | if (is_intrabc_block(mbmi)) return DCT_DCT; |
Alex Converse | daa15e4 | 2017-05-02 14:27:16 -0700 | [diff] [blame] | 1313 | #endif // CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL) |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1314 | |
| 1315 | #if CONFIG_TXK_SEL |
| 1316 | TX_TYPE tx_type; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1317 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] >= TX_32X32) { |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1318 | tx_type = DCT_DCT; |
| 1319 | } else { |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1320 | if (plane_type == PLANE_TYPE_Y) |
| 1321 | tx_type = mbmi->txk_type[(blk_row << 4) + blk_col]; |
| 1322 | else if (is_inter_block(mbmi)) |
| 1323 | tx_type = mbmi->txk_type[(blk_row << 5) + (blk_col << 1)]; |
| 1324 | else |
| 1325 | tx_type = intra_mode_to_tx_type_context[mbmi->uv_mode]; |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1326 | } |
| 1327 | assert(tx_type >= DCT_DCT && tx_type < TX_TYPES); |
| 1328 | return tx_type; |
| 1329 | #endif // CONFIG_TXK_SEL |
| 1330 | |
James Zern | 7cdaa60 | 2017-04-20 20:12:46 -0700 | [diff] [blame] | 1331 | #if FIXED_TX_TYPE |
Angie Chiang | c2ebfbf | 2017-04-15 13:56:58 -0700 | [diff] [blame] | 1332 | const int block_raster_idx = av1_block_index_to_raster_order(tx_size, block); |
James Zern | 7cdaa60 | 2017-04-20 20:12:46 -0700 | [diff] [blame] | 1333 | return get_default_tx_type(plane_type, xd, block_raster_idx, tx_size); |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1334 | #endif // FIXED_TX_TYPE |
| 1335 | |
| 1336 | #if CONFIG_EXT_TX |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1337 | #if CONFIG_MRC_TX |
| 1338 | if (mbmi->tx_type == MRC_DCT) { |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 1339 | assert(((is_inter_block(mbmi) && USE_MRC_INTER) || |
| 1340 | (!is_inter_block(mbmi) && USE_MRC_INTRA)) && |
| 1341 | "INVALID BLOCK TYPE FOR MRC_DCT"); |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1342 | if (plane_type == PLANE_TYPE_Y) { |
| 1343 | assert(tx_size == TX_32X32); |
| 1344 | return mbmi->tx_type; |
| 1345 | } |
| 1346 | return DCT_DCT; |
| 1347 | } |
| 1348 | #endif // CONFIG_MRC_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1349 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 || |
| 1350 | (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi))) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1351 | return DCT_DCT; |
Jingning Han | 8260d8b | 2016-12-28 13:48:43 -0800 | [diff] [blame] | 1352 | if (mbmi->sb_type >= BLOCK_8X8 || CONFIG_CB4X4) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1353 | if (plane_type == PLANE_TYPE_Y) { |
| 1354 | #if !ALLOW_INTRA_EXT_TX |
| 1355 | if (is_inter_block(mbmi)) |
| 1356 | #endif // ALLOW_INTRA_EXT_TX |
| 1357 | return mbmi->tx_type; |
| 1358 | } |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1359 | |
| 1360 | if (is_inter_block(mbmi)) { |
| 1361 | // UV Inter only |
Timothy B. Terriberry | fe67ed6 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1362 | #if CONFIG_CHROMA_2X2 |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1363 | if (tx_size < TX_4X4) return DCT_DCT; |
| 1364 | #endif |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 1365 | return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1366 | ? DCT_DCT |
| 1367 | : mbmi->tx_type; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1368 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Jingning Han | 8260d8b | 2016-12-28 13:48:43 -0800 | [diff] [blame] | 1371 | #if CONFIG_CB4X4 |
Thomas Daede | b7e72f3 | 2017-04-26 13:40:31 -0700 | [diff] [blame] | 1372 | (void)block; |
Timothy B. Terriberry | fe67ed6 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1373 | #if CONFIG_CHROMA_2X2 |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 1374 | if (tx_size < TX_4X4) |
| 1375 | return DCT_DCT; |
| 1376 | else |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1377 | #endif // CONFIG_CHROMA_2X2 |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1378 | return intra_mode_to_tx_type_context[get_uv_mode(mbmi->uv_mode)]; |
Timothy B. Terriberry | fe67ed6 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1379 | #else // CONFIG_CB4X4 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1380 | // Sub8x8-Inter/Intra OR UV-Intra |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1381 | if (is_inter_block(mbmi)) { // Sub8x8-Inter |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1382 | return DCT_DCT; |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1383 | } else { // Sub8x8 Intra OR UV-Intra |
| 1384 | const int block_raster_idx = |
| 1385 | av1_block_index_to_raster_order(tx_size, block); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1386 | return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1387 | ? get_y_mode(mi, block_raster_idx) |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1388 | : get_uv_mode(mbmi->uv_mode)]; |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1389 | } |
Thomas Daede | b7e72f3 | 2017-04-26 13:40:31 -0700 | [diff] [blame] | 1390 | #endif // CONFIG_CB4X4 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1391 | #else // CONFIG_EXT_TX |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1392 | (void)block; |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1393 | #if CONFIG_MRC_TX |
| 1394 | if (mbmi->tx_type == MRC_DCT) { |
| 1395 | if (plane_type == PLANE_TYPE_Y && !xd->lossless[mbmi->segment_id]) { |
| 1396 | assert(tx_size == TX_32X32); |
| 1397 | return mbmi->tx_type; |
| 1398 | } |
| 1399 | return DCT_DCT; |
| 1400 | } |
| 1401 | #endif // CONFIG_MRC_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1402 | if (plane_type != PLANE_TYPE_Y || xd->lossless[mbmi->segment_id] || |
| 1403 | txsize_sqr_map[tx_size] >= TX_32X32) |
| 1404 | return DCT_DCT; |
| 1405 | return mbmi->tx_type; |
| 1406 | #endif // CONFIG_EXT_TX |
| 1407 | } |
| 1408 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1409 | 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] | 1410 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1411 | static INLINE int tx_size_to_depth(TX_SIZE tx_size) { |
Timothy B. Terriberry | fe0fb1d | 2017-05-18 12:15:16 -0700 | [diff] [blame] | 1412 | return (int)(tx_size - TX_SIZE_LUMA_MIN); |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1415 | static INLINE TX_SIZE depth_to_tx_size(int depth) { |
Timothy B. Terriberry | fe0fb1d | 2017-05-18 12:15:16 -0700 | [diff] [blame] | 1416 | return (TX_SIZE)(depth + TX_SIZE_LUMA_MIN); |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1419 | static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi, |
| 1420 | const struct macroblockd_plane *pd) { |
Timothy B. Terriberry | fe67ed6 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1421 | #if CONFIG_CHROMA_2X2 |
Jingning Han | 9353124 | 2016-12-20 11:54:36 -0800 | [diff] [blame] | 1422 | assert(mbmi->tx_size > TX_2X2); |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1423 | #endif // CONFIG_CHROMA_2X2 |
Jingning Han | 9353124 | 2016-12-20 11:54:36 -0800 | [diff] [blame] | 1424 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1425 | #if CONFIG_SUPERTX |
| 1426 | if (supertx_enabled(mbmi)) |
| 1427 | return uvsupertx_size_lookup[txsize_sqr_map[mbmi->tx_size]] |
| 1428 | [pd->subsampling_x][pd->subsampling_y]; |
| 1429 | #endif // CONFIG_SUPERTX |
Jingning Han | cabd989 | 2016-12-01 12:28:42 -0800 | [diff] [blame] | 1430 | |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1431 | const TX_SIZE uv_txsize = |
| 1432 | uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x] |
| 1433 | [pd->subsampling_y]; |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 1434 | assert(uv_txsize != TX_INVALID); |
| 1435 | return uv_txsize; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1438 | static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) { |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 1439 | const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1440 | if (plane == 0) return mbmi->tx_size; |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 1441 | const MACROBLOCKD_PLANE *pd = &xd->plane[plane]; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1442 | return av1_get_uv_tx_size(mbmi, pd); |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 1443 | } |
| 1444 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1445 | static INLINE BLOCK_SIZE |
| 1446 | get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) { |
| 1447 | return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y]; |
| 1448 | } |
| 1449 | |
Timothy B. Terriberry | a2d5cde | 2017-05-10 18:33:50 -0700 | [diff] [blame] | 1450 | void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col, |
| 1451 | BLOCK_SIZE bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1452 | |
| 1453 | typedef void (*foreach_transformed_block_visitor)(int plane, int block, |
| 1454 | int blk_row, int blk_col, |
| 1455 | BLOCK_SIZE plane_bsize, |
| 1456 | TX_SIZE tx_size, void *arg); |
| 1457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1458 | void av1_foreach_transformed_block_in_plane( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1459 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane, |
| 1460 | foreach_transformed_block_visitor visit, void *arg); |
| 1461 | |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 1462 | #if CONFIG_LV_MAP |
| 1463 | void av1_foreach_transformed_block(const MACROBLOCKD *const xd, |
Jingning Han | 94652b8 | 2017-04-04 09:45:02 -0700 | [diff] [blame] | 1464 | BLOCK_SIZE bsize, int mi_row, int mi_col, |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 1465 | foreach_transformed_block_visitor visit, |
| 1466 | void *arg); |
| 1467 | #endif |
| 1468 | |
iole moccagatta | f25a4cf | 2016-11-11 23:57:57 -0800 | [diff] [blame] | 1469 | #if CONFIG_COEF_INTERLEAVE |
| 1470 | static INLINE int get_max_4x4_size(int num_4x4, int mb_to_edge, |
| 1471 | int subsampling) { |
| 1472 | return num_4x4 + (mb_to_edge >= 0 ? 0 : mb_to_edge >> (5 + subsampling)); |
| 1473 | } |
| 1474 | |
| 1475 | void av1_foreach_transformed_block_interleave( |
| 1476 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, |
| 1477 | foreach_transformed_block_visitor visit, void *arg); |
| 1478 | #endif |
| 1479 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1480 | void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, |
Jingning Han | eee4315 | 2016-12-05 09:58:45 -0800 | [diff] [blame] | 1481 | int plane, TX_SIZE tx_size, int has_eob, int aoff, |
| 1482 | int loff); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1483 | |
| 1484 | #if CONFIG_EXT_INTER |
| 1485 | static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) { |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1486 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1487 | // TODO(debargha): Should this be bsize < BLOCK_LARGEST? |
| 1488 | return (bsize >= BLOCK_8X8) && (bsize < BLOCK_64X64); |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1489 | #else |
| 1490 | (void)bsize; |
| 1491 | return 0; |
| 1492 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) { |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1496 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1497 | return (mode >= NEARESTMV) && (mode <= NEWMV); |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1498 | #else |
| 1499 | (void)mode; |
| 1500 | return 0; |
| 1501 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) { |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1505 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1506 | return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME); |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1507 | #else |
| 1508 | (void)rf; |
| 1509 | return 0; |
| 1510 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) { |
| 1514 | return is_interintra_allowed_bsize(mbmi->sb_type) && |
| 1515 | is_interintra_allowed_mode(mbmi->mode) && |
| 1516 | is_interintra_allowed_ref(mbmi->ref_frame); |
| 1517 | } |
| 1518 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1519 | static INLINE int is_interintra_allowed_bsize_group(int group) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1520 | int i; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1521 | for (i = 0; i < BLOCK_SIZES_ALL; i++) { |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 1522 | if (size_group_lookup[i] == group && |
| 1523 | is_interintra_allowed_bsize((BLOCK_SIZE)i)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1524 | return 1; |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 1525 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1526 | } |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) { |
| 1531 | return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi); |
| 1532 | } |
| 1533 | #endif // CONFIG_EXT_INTER |
| 1534 | |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 1535 | #if CONFIG_VAR_TX |
| 1536 | static INLINE int get_vartx_max_txsize(const MB_MODE_INFO *const mbmi, |
| 1537 | BLOCK_SIZE bsize) { |
| 1538 | #if CONFIG_CB4X4 |
| 1539 | (void)mbmi; |
| 1540 | return max_txsize_rect_lookup[bsize]; |
| 1541 | #endif // CONFIG_C4X4 |
| 1542 | return mbmi->sb_type < BLOCK_8X8 ? max_txsize_rect_lookup[mbmi->sb_type] |
| 1543 | : max_txsize_rect_lookup[bsize]; |
| 1544 | } |
| 1545 | #endif // CONFIG_VAR_TX |
| 1546 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1547 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 1548 | static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) { |
Debargha Mukherjee | c17a443 | 2017-08-28 22:22:45 -0700 | [diff] [blame] | 1549 | return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1552 | static INLINE int is_motion_variation_allowed_compound( |
| 1553 | const MB_MODE_INFO *mbmi) { |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1554 | #if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
| 1555 | if (!has_second_ref(mbmi) && !is_inter_singleref_comp_mode(mbmi->mode)) |
| 1556 | #else |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1557 | if (!has_second_ref(mbmi)) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1558 | #endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1559 | return 1; |
| 1560 | else |
| 1561 | return 0; |
| 1562 | } |
| 1563 | |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1564 | #if CONFIG_MOTION_VAR |
Yue Chen | 1bd42be | 2017-03-15 18:07:04 -0700 | [diff] [blame] | 1565 | // input: log2 of length, 0(4), 1(8), ... |
| 1566 | static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 }; |
| 1567 | |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1568 | static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) { |
Yue Chen | 1bd42be | 2017-03-15 18:07:04 -0700 | [diff] [blame] | 1569 | return !(mbmi->overlappable_neighbors[0] == 0 && |
| 1570 | mbmi->overlappable_neighbors[1] == 0); |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1571 | } |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1572 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 1573 | static INLINE NCOBMC_MODE ncobmc_mode_allowed_bsize(BLOCK_SIZE bsize) { |
| 1574 | if (bsize < BLOCK_8X8 || bsize >= BLOCK_64X64) |
| 1575 | return NO_OVERLAP; |
| 1576 | else |
| 1577 | return MAX_NCOBMC_MODES; |
| 1578 | } |
| 1579 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
| 1580 | #endif // CONFIG_MOTION_VAR |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1581 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1582 | static INLINE MOTION_MODE motion_mode_allowed( |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1583 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1584 | int block, const WarpedMotionParams *gm_params, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1585 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1586 | #if CONFIG_WARPED_MOTION |
| 1587 | const MACROBLOCKD *xd, |
| 1588 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1589 | const MODE_INFO *mi) { |
| 1590 | const MB_MODE_INFO *mbmi = &mi->mbmi; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1591 | #if CONFIG_AMVR |
| 1592 | if (xd->cur_frame_mv_precision_level == 0) { |
| 1593 | #endif |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1594 | #if CONFIG_GLOBAL_MOTION |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1595 | const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype; |
| 1596 | if (is_global_mv_block(mi, block, gm_type)) return SIMPLE_TRANSLATION; |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1597 | #endif // CONFIG_GLOBAL_MOTION |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1598 | #if CONFIG_AMVR |
| 1599 | } |
| 1600 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1601 | #if CONFIG_EXT_INTER |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1602 | if (is_motion_variation_allowed_bsize(mbmi->sb_type) && |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1603 | is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME && |
| 1604 | is_motion_variation_allowed_compound(mbmi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1605 | #else |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1606 | if (is_motion_variation_allowed_bsize(mbmi->sb_type) && |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1607 | is_inter_mode(mbmi->mode) && is_motion_variation_allowed_compound(mbmi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1608 | #endif // CONFIG_EXT_INTER |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1609 | #if CONFIG_MOTION_VAR |
| 1610 | if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION; |
| 1611 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1612 | #if CONFIG_WARPED_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1613 | if (!has_second_ref(mbmi) && mbmi->num_proj_ref[0] >= 1 && |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1614 | !av1_is_scaled(&(xd->block_refs[0]->sf))) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1615 | #if CONFIG_AMVR |
| 1616 | if (xd->cur_frame_mv_precision_level) { |
| 1617 | return OBMC_CAUSAL; |
| 1618 | } |
| 1619 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1620 | return WARPED_CAUSAL; |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1621 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1622 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1623 | #endif // CONFIG_WARPED_MOTION |
| 1624 | #if CONFIG_MOTION_VAR |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1625 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1626 | if (ncobmc_mode_allowed_bsize(mbmi->sb_type) < NO_OVERLAP) |
| 1627 | return NCOBMC_ADAPT_WEIGHT; |
| 1628 | else |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1629 | #endif |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1630 | return OBMC_CAUSAL; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1631 | #else |
| 1632 | return SIMPLE_TRANSLATION; |
| 1633 | #endif // CONFIG_MOTION_VAR |
| 1634 | } else { |
| 1635 | return SIMPLE_TRANSLATION; |
| 1636 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1639 | static INLINE void assert_motion_mode_valid(MOTION_MODE mode, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1640 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1641 | int block, |
| 1642 | const WarpedMotionParams *gm_params, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1643 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1644 | #if CONFIG_WARPED_MOTION |
| 1645 | const MACROBLOCKD *xd, |
| 1646 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1647 | const MODE_INFO *mi) { |
| 1648 | const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed( |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1649 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1650 | block, gm_params, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1651 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1652 | #if CONFIG_WARPED_MOTION |
| 1653 | xd, |
| 1654 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1655 | mi); |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1656 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1657 | // Check that the input mode is not illegal |
| 1658 | if (last_motion_mode_allowed < mode) |
| 1659 | assert(0 && "Illegal motion mode selected"); |
| 1660 | } |
| 1661 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1662 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1663 | static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) { |
| 1664 | return (is_inter_block(mbmi)); |
| 1665 | } |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1666 | #endif // CONFIG_MOTION_VAR |
| 1667 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1668 | |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1669 | // Returns sub-sampled dimensions of the given block. |
| 1670 | // The output values for 'rows_within_bounds' and 'cols_within_bounds' will |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1671 | // differ from 'height' and 'width' when part of the block is outside the |
| 1672 | // right |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1673 | // and/or bottom image boundary. |
| 1674 | static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane, |
| 1675 | const MACROBLOCKD *xd, int *width, |
| 1676 | int *height, |
| 1677 | int *rows_within_bounds, |
| 1678 | int *cols_within_bounds) { |
| 1679 | const int block_height = block_size_high[bsize]; |
| 1680 | const int block_width = block_size_wide[bsize]; |
| 1681 | const int block_rows = (xd->mb_to_bottom_edge >= 0) |
| 1682 | ? block_height |
| 1683 | : (xd->mb_to_bottom_edge >> 3) + block_height; |
| 1684 | const int block_cols = (xd->mb_to_right_edge >= 0) |
| 1685 | ? block_width |
| 1686 | : (xd->mb_to_right_edge >> 3) + block_width; |
| 1687 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1688 | assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0)); |
| 1689 | assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0)); |
| 1690 | assert(block_width >= block_cols); |
| 1691 | assert(block_height >= block_rows); |
| 1692 | if (width) *width = block_width >> pd->subsampling_x; |
| 1693 | if (height) *height = block_height >> pd->subsampling_y; |
| 1694 | if (rows_within_bounds) *rows_within_bounds = block_rows >> pd->subsampling_y; |
| 1695 | if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x; |
| 1696 | } |
| 1697 | |
Sarah Parker | efd8af2 | 2017-08-25 16:36:06 -0700 | [diff] [blame] | 1698 | /* clang-format off */ |
| 1699 | typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS] |
| 1700 | [CDF_SIZE(PALETTE_COLORS)]; |
| 1701 | typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS] |
| 1702 | [PALETTE_COLORS]; |
| 1703 | /* clang-format on */ |
| 1704 | |
| 1705 | typedef struct { |
| 1706 | int rows; |
| 1707 | int cols; |
| 1708 | int n_colors; |
| 1709 | int plane_width; |
| 1710 | int plane_height; |
| 1711 | uint8_t *color_map; |
| 1712 | MapCdf map_cdf; |
| 1713 | ColorCost color_cost; |
| 1714 | } Av1ColorMapParam; |
| 1715 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1716 | #if CONFIG_GLOBAL_MOTION |
| 1717 | static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) { |
| 1718 | const MODE_INFO *mi = xd->mi[0]; |
| 1719 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1720 | int ref; |
| 1721 | #if CONFIG_CB4X4 |
| 1722 | const int unify_bsize = 1; |
| 1723 | #else |
| 1724 | const int unify_bsize = 0; |
| 1725 | #endif |
| 1726 | |
| 1727 | // First check if all modes are ZEROMV |
| 1728 | if (mbmi->sb_type >= BLOCK_8X8 || unify_bsize) { |
| 1729 | #if CONFIG_EXT_INTER |
| 1730 | if (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV) return 0; |
| 1731 | #else |
| 1732 | if (mbmi->mode != ZEROMV) return 0; |
| 1733 | #endif // CONFIG_EXT_INTER |
| 1734 | } else { |
| 1735 | #if CONFIG_EXT_INTER |
David Barker | a0c1638 | 2017-07-07 17:01:30 +0100 | [diff] [blame] | 1736 | if ((mi->bmi[0].as_mode != ZEROMV && mi->bmi[0].as_mode != ZERO_ZEROMV) || |
| 1737 | (mi->bmi[1].as_mode != ZEROMV && mi->bmi[1].as_mode != ZERO_ZEROMV) || |
| 1738 | (mi->bmi[2].as_mode != ZEROMV && mi->bmi[2].as_mode != ZERO_ZEROMV) || |
| 1739 | (mi->bmi[3].as_mode != ZEROMV && mi->bmi[3].as_mode != ZERO_ZEROMV)) |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1740 | return 0; |
| 1741 | #else |
| 1742 | if (mi->bmi[0].as_mode != ZEROMV || mi->bmi[1].as_mode != ZEROMV || |
| 1743 | mi->bmi[2].as_mode != ZEROMV || mi->bmi[3].as_mode != ZEROMV) |
| 1744 | return 0; |
| 1745 | #endif // CONFIG_EXT_INTER |
| 1746 | } |
Jingning Han | 3ca0e67 | 2017-04-14 19:48:05 -0700 | [diff] [blame] | 1747 | |
| 1748 | #if !GLOBAL_SUB8X8_USED |
| 1749 | if (mbmi->sb_type < BLOCK_8X8) return 0; |
| 1750 | #endif |
| 1751 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1752 | // Now check if all global motion is non translational |
| 1753 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
| 1754 | if (xd->global_motion[mbmi->ref_frame[ref]].wmtype <= TRANSLATION) return 0; |
| 1755 | } |
| 1756 | return 1; |
| 1757 | } |
| 1758 | #endif // CONFIG_GLOBAL_MOTION |
| 1759 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1760 | static INLINE PLANE_TYPE get_plane_type(int plane) { |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 1761 | return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV; |
| 1762 | } |
| 1763 | |
Angie Chiang | 155bf9a | 2017-08-06 19:52:57 -0700 | [diff] [blame] | 1764 | static INLINE void transpose_uint8(uint8_t *dst, int dst_stride, |
| 1765 | const uint8_t *src, int src_stride, int w, |
| 1766 | int h) { |
| 1767 | int r, c; |
| 1768 | for (r = 0; r < h; ++r) |
| 1769 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1770 | } |
| 1771 | |
| 1772 | static INLINE void transpose_uint16(uint16_t *dst, int dst_stride, |
| 1773 | const uint16_t *src, int src_stride, int w, |
| 1774 | int h) { |
| 1775 | int r, c; |
| 1776 | for (r = 0; r < h; ++r) |
| 1777 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1778 | } |
| 1779 | |
| 1780 | static INLINE void transpose_int16(int16_t *dst, int dst_stride, |
| 1781 | const int16_t *src, int src_stride, int w, |
| 1782 | int h) { |
| 1783 | int r, c; |
| 1784 | for (r = 0; r < h; ++r) |
| 1785 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1786 | } |
| 1787 | |
| 1788 | static INLINE void transpose_int32(int32_t *dst, int dst_stride, |
| 1789 | const int32_t *src, int src_stride, int w, |
| 1790 | int h) { |
| 1791 | int r, c; |
| 1792 | for (r = 0; r < h; ++r) |
| 1793 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1794 | } |
| 1795 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1796 | #ifdef __cplusplus |
| 1797 | } // extern "C" |
| 1798 | #endif |
| 1799 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1800 | #endif // AV1_COMMON_BLOCKD_H_ |