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