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