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