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