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 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 15 | #include "config/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 | |
Debargha Mukherjee | 6cf2b46 | 2018-01-12 15:53:50 -0800 | [diff] [blame] | 34 | #define USE_B_QUANT_NO_TRELLIS 1 |
Debargha Mukherjee | 6cf2b46 | 2018-01-12 15:53:50 -0800 | [diff] [blame] | 35 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #define MAX_MB_PLANE 3 |
| 37 | |
Sarah Parker | 5b4df2b | 2018-04-02 14:48:25 -0700 | [diff] [blame] | 38 | #define MAX_DIFFWTD_MASK_BITS 1 |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 39 | |
Sarah Parker | 5b4df2b | 2018-04-02 14:48:25 -0700 | [diff] [blame] | 40 | // DIFFWTD_MASK_TYPES should not surpass 1 << MAX_DIFFWTD_MASK_BITS |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 41 | typedef enum { |
Sarah Parker | 7bb84f3 | 2017-05-09 15:17:46 -0700 | [diff] [blame] | 42 | DIFFWTD_38 = 0, |
| 43 | DIFFWTD_38_INV, |
Sarah Parker | 5b4df2b | 2018-04-02 14:48:25 -0700 | [diff] [blame] | 44 | DIFFWTD_MASK_TYPES, |
| 45 | } DIFFWTD_MASK_TYPE; |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 46 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | typedef enum { |
| 48 | KEY_FRAME = 0, |
| 49 | INTER_FRAME = 1, |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 50 | INTRA_ONLY_FRAME = 2, // replaces intra-only |
| 51 | S_FRAME = 3, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 52 | FRAME_TYPES, |
| 53 | } FRAME_TYPE; |
| 54 | |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 55 | static INLINE int is_comp_ref_allowed(BLOCK_SIZE bsize) { |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 56 | return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | static INLINE int is_inter_mode(PREDICTION_MODE mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | return mode >= NEARESTMV && mode <= NEW_NEWMV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | } |
| 62 | |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 63 | typedef struct { |
| 64 | uint8_t *plane[MAX_MB_PLANE]; |
| 65 | int stride[MAX_MB_PLANE]; |
| 66 | } BUFFER_SET; |
| 67 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) { |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 69 | return mode >= NEARESTMV && mode <= NEWMV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 71 | static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) { |
| 72 | return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV; |
| 73 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | |
| 75 | static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) { |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 76 | static PREDICTION_MODE lut[] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 77 | MB_MODE_COUNT, // DC_PRED |
| 78 | MB_MODE_COUNT, // V_PRED |
| 79 | MB_MODE_COUNT, // H_PRED |
| 80 | MB_MODE_COUNT, // D45_PRED |
| 81 | MB_MODE_COUNT, // D135_PRED |
Hui Su | 439bcb5 | 2018-02-21 10:52:16 -0800 | [diff] [blame] | 82 | MB_MODE_COUNT, // D113_PRED |
| 83 | MB_MODE_COUNT, // D157_PRED |
| 84 | MB_MODE_COUNT, // D203_PRED |
| 85 | MB_MODE_COUNT, // D67_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 86 | MB_MODE_COUNT, // SMOOTH_PRED |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 87 | MB_MODE_COUNT, // SMOOTH_V_PRED |
| 88 | MB_MODE_COUNT, // SMOOTH_H_PRED |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 89 | MB_MODE_COUNT, // PAETH_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 90 | MB_MODE_COUNT, // NEARESTMV |
| 91 | MB_MODE_COUNT, // NEARMV |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 92 | MB_MODE_COUNT, // GLOBALMV |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 93 | MB_MODE_COUNT, // NEWMV |
Sebastien Alaiwan | 34d5566 | 2017-11-15 09:36:03 +0100 | [diff] [blame] | 94 | NEARESTMV, // NEAREST_NEARESTMV |
| 95 | NEARMV, // NEAR_NEARMV |
| 96 | NEARESTMV, // NEAREST_NEWMV |
| 97 | NEWMV, // NEW_NEARESTMV |
| 98 | NEARMV, // NEAR_NEWMV |
| 99 | NEWMV, // NEW_NEARMV |
| 100 | GLOBALMV, // GLOBAL_GLOBALMV |
| 101 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | }; |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 103 | assert(NELEMENTS(lut) == MB_MODE_COUNT); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | assert(is_inter_compound_mode(mode)); |
| 105 | return lut[mode]; |
| 106 | } |
| 107 | |
| 108 | static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) { |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 109 | static PREDICTION_MODE lut[] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 110 | MB_MODE_COUNT, // DC_PRED |
| 111 | MB_MODE_COUNT, // V_PRED |
| 112 | MB_MODE_COUNT, // H_PRED |
| 113 | MB_MODE_COUNT, // D45_PRED |
| 114 | MB_MODE_COUNT, // D135_PRED |
Hui Su | 439bcb5 | 2018-02-21 10:52:16 -0800 | [diff] [blame] | 115 | MB_MODE_COUNT, // D113_PRED |
| 116 | MB_MODE_COUNT, // D157_PRED |
| 117 | MB_MODE_COUNT, // D203_PRED |
| 118 | MB_MODE_COUNT, // D67_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 119 | MB_MODE_COUNT, // SMOOTH_PRED |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 120 | MB_MODE_COUNT, // SMOOTH_V_PRED |
| 121 | MB_MODE_COUNT, // SMOOTH_H_PRED |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 122 | MB_MODE_COUNT, // PAETH_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 123 | MB_MODE_COUNT, // NEARESTMV |
| 124 | MB_MODE_COUNT, // NEARMV |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 125 | MB_MODE_COUNT, // GLOBALMV |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 126 | MB_MODE_COUNT, // NEWMV |
Sebastien Alaiwan | 34d5566 | 2017-11-15 09:36:03 +0100 | [diff] [blame] | 127 | NEARESTMV, // NEAREST_NEARESTMV |
| 128 | NEARMV, // NEAR_NEARMV |
| 129 | NEWMV, // NEAREST_NEWMV |
| 130 | NEARESTMV, // NEW_NEARESTMV |
| 131 | NEWMV, // NEAR_NEWMV |
| 132 | NEARMV, // NEW_NEARMV |
| 133 | GLOBALMV, // GLOBAL_GLOBALMV |
| 134 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 135 | }; |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 136 | assert(NELEMENTS(lut) == MB_MODE_COUNT); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 137 | assert(is_inter_compound_mode(mode)); |
| 138 | return lut[mode]; |
| 139 | } |
| 140 | |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 141 | static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) { |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 142 | return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV || |
| 143 | mode == NEW_NEARMV); |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) { |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 147 | return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV || |
| 148 | mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 149 | } |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 150 | |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 151 | static INLINE int use_masked_motion_search(COMPOUND_TYPE type) { |
| 152 | return (type == COMPOUND_WEDGE); |
| 153 | } |
| 154 | |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 155 | static INLINE int is_masked_compound_type(COMPOUND_TYPE type) { |
Sarah Parker | 5b4df2b | 2018-04-02 14:48:25 -0700 | [diff] [blame] | 156 | return (type == COMPOUND_WEDGE || type == COMPOUND_DIFFWTD); |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 157 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 158 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 159 | /* For keyframes, intra block modes are predicted by the (already decoded) |
| 160 | modes for the Y blocks to the left and above us; for interframes, there |
| 161 | is a single probability table. */ |
| 162 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 163 | typedef int8_t MV_REFERENCE_FRAME; |
| 164 | |
| 165 | typedef struct { |
| 166 | // Number of base colors for Y (0) and UV (1) |
| 167 | uint8_t palette_size[2]; |
hui su | fa4ff85 | 2017-05-15 12:20:50 -0700 | [diff] [blame] | 168 | // Value of base colors for Y, U, and V |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | uint16_t palette_colors[3 * PALETTE_MAX_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | } PALETTE_MODE_INFO; |
| 171 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | typedef struct { |
Yue Chen | b057187 | 2017-12-18 18:12:59 -0800 | [diff] [blame] | 173 | uint8_t use_filter_intra; |
| 174 | FILTER_INTRA_MODE filter_intra_mode; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 175 | } FILTER_INTRA_MODE_INFO; |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 176 | |
| 177 | static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = { |
Hui Su | 69ae7b8 | 2018-02-20 20:10:51 -0800 | [diff] [blame] | 178 | DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 179 | }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 180 | |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 181 | #if CONFIG_RD_DEBUG |
Jingning Han | f32f678 | 2018-02-15 09:29:15 -0800 | [diff] [blame] | 182 | #define TXB_COEFF_COST_MAP_SIZE (MAX_MIB_SIZE) |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 183 | #endif |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 184 | |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 185 | typedef struct RD_STATS { |
| 186 | int rate; |
| 187 | int64_t dist; |
Angie Chiang | 7bbd3b1 | 2017-04-26 11:06:09 -0700 | [diff] [blame] | 188 | // Please be careful of using rdcost, it's not guaranteed to be set all the |
| 189 | // time. |
| 190 | // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In |
| 191 | // these functions, make sure rdcost is always up-to-date according to |
| 192 | // rate/dist. |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 193 | int64_t rdcost; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 194 | int64_t sse; |
Angie Chiang | 7bbd3b1 | 2017-04-26 11:06:09 -0700 | [diff] [blame] | 195 | int skip; // sse should equal to dist when skip == 1 |
Jingning Han | 3bce754 | 2017-07-25 10:53:57 -0700 | [diff] [blame] | 196 | int64_t ref_rdcost; |
| 197 | int zero_rate; |
Jingning Han | 1a7f0a8 | 2017-07-27 09:48:05 -0700 | [diff] [blame] | 198 | uint8_t invalid_rate; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 199 | #if CONFIG_RD_DEBUG |
| 200 | int txb_coeff_cost[MAX_MB_PLANE]; |
| 201 | int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE] |
| 202 | [TXB_COEFF_COST_MAP_SIZE]; |
Angie Chiang | 3963d63 | 2016-11-10 18:41:40 -0800 | [diff] [blame] | 203 | #endif // CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 204 | } RD_STATS; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 205 | |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 206 | // This struct is used to group function args that are commonly |
| 207 | // sent together in functions related to interinter compound modes |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 208 | typedef struct { |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 209 | int wedge_index; |
| 210 | int wedge_sign; |
Sarah Parker | 5b4df2b | 2018-04-02 14:48:25 -0700 | [diff] [blame] | 211 | DIFFWTD_MASK_TYPE mask_type; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 212 | uint8_t *seg_mask; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 213 | COMPOUND_TYPE interinter_compound_type; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 214 | } INTERINTER_COMPOUND_DATA; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 215 | |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 216 | #define INTER_TX_SIZE_BUF_LEN 16 |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 217 | #define TXK_TYPE_BUF_LEN 64 |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 218 | // This structure now relates to 4x4 block regions. |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 219 | typedef struct MB_MODE_INFO { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 220 | // Common for both INTER and INTRA blocks |
| 221 | BLOCK_SIZE sb_type; |
| 222 | PREDICTION_MODE mode; |
| 223 | TX_SIZE tx_size; |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 224 | uint8_t inter_tx_size[INTER_TX_SIZE_BUF_LEN]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 225 | int8_t skip; |
Zoe Liu | f704a1c | 2017-10-02 16:55:59 -0700 | [diff] [blame] | 226 | int8_t skip_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 227 | int8_t segment_id; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 228 | int8_t seg_id_predicted; // valid only when temporal_update is enabled |
| 229 | |
| 230 | // Only for INTRA blocks |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 231 | UV_PREDICTION_MODE uv_mode; |
Urvang Joshi | c6300aa | 2017-06-01 14:46:23 -0700 | [diff] [blame] | 232 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 233 | PALETTE_MODE_INFO palette_mode_info; |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 234 | uint8_t use_intrabc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 236 | // Only for INTER blocks |
| 237 | InterpFilters interp_filters; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 238 | MV_REFERENCE_FRAME ref_frame[2]; |
Hui Su | 56393b3 | 2018-02-27 10:34:27 -0800 | [diff] [blame] | 239 | |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 240 | TX_TYPE txk_type[TXK_TYPE_BUF_LEN]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 241 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 242 | FILTER_INTRA_MODE_INFO filter_intra_mode_info; |
Yue Chen | 69d9aef | 2018-02-26 17:49:59 -0800 | [diff] [blame] | 243 | |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 244 | // The actual prediction angle is the base angle + (angle_delta * step). |
Luc Trudeau | 7bb3a4f | 2018-02-12 09:59:21 -0500 | [diff] [blame] | 245 | int8_t angle_delta[PLANE_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 247 | // interintra members |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 248 | INTERINTRA_MODE interintra_mode; |
| 249 | // TODO(debargha): Consolidate these flags |
| 250 | int use_wedge_interintra; |
| 251 | int interintra_wedge_index; |
| 252 | int interintra_wedge_sign; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 253 | // interinter members |
| 254 | COMPOUND_TYPE interinter_compound_type; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 255 | int wedge_index; |
| 256 | int wedge_sign; |
Sarah Parker | 5b4df2b | 2018-04-02 14:48:25 -0700 | [diff] [blame] | 257 | DIFFWTD_MASK_TYPE mask_type; |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 258 | MOTION_MODE motion_mode; |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 259 | int overlappable_neighbors[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 260 | int_mv mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 261 | uint8_t ref_mv_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 262 | PARTITION_TYPE partition; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | /* deringing gain *per-superblock* */ |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 264 | int8_t cdef_strength; |
Wan-Teh Chang | 413f5ef | 2018-06-05 17:36:03 -0700 | [diff] [blame^] | 265 | int current_qindex; |
| 266 | int delta_lf_from_base; |
| 267 | int delta_lf[FRAME_LF_COUNT]; |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 268 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 269 | RD_STATS rd_stats; |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 270 | int mi_row; |
| 271 | int mi_col; |
| 272 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 273 | int num_proj_ref[2]; |
| 274 | WarpedMotionParams wm_params[2]; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 275 | |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 276 | // Index of the alpha Cb and alpha Cr combination |
Luc Trudeau | a9bd85f | 2017-05-11 14:37:56 -0400 | [diff] [blame] | 277 | int cfl_alpha_idx; |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 278 | // Joint sign of alpha Cb and alpha Cr |
| 279 | int cfl_alpha_signs; |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 280 | |
Cheng Chen | ca6958c | 2017-10-10 14:00:50 -0700 | [diff] [blame] | 281 | int compound_idx; |
Cheng Chen | 33a13d9 | 2017-11-28 16:49:59 -0800 | [diff] [blame] | 282 | int comp_group_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | } MB_MODE_INFO; |
| 284 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 285 | static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) { |
| 286 | return mbmi->use_intrabc; |
| 287 | } |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 288 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 289 | static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) { |
Luc Trudeau | 5d5078e | 2017-12-13 16:43:16 -0500 | [diff] [blame] | 290 | assert(mode < UV_INTRA_MODES); |
Luc Trudeau | 2f052ee | 2018-01-16 14:43:06 -0500 | [diff] [blame] | 291 | static const PREDICTION_MODE uv2y[] = { |
Urvang Joshi | b7301cd | 2017-11-09 15:08:56 -0800 | [diff] [blame] | 292 | DC_PRED, // UV_DC_PRED |
| 293 | V_PRED, // UV_V_PRED |
| 294 | H_PRED, // UV_H_PRED |
| 295 | D45_PRED, // UV_D45_PRED |
| 296 | D135_PRED, // UV_D135_PRED |
Hui Su | 69ae7b8 | 2018-02-20 20:10:51 -0800 | [diff] [blame] | 297 | D113_PRED, // UV_D113_PRED |
| 298 | D157_PRED, // UV_D157_PRED |
| 299 | D203_PRED, // UV_D203_PRED |
| 300 | D67_PRED, // UV_D67_PRED |
Urvang Joshi | b7301cd | 2017-11-09 15:08:56 -0800 | [diff] [blame] | 301 | SMOOTH_PRED, // UV_SMOOTH_PRED |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 302 | SMOOTH_V_PRED, // UV_SMOOTH_V_PRED |
| 303 | SMOOTH_H_PRED, // UV_SMOOTH_H_PRED |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 304 | PAETH_PRED, // UV_PAETH_PRED |
Luc Trudeau | 2f052ee | 2018-01-16 14:43:06 -0500 | [diff] [blame] | 305 | DC_PRED, // UV_CFL_PRED |
| 306 | INTRA_INVALID, // UV_INTRA_MODES |
| 307 | INTRA_INVALID, // UV_MODE_INVALID |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 308 | }; |
| 309 | return uv2y[mode]; |
| 310 | } |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 311 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 312 | static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) { |
Hui Su | 293f281 | 2018-02-26 14:41:18 -0800 | [diff] [blame] | 313 | return is_intrabc_block(mbmi) || mbmi->ref_frame[0] > INTRA_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) { |
| 317 | return mbmi->ref_frame[1] > INTRA_FRAME; |
| 318 | } |
| 319 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 320 | static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) { |
| 321 | return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^ |
| 322 | (mbmi->ref_frame[1] >= BWDREF_FRAME))); |
| 323 | } |
| 324 | |
| 325 | static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) { |
| 326 | static const MV_REFERENCE_FRAME lut[] = { |
Zoe Liu | 057f97b | 2018-01-24 13:45:25 -0800 | [diff] [blame] | 327 | LAST_FRAME, // LAST_LAST2_FRAMES, |
| 328 | LAST_FRAME, // LAST_LAST3_FRAMES, |
| 329 | LAST_FRAME, // LAST_GOLDEN_FRAMES, |
| 330 | BWDREF_FRAME, // BWDREF_ALTREF_FRAMES, |
| 331 | LAST2_FRAME, // LAST2_LAST3_FRAMES |
| 332 | LAST2_FRAME, // LAST2_GOLDEN_FRAMES, |
| 333 | LAST3_FRAME, // LAST3_GOLDEN_FRAMES, |
| 334 | BWDREF_FRAME, // BWDREF_ALTREF2_FRAMES, |
| 335 | ALTREF2_FRAME, // ALTREF2_ALTREF_FRAMES, |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 336 | }; |
Zoe Liu | 057f97b | 2018-01-24 13:45:25 -0800 | [diff] [blame] | 337 | assert(NELEMENTS(lut) == TOTAL_UNIDIR_COMP_REFS); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 338 | return lut[ref_idx]; |
| 339 | } |
| 340 | |
| 341 | static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) { |
| 342 | static const MV_REFERENCE_FRAME lut[] = { |
Zoe Liu | 057f97b | 2018-01-24 13:45:25 -0800 | [diff] [blame] | 343 | LAST2_FRAME, // LAST_LAST2_FRAMES, |
| 344 | LAST3_FRAME, // LAST_LAST3_FRAMES, |
| 345 | GOLDEN_FRAME, // LAST_GOLDEN_FRAMES, |
| 346 | ALTREF_FRAME, // BWDREF_ALTREF_FRAMES, |
| 347 | LAST3_FRAME, // LAST2_LAST3_FRAMES |
| 348 | GOLDEN_FRAME, // LAST2_GOLDEN_FRAMES, |
| 349 | GOLDEN_FRAME, // LAST3_GOLDEN_FRAMES, |
| 350 | ALTREF2_FRAME, // BWDREF_ALTREF2_FRAMES, |
| 351 | ALTREF_FRAME, // ALTREF2_ALTREF_FRAMES, |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 352 | }; |
Zoe Liu | 057f97b | 2018-01-24 13:45:25 -0800 | [diff] [blame] | 353 | assert(NELEMENTS(lut) == TOTAL_UNIDIR_COMP_REFS); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 354 | return lut[ref_idx]; |
| 355 | } |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 356 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 357 | PREDICTION_MODE av1_left_block_mode(const MB_MODE_INFO *left_mi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 359 | PREDICTION_MODE av1_above_block_mode(const MB_MODE_INFO *above_mi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 360 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 361 | static INLINE int is_global_mv_block(const MB_MODE_INFO *const mbmi, |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 362 | TransformationType type) { |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 363 | const PREDICTION_MODE mode = mbmi->mode; |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 364 | const BLOCK_SIZE bsize = mbmi->sb_type; |
Debargha Mukherjee | c17a443 | 2017-08-28 22:22:45 -0700 | [diff] [blame] | 365 | const int block_size_allowed = |
| 366 | AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 367 | return (mode == GLOBALMV || mode == GLOBAL_GLOBALMV) && type > TRANSLATION && |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 368 | block_size_allowed; |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 369 | } |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 370 | |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 371 | #if CONFIG_MISMATCH_DEBUG |
| 372 | static INLINE void mi_to_pixel_loc(int *pixel_c, int *pixel_r, int mi_col, |
| 373 | int mi_row, int tx_blk_col, int tx_blk_row, |
| 374 | int subsampling_x, int subsampling_y) { |
| 375 | *pixel_c = ((mi_col >> subsampling_x) << MI_SIZE_LOG2) + |
| 376 | (tx_blk_col << tx_size_wide_log2[0]); |
| 377 | *pixel_r = ((mi_row >> subsampling_y) << MI_SIZE_LOG2) + |
| 378 | (tx_blk_row << tx_size_high_log2[0]); |
| 379 | } |
| 380 | #endif |
| 381 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 382 | enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 }; |
| 383 | |
| 384 | struct buf_2d { |
| 385 | uint8_t *buf; |
| 386 | uint8_t *buf0; |
| 387 | int width; |
| 388 | int height; |
| 389 | int stride; |
| 390 | }; |
| 391 | |
| 392 | typedef struct macroblockd_plane { |
| 393 | tran_low_t *dqcoeff; |
| 394 | PLANE_TYPE plane_type; |
| 395 | int subsampling_x; |
| 396 | int subsampling_y; |
| 397 | struct buf_2d dst; |
| 398 | struct buf_2d pre[2]; |
| 399 | ENTROPY_CONTEXT *above_context; |
| 400 | ENTROPY_CONTEXT *left_context; |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 401 | |
| 402 | // The dequantizers below are true dequntizers used only in the |
| 403 | // dequantization process. They have the same coefficient |
| 404 | // shift/scale as TX. |
| 405 | int16_t seg_dequant_QTX[MAX_SEGMENTS][2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 406 | uint8_t *color_index_map; |
| 407 | |
Jingning Han | c47fe6c | 2016-10-21 16:40:47 -0700 | [diff] [blame] | 408 | // block size in pixels |
| 409 | uint8_t width, height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 410 | |
Thomas Davies | dd3cf83 | 2017-10-20 15:49:57 +0100 | [diff] [blame] | 411 | qm_val_t *seg_iqmatrix[MAX_SEGMENTS][TX_SIZES_ALL]; |
| 412 | qm_val_t *seg_qmatrix[MAX_SEGMENTS][TX_SIZES_ALL]; |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 413 | |
| 414 | // the 'dequantizers' below are not literal dequantizer values. |
| 415 | // They're used by encoder RDO to generate ad-hoc lambda values. |
| 416 | // They use a hardwired Q3 coeff shift and do not necessarily match |
| 417 | // the TX scale in use. |
| 418 | const int16_t *dequant_Q3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | } MACROBLOCKD_PLANE; |
| 420 | |
Jingning Han | 3468df1 | 2016-12-05 17:53:16 -0800 | [diff] [blame] | 421 | #define BLOCK_OFFSET(x, i) \ |
| 422 | ((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] | 423 | |
| 424 | typedef struct RefBuffer { |
Yaowu Xu | 0eb6b6c | 2018-03-28 12:44:57 -0700 | [diff] [blame] | 425 | int idx; // frame buf idx |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 426 | int map_idx; // frame map idx |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | YV12_BUFFER_CONFIG *buf; |
| 428 | struct scale_factors sf; |
| 429 | } RefBuffer; |
| 430 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 431 | typedef struct { |
| 432 | DECLARE_ALIGNED(16, InterpKernel, vfilter); |
| 433 | DECLARE_ALIGNED(16, InterpKernel, hfilter); |
| 434 | } WienerInfo; |
| 435 | |
| 436 | typedef struct { |
| 437 | int ep; |
| 438 | int xqd[2]; |
| 439 | } SgrprojInfo; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 440 | |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 441 | #if CONFIG_DEBUG |
Luc Trudeau | 03b7e7d | 2017-09-19 13:20:52 -0400 | [diff] [blame] | 442 | #define CFL_SUB8X8_VAL_MI_SIZE (4) |
| 443 | #define CFL_SUB8X8_VAL_MI_SQUARE \ |
| 444 | (CFL_SUB8X8_VAL_MI_SIZE * CFL_SUB8X8_VAL_MI_SIZE) |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 445 | #endif // CONFIG_DEBUG |
Luc Trudeau | e425f47 | 2017-12-08 14:48:46 -0500 | [diff] [blame] | 446 | #define CFL_MAX_BLOCK_SIZE (BLOCK_32X32) |
Luc Trudeau | 467205a | 2017-12-12 23:23:47 -0500 | [diff] [blame] | 447 | #define CFL_BUF_LINE (32) |
Luc Trudeau | 365f73b | 2017-12-23 00:07:29 -0500 | [diff] [blame] | 448 | #define CFL_BUF_LINE_I128 (CFL_BUF_LINE >> 3) |
| 449 | #define CFL_BUF_LINE_I256 (CFL_BUF_LINE >> 4) |
Luc Trudeau | 467205a | 2017-12-12 23:23:47 -0500 | [diff] [blame] | 450 | #define CFL_BUF_SQUARE (CFL_BUF_LINE * CFL_BUF_LINE) |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 451 | typedef struct cfl_ctx { |
Luc Trudeau | 8a19211 | 2018-05-09 22:38:28 -0400 | [diff] [blame] | 452 | // Q3 reconstructed luma pixels (only Q2 is required, but Q3 is used to avoid |
| 453 | // shifts) |
Luc Trudeau | 1f43117 | 2018-05-10 11:37:23 -0400 | [diff] [blame] | 454 | uint16_t recon_buf_q3[CFL_BUF_SQUARE]; |
Luc Trudeau | 8a19211 | 2018-05-09 22:38:28 -0400 | [diff] [blame] | 455 | // Q3 AC contributions (reconstructed luma pixels - tx block avg) |
| 456 | int16_t ac_buf_q3[CFL_BUF_SQUARE]; |
Luc Trudeau | 467205a | 2017-12-12 23:23:47 -0500 | [diff] [blame] | 457 | |
| 458 | // Cache the DC_PRED when performing RDO, so it does not have to be recomputed |
| 459 | // for every scaling parameter |
| 460 | int dc_pred_is_cached[CFL_PRED_PLANES]; |
| 461 | // The DC_PRED cache is disable when decoding |
| 462 | int use_dc_pred_cache; |
| 463 | // Only cache the first row of the DC_PRED |
| 464 | int16_t dc_pred_cache[CFL_PRED_PLANES][CFL_BUF_LINE]; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 465 | |
Luc Trudeau | 4e26d66 | 2017-09-11 13:08:40 -0400 | [diff] [blame] | 466 | // Height and width currently used in the CfL prediction buffer. |
| 467 | int buf_height, buf_width; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 468 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 469 | int are_parameters_computed; |
| 470 | |
| 471 | // Chroma subsampling |
| 472 | int subsampling_x, subsampling_y; |
| 473 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 474 | int mi_row, mi_col; |
| 475 | |
| 476 | // Whether the reconstructed luma pixels need to be stored |
| 477 | int store_y; |
| 478 | |
David Michael Barr | 1f8d095 | 2017-10-11 17:46:39 +0900 | [diff] [blame] | 479 | #if CONFIG_DEBUG |
| 480 | int rate; |
| 481 | #endif // CONFIG_DEBUG |
| 482 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 483 | int is_chroma_reference; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 484 | } CFL_CTX; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 485 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 486 | typedef struct jnt_comp_params { |
Cheng Chen | 8263f80 | 2017-11-14 15:50:00 -0800 | [diff] [blame] | 487 | int use_jnt_comp_avg; |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 488 | int fwd_offset; |
| 489 | int bck_offset; |
| 490 | } JNT_COMP_PARAMS; |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 491 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 492 | typedef struct macroblockd { |
| 493 | struct macroblockd_plane plane[MAX_MB_PLANE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 494 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 495 | TileInfo tile; |
| 496 | |
| 497 | int mi_stride; |
| 498 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 499 | MB_MODE_INFO **mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 500 | MB_MODE_INFO *left_mbmi; |
| 501 | MB_MODE_INFO *above_mbmi; |
David Barker | d3afdb9 | 2018-02-14 15:45:58 +0000 | [diff] [blame] | 502 | MB_MODE_INFO *chroma_left_mbmi; |
| 503 | MB_MODE_INFO *chroma_above_mbmi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 504 | |
| 505 | int up_available; |
| 506 | int left_available; |
Jingning Han | 3da18d6 | 2017-05-02 12:43:58 -0700 | [diff] [blame] | 507 | int chroma_up_available; |
| 508 | int chroma_left_available; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 509 | |
Rupert Swarbrick | 57486c5 | 2017-08-14 10:53:49 +0100 | [diff] [blame] | 510 | /* Distance of MB away from frame edges in subpixels (1/8th pixel) */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 511 | int mb_to_left_edge; |
| 512 | int mb_to_right_edge; |
| 513 | int mb_to_top_edge; |
| 514 | int mb_to_bottom_edge; |
| 515 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 516 | /* pointers to reference frames */ |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 517 | const RefBuffer *block_refs[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | |
| 519 | /* pointer to current frame */ |
| 520 | const YV12_BUFFER_CONFIG *cur_buf; |
| 521 | |
| 522 | ENTROPY_CONTEXT *above_context[MAX_MB_PLANE]; |
Wan-Teh Chang | 733de9b | 2018-05-02 16:36:19 -0700 | [diff] [blame] | 523 | ENTROPY_CONTEXT left_context[MAX_MB_PLANE][MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 524 | |
| 525 | PARTITION_CONTEXT *above_seg_context; |
| 526 | PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE]; |
| 527 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | TXFM_CONTEXT *above_txfm_context; |
| 529 | TXFM_CONTEXT *left_txfm_context; |
Wan-Teh Chang | 733de9b | 2018-05-02 16:36:19 -0700 | [diff] [blame] | 530 | TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 531 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 532 | WienerInfo wiener_info[MAX_MB_PLANE]; |
| 533 | SgrprojInfo sgrproj_info[MAX_MB_PLANE]; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 534 | |
Jingning Han | ff6ee6a | 2016-12-07 09:55:21 -0800 | [diff] [blame] | 535 | // block dimension in the unit of mode_info. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 536 | uint8_t n8_w, n8_h; |
| 537 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 538 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES]; |
| 539 | CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE]; |
| 540 | uint8_t is_sec_rect; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 541 | |
Zoe Liu | fa8bad1 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 542 | // Counts of each reference frame in the above and left neighboring blocks. |
| 543 | // NOTE: Take into account both single and comp references. |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 544 | uint8_t neighbors_ref_counts[REF_FRAMES]; |
Zoe Liu | fa8bad1 | 2018-01-23 14:32:31 -0800 | [diff] [blame] | 545 | |
Thomas Davies | f77d4ad | 2017-01-10 18:55:42 +0000 | [diff] [blame] | 546 | FRAME_CONTEXT *tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 547 | /* Bit depth: 8, 10, 12 */ |
| 548 | int bd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 549 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 550 | int qindex[MAX_SEGMENTS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 551 | int lossless[MAX_SEGMENTS]; |
| 552 | int corrupted; |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 553 | int cur_frame_force_integer_mv; |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 554 | // same with that in AV1_COMMON |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 555 | struct aom_internal_error_info *error_info; |
Luc Trudeau | f3bf8b1 | 2017-12-08 14:38:41 -0500 | [diff] [blame] | 556 | const WarpedMotionParams *global_motion; |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 557 | int delta_qindex; |
| 558 | int current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 559 | // Since actual frame level loop filtering level value is not available |
| 560 | // at the beginning of the tile (only available during actual filtering) |
| 561 | // at encoder side.we record the delta_lf (against the frame level loop |
| 562 | // filtering level) and code the delta between previous superblock's delta |
| 563 | // lf and current delta lf. It is equivalent to the delta between previous |
| 564 | // superblock's actual lf and current lf. |
Wan-Teh Chang | 413f5ef | 2018-06-05 17:36:03 -0700 | [diff] [blame^] | 565 | int delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 566 | // For this experiment, we have four frame filter levels for different plane |
| 567 | // and direction. So, to support the per superblock update, we need to add |
| 568 | // a few more params as below. |
| 569 | // 0: delta loop filter level for y plane vertical |
| 570 | // 1: delta loop filter level for y plane horizontal |
| 571 | // 2: delta loop filter level for u plane |
| 572 | // 3: delta loop filter level for v plane |
| 573 | // To make it consistent with the reference to each filter level in segment, |
| 574 | // we need to -1, since |
| 575 | // SEG_LVL_ALT_LF_Y_V = 1; |
| 576 | // SEG_LVL_ALT_LF_Y_H = 2; |
| 577 | // SEG_LVL_ALT_LF_U = 3; |
| 578 | // SEG_LVL_ALT_LF_V = 4; |
Wan-Teh Chang | 413f5ef | 2018-06-05 17:36:03 -0700 | [diff] [blame^] | 579 | int delta_lf[FRAME_LF_COUNT]; |
Cherma Rajan A | 3561023 | 2018-04-18 18:19:12 +0530 | [diff] [blame] | 580 | int cdef_preset[4]; |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 581 | |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 582 | DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]); |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 583 | |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 584 | CFL_CTX cfl; |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 585 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 586 | JNT_COMP_PARAMS jcp_param; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | } MACROBLOCKD; |
| 588 | |
Yi Luo | 5128109 | 2017-06-26 16:36:15 -0700 | [diff] [blame] | 589 | static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) { |
| 590 | return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0; |
| 591 | } |
| 592 | |
Cheng Chen | 82b4fa1 | 2018-05-02 18:43:17 -0700 | [diff] [blame] | 593 | static INLINE int get_sqr_bsize_idx(BLOCK_SIZE bsize) { |
| 594 | switch (bsize) { |
| 595 | case BLOCK_4X4: return 0; |
| 596 | case BLOCK_8X8: return 1; |
| 597 | case BLOCK_16X16: return 2; |
| 598 | case BLOCK_32X32: return 3; |
| 599 | case BLOCK_64X64: return 4; |
| 600 | case BLOCK_128X128: return 5; |
| 601 | default: return SQR_BLOCK_SIZES; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // Note: the input block size should be square. |
| 606 | // Otherwise it's considered invalid. |
| 607 | static INLINE BLOCK_SIZE get_partition_subsize(BLOCK_SIZE bsize, |
| 608 | PARTITION_TYPE partition) { |
| 609 | if (partition == PARTITION_INVALID) { |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 610 | return BLOCK_INVALID; |
Cheng Chen | 82b4fa1 | 2018-05-02 18:43:17 -0700 | [diff] [blame] | 611 | } else { |
| 612 | const int sqr_bsize_idx = get_sqr_bsize_idx(bsize); |
| 613 | return sqr_bsize_idx >= SQR_BLOCK_SIZES |
| 614 | ? BLOCK_INVALID |
| 615 | : subsize_lookup[partition][sqr_bsize_idx]; |
| 616 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Luc Trudeau | 6e69131 | 2018-04-11 13:03:16 -0400 | [diff] [blame] | 619 | static TX_TYPE intra_mode_to_tx_type(const MB_MODE_INFO *mbmi, |
| 620 | PLANE_TYPE plane_type) { |
| 621 | static const TX_TYPE _intra_mode_to_tx_type[INTRA_MODES] = { |
Luc Trudeau | 9cea993 | 2017-12-13 21:14:13 -0500 | [diff] [blame] | 622 | DCT_DCT, // DC |
| 623 | ADST_DCT, // V |
| 624 | DCT_ADST, // H |
| 625 | DCT_DCT, // D45 |
| 626 | ADST_ADST, // D135 |
| 627 | ADST_DCT, // D117 |
| 628 | DCT_ADST, // D153 |
| 629 | DCT_ADST, // D207 |
| 630 | ADST_DCT, // D63 |
| 631 | ADST_ADST, // SMOOTH |
| 632 | ADST_DCT, // SMOOTH_V |
| 633 | DCT_ADST, // SMOOTH_H |
| 634 | ADST_ADST, // PAETH |
| 635 | }; |
Luc Trudeau | 6e69131 | 2018-04-11 13:03:16 -0400 | [diff] [blame] | 636 | const PREDICTION_MODE mode = |
| 637 | (plane_type == PLANE_TYPE_Y) ? mbmi->mode : get_uv_mode(mbmi->uv_mode); |
| 638 | assert(mode < INTRA_MODES); |
| 639 | return _intra_mode_to_tx_type[mode]; |
Luc Trudeau | 9cea993 | 2017-12-13 21:14:13 -0500 | [diff] [blame] | 640 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 641 | |
Sarah Parker | 076437f | 2017-03-14 17:39:53 -0700 | [diff] [blame] | 642 | 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] | 643 | |
Rupert Swarbrick | fcff0b2 | 2017-10-05 09:26:04 +0100 | [diff] [blame] | 644 | static INLINE int block_signals_txsize(BLOCK_SIZE bsize) { |
Rupert Swarbrick | fcff0b2 | 2017-10-05 09:26:04 +0100 | [diff] [blame] | 645 | return bsize > BLOCK_4X4; |
Rupert Swarbrick | fcff0b2 | 2017-10-05 09:26:04 +0100 | [diff] [blame] | 646 | } |
| 647 | |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 648 | // Number of transform types in each set type |
| 649 | static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = { |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 650 | 1, 2, 5, 7, 12, 16, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 651 | }; |
| 652 | |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 653 | static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = { |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 654 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 655 | { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, |
| 656 | { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, |
| 657 | { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 }, |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 658 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, |
| 659 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 660 | }; |
| 661 | |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 662 | static INLINE TxSetType av1_get_ext_tx_set_type(TX_SIZE tx_size, int is_inter, |
| 663 | int use_reduced_set) { |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 664 | const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size]; |
Debargha Mukherjee | 570423c | 2017-10-01 00:35:20 -0700 | [diff] [blame] | 665 | if (tx_size_sqr_up > TX_32X32) return EXT_TX_SET_DCTONLY; |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 666 | if (tx_size_sqr_up == TX_32X32) |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 667 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY; |
Sarah Parker | c7fa12c | 2018-01-29 14:48:46 -0800 | [diff] [blame] | 668 | if (use_reduced_set) |
| 669 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX; |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 670 | const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size]; |
Hui Su | 3e509e3 | 2018-01-29 11:42:46 -0800 | [diff] [blame] | 671 | if (is_inter) { |
| 672 | return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT |
Sarah Parker | cec7ba1 | 2017-11-03 16:46:09 -0700 | [diff] [blame] | 673 | : EXT_TX_SET_ALL16); |
Hui Su | 3e509e3 | 2018-01-29 11:42:46 -0800 | [diff] [blame] | 674 | } else { |
| 675 | return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT4_IDTX |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 676 | : EXT_TX_SET_DTT4_IDTX_1DDCT); |
Hui Su | 3e509e3 | 2018-01-29 11:42:46 -0800 | [diff] [blame] | 677 | } |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 678 | } |
| 679 | |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 680 | // Maps tx set types to the indices. |
| 681 | static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = { |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 682 | { // Intra |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 683 | 0, -1, 2, 1, -1, -1 }, |
Johann | 6b41d4d | 2018-02-08 14:32:53 -0800 | [diff] [blame] | 684 | { // Inter |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 685 | 0, 3, -1, -1, 2, 1 }, |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 686 | }; |
| 687 | |
Jingning Han | 47eb232 | 2018-03-19 16:33:48 -0700 | [diff] [blame] | 688 | static INLINE int get_ext_tx_set(TX_SIZE tx_size, int is_inter, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 689 | int use_reduced_set) { |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 690 | const TxSetType set_type = |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 691 | av1_get_ext_tx_set_type(tx_size, is_inter, use_reduced_set); |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 692 | return ext_tx_set_index[is_inter][set_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Jingning Han | a689cab | 2018-03-19 16:40:42 -0700 | [diff] [blame] | 695 | static INLINE int get_ext_tx_types(TX_SIZE tx_size, int is_inter, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 696 | int use_reduced_set) { |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 697 | const int set_type = |
| 698 | av1_get_ext_tx_set_type(tx_size, is_inter, use_reduced_set); |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 699 | return av1_num_ext_tx_set[set_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Debargha Mukherjee | 3ebb0d0 | 2017-12-14 05:05:18 -0800 | [diff] [blame] | 702 | #define TXSIZEMAX(t1, t2) (tx_size_2d[(t1)] >= tx_size_2d[(t2)] ? (t1) : (t2)) |
| 703 | #define TXSIZEMIN(t1, t2) (tx_size_2d[(t1)] <= tx_size_2d[(t2)] ? (t1) : (t2)) |
| 704 | |
Yaowu Xu | 25ff26a | 2018-02-26 11:20:10 -0800 | [diff] [blame] | 705 | static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 706 | const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; |
Urvang Joshi | dd0376f | 2018-05-02 16:37:25 -0700 | [diff] [blame] | 707 | const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize]; |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 708 | if (bsize == BLOCK_4X4) |
| 709 | return AOMMIN(max_txsize_lookup[bsize], largest_tx_size); |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 710 | if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size) |
| 711 | return max_rect_tx_size; |
| 712 | else |
| 713 | return largest_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 714 | } |
| 715 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 716 | extern const int16_t dr_intra_derivative[90]; |
hui su | 02c7974 | 2017-05-16 17:19:04 -0700 | [diff] [blame] | 717 | static const uint8_t mode_to_angle_map[] = { |
Urvang Joshi | b7301cd | 2017-11-09 15:08:56 -0800 | [diff] [blame] | 718 | 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] | 719 | }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 720 | |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 721 | // Converts block_index for given transform size to index of the block in raster |
| 722 | // order. |
| 723 | static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size, |
| 724 | int block_idx) { |
| 725 | // For transform size 4x8, the possible block_idx values are 0 & 2, because |
| 726 | // block_idx values are incremented in steps of size 'tx_width_unit x |
| 727 | // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to |
| 728 | // block number 1 in raster order, inside an 8x8 MI block. |
| 729 | // For any other transform size, the two indices are equivalent. |
| 730 | return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx; |
| 731 | } |
| 732 | |
| 733 | // Inverse of above function. |
| 734 | // Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now. |
| 735 | static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size, |
| 736 | int raster_order) { |
| 737 | assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4); |
| 738 | // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4. |
| 739 | return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0; |
| 740 | } |
| 741 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 742 | static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type, |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 743 | const MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 744 | TX_SIZE tx_size) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 745 | const MB_MODE_INFO *const mbmi = xd->mi[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 746 | |
Hui Su | 7448fc2 | 2018-01-11 16:47:45 -0800 | [diff] [blame] | 747 | if (is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 748 | xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32) |
| 749 | return DCT_DCT; |
| 750 | |
Luc Trudeau | 6e69131 | 2018-04-11 13:03:16 -0400 | [diff] [blame] | 751 | return intra_mode_to_tx_type(mbmi, plane_type); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 754 | static INLINE BLOCK_SIZE get_plane_block_size(BLOCK_SIZE bsize, |
| 755 | int subsampling_x, |
| 756 | int subsampling_y) { |
Cheng Chen | 82b4fa1 | 2018-05-02 18:43:17 -0700 | [diff] [blame] | 757 | if (bsize == BLOCK_INVALID) return BLOCK_INVALID; |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 758 | return ss_size_lookup[bsize][subsampling_x][subsampling_y]; |
Sarah Parker | 90024e4 | 2017-10-06 16:50:47 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 761 | static INLINE int av1_get_txb_size_index(BLOCK_SIZE bsize, int blk_row, |
| 762 | int blk_col) { |
Jingning Han | d26fde2 | 2018-02-21 09:24:37 -0800 | [diff] [blame] | 763 | TX_SIZE txs = max_txsize_rect_lookup[bsize]; |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 764 | for (int level = 0; level < MAX_VARTX_DEPTH - 1; ++level) |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 765 | txs = sub_tx_size_map[txs]; |
Hui Su | c7645d5 | 2018-03-21 15:51:50 -0700 | [diff] [blame] | 766 | const int tx_w_log2 = tx_size_wide_log2[txs] - MI_SIZE_LOG2; |
| 767 | const int tx_h_log2 = tx_size_high_log2[txs] - MI_SIZE_LOG2; |
Hui Su | 07baee9 | 2018-03-21 19:40:17 -0700 | [diff] [blame] | 768 | const int bw_log2 = mi_size_wide_log2[bsize]; |
Hui Su | c7645d5 | 2018-03-21 15:51:50 -0700 | [diff] [blame] | 769 | const int stride_log2 = bw_log2 - tx_w_log2; |
| 770 | const int index = |
| 771 | ((blk_row >> tx_h_log2) << stride_log2) + (blk_col >> tx_w_log2); |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 772 | assert(index < INTER_TX_SIZE_BUF_LEN); |
| 773 | return index; |
| 774 | } |
| 775 | |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 776 | static INLINE int av1_get_txk_type_index(BLOCK_SIZE bsize, int blk_row, |
| 777 | int blk_col) { |
| 778 | TX_SIZE txs = max_txsize_rect_lookup[bsize]; |
| 779 | for (int level = 0; level < MAX_VARTX_DEPTH; ++level) |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 780 | txs = sub_tx_size_map[txs]; |
Peng Bin | 2610392 | 2018-03-15 21:04:58 +0800 | [diff] [blame] | 781 | const int tx_w_log2 = tx_size_wide_log2[txs] - MI_SIZE_LOG2; |
| 782 | const int tx_h_log2 = tx_size_high_log2[txs] - MI_SIZE_LOG2; |
Hui Su | 07baee9 | 2018-03-21 19:40:17 -0700 | [diff] [blame] | 783 | const int bw_uint_log2 = mi_size_wide_log2[bsize]; |
Peng Bin | 2610392 | 2018-03-15 21:04:58 +0800 | [diff] [blame] | 784 | const int stride_log2 = bw_uint_log2 - tx_w_log2; |
| 785 | const int index = |
| 786 | ((blk_row >> tx_h_log2) << stride_log2) + (blk_col >> tx_w_log2); |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 787 | assert(index < TXK_TYPE_BUF_LEN); |
| 788 | return index; |
| 789 | } |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 790 | |
Jingning Han | 4f4922a | 2018-02-28 21:39:00 -0800 | [diff] [blame] | 791 | static INLINE void update_txk_array(TX_TYPE *txk_type, BLOCK_SIZE bsize, |
| 792 | int blk_row, int blk_col, TX_SIZE tx_size, |
| 793 | TX_TYPE tx_type) { |
| 794 | const int txk_type_idx = av1_get_txk_type_index(bsize, blk_row, blk_col); |
| 795 | txk_type[txk_type_idx] = tx_type; |
| 796 | |
| 797 | const int txw = tx_size_wide_unit[tx_size]; |
| 798 | const int txh = tx_size_high_unit[tx_size]; |
| 799 | // The 16x16 unit is due to the constraint from tx_64x64 which sets the |
| 800 | // maximum tx size for chroma as 32x32. Coupled with 4x1 transform block |
| 801 | // size, the constraint takes effect in 32x16 / 16x32 size too. To solve |
| 802 | // the intricacy, cover all the 16x16 units inside a 64 level transform. |
| 803 | if (txw == tx_size_wide_unit[TX_64X64] || |
| 804 | txh == tx_size_high_unit[TX_64X64]) { |
| 805 | const int tx_unit = tx_size_wide_unit[TX_16X16]; |
| 806 | for (int idy = 0; idy < txh; idy += tx_unit) { |
| 807 | for (int idx = 0; idx < txw; idx += tx_unit) { |
| 808 | const int this_index = |
| 809 | av1_get_txk_type_index(bsize, blk_row + idy, blk_col + idx); |
| 810 | txk_type[this_index] = tx_type; |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 816 | static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type, |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 817 | const MACROBLOCKD *xd, int blk_row, |
Sarah Parker | 7c71cc0 | 2018-01-29 12:27:58 -0800 | [diff] [blame] | 818 | int blk_col, TX_SIZE tx_size, |
| 819 | int reduced_tx_set) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 820 | const MB_MODE_INFO *const mbmi = xd->mi[0]; |
Sarah Parker | 90024e4 | 2017-10-06 16:50:47 -0700 | [diff] [blame] | 821 | const struct macroblockd_plane *const pd = &xd->plane[plane_type]; |
Jingning Han | e2ceec1 | 2018-03-19 16:27:55 -0700 | [diff] [blame] | 822 | const TxSetType tx_set_type = |
Hui Su | 2254c36 | 2018-04-10 11:22:38 -0700 | [diff] [blame] | 823 | av1_get_ext_tx_set_type(tx_size, is_inter_block(mbmi), reduced_tx_set); |
Sarah Parker | 90024e4 | 2017-10-06 16:50:47 -0700 | [diff] [blame] | 824 | |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 825 | TX_TYPE tx_type; |
Thomas Daede | af73d53 | 2018-01-30 14:21:32 -0800 | [diff] [blame] | 826 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_up_map[tx_size] > TX_32X32) { |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 827 | tx_type = DCT_DCT; |
| 828 | } else { |
Angie Chiang | bce07f1 | 2017-12-01 16:34:31 -0800 | [diff] [blame] | 829 | if (plane_type == PLANE_TYPE_Y) { |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 830 | const int txk_type_idx = |
| 831 | av1_get_txk_type_index(mbmi->sb_type, blk_row, blk_col); |
| 832 | tx_type = mbmi->txk_type[txk_type_idx]; |
Angie Chiang | bce07f1 | 2017-12-01 16:34:31 -0800 | [diff] [blame] | 833 | } else if (is_inter_block(mbmi)) { |
| 834 | // scale back to y plane's coordinate |
| 835 | blk_row <<= pd->subsampling_y; |
| 836 | blk_col <<= pd->subsampling_x; |
Hui Su | de1a5db | 2018-02-22 15:44:49 -0800 | [diff] [blame] | 837 | const int txk_type_idx = |
| 838 | av1_get_txk_type_index(mbmi->sb_type, blk_row, blk_col); |
| 839 | tx_type = mbmi->txk_type[txk_type_idx]; |
Angie Chiang | bce07f1 | 2017-12-01 16:34:31 -0800 | [diff] [blame] | 840 | } else { |
| 841 | // In intra mode, uv planes don't share the same prediction mode as y |
| 842 | // plane, so the tx_type should not be shared |
Debargha Mukherjee | c8c0fbc | 2018-05-22 19:01:33 +0000 | [diff] [blame] | 843 | tx_type = intra_mode_to_tx_type(mbmi, PLANE_TYPE_UV); |
Angie Chiang | bce07f1 | 2017-12-01 16:34:31 -0800 | [diff] [blame] | 844 | } |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 845 | } |
Angie Chiang | 840c66e | 2017-12-11 16:43:38 -0800 | [diff] [blame] | 846 | assert(tx_type < TX_TYPES); |
Angie Chiang | 2ac1868 | 2017-12-01 18:02:59 -0800 | [diff] [blame] | 847 | if (!av1_ext_tx_used[tx_set_type][tx_type]) return DCT_DCT; |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 848 | return tx_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 851 | void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y, |
| 852 | const int num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 853 | |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 854 | static INLINE int bsize_to_max_depth(BLOCK_SIZE bsize) { |
Urvang Joshi | dd0376f | 2018-05-02 16:37:25 -0700 | [diff] [blame] | 855 | TX_SIZE tx_size = max_txsize_rect_lookup[bsize]; |
Debargha Mukherjee | 0fa057f | 2017-12-06 17:06:29 -0800 | [diff] [blame] | 856 | int depth = 0; |
| 857 | while (depth < MAX_TX_DEPTH && tx_size != TX_4X4) { |
| 858 | depth++; |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 859 | tx_size = sub_tx_size_map[tx_size]; |
Debargha Mukherjee | 0fa057f | 2017-12-06 17:06:29 -0800 | [diff] [blame] | 860 | } |
| 861 | return depth; |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 864 | static INLINE int bsize_to_tx_size_cat(BLOCK_SIZE bsize) { |
Urvang Joshi | dd0376f | 2018-05-02 16:37:25 -0700 | [diff] [blame] | 865 | TX_SIZE tx_size = max_txsize_rect_lookup[bsize]; |
Debargha Mukherjee | e4e18fc | 2017-12-06 23:43:24 -0800 | [diff] [blame] | 866 | assert(tx_size != TX_4X4); |
| 867 | int depth = 0; |
| 868 | while (tx_size != TX_4X4) { |
| 869 | depth++; |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 870 | tx_size = sub_tx_size_map[tx_size]; |
Debargha Mukherjee | e4e18fc | 2017-12-06 23:43:24 -0800 | [diff] [blame] | 871 | assert(depth < 10); |
| 872 | } |
| 873 | assert(depth <= MAX_TX_CATS); |
| 874 | return depth - 1; |
| 875 | } |
| 876 | |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 877 | static INLINE TX_SIZE depth_to_tx_size(int depth, BLOCK_SIZE bsize) { |
Urvang Joshi | dd0376f | 2018-05-02 16:37:25 -0700 | [diff] [blame] | 878 | TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize]; |
Debargha Mukherjee | 0fa057f | 2017-12-06 17:06:29 -0800 | [diff] [blame] | 879 | TX_SIZE tx_size = max_tx_size; |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 880 | for (int d = 0; d < depth; ++d) tx_size = sub_tx_size_map[tx_size]; |
Debargha Mukherjee | 0fa057f | 2017-12-06 17:06:29 -0800 | [diff] [blame] | 881 | return tx_size; |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Urvang Joshi | 82ebc9c | 2018-05-02 17:20:45 -0700 | [diff] [blame] | 884 | static INLINE TX_SIZE av1_get_adjusted_tx_size(TX_SIZE tx_size) { |
| 885 | switch (tx_size) { |
Debargha Mukherjee | 80592c7 | 2017-12-16 08:23:34 -0800 | [diff] [blame] | 886 | case TX_64X64: |
| 887 | case TX_64X32: |
| 888 | case TX_32X64: return TX_32X32; |
| 889 | case TX_64X16: return TX_32X16; |
| 890 | case TX_16X64: return TX_16X32; |
Urvang Joshi | 82ebc9c | 2018-05-02 17:20:45 -0700 | [diff] [blame] | 891 | default: return tx_size; |
Luc Trudeau | d1941f3 | 2017-11-22 14:17:21 -0500 | [diff] [blame] | 892 | } |
Urvang Joshi | 82ebc9c | 2018-05-02 17:20:45 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 895 | static INLINE TX_SIZE av1_get_max_uv_txsize(BLOCK_SIZE bsize, int subsampling_x, |
| 896 | int subsampling_y) { |
| 897 | const BLOCK_SIZE plane_bsize = |
| 898 | get_plane_block_size(bsize, subsampling_x, subsampling_y); |
Urvang Joshi | 82ebc9c | 2018-05-02 17:20:45 -0700 | [diff] [blame] | 899 | assert(plane_bsize < BLOCK_SIZES_ALL); |
| 900 | const TX_SIZE uv_tx = max_txsize_rect_lookup[plane_bsize]; |
| 901 | return av1_get_adjusted_tx_size(uv_tx); |
Debargha Mukherjee | 80592c7 | 2017-12-16 08:23:34 -0800 | [diff] [blame] | 902 | } |
| 903 | |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 904 | static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 905 | const MB_MODE_INFO *mbmi = xd->mi[0]; |
Debargha Mukherjee | 80592c7 | 2017-12-16 08:23:34 -0800 | [diff] [blame] | 906 | if (xd->lossless[mbmi->segment_id]) return TX_4X4; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 907 | if (plane == 0) return mbmi->tx_size; |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 908 | const MACROBLOCKD_PLANE *pd = &xd->plane[plane]; |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 909 | return av1_get_max_uv_txsize(mbmi->sb_type, pd->subsampling_x, |
| 910 | pd->subsampling_y); |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 911 | } |
| 912 | |
Timothy B. Terriberry | a2d5cde | 2017-05-10 18:33:50 -0700 | [diff] [blame] | 913 | void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col, |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 914 | BLOCK_SIZE bsize, const int num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 915 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 916 | void av1_reset_loop_restoration(MACROBLOCKD *xd, const int num_planes); |
Rupert Swarbrick | 7640520 | 2017-11-07 16:35:55 +0000 | [diff] [blame] | 917 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 918 | typedef void (*foreach_transformed_block_visitor)(int plane, int block, |
| 919 | int blk_row, int blk_col, |
| 920 | BLOCK_SIZE plane_bsize, |
| 921 | TX_SIZE tx_size, void *arg); |
| 922 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 923 | void av1_foreach_transformed_block_in_plane( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 924 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane, |
| 925 | foreach_transformed_block_visitor visit, void *arg); |
| 926 | |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 927 | void av1_foreach_transformed_block(const MACROBLOCKD *const xd, |
Jingning Han | 94652b8 | 2017-04-04 09:45:02 -0700 | [diff] [blame] | 928 | BLOCK_SIZE bsize, int mi_row, int mi_col, |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 929 | foreach_transformed_block_visitor visit, |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 930 | void *arg, const int num_planes); |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 931 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 932 | void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, |
Hui Su | e674dec | 2018-04-02 13:02:08 -0700 | [diff] [blame] | 933 | int plane, BLOCK_SIZE plane_bsize, TX_SIZE tx_size, |
| 934 | int has_eob, int aoff, int loff); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 935 | |
Yue Chen | b8aa399 | 2017-12-13 15:27:52 -0800 | [diff] [blame] | 936 | #define MAX_INTERINTRA_SB_SQUARE 32 * 32 |
Yue Chen | 73335fa | 2017-12-20 23:33:41 -0800 | [diff] [blame] | 937 | static INLINE int is_interintra_mode(const MB_MODE_INFO *mbmi) { |
| 938 | return (mbmi->ref_frame[0] > INTRA_FRAME && |
| 939 | mbmi->ref_frame[1] == INTRA_FRAME); |
| 940 | } |
| 941 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) { |
Yue Chen | 9ddd409 | 2017-10-30 16:13:39 -0700 | [diff] [blame] | 943 | return (bsize >= BLOCK_8X8) && (bsize <= BLOCK_32X32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) { |
| 947 | return (mode >= NEARESTMV) && (mode <= NEWMV); |
| 948 | } |
| 949 | |
| 950 | static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) { |
| 951 | return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME); |
| 952 | } |
| 953 | |
| 954 | static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) { |
| 955 | return is_interintra_allowed_bsize(mbmi->sb_type) && |
| 956 | is_interintra_allowed_mode(mbmi->mode) && |
| 957 | is_interintra_allowed_ref(mbmi->ref_frame); |
| 958 | } |
| 959 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 960 | static INLINE int is_interintra_allowed_bsize_group(int group) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 961 | int i; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 962 | for (i = 0; i < BLOCK_SIZES_ALL; i++) { |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 963 | if (size_group_lookup[i] == group && |
| 964 | is_interintra_allowed_bsize((BLOCK_SIZE)i)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 965 | return 1; |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 966 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 967 | } |
| 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) { |
Yue Chen | b8aa399 | 2017-12-13 15:27:52 -0800 | [diff] [blame] | 972 | return mbmi->ref_frame[0] > INTRA_FRAME && |
| 973 | mbmi->ref_frame[1] == INTRA_FRAME && is_interintra_allowed(mbmi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 974 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 975 | |
Debargha Mukherjee | 891a877 | 2017-11-22 10:09:37 -0800 | [diff] [blame] | 976 | static INLINE int get_vartx_max_txsize(const MACROBLOCKD *xd, BLOCK_SIZE bsize, |
Urvang Joshi | 49c57d6 | 2018-05-03 11:37:38 -0700 | [diff] [blame] | 977 | int plane) { |
Urvang Joshi | 5eab6e7 | 2018-05-03 11:19:04 -0700 | [diff] [blame] | 978 | if (xd->lossless[xd->mi[0]->segment_id]) return TX_4X4; |
| 979 | const TX_SIZE max_txsize = max_txsize_rect_lookup[bsize]; |
Urvang Joshi | 49c57d6 | 2018-05-03 11:37:38 -0700 | [diff] [blame] | 980 | if (plane == 0) return max_txsize; // luma |
| 981 | return av1_get_adjusted_tx_size(max_txsize); // chroma |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 982 | } |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 983 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 984 | static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) { |
Debargha Mukherjee | c17a443 | 2017-08-28 22:22:45 -0700 | [diff] [blame] | 985 | return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 988 | static INLINE int is_motion_variation_allowed_compound( |
| 989 | const MB_MODE_INFO *mbmi) { |
| 990 | if (!has_second_ref(mbmi)) |
| 991 | return 1; |
| 992 | else |
| 993 | return 0; |
| 994 | } |
| 995 | |
Yue Chen | 1bd42be | 2017-03-15 18:07:04 -0700 | [diff] [blame] | 996 | // input: log2 of length, 0(4), 1(8), ... |
| 997 | static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 }; |
| 998 | |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 999 | static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) { |
Yue Chen | 1bd42be | 2017-03-15 18:07:04 -0700 | [diff] [blame] | 1000 | return !(mbmi->overlappable_neighbors[0] == 0 && |
| 1001 | mbmi->overlappable_neighbors[1] == 0); |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1002 | } |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1003 | |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 1004 | static INLINE MOTION_MODE |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1005 | motion_mode_allowed(const WarpedMotionParams *gm_params, const MACROBLOCKD *xd, |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 1006 | const MB_MODE_INFO *mbmi, int allow_warped_motion) { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1007 | if (xd->cur_frame_force_integer_mv == 0) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1008 | const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype; |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 1009 | if (is_global_mv_block(mbmi, gm_type)) return SIMPLE_TRANSLATION; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1010 | } |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1011 | if (is_motion_variation_allowed_bsize(mbmi->sb_type) && |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1012 | is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME && |
| 1013 | is_motion_variation_allowed_compound(mbmi)) { |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1014 | if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION; |
Zoe Liu | 70539b1 | 2017-12-02 19:03:36 -0800 | [diff] [blame] | 1015 | assert(!has_second_ref(mbmi)); |
| 1016 | if (mbmi->num_proj_ref[0] >= 1 && |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 1017 | (allow_warped_motion && !av1_is_scaled(&(xd->block_refs[0]->sf)))) { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1018 | if (xd->cur_frame_force_integer_mv) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1019 | return OBMC_CAUSAL; |
| 1020 | } |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1021 | return WARPED_CAUSAL; |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1022 | } |
Yue Chen | 80daf0c | 2017-11-02 17:14:18 -0700 | [diff] [blame] | 1023 | return OBMC_CAUSAL; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1024 | } else { |
| 1025 | return SIMPLE_TRANSLATION; |
| 1026 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Luc Trudeau | 2eb9b84 | 2017-12-13 11:19:16 -0500 | [diff] [blame] | 1029 | static INLINE void assert_motion_mode_valid(MOTION_MODE mode, |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1030 | const WarpedMotionParams *gm_params, |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1031 | const MACROBLOCKD *xd, |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 1032 | const MB_MODE_INFO *mbmi, |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 1033 | int allow_warped_motion) { |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 1034 | const MOTION_MODE last_motion_mode_allowed = |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 1035 | motion_mode_allowed(gm_params, xd, mbmi, allow_warped_motion); |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1036 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1037 | // Check that the input mode is not illegal |
| 1038 | if (last_motion_mode_allowed < mode) |
| 1039 | assert(0 && "Illegal motion mode selected"); |
| 1040 | } |
| 1041 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1042 | static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) { |
| 1043 | return (is_inter_block(mbmi)); |
| 1044 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1045 | |
Hui Su | e87fb23 | 2017-10-05 15:00:15 -0700 | [diff] [blame] | 1046 | static INLINE int av1_allow_palette(int allow_screen_content_tools, |
| 1047 | BLOCK_SIZE sb_type) { |
Hui Su | 8b618f6 | 2017-12-20 12:03:35 -0800 | [diff] [blame] | 1048 | return allow_screen_content_tools && block_size_wide[sb_type] <= 64 && |
Hui Su | 0f9dafb | 2018-02-09 17:20:29 -0800 | [diff] [blame] | 1049 | block_size_high[sb_type] <= 64 && sb_type >= BLOCK_8X8; |
Hui Su | e87fb23 | 2017-10-05 15:00:15 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1052 | // Returns sub-sampled dimensions of the given block. |
| 1053 | // The output values for 'rows_within_bounds' and 'cols_within_bounds' will |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1054 | // differ from 'height' and 'width' when part of the block is outside the |
| 1055 | // right |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1056 | // and/or bottom image boundary. |
| 1057 | static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane, |
| 1058 | const MACROBLOCKD *xd, int *width, |
| 1059 | int *height, |
| 1060 | int *rows_within_bounds, |
| 1061 | int *cols_within_bounds) { |
| 1062 | const int block_height = block_size_high[bsize]; |
| 1063 | const int block_width = block_size_wide[bsize]; |
| 1064 | const int block_rows = (xd->mb_to_bottom_edge >= 0) |
| 1065 | ? block_height |
| 1066 | : (xd->mb_to_bottom_edge >> 3) + block_height; |
| 1067 | const int block_cols = (xd->mb_to_right_edge >= 0) |
| 1068 | ? block_width |
| 1069 | : (xd->mb_to_right_edge >> 3) + block_width; |
| 1070 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1071 | assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0)); |
| 1072 | assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0)); |
| 1073 | assert(block_width >= block_cols); |
| 1074 | assert(block_height >= block_rows); |
Hui Su | 8b618f6 | 2017-12-20 12:03:35 -0800 | [diff] [blame] | 1075 | const int plane_block_width = block_width >> pd->subsampling_x; |
| 1076 | const int plane_block_height = block_height >> pd->subsampling_y; |
| 1077 | // Special handling for chroma sub8x8. |
| 1078 | const int is_chroma_sub8_x = plane > 0 && plane_block_width < 4; |
| 1079 | const int is_chroma_sub8_y = plane > 0 && plane_block_height < 4; |
| 1080 | if (width) *width = plane_block_width + 2 * is_chroma_sub8_x; |
| 1081 | if (height) *height = plane_block_height + 2 * is_chroma_sub8_y; |
| 1082 | if (rows_within_bounds) { |
| 1083 | *rows_within_bounds = |
| 1084 | (block_rows >> pd->subsampling_y) + 2 * is_chroma_sub8_y; |
| 1085 | } |
| 1086 | if (cols_within_bounds) { |
| 1087 | *cols_within_bounds = |
| 1088 | (block_cols >> pd->subsampling_x) + 2 * is_chroma_sub8_x; |
| 1089 | } |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Sarah Parker | efd8af2 | 2017-08-25 16:36:06 -0700 | [diff] [blame] | 1092 | /* clang-format off */ |
| 1093 | typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS] |
| 1094 | [CDF_SIZE(PALETTE_COLORS)]; |
| 1095 | typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS] |
| 1096 | [PALETTE_COLORS]; |
| 1097 | /* clang-format on */ |
| 1098 | |
| 1099 | typedef struct { |
| 1100 | int rows; |
| 1101 | int cols; |
| 1102 | int n_colors; |
| 1103 | int plane_width; |
| 1104 | int plane_height; |
| 1105 | uint8_t *color_map; |
| 1106 | MapCdf map_cdf; |
| 1107 | ColorCost color_cost; |
| 1108 | } Av1ColorMapParam; |
| 1109 | |
Debargha Mukherjee | 0565387 | 2018-04-26 15:31:27 -0700 | [diff] [blame] | 1110 | static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd, |
| 1111 | const MB_MODE_INFO *mbmi) { |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1112 | int ref; |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1113 | |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 1114 | // First check if all modes are GLOBALMV |
| 1115 | if (mbmi->mode != GLOBALMV && mbmi->mode != GLOBAL_GLOBALMV) return 0; |
Jingning Han | 3ca0e67 | 2017-04-14 19:48:05 -0700 | [diff] [blame] | 1116 | |
Debargha Mukherjee | 98ec459 | 2018-04-26 09:39:50 -0700 | [diff] [blame] | 1117 | if (AOMMIN(mi_size_wide[mbmi->sb_type], mi_size_high[mbmi->sb_type]) < 2) |
Jingning Han | 19d0521 | 2017-12-22 12:09:49 -0800 | [diff] [blame] | 1118 | return 0; |
Jingning Han | 3ca0e67 | 2017-04-14 19:48:05 -0700 | [diff] [blame] | 1119 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1120 | // Now check if all global motion is non translational |
| 1121 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
Debargha Mukherjee | 0565387 | 2018-04-26 15:31:27 -0700 | [diff] [blame] | 1122 | if (xd->global_motion[mbmi->ref_frame[ref]].wmtype == TRANSLATION) return 0; |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1123 | } |
| 1124 | return 1; |
| 1125 | } |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1126 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1127 | static INLINE PLANE_TYPE get_plane_type(int plane) { |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 1128 | return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV; |
| 1129 | } |
| 1130 | |
Angie Chiang | 155bf9a | 2017-08-06 19:52:57 -0700 | [diff] [blame] | 1131 | static INLINE void transpose_uint8(uint8_t *dst, int dst_stride, |
| 1132 | const uint8_t *src, int src_stride, int w, |
| 1133 | int h) { |
| 1134 | int r, c; |
| 1135 | for (r = 0; r < h; ++r) |
| 1136 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1137 | } |
| 1138 | |
| 1139 | static INLINE void transpose_uint16(uint16_t *dst, int dst_stride, |
| 1140 | const uint16_t *src, int src_stride, int w, |
| 1141 | int h) { |
| 1142 | int r, c; |
| 1143 | for (r = 0; r < h; ++r) |
| 1144 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1145 | } |
| 1146 | |
| 1147 | static INLINE void transpose_int16(int16_t *dst, int dst_stride, |
| 1148 | const int16_t *src, int src_stride, int w, |
| 1149 | int h) { |
| 1150 | int r, c; |
| 1151 | for (r = 0; r < h; ++r) |
| 1152 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1153 | } |
| 1154 | |
| 1155 | static INLINE void transpose_int32(int32_t *dst, int dst_stride, |
| 1156 | const int32_t *src, int src_stride, int w, |
| 1157 | int h) { |
| 1158 | int r, c; |
| 1159 | for (r = 0; r < h; ++r) |
| 1160 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1161 | } |
| 1162 | |
Urvang Joshi | 8089315 | 2017-10-27 11:51:14 -0700 | [diff] [blame] | 1163 | static INLINE int av1_get_max_eob(TX_SIZE tx_size) { |
Urvang Joshi | 030cea9 | 2017-12-05 15:27:09 -0800 | [diff] [blame] | 1164 | if (tx_size == TX_64X64 || tx_size == TX_64X32 || tx_size == TX_32X64) { |
| 1165 | return 1024; |
| 1166 | } |
| 1167 | if (tx_size == TX_16X64 || tx_size == TX_64X16) { |
| 1168 | return 512; |
| 1169 | } |
Urvang Joshi | 030cea9 | 2017-12-05 15:27:09 -0800 | [diff] [blame] | 1170 | return tx_size_2d[tx_size]; |
Urvang Joshi | 8089315 | 2017-10-27 11:51:14 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1173 | #ifdef __cplusplus |
| 1174 | } // extern "C" |
| 1175 | #endif |
| 1176 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1177 | #endif // AV1_COMMON_BLOCKD_H_ |