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