blob: 5d2d2ca677c18e18653099153babd8ac3d74d005 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_BLOCKD_H_
13#define AV1_COMMON_BLOCKD_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070016
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070018#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 Chod0b77ac2017-10-20 17:33:16 -070029
Yaowu Xuc27fc142016-08-22 16:08:15 -070030#ifdef __cplusplus
31extern "C" {
32#endif
33
34#define MAX_MB_PLANE 3
35
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080036#if CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080037// Set COMPOUND_SEGMENT_TYPE to one of the three
38// 0: Uniform
39// 1: Difference weighted
40#define COMPOUND_SEGMENT_TYPE 1
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080041#define MAX_SEG_MASK_BITS 1
Yaowu Xuf35f5272017-05-10 08:00:02 -070042
Sarah Parkerb9f757c2017-01-06 17:12:24 -080043// SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS
44typedef enum {
Yaowu Xuf35f5272017-05-10 08:00:02 -070045#if COMPOUND_SEGMENT_TYPE == 0
Sarah Parkerb9f757c2017-01-06 17:12:24 -080046 UNIFORM_45 = 0,
47 UNIFORM_45_INV,
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080048#elif COMPOUND_SEGMENT_TYPE == 1
Sarah Parker7bb84f32017-05-09 15:17:46 -070049 DIFFWTD_38 = 0,
50 DIFFWTD_38_INV,
Yaowu Xuf35f5272017-05-10 08:00:02 -070051#endif // COMPOUND_SEGMENT_TYPE
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080052 SEG_MASK_TYPES,
53} SEG_MASK_TYPE;
54
Sarah Parkerb9f757c2017-01-06 17:12:24 -080055#endif // CONFIG_COMPOUND_SEGMENT
David Barkerac37fa32016-12-02 12:30:21 +000056
Yaowu Xuc27fc142016-08-22 16:08:15 -070057typedef enum {
58 KEY_FRAME = 0,
59 INTER_FRAME = 1,
Soo-Chul Han65c00ae2017-09-07 13:12:35 -040060#if CONFIG_OBU
61 INTRA_ONLY_FRAME = 2, // replaces intra-only
62 S_FRAME = 3,
63#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070064 FRAME_TYPES,
65} FRAME_TYPE;
66
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070067static INLINE int is_comp_ref_allowed(BLOCK_SIZE bsize) {
68 (void)bsize;
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070069 return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070070}
71
Yaowu Xuc27fc142016-08-22 16:08:15 -070072static INLINE int is_inter_mode(PREDICTION_MODE mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070073 return mode >= NEARESTMV && mode <= NEW_NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -070074}
75
Wei-Ting Lin482551b2017-08-03 12:29:24 -070076#if CONFIG_NCOBMC_ADAPT_WEIGHT
77typedef struct superblock_mi_boundaries {
78 int mi_row_begin;
79 int mi_col_begin;
80 int mi_row_end;
81 int mi_col_end;
82} SB_MI_BD;
83
Wei-Ting Linb586de82017-08-03 15:17:38 -070084typedef struct { int16_t KERNEL[4][MAX_SB_SIZE][MAX_SB_SIZE]; } NCOBMC_KERNELS;
Wei-Ting Lin482551b2017-08-03 12:29:24 -070085#endif
86
David Barkerac37fa32016-12-02 12:30:21 +000087typedef struct {
88 uint8_t *plane[MAX_MB_PLANE];
89 int stride[MAX_MB_PLANE];
90} BUFFER_SET;
91
Yaowu Xuc27fc142016-08-22 16:08:15 -070092static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -070093 return mode >= NEARESTMV && mode <= NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -070094}
Zoe Liu85b66462017-04-20 14:28:19 -070095static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) {
96 return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV;
97}
Zoe Liu239f06b2017-04-20 13:10:55 -070098#if CONFIG_COMPOUND_SINGLEREF
99static INLINE int is_inter_singleref_comp_mode(PREDICTION_MODE mode) {
100 return mode >= SR_NEAREST_NEARMV && mode <= SR_NEW_NEWMV;
101}
Zoe Liu85b66462017-04-20 14:28:19 -0700102static INLINE int is_inter_anyref_comp_mode(PREDICTION_MODE mode) {
103 return is_inter_compound_mode(mode) || is_inter_singleref_comp_mode(mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700104}
Zoe Liu85b66462017-04-20 14:28:19 -0700105#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700106
107static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700108 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800109 MB_MODE_COUNT, // DC_PRED
110 MB_MODE_COUNT, // V_PRED
111 MB_MODE_COUNT, // H_PRED
112 MB_MODE_COUNT, // D45_PRED
113 MB_MODE_COUNT, // D135_PRED
114 MB_MODE_COUNT, // D117_PRED
115 MB_MODE_COUNT, // D153_PRED
116 MB_MODE_COUNT, // D207_PRED
117 MB_MODE_COUNT, // D63_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800118 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700119#if CONFIG_SMOOTH_HV
120 MB_MODE_COUNT, // SMOOTH_V_PRED
121 MB_MODE_COUNT, // SMOOTH_H_PRED
122#endif // CONFIG_SMOOTH_HV
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700123 MB_MODE_COUNT, // PAETH_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800124 MB_MODE_COUNT, // NEARESTMV
125 MB_MODE_COUNT, // NEARMV
126 MB_MODE_COUNT, // ZEROMV
127 MB_MODE_COUNT, // NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700128#if CONFIG_COMPOUND_SINGLEREF
129 NEARESTMV, // SR_NEAREST_NEARMV
Zoe Liu85b66462017-04-20 14:28:19 -0700130 // NEARESTMV, // SR_NEAREST_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700131 NEARMV, // SR_NEAR_NEWMV
132 ZEROMV, // SR_ZERO_NEWMV
133 NEWMV, // SR_NEW_NEWMV
134#endif // CONFIG_COMPOUND_SINGLEREF
135 NEARESTMV, // NEAREST_NEARESTMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700136 NEARMV, // NEAR_NEARMV
137 NEARESTMV, // NEAREST_NEWMV
138 NEWMV, // NEW_NEARESTMV
139 NEARMV, // NEAR_NEWMV
140 NEWMV, // NEW_NEARMV
141 ZEROMV, // ZERO_ZEROMV
142 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700144 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Zoe Liu85b66462017-04-20 14:28:19 -0700145#if CONFIG_COMPOUND_SINGLEREF
146 assert(is_inter_anyref_comp_mode(mode));
147#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700148 assert(is_inter_compound_mode(mode));
Zoe Liu85b66462017-04-20 14:28:19 -0700149#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700150 return lut[mode];
151}
152
153static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700154 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800155 MB_MODE_COUNT, // DC_PRED
156 MB_MODE_COUNT, // V_PRED
157 MB_MODE_COUNT, // H_PRED
158 MB_MODE_COUNT, // D45_PRED
159 MB_MODE_COUNT, // D135_PRED
160 MB_MODE_COUNT, // D117_PRED
161 MB_MODE_COUNT, // D153_PRED
162 MB_MODE_COUNT, // D207_PRED
163 MB_MODE_COUNT, // D63_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800164 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700165#if CONFIG_SMOOTH_HV
166 MB_MODE_COUNT, // SMOOTH_V_PRED
167 MB_MODE_COUNT, // SMOOTH_H_PRED
168#endif // CONFIG_SMOOTH_HV
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700169 MB_MODE_COUNT, // PAETH_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800170 MB_MODE_COUNT, // NEARESTMV
171 MB_MODE_COUNT, // NEARMV
172 MB_MODE_COUNT, // ZEROMV
173 MB_MODE_COUNT, // NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700174#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu85b66462017-04-20 14:28:19 -0700175 NEARMV, // SR_NEAREST_NEARMV
176 // NEWMV, // SR_NEAREST_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700177 NEWMV, // SR_NEAR_NEWMV
178 NEWMV, // SR_ZERO_NEWMV
179 NEWMV, // SR_NEW_NEWMV
180#endif // CONFIG_COMPOUND_SINGLEREF
181 NEARESTMV, // NEAREST_NEARESTMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700182 NEARMV, // NEAR_NEARMV
183 NEWMV, // NEAREST_NEWMV
184 NEARESTMV, // NEW_NEARESTMV
185 NEWMV, // NEAR_NEWMV
186 NEARMV, // NEW_NEARMV
187 ZEROMV, // ZERO_ZEROMV
188 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700189 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700190 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Zoe Liu85b66462017-04-20 14:28:19 -0700191#if CONFIG_COMPOUND_SINGLEREF
192 assert(is_inter_anyref_comp_mode(mode));
193#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700194 assert(is_inter_compound_mode(mode));
Zoe Liu85b66462017-04-20 14:28:19 -0700195#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196 return lut[mode];
197}
198
David Barker3dfba992017-04-03 16:10:09 +0100199static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700200 return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -0700201#if CONFIG_COMPOUND_SINGLEREF
202 mode == SR_NEAREST_NEARMV || mode == SR_NEAR_NEWMV ||
203#endif // CONFIG_COMPOUND_SINGLEREF
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700204 mode == NEW_NEARMV);
David Barker3dfba992017-04-03 16:10:09 +0100205}
206
Yaowu Xuc27fc142016-08-22 16:08:15 -0700207static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700208 return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -0700209#if CONFIG_COMPOUND_SINGLEREF
210 /* mode == SR_NEAREST_NEWMV || */ mode == SR_NEAR_NEWMV ||
211 mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV ||
212#endif // CONFIG_COMPOUND_SINGLEREF
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700213 mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700214}
Sarah Parker6fdc8532016-11-16 17:47:13 -0800215
Sarah Parker2e604882017-01-17 17:31:25 -0800216static INLINE int use_masked_motion_search(COMPOUND_TYPE type) {
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000217#if CONFIG_WEDGE
Sarah Parker2e604882017-01-17 17:31:25 -0800218 return (type == COMPOUND_WEDGE);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000219#else
220 (void)type;
221 return 0;
222#endif
Sarah Parker2e604882017-01-17 17:31:25 -0800223}
224
Sarah Parker6fdc8532016-11-16 17:47:13 -0800225static INLINE int is_masked_compound_type(COMPOUND_TYPE type) {
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000226#if CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE
Sarah Parker569edda2016-12-14 14:57:38 -0800227 return (type == COMPOUND_WEDGE || type == COMPOUND_SEG);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000228#elif !CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE
Sarah Parker6fdc8532016-11-16 17:47:13 -0800229 return (type == COMPOUND_WEDGE);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000230#elif CONFIG_COMPOUND_SEGMENT && !CONFIG_WEDGE
231 return (type == COMPOUND_SEG);
Sarah Parker569edda2016-12-14 14:57:38 -0800232#endif // CONFIG_COMPOUND_SEGMENT
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000233 (void)type;
234 return 0;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800235}
Zoe Liu85b66462017-04-20 14:28:19 -0700236
Yaowu Xuc27fc142016-08-22 16:08:15 -0700237/* For keyframes, intra block modes are predicted by the (already decoded)
238 modes for the Y blocks to the left and above us; for interframes, there
239 is a single probability table. */
240
241typedef struct {
242 PREDICTION_MODE as_mode;
243 int_mv as_mv[2]; // first, second inter predictor motion vectors
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -0700244 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700245 int_mv ref_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700246} b_mode_info;
247
248typedef int8_t MV_REFERENCE_FRAME;
249
250typedef struct {
251 // Number of base colors for Y (0) and UV (1)
252 uint8_t palette_size[2];
hui sufa4ff852017-05-15 12:20:50 -0700253 // Value of base colors for Y, U, and V
Yaowu Xuc27fc142016-08-22 16:08:15 -0700254 uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700255} PALETTE_MODE_INFO;
256
hui su5db97432016-10-14 16:10:14 -0700257#if CONFIG_FILTER_INTRA
Yue Chen8d8638a2017-02-21 13:28:16 +0800258#define USE_3TAP_INTRA_FILTER 1 // 0: 4-tap; 1: 3-tap
Yaowu Xuc27fc142016-08-22 16:08:15 -0700259typedef struct {
260 // 1: an ext intra mode is used; 0: otherwise.
hui su5db97432016-10-14 16:10:14 -0700261 uint8_t use_filter_intra_mode[PLANE_TYPES];
262 FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES];
263} FILTER_INTRA_MODE_INFO;
Yue Chen57b8ff62017-10-10 23:37:31 -0700264
265static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = {
266 DC_PRED, V_PRED, H_PRED, D117_PRED, D153_PRED, DC_PRED
267};
hui su5db97432016-10-14 16:10:14 -0700268#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700269
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800270#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800271#define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE)
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800272#endif
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800273
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800274typedef struct RD_STATS {
275 int rate;
276 int64_t dist;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700277 // Please be careful of using rdcost, it's not guaranteed to be set all the
278 // time.
279 // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In
280 // these functions, make sure rdcost is always up-to-date according to
281 // rate/dist.
Angie Chiang2a2a7dd2017-04-25 16:08:47 -0700282 int64_t rdcost;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800283 int64_t sse;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700284 int skip; // sse should equal to dist when skip == 1
Jingning Han3bce7542017-07-25 10:53:57 -0700285 int64_t ref_rdcost;
286 int zero_rate;
Jingning Han1a7f0a82017-07-27 09:48:05 -0700287 uint8_t invalid_rate;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800288#if CONFIG_RD_DEBUG
289 int txb_coeff_cost[MAX_MB_PLANE];
290 int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE]
291 [TXB_COEFF_COST_MAP_SIZE];
Angie Chiang3963d632016-11-10 18:41:40 -0800292#endif // CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800293} RD_STATS;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800294
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000295// This struct is used to group function args that are commonly
296// sent together in functions related to interinter compound modes
Sarah Parker6fdc8532016-11-16 17:47:13 -0800297typedef struct {
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000298#if CONFIG_WEDGE
Sarah Parker6fdc8532016-11-16 17:47:13 -0800299 int wedge_index;
300 int wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000301#endif // CONFIG_WEDGE
Sarah Parker569edda2016-12-14 14:57:38 -0800302#if CONFIG_COMPOUND_SEGMENT
Sarah Parkerb9f757c2017-01-06 17:12:24 -0800303 SEG_MASK_TYPE mask_type;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000304 uint8_t *seg_mask;
Sarah Parker569edda2016-12-14 14:57:38 -0800305#endif // CONFIG_COMPOUND_SEGMENT
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000306 COMPOUND_TYPE interinter_compound_type;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800307} INTERINTER_COMPOUND_DATA;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800308
Yaowu Xuc27fc142016-08-22 16:08:15 -0700309// This structure now relates to 8x8 block regions.
Luc Trudeauf5334002017-04-25 12:21:26 -0400310typedef struct MB_MODE_INFO {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700311 // Common for both INTER and INTRA blocks
312 BLOCK_SIZE sb_type;
313 PREDICTION_MODE mode;
314 TX_SIZE tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700315 // TODO(jingning): This effectively assigned a separate entry for each
316 // 8x8 block. Apparently it takes much more space than needed.
317 TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE];
Jingning Hane67b38a2016-11-04 10:30:00 -0700318 TX_SIZE min_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700319 int8_t skip;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700320 int8_t segment_id;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700321 int8_t seg_id_predicted; // valid only when temporal_update is enabled
322
Sarah Parkerc5ccd4c2017-08-03 11:27:50 -0700323#if CONFIG_MRC_TX
324 int valid_mrc_mask;
325#endif // CONFIG_MRC_TX
326
Yaowu Xuc27fc142016-08-22 16:08:15 -0700327 // Only for INTRA blocks
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400328 UV_PREDICTION_MODE uv_mode;
Urvang Joshic6300aa2017-06-01 14:46:23 -0700329
Yaowu Xuc27fc142016-08-22 16:08:15 -0700330 PALETTE_MODE_INFO palette_mode_info;
Alex Converse28744302017-04-13 14:46:22 -0700331#if CONFIG_INTRABC
332 uint8_t use_intrabc;
333#endif // CONFIG_INTRABC
Yaowu Xuc27fc142016-08-22 16:08:15 -0700334
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100335 // Only for INTER blocks
336 InterpFilters interp_filters;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700337 MV_REFERENCE_FRAME ref_frame[2];
338 TX_TYPE tx_type;
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700339#if CONFIG_TXK_SEL
Angie Chiang808d8592017-04-06 18:36:55 -0700340 TX_TYPE txk_type[MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)];
341#endif
Lester Lu432012f2017-08-17 14:39:29 -0700342#if CONFIG_LGT_FROM_PRED
343 int use_lgt;
344#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700345
hui su5db97432016-10-14 16:10:14 -0700346#if CONFIG_FILTER_INTRA
347 FILTER_INTRA_MODE_INFO filter_intra_mode_info;
348#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349#if CONFIG_EXT_INTRA
hui sueda3d762016-12-06 16:58:23 -0800350 // The actual prediction angle is the base angle + (angle_delta * step).
Yaowu Xuc27fc142016-08-22 16:08:15 -0700351 int8_t angle_delta[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700352#endif // CONFIG_EXT_INTRA
353
Yue Chen4d26acb2017-05-01 12:28:34 -0700354#if CONFIG_INTERINTRA
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000355 // interintra members
Yaowu Xuc27fc142016-08-22 16:08:15 -0700356 INTERINTRA_MODE interintra_mode;
Yue Chen4d26acb2017-05-01 12:28:34 -0700357#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700358 // TODO(debargha): Consolidate these flags
359 int use_wedge_interintra;
360 int interintra_wedge_index;
361 int interintra_wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000362 // interinter members
363 COMPOUND_TYPE interinter_compound_type;
364#if CONFIG_WEDGE
365 int wedge_index;
366 int wedge_sign;
367#endif // CONFIG_WEDGE
368#if CONFIG_COMPOUND_SEGMENT
369 SEG_MASK_TYPE mask_type;
370#endif // CONFIG_COMPOUND_SEGMENT
Yue Chencb60b182016-10-13 15:18:22 -0700371 MOTION_MODE motion_mode;
Yue Chen5329a2b2017-02-28 17:33:00 +0800372#if CONFIG_MOTION_VAR
373 int overlappable_neighbors[2];
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700374#if CONFIG_NCOBMC_ADAPT_WEIGHT
375 // Applying different weighting kernels in ncobmc
376 // In current implementation, interpolation modes only defined for squared
377 // blocks. A rectangular block is divided into two squared blocks and each
378 // squared block has an interpolation mode.
379 NCOBMC_MODE ncobmc_mode[2];
Wei-Ting Lin482551b2017-08-03 12:29:24 -0700380#endif // CONFIG_NCOBMC_ADAPT_WEIGHT
Yue Chen5329a2b2017-02-28 17:33:00 +0800381#endif // CONFIG_MOTION_VAR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700382 int_mv mv[2];
383 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700384 uint8_t ref_mv_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700385#if CONFIG_EXT_PARTITION_TYPES
386 PARTITION_TYPE partition;
387#endif
388#if CONFIG_NEW_QUANT
389 int dq_off_index;
390 int send_dq_bit;
391#endif // CONFIG_NEW_QUANT
392 /* deringing gain *per-superblock* */
Jean-Marc Valin5f5c1322017-03-21 16:20:21 -0400393 int8_t cdef_strength;
Arild Fuldseth07441162016-08-15 15:07:52 +0200394 int current_q_index;
Fangwen Fu231fe422017-04-24 17:52:29 -0700395#if CONFIG_EXT_DELTA_Q
396 int current_delta_lf_from_base;
Cheng Chena97394f2017-09-27 15:05:14 -0700397#if CONFIG_LOOPFILTER_LEVEL
398 int curr_delta_lf[FRAME_LF_COUNT];
399#endif // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu231fe422017-04-24 17:52:29 -0700400#endif
Angie Chiangd4022822016-11-02 18:30:25 -0700401#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800402 RD_STATS rd_stats;
Angie Chiangd4022822016-11-02 18:30:25 -0700403 int mi_row;
404 int mi_col;
405#endif
Yue Chen69f18e12016-09-08 14:48:15 -0700406#if CONFIG_WARPED_MOTION
407 int num_proj_ref[2];
408 WarpedMotionParams wm_params[2];
409#endif // CONFIG_WARPED_MOTION
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800410
Luc Trudeauf5334002017-04-25 12:21:26 -0400411#if CONFIG_CFL
412 // Index of the alpha Cb and alpha Cr combination
Luc Trudeaua9bd85f2017-05-11 14:37:56 -0400413 int cfl_alpha_idx;
David Michael Barrf6eaa152017-07-19 19:42:28 +0900414 // Joint sign of alpha Cb and alpha Cr
415 int cfl_alpha_signs;
Luc Trudeauf5334002017-04-25 12:21:26 -0400416#endif
417
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800418 BOUNDARY_TYPE boundary_info;
Cheng Chenf572cd32017-08-25 18:34:51 -0700419#if CONFIG_LPF_SB
420 uint8_t filt_lvl;
Cheng Chen41d37c22017-09-08 19:00:21 -0700421 int reuse_sb_lvl;
422 int sign;
423 int delta;
Cheng Chenf572cd32017-08-25 18:34:51 -0700424#endif
Cheng Chenca6958c2017-10-10 14:00:50 -0700425
426#if CONFIG_JNT_COMP
427 int compound_idx;
428#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700429} MB_MODE_INFO;
430
431typedef struct MODE_INFO {
432 MB_MODE_INFO mbmi;
433 b_mode_info bmi[4];
434} MODE_INFO;
435
Alex Converse28744302017-04-13 14:46:22 -0700436#if CONFIG_INTRABC
437static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) {
438 return mbmi->use_intrabc;
439}
440#endif
441
Yaowu Xuc27fc142016-08-22 16:08:15 -0700442static INLINE PREDICTION_MODE get_y_mode(const MODE_INFO *mi, int block) {
Jingning Hand7d20472016-12-14 11:13:48 -0800443 (void)block;
444 return mi->mbmi.mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700445}
446
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400447#if CONFIG_CFL
448static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) {
449 static const PREDICTION_MODE uv2y[UV_INTRA_MODES] = {
Urvang Joshi93b543a2017-06-01 17:32:41 -0700450 DC_PRED, // UV_DC_PRED
451 V_PRED, // UV_V_PRED
452 H_PRED, // UV_H_PRED
453 D45_PRED, // UV_D45_PRED
454 D135_PRED, // UV_D135_PRED
455 D117_PRED, // UV_D117_PRED
456 D153_PRED, // UV_D153_PRED
457 D207_PRED, // UV_D207_PRED
458 D63_PRED, // UV_D63_PRED
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400459 SMOOTH_PRED, // UV_SMOOTH_PRED
460#if CONFIG_SMOOTH_HV
461 SMOOTH_V_PRED, // UV_SMOOTH_V_PRED
462 SMOOTH_H_PRED, // UV_SMOOTH_H_PRED
463#endif // CONFIG_SMOOTH_HV
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700464 PAETH_PRED, // UV_PAETH_PRED
Luc Trudeau6e1cd782017-06-21 13:52:36 -0400465 DC_PRED, // CFL_PRED
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400466 };
467 return uv2y[mode];
468}
469#else
470static INLINE PREDICTION_MODE get_uv_mode(PREDICTION_MODE mode) { return mode; }
471#endif // CONFIG_CFL
472
Yaowu Xuc27fc142016-08-22 16:08:15 -0700473static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
Alex Converse28744302017-04-13 14:46:22 -0700474#if CONFIG_INTRABC
475 if (is_intrabc_block(mbmi)) return 1;
476#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700477 return mbmi->ref_frame[0] > INTRA_FRAME;
478}
479
480static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
481 return mbmi->ref_frame[1] > INTRA_FRAME;
482}
483
Zoe Liuc082bbc2017-05-17 13:31:37 -0700484#if CONFIG_EXT_COMP_REFS
485static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) {
486 return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^
487 (mbmi->ref_frame[1] >= BWDREF_FRAME)));
488}
489
490static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) {
491 static const MV_REFERENCE_FRAME lut[] = {
492 LAST_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700493 LAST_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700494 LAST_FRAME, // LAST_GOLDEN_FRAMES,
495 BWDREF_FRAME, // BWDREF_ALTREF_FRAMES,
496 };
497 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
498 return lut[ref_idx];
499}
500
501static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) {
502 static const MV_REFERENCE_FRAME lut[] = {
503 LAST2_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700504 LAST3_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700505 GOLDEN_FRAME, // LAST_GOLDEN_FRAMES,
506 ALTREF_FRAME, // BWDREF_ALTREF_FRAMES,
507 };
508 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
509 return lut[ref_idx];
510}
511#endif // CONFIG_EXT_COMP_REFS
512
Yaowu Xuf883b422016-08-30 14:01:10 -0700513PREDICTION_MODE av1_left_block_mode(const MODE_INFO *cur_mi,
514 const MODE_INFO *left_mi, int b);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700515
Yaowu Xuf883b422016-08-30 14:01:10 -0700516PREDICTION_MODE av1_above_block_mode(const MODE_INFO *cur_mi,
517 const MODE_INFO *above_mi, int b);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700518
Sarah Parker19234cc2017-03-10 16:43:25 -0800519#if CONFIG_GLOBAL_MOTION
520static INLINE int is_global_mv_block(const MODE_INFO *mi, int block,
521 TransformationType type) {
522 PREDICTION_MODE mode = get_y_mode(mi, block);
523#if GLOBAL_SUB8X8_USED
524 const int block_size_allowed = 1;
525#else
526 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
Debargha Mukherjeec17a4432017-08-28 22:22:45 -0700527 const int block_size_allowed =
528 AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Sarah Parker19234cc2017-03-10 16:43:25 -0800529#endif // GLOBAL_SUB8X8_USED
Sarah Parker19234cc2017-03-10 16:43:25 -0800530 return (mode == ZEROMV || mode == ZERO_ZEROMV) && type > TRANSLATION &&
531 block_size_allowed;
Sarah Parker19234cc2017-03-10 16:43:25 -0800532}
533#endif // CONFIG_GLOBAL_MOTION
534
Yaowu Xuc27fc142016-08-22 16:08:15 -0700535enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 };
536
537struct buf_2d {
538 uint8_t *buf;
539 uint8_t *buf0;
540 int width;
541 int height;
542 int stride;
543};
544
545typedef struct macroblockd_plane {
546 tran_low_t *dqcoeff;
547 PLANE_TYPE plane_type;
548 int subsampling_x;
549 int subsampling_y;
550 struct buf_2d dst;
551 struct buf_2d pre[2];
552 ENTROPY_CONTEXT *above_context;
553 ENTROPY_CONTEXT *left_context;
554 int16_t seg_dequant[MAX_SEGMENTS][2];
555#if CONFIG_NEW_QUANT
clang-format67948d32016-09-07 22:40:40 -0700556 dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][QUANT_PROFILES]
557 [COEF_BANDS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700558#endif
559 uint8_t *color_index_map;
560
561 // number of 4x4s in current block
562 uint16_t n4_w, n4_h;
563 // log2 of n4_w, n4_h
564 uint8_t n4_wl, n4_hl;
Jingning Hanc47fe6c2016-10-21 16:40:47 -0700565 // block size in pixels
566 uint8_t width, height;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700567
568#if CONFIG_AOM_QM
Thomas Daviesdd3cf832017-10-20 15:49:57 +0100569 qm_val_t *seg_iqmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
570 qm_val_t *seg_qmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700571#endif
572 // encoder
573 const int16_t *dequant;
574#if CONFIG_NEW_QUANT
575 const dequant_val_type_nuq *dequant_val_nuq[QUANT_PROFILES];
576#endif // CONFIG_NEW_QUANT
Yushin Cho77bba8d2016-11-04 16:36:56 -0700577
Yushin Chod0b77ac2017-10-20 17:33:16 -0700578#if CONFIG_DIST_8X8
Yushin Cho77bba8d2016-11-04 16:36:56 -0700579 DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]);
Yushin Chob7b60c52017-07-14 16:18:52 -0700580#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700581} MACROBLOCKD_PLANE;
582
Jingning Han3468df12016-12-05 17:53:16 -0800583#define BLOCK_OFFSET(x, i) \
584 ((x) + (i) * (1 << (tx_size_wide_log2[0] + tx_size_high_log2[0])))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700585
586typedef struct RefBuffer {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700587 int idx;
588 YV12_BUFFER_CONFIG *buf;
589 struct scale_factors sf;
Zoe Liu7b1ec7a2017-05-24 22:28:24 -0700590#if CONFIG_VAR_REFS
Zoe Liu7b1ec7a2017-05-24 22:28:24 -0700591 int is_valid;
592#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700593} RefBuffer;
594
Yi Luo2ab63cb2017-05-11 16:44:22 -0700595#if CONFIG_ADAPT_SCAN
596typedef int16_t EobThresholdMD[TX_TYPES][EOB_THRESHOLD_NUM];
597#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400598
Rupert Swarbrick6c545212017-09-01 17:17:25 +0100599#if CONFIG_LOOP_RESTORATION
600typedef struct {
601 DECLARE_ALIGNED(16, InterpKernel, vfilter);
602 DECLARE_ALIGNED(16, InterpKernel, hfilter);
603} WienerInfo;
604
605typedef struct {
606 int ep;
607 int xqd[2];
608} SgrprojInfo;
609#endif // CONFIG_LOOP_RESTORATION
610
David Michael Barr5b2021e2017-08-17 18:12:39 +0900611#if CONFIG_CFL
Hui Su9fa96232017-10-23 15:46:04 -0700612#if CONFIG_DEBUG
Luc Trudeau03b7e7d2017-09-19 13:20:52 -0400613#define CFL_SUB8X8_VAL_MI_SIZE (4)
614#define CFL_SUB8X8_VAL_MI_SQUARE \
615 (CFL_SUB8X8_VAL_MI_SIZE * CFL_SUB8X8_VAL_MI_SIZE)
Hui Su9fa96232017-10-23 15:46:04 -0700616#endif // CONFIG_DEBUG
David Michael Barr5b2021e2017-08-17 18:12:39 +0900617typedef struct cfl_ctx {
Luc Trudeau4e26d662017-09-11 13:08:40 -0400618 // The CfL prediction buffer is used in two steps:
619 // 1. Stores Q3 reconstructed luma pixels
620 // (only Q2 is required, but Q3 is used to avoid shifts)
621 // 2. Stores Q3 AC contributions (step1 - tx block avg)
622 int16_t pred_buf_q3[MAX_SB_SQUARE];
David Michael Barr5b2021e2017-08-17 18:12:39 +0900623
Luc Trudeau4e26d662017-09-11 13:08:40 -0400624 // Height and width currently used in the CfL prediction buffer.
625 int buf_height, buf_width;
David Michael Barr5b2021e2017-08-17 18:12:39 +0900626
627 // Height and width of the chroma prediction block currently associated with
628 // this context
629 int uv_height, uv_width;
630
David Michael Barr5b2021e2017-08-17 18:12:39 +0900631 int are_parameters_computed;
632
633 // Chroma subsampling
634 int subsampling_x, subsampling_y;
635
636 // Block level DC_PRED for each chromatic plane
637 int dc_pred[CFL_PRED_PLANES];
638
639 int mi_row, mi_col;
640
641 // Whether the reconstructed luma pixels need to be stored
642 int store_y;
643
David Michael Barr1f8d0952017-10-11 17:46:39 +0900644#if CONFIG_DEBUG
645 int rate;
646#endif // CONFIG_DEBUG
647
David Michael Barr5b2021e2017-08-17 18:12:39 +0900648 int is_chroma_reference;
Hui Su9fa96232017-10-23 15:46:04 -0700649#if CONFIG_DEBUG
David Michael Barr5b2021e2017-08-17 18:12:39 +0900650 // The prediction used for sub8x8 blocks originates from multiple luma blocks,
651 // this array is used to validate that cfl_store() is called only once for
652 // each luma block
Luc Trudeau03b7e7d2017-09-19 13:20:52 -0400653 uint8_t sub8x8_val[CFL_SUB8X8_VAL_MI_SQUARE];
Hui Su9fa96232017-10-23 15:46:04 -0700654#endif // CONFIG_DEBUG
David Michael Barr5b2021e2017-08-17 18:12:39 +0900655} CFL_CTX;
656#endif // CONFIG_CFL
657
Yaowu Xuc27fc142016-08-22 16:08:15 -0700658typedef struct macroblockd {
659 struct macroblockd_plane plane[MAX_MB_PLANE];
660 uint8_t bmode_blocks_wl;
661 uint8_t bmode_blocks_hl;
662
663 FRAME_COUNTS *counts;
664 TileInfo tile;
665
666 int mi_stride;
667
668 MODE_INFO **mi;
669 MODE_INFO *left_mi;
670 MODE_INFO *above_mi;
671 MB_MODE_INFO *left_mbmi;
672 MB_MODE_INFO *above_mbmi;
673
674 int up_available;
675 int left_available;
Jingning Han3da18d62017-05-02 12:43:58 -0700676 int chroma_up_available;
677 int chroma_left_available;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700678
Yaowu Xuf883b422016-08-30 14:01:10 -0700679 const aom_prob (*partition_probs)[PARTITION_TYPES - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700680
Rupert Swarbrick57486c52017-08-14 10:53:49 +0100681 /* Distance of MB away from frame edges in subpixels (1/8th pixel) */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700682 int mb_to_left_edge;
683 int mb_to_right_edge;
684 int mb_to_top_edge;
685 int mb_to_bottom_edge;
686
687 FRAME_CONTEXT *fc;
688
689 /* pointers to reference frames */
Urvang Joshi52648442016-10-13 17:27:51 -0700690 const RefBuffer *block_refs[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700691
692 /* pointer to current frame */
693 const YV12_BUFFER_CONFIG *cur_buf;
694
Alex Conversee816b312017-05-01 09:51:24 -0700695#if CONFIG_INTRABC
696 /* Scale of the current frame with respect to itself */
697 struct scale_factors sf_identity;
698#endif
699
Yaowu Xuc27fc142016-08-22 16:08:15 -0700700 ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
701 ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE];
702
703 PARTITION_CONTEXT *above_seg_context;
704 PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE];
705
Yaowu Xuc27fc142016-08-22 16:08:15 -0700706 TXFM_CONTEXT *above_txfm_context;
707 TXFM_CONTEXT *left_txfm_context;
Jingning Han331662e2017-05-30 17:03:32 -0700708 TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700709
Rupert Swarbrick6c545212017-09-01 17:17:25 +0100710#if CONFIG_LOOP_RESTORATION
711 WienerInfo wiener_info[MAX_MB_PLANE];
712 SgrprojInfo sgrproj_info[MAX_MB_PLANE];
713#endif // CONFIG_LOOP_RESTORATION
714
Jingning Hanff6ee6a2016-12-07 09:55:21 -0800715 // block dimension in the unit of mode_info.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700716 uint8_t n8_w, n8_h;
717
Yaowu Xuc27fc142016-08-22 16:08:15 -0700718 uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
719 CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
720 uint8_t is_sec_rect;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700721
Thomas Daviesf77d4ad2017-01-10 18:55:42 +0000722 FRAME_CONTEXT *tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700723 /* Bit depth: 8, 10, 12 */
724 int bd;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700725
Debargha Mukherjee3c42c092016-09-29 09:17:36 -0700726 int qindex[MAX_SEGMENTS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700727 int lossless[MAX_SEGMENTS];
728 int corrupted;
RogerZhou3b635242017-09-19 10:06:46 -0700729#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -0700730 int cur_frame_force_integer_mv;
RogerZhou3b635242017-09-19 10:06:46 -0700731// same with that in AV1_COMMON
732#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700733 struct aom_internal_error_info *error_info;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700734#if CONFIG_GLOBAL_MOTION
David Barkercf3d0b02016-11-10 10:14:49 +0000735 WarpedMotionParams *global_motion;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736#endif // CONFIG_GLOBAL_MOTION
Arild Fuldseth07441162016-08-15 15:07:52 +0200737 int prev_qindex;
738 int delta_qindex;
739 int current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -0700740#if CONFIG_EXT_DELTA_Q
741 // Since actual frame level loop filtering level value is not available
742 // at the beginning of the tile (only available during actual filtering)
743 // at encoder side.we record the delta_lf (against the frame level loop
744 // filtering level) and code the delta between previous superblock's delta
745 // lf and current delta lf. It is equivalent to the delta between previous
746 // superblock's actual lf and current lf.
747 int prev_delta_lf_from_base;
748 int current_delta_lf_from_base;
Cheng Chena97394f2017-09-27 15:05:14 -0700749#if CONFIG_LOOPFILTER_LEVEL
750 // For this experiment, we have four frame filter levels for different plane
751 // and direction. So, to support the per superblock update, we need to add
752 // a few more params as below.
753 // 0: delta loop filter level for y plane vertical
754 // 1: delta loop filter level for y plane horizontal
755 // 2: delta loop filter level for u plane
756 // 3: delta loop filter level for v plane
757 // To make it consistent with the reference to each filter level in segment,
758 // we need to -1, since
759 // SEG_LVL_ALT_LF_Y_V = 1;
760 // SEG_LVL_ALT_LF_Y_H = 2;
761 // SEG_LVL_ALT_LF_U = 3;
762 // SEG_LVL_ALT_LF_V = 4;
763 int prev_delta_lf[FRAME_LF_COUNT];
764 int curr_delta_lf[FRAME_LF_COUNT];
765#endif // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu231fe422017-04-24 17:52:29 -0700766#endif
Yi Luof8e87b42017-04-14 17:20:27 -0700767#if CONFIG_ADAPT_SCAN
768 const EobThresholdMD *eob_threshold_md;
769#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400770
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200771#if CONFIG_COMPOUND_SEGMENT
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000772 DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]);
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200773#endif // CONFIG_COMPOUND_SEGMENT
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000774
Sarah Parker5c6744b2017-08-25 17:27:45 -0700775#if CONFIG_MRC_TX
776 uint8_t *mrc_mask;
777#endif // CONFIG_MRC_TX
778
Luc Trudeauf8164152017-04-11 16:20:51 -0400779#if CONFIG_CFL
780 CFL_CTX *cfl;
781#endif
Wei-Ting Lin482551b2017-08-03 12:29:24 -0700782
783#if CONFIG_NCOBMC_ADAPT_WEIGHT
784 uint8_t *ncobmc_pred_buf[MAX_MB_PLANE];
785 int ncobmc_pred_buf_stride[MAX_MB_PLANE];
786 SB_MI_BD sb_mi_bd;
787#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700788} MACROBLOCKD;
789
Yi Luo51281092017-06-26 16:36:15 -0700790static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) {
791 return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0;
792}
793
Yaowu Xuc27fc142016-08-22 16:08:15 -0700794static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize,
795 PARTITION_TYPE partition) {
796 if (partition == PARTITION_INVALID)
Urvang Joshicb586f32016-09-20 11:36:33 -0700797 return BLOCK_INVALID;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700798 else
799 return subsize_lookup[partition][bsize];
800}
801
802static const TX_TYPE intra_mode_to_tx_type_context[INTRA_MODES] = {
803 DCT_DCT, // DC
804 ADST_DCT, // V
805 DCT_ADST, // H
806 DCT_DCT, // D45
807 ADST_ADST, // D135
808 ADST_DCT, // D117
809 DCT_ADST, // D153
810 DCT_ADST, // D207
811 ADST_DCT, // D63
Urvang Joshi6be4a542016-11-03 15:24:05 -0700812 ADST_ADST, // SMOOTH
Urvang Joshie6ca8e82017-03-15 14:57:41 -0700813#if CONFIG_SMOOTH_HV
814 ADST_DCT, // SMOOTH_V
815 DCT_ADST, // SMOOTH_H
816#endif // CONFIG_SMOOTH_HV
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700817 ADST_ADST, // PAETH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700818};
819
Jingning Hanb83e64b2017-03-01 14:52:04 -0800820#define USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 1
Debargha Mukherjee5a488a62016-11-22 22:24:10 -0800821
Sarah Parker076437f2017-03-14 17:39:53 -0700822#if CONFIG_RECT_TX
Sarah Parker076437f2017-03-14 17:39:53 -0700823static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; }
824#endif // CONFIG_RECT_TX
825
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100826static INLINE int block_signals_txsize(BLOCK_SIZE bsize) {
Sebastien Alaiwanfb838772017-10-24 12:02:54 +0200827#if CONFIG_RECT_TX
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100828 return bsize > BLOCK_4X4;
829#else
830 return bsize >= BLOCK_8X8;
831#endif
832}
833
Sarah Parker2e08d962017-08-01 19:51:20 -0700834#if CONFIG_MRC_TX
835#define USE_MRC_INTRA 0
836#define USE_MRC_INTER 1
Sarah Parker99e7daa2017-08-29 10:30:13 -0700837#define SIGNAL_MRC_MASK_INTRA (USE_MRC_INTRA && 0)
838#define SIGNAL_MRC_MASK_INTER (USE_MRC_INTER && 1)
839#define SIGNAL_ANY_MRC_MASK (SIGNAL_MRC_MASK_INTRA || SIGNAL_MRC_MASK_INTER)
Sarah Parker2e08d962017-08-01 19:51:20 -0700840#endif // CONFIG_MRC_TX
841
Jingning Hanb83e64b2017-03-01 14:52:04 -0800842#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700843#define ALLOW_INTRA_EXT_TX 1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700844
Hui Suddbcde22017-09-18 17:22:02 -0700845// Number of transform types in each set type
846static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = {
847 1, 2,
Sarah Parker53f93db2017-07-11 17:20:04 -0700848#if CONFIG_MRC_TX
Hui Suddbcde22017-09-18 17:22:02 -0700849 2, 3,
850#endif // CONFIG_MRC_TX
851 5, 7, 12, 16,
852};
853
Hui Su4a9be2a2017-09-19 14:41:49 -0700854static const int av1_ext_tx_set_idx_to_type[2][AOMMAX(EXT_TX_SETS_INTRA,
855 EXT_TX_SETS_INTER)] = {
856 {
857 // Intra
858 EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX,
Hui Suddbcde22017-09-18 17:22:02 -0700859#if CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700860 EXT_TX_SET_MRC_DCT,
Hui Suddbcde22017-09-18 17:22:02 -0700861#endif // CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700862 },
863 {
864 // Inter
865 EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT,
866 EXT_TX_SET_DCT_IDTX,
Hui Suddbcde22017-09-18 17:22:02 -0700867#if CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700868 EXT_TX_SET_MRC_DCT_IDTX,
Sarah Parker53f93db2017-07-11 17:20:04 -0700869#endif // CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700870 }
Hui Suddbcde22017-09-18 17:22:02 -0700871};
872
Hui Suddbcde22017-09-18 17:22:02 -0700873#if CONFIG_MRC_TX
874static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = {
875 {
876 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
877 },
878 {
879 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
880 },
881 {
882 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
883 },
884 {
885 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
886 },
887 {
888 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
889 },
890 {
891 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
892 },
893 {
894 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
895 },
896 {
897 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
898 },
899};
900#else // CONFIG_MRC_TX
901static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = {
902 {
903 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
904 },
905 {
906 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
907 },
908 {
909 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
910 },
911 {
912 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
913 },
914 {
915 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
916 },
917 {
918 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
919 },
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800920};
Sarah Parker53f93db2017-07-11 17:20:04 -0700921#endif // CONFIG_MRC_TX
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800922
923static INLINE TxSetType get_ext_tx_set_type(TX_SIZE tx_size, BLOCK_SIZE bs,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800924 int is_inter, int use_reduced_set) {
Yue Chen56e226e2017-05-02 16:21:40 -0700925 const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
926 const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size];
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -0700927#if USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Jingning Han1a00cff2016-12-28 14:53:14 -0800928 (void)bs;
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700929 if (tx_size_sqr_up > TX_32X32) return EXT_TX_SET_DCTONLY;
Jingning Han1a00cff2016-12-28 14:53:14 -0800930#else
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700931 if (tx_size_sqr_up > TX_32X32 || bs < BLOCK_8X8) return EXT_TX_SET_DCTONLY;
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -0700932#endif // USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Sarah Parker5effe3f2017-02-23 12:49:10 -0800933 if (use_reduced_set)
934 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX;
Sarah Parker53f93db2017-07-11 17:20:04 -0700935#if CONFIG_MRC_TX
Sarah Parker2e08d962017-08-01 19:51:20 -0700936 if (tx_size == TX_32X32) {
937 if (is_inter && USE_MRC_INTER)
938 return EXT_TX_SET_MRC_DCT_IDTX;
939 else if (!is_inter && USE_MRC_INTRA)
940 return EXT_TX_SET_MRC_DCT;
941 }
Sarah Parker53f93db2017-07-11 17:20:04 -0700942#endif // CONFIG_MRC_TX
Nathan E. Eggef73e47e2017-10-22 06:41:55 -0400943#if CONFIG_DAALA_TX32
944 if (tx_size_sqr_up > TX_32X32)
945 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
946 if (is_inter)
947 return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT
948 : EXT_TX_SET_ALL16);
949 else
950 return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT4_IDTX
951 : EXT_TX_SET_DTT4_IDTX_1DDCT);
952#endif
Yue Chen56e226e2017-05-02 16:21:40 -0700953 if (tx_size_sqr_up == TX_32X32)
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800954 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
955 if (is_inter)
Yue Chen56e226e2017-05-02 16:21:40 -0700956 return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT
957 : EXT_TX_SET_ALL16);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800958 else
Yue Chen56e226e2017-05-02 16:21:40 -0700959 return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT4_IDTX
960 : EXT_TX_SET_DTT4_IDTX_1DDCT);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800961}
962
Hui Su4a9be2a2017-09-19 14:41:49 -0700963// Maps tx set types to the indices.
964static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = {
965 {
966 // Intra
967 0, -1,
968#if CONFIG_MRC_TX
969 3, -1,
970#endif // CONFIG_MRC_TX
971 2, 1, -1, -1,
972 },
973 {
974 // Inter
975 0, 3,
976#if CONFIG_MRC_TX
977 -1, 4,
978#endif // CONFIG_MRC_TX
979 -1, -1, 2, 1,
980 },
981};
982
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800983static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800984 int use_reduced_set) {
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800985 const TxSetType set_type =
Sarah Parker5effe3f2017-02-23 12:49:10 -0800986 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Hui Su4a9be2a2017-09-19 14:41:49 -0700987 return ext_tx_set_index[is_inter][set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700988}
989
Sarah Parkere68a3e42017-02-16 14:03:24 -0800990static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800991 int use_reduced_set) {
992 const int set_type =
993 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Hui Suddbcde22017-09-18 17:22:02 -0700994 return av1_num_ext_tx_set[set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700995}
996
Lester Lu432012f2017-08-17 14:39:29 -0700997#if CONFIG_LGT_FROM_PRED
998static INLINE int is_lgt_allowed(PREDICTION_MODE mode, TX_SIZE tx_size) {
999 if (!LGT_FROM_PRED_INTRA && !is_inter_mode(mode)) return 0;
1000 if (!LGT_FROM_PRED_INTER && is_inter_mode(mode)) return 0;
1001
1002 switch (mode) {
1003 case D45_PRED:
1004 case D63_PRED:
1005 case D117_PRED:
1006 case V_PRED:
1007#if CONFIG_SMOOTH_HV
1008 case SMOOTH_V_PRED:
1009#endif
1010 return tx_size_wide[tx_size] <= 8;
1011 case D135_PRED:
1012 case D153_PRED:
1013 case D207_PRED:
1014 case H_PRED:
1015#if CONFIG_SMOOTH_HV
1016 case SMOOTH_H_PRED:
1017#endif
1018 return tx_size_high[tx_size] <= 8;
1019 case DC_PRED:
1020 case SMOOTH_PRED: return 0;
Urvang Joshi96d1c0a2017-10-10 13:15:32 -07001021 case PAETH_PRED:
Lester Lu432012f2017-08-17 14:39:29 -07001022 default: return tx_size_wide[tx_size] <= 8 || tx_size_high[tx_size] <= 8;
1023 }
1024}
1025#endif // CONFIG_LGT_FROM_PRED
1026
Yaowu Xuc27fc142016-08-22 16:08:15 -07001027#if CONFIG_RECT_TX
1028static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001029 static const char LUT[BLOCK_SIZES_ALL] = {
Jingning Hanf4e097b2017-01-20 09:23:58 -08001030 0, // BLOCK_2X2
1031 0, // BLOCK_2X4
1032 0, // BLOCK_4X2
Yaowu Xuc27fc142016-08-22 16:08:15 -07001033 0, // BLOCK_4X4
1034 1, // BLOCK_4X8
1035 1, // BLOCK_8X4
1036 0, // BLOCK_8X8
1037 1, // BLOCK_8X16
1038 1, // BLOCK_16X8
1039 0, // BLOCK_16X16
1040 1, // BLOCK_16X32
1041 1, // BLOCK_32X16
1042 0, // BLOCK_32X32
Debargha Mukherjee1a86b012017-10-02 23:58:11 -07001043 1, // BLOCK_32X64
1044 1, // BLOCK_64X32
Yaowu Xuc27fc142016-08-22 16:08:15 -07001045 0, // BLOCK_64X64
1046#if CONFIG_EXT_PARTITION
1047 0, // BLOCK_64X128
1048 0, // BLOCK_128X64
1049 0, // BLOCK_128X128
1050#endif // CONFIG_EXT_PARTITION
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001051 0, // BLOCK_4X16
1052 0, // BLOCK_16X4
1053 0, // BLOCK_8X32
1054 0, // BLOCK_32X8
Rupert Swarbrick72678572017-08-02 12:05:26 +01001055 0, // BLOCK_16X64
1056 0, // BLOCK_64X16
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001057#if CONFIG_EXT_PARTITION
1058 0, // BLOCK_32X128
1059 0, // BLOCK_128X32
1060#endif // CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -07001061 };
1062
1063 return LUT[bsize];
1064}
1065
Yue Chen49587a72016-09-28 17:09:47 -07001066static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd,
1067 const MB_MODE_INFO *mbmi) {
Urvang Joshifeb925f2016-12-05 10:37:29 -08001068 return is_rect_tx_allowed_bsize(mbmi->sb_type) &&
Yue Chen49587a72016-09-28 17:09:47 -07001069 !xd->lossless[mbmi->segment_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001070}
Yue Chend6bdd462017-07-19 16:05:43 -07001071#endif // CONFIG_RECT_TX
1072#endif // CONFIG_EXT_TX
Yue Chen56e226e2017-05-02 16:21:40 -07001073
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02001074#if CONFIG_RECT_TX_EXT
Yue Chen56e226e2017-05-02 16:21:40 -07001075static INLINE int is_quarter_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001076 static const char LUT_QTTX[BLOCK_SIZES_ALL] = {
Yue Chen56e226e2017-05-02 16:21:40 -07001077 0, // BLOCK_2X2
1078 0, // BLOCK_2X4
1079 0, // BLOCK_4X2
Yue Chen56e226e2017-05-02 16:21:40 -07001080 0, // BLOCK_4X4
1081 0, // BLOCK_4X8
1082 0, // BLOCK_8X4
1083 0, // BLOCK_8X8
1084 1, // BLOCK_8X16
1085 1, // BLOCK_16X8
1086 0, // BLOCK_16X16
1087 0, // BLOCK_16X32
1088 0, // BLOCK_32X16
1089 0, // BLOCK_32X32
1090 0, // BLOCK_32X64
1091 0, // BLOCK_64X32
1092 0, // BLOCK_64X64
1093#if CONFIG_EXT_PARTITION
1094 0, // BLOCK_64X128
1095 0, // BLOCK_128X64
1096 0, // BLOCK_128X128
1097#endif // CONFIG_EXT_PARTITION
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001098 0, // BLOCK_4X16
1099 0, // BLOCK_16X4
1100 0, // BLOCK_8X32
1101 0, // BLOCK_32X8
Rupert Swarbrick72678572017-08-02 12:05:26 +01001102 0, // BLOCK_16X64
1103 0, // BLOCK_64X16
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001104#if CONFIG_EXT_PARTITION
1105 0, // BLOCK_32X128
1106 0, // BLOCK_128X32
1107#endif // CONFIG_EXT_PARTITION
Yue Chen56e226e2017-05-02 16:21:40 -07001108 };
1109
1110 return LUT_QTTX[bsize];
1111}
1112
1113static INLINE int is_quarter_tx_allowed(const MACROBLOCKD *xd,
1114 const MB_MODE_INFO *mbmi,
1115 int is_inter) {
1116 return is_quarter_tx_allowed_bsize(mbmi->sb_type) && is_inter &&
1117 !xd->lossless[mbmi->segment_id];
1118}
Yue Chend6bdd462017-07-19 16:05:43 -07001119#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001120
1121static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode,
1122 int is_inter) {
1123 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02001124#if CONFIG_RECT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001125 const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize];
Jingning Han70e5f3f2016-11-09 17:03:07 -08001126#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001127 const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02001128#endif // CONFIG_RECT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001129 (void)is_inter;
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02001130#if CONFIG_RECT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001131 if (bsize == BLOCK_4X4)
1132 return AOMMIN(max_txsize_lookup[bsize], largest_tx_size);
Urvang Joshifeb925f2016-12-05 10:37:29 -08001133 if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size)
1134 return max_rect_tx_size;
1135 else
1136 return largest_tx_size;
1137#elif CONFIG_EXT_TX && CONFIG_RECT_TX
1138 if (txsize_sqr_up_map[max_rect_tx_size] <= largest_tx_size) {
1139 return max_rect_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001140 } else {
Urvang Joshifeb925f2016-12-05 10:37:29 -08001141 return largest_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001142 }
1143#else
Yaowu Xuf883b422016-08-30 14:01:10 -07001144 return AOMMIN(max_tx_size, largest_tx_size);
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02001145#endif // CONFIG_RECT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001146}
1147
hui su5db97432016-10-14 16:10:14 -07001148#if CONFIG_EXT_INTRA
hui su0a6731f2017-04-26 15:23:47 -07001149#define MAX_ANGLE_DELTA 3
1150#define ANGLE_STEP 3
hui su5db97432016-10-14 16:10:14 -07001151extern const int16_t dr_intra_derivative[90];
hui su02c79742017-05-16 17:19:04 -07001152static const uint8_t mode_to_angle_map[] = {
Urvang Joshi93b543a2017-06-01 17:32:41 -07001153 0, 90, 180, 45, 135, 111, 157, 203, 67, 0, 0,
hui su02c79742017-05-16 17:19:04 -07001154#if CONFIG_SMOOTH_HV
1155 0, 0,
1156#endif // CONFIG_SMOOTH_HV
hui su5db97432016-10-14 16:10:14 -07001157};
Yaowu Xuc27fc142016-08-22 16:08:15 -07001158#endif // CONFIG_EXT_INTRA
1159
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001160#if CONFIG_DCT_ONLY
1161#define FIXED_TX_TYPE 1
1162#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001163#define FIXED_TX_TYPE 0
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001164#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001165
Angie Chiang752ccce2017-04-09 13:41:13 -07001166// Converts block_index for given transform size to index of the block in raster
1167// order.
1168static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size,
1169 int block_idx) {
1170 // For transform size 4x8, the possible block_idx values are 0 & 2, because
1171 // block_idx values are incremented in steps of size 'tx_width_unit x
1172 // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to
1173 // block number 1 in raster order, inside an 8x8 MI block.
1174 // For any other transform size, the two indices are equivalent.
1175 return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx;
1176}
1177
1178// Inverse of above function.
1179// Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now.
1180static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size,
1181 int raster_order) {
1182 assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4);
1183 // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4.
1184 return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0;
1185}
1186
Yaowu Xuc27fc142016-08-22 16:08:15 -07001187static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type,
1188 const MACROBLOCKD *xd, int block_idx,
1189 TX_SIZE tx_size) {
1190 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1191
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001192 if (CONFIG_DCT_ONLY || is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07001193 xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32)
1194 return DCT_DCT;
1195
1196 return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y
1197 ? get_y_mode(xd->mi[0], block_idx)
Luc Trudeaud6d9eee2017-07-12 12:36:50 -04001198 : get_uv_mode(mbmi->uv_mode)];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001199}
1200
hui su45b64752017-07-12 16:54:35 -07001201static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type,
Jingning Han19b5c8f2017-07-06 15:10:12 -07001202 const MACROBLOCKD *xd, int blk_row,
1203 int blk_col, int block, TX_SIZE tx_size) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001204 const MODE_INFO *const mi = xd->mi[0];
1205 const MB_MODE_INFO *const mbmi = &mi->mbmi;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001206 (void)blk_row;
1207 (void)blk_col;
Alex Conversedaa15e42017-05-02 14:27:16 -07001208#if CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL)
1209 // TODO(aconverse@google.com): Handle INTRABC + EXT_TX + TXK_SEL
Alex Converse28744302017-04-13 14:46:22 -07001210 if (is_intrabc_block(mbmi)) return DCT_DCT;
Alex Conversedaa15e42017-05-02 14:27:16 -07001211#endif // CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL)
hui su45b64752017-07-12 16:54:35 -07001212
1213#if CONFIG_TXK_SEL
1214 TX_TYPE tx_type;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001215 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] >= TX_32X32) {
hui su45b64752017-07-12 16:54:35 -07001216 tx_type = DCT_DCT;
1217 } else {
Jingning Han19b5c8f2017-07-06 15:10:12 -07001218 if (plane_type == PLANE_TYPE_Y)
1219 tx_type = mbmi->txk_type[(blk_row << 4) + blk_col];
1220 else if (is_inter_block(mbmi))
1221 tx_type = mbmi->txk_type[(blk_row << 5) + (blk_col << 1)];
1222 else
1223 tx_type = intra_mode_to_tx_type_context[mbmi->uv_mode];
hui su45b64752017-07-12 16:54:35 -07001224 }
1225 assert(tx_type >= DCT_DCT && tx_type < TX_TYPES);
1226 return tx_type;
1227#endif // CONFIG_TXK_SEL
1228
James Zern7cdaa602017-04-20 20:12:46 -07001229#if FIXED_TX_TYPE
Angie Chiangc2ebfbf2017-04-15 13:56:58 -07001230 const int block_raster_idx = av1_block_index_to_raster_order(tx_size, block);
James Zern7cdaa602017-04-20 20:12:46 -07001231 return get_default_tx_type(plane_type, xd, block_raster_idx, tx_size);
hui su45b64752017-07-12 16:54:35 -07001232#endif // FIXED_TX_TYPE
1233
1234#if CONFIG_EXT_TX
Sarah Parker53f93db2017-07-11 17:20:04 -07001235#if CONFIG_MRC_TX
1236 if (mbmi->tx_type == MRC_DCT) {
Sarah Parker2e08d962017-08-01 19:51:20 -07001237 assert(((is_inter_block(mbmi) && USE_MRC_INTER) ||
1238 (!is_inter_block(mbmi) && USE_MRC_INTRA)) &&
1239 "INVALID BLOCK TYPE FOR MRC_DCT");
Sarah Parker53f93db2017-07-11 17:20:04 -07001240 if (plane_type == PLANE_TYPE_Y) {
1241 assert(tx_size == TX_32X32);
1242 return mbmi->tx_type;
1243 }
1244 return DCT_DCT;
1245 }
1246#endif // CONFIG_MRC_TX
Nathan E. Egge856d1792017-10-26 17:55:20 -04001247#if CONFIG_DAALA_TX32
1248 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32)
1249#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001250 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 ||
1251 (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi)))
Nathan E. Egge856d1792017-10-26 17:55:20 -04001252#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001253 return DCT_DCT;
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001254 if (plane_type == PLANE_TYPE_Y) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001255#if !ALLOW_INTRA_EXT_TX
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001256 if (is_inter_block(mbmi))
Yaowu Xuc27fc142016-08-22 16:08:15 -07001257#endif // ALLOW_INTRA_EXT_TX
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001258 return mbmi->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001259 }
1260
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001261 if (is_inter_block(mbmi)) {
1262 // UV Inter only
1263 return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32)
1264 ? DCT_DCT
1265 : mbmi->tx_type;
1266 }
1267
Thomas Daedeb7e72f32017-04-26 13:40:31 -07001268 (void)block;
Sebastien Alaiwand8b93f52017-10-17 09:22:01 +02001269 return intra_mode_to_tx_type_context[get_uv_mode(mbmi->uv_mode)];
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001270#else // CONFIG_EXT_TX
Angie Chiang752ccce2017-04-09 13:41:13 -07001271 (void)block;
Sarah Parker53f93db2017-07-11 17:20:04 -07001272#if CONFIG_MRC_TX
1273 if (mbmi->tx_type == MRC_DCT) {
1274 if (plane_type == PLANE_TYPE_Y && !xd->lossless[mbmi->segment_id]) {
1275 assert(tx_size == TX_32X32);
1276 return mbmi->tx_type;
1277 }
1278 return DCT_DCT;
1279 }
1280#endif // CONFIG_MRC_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001281 if (plane_type != PLANE_TYPE_Y || xd->lossless[mbmi->segment_id] ||
1282 txsize_sqr_map[tx_size] >= TX_32X32)
1283 return DCT_DCT;
1284 return mbmi->tx_type;
1285#endif // CONFIG_EXT_TX
1286}
1287
Yaowu Xuf883b422016-08-30 14:01:10 -07001288void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001289
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001290static INLINE int tx_size_to_depth(TX_SIZE tx_size) {
Timothy B. Terriberryfe0fb1d2017-05-18 12:15:16 -07001291 return (int)(tx_size - TX_SIZE_LUMA_MIN);
Jingning Han4e1737a2016-10-25 16:05:02 -07001292}
1293
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001294static INLINE TX_SIZE depth_to_tx_size(int depth) {
Timothy B. Terriberryfe0fb1d2017-05-18 12:15:16 -07001295 return (TX_SIZE)(depth + TX_SIZE_LUMA_MIN);
Jingning Han4e1737a2016-10-25 16:05:02 -07001296}
1297
hui su0c6244b2017-07-12 17:11:43 -07001298static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi,
1299 const struct macroblockd_plane *pd) {
hui su0c6244b2017-07-12 17:11:43 -07001300 const TX_SIZE uv_txsize =
1301 uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x]
1302 [pd->subsampling_y];
Debargha Mukherjee2f123402016-08-30 17:43:38 -07001303 assert(uv_txsize != TX_INVALID);
1304 return uv_txsize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001305}
1306
hui su0c6244b2017-07-12 17:11:43 -07001307static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) {
Angie Chiang80b82262017-02-24 11:39:47 -08001308 const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
hui su0c6244b2017-07-12 17:11:43 -07001309 if (plane == 0) return mbmi->tx_size;
Angie Chiang80b82262017-02-24 11:39:47 -08001310 const MACROBLOCKD_PLANE *pd = &xd->plane[plane];
hui su0c6244b2017-07-12 17:11:43 -07001311 return av1_get_uv_tx_size(mbmi, pd);
Angie Chiang80b82262017-02-24 11:39:47 -08001312}
1313
Yaowu Xuc27fc142016-08-22 16:08:15 -07001314static INLINE BLOCK_SIZE
1315get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) {
1316 return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y];
1317}
1318
Timothy B. Terriberrya2d5cde2017-05-10 18:33:50 -07001319void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
1320 BLOCK_SIZE bsize);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001321
1322typedef void (*foreach_transformed_block_visitor)(int plane, int block,
1323 int blk_row, int blk_col,
1324 BLOCK_SIZE plane_bsize,
1325 TX_SIZE tx_size, void *arg);
1326
Yaowu Xuf883b422016-08-30 14:01:10 -07001327void av1_foreach_transformed_block_in_plane(
Yaowu Xuc27fc142016-08-22 16:08:15 -07001328 const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
1329 foreach_transformed_block_visitor visit, void *arg);
1330
Angie Chiang0397eda2017-03-15 16:57:14 -07001331#if CONFIG_LV_MAP
1332void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
Jingning Han94652b82017-04-04 09:45:02 -07001333 BLOCK_SIZE bsize, int mi_row, int mi_col,
Angie Chiang0397eda2017-03-15 16:57:14 -07001334 foreach_transformed_block_visitor visit,
1335 void *arg);
1336#endif
1337
iole moccagattaf25a4cf2016-11-11 23:57:57 -08001338#if CONFIG_COEF_INTERLEAVE
1339static INLINE int get_max_4x4_size(int num_4x4, int mb_to_edge,
1340 int subsampling) {
1341 return num_4x4 + (mb_to_edge >= 0 ? 0 : mb_to_edge >> (5 + subsampling));
1342}
1343
1344void av1_foreach_transformed_block_interleave(
1345 const MACROBLOCKD *const xd, BLOCK_SIZE bsize,
1346 foreach_transformed_block_visitor visit, void *arg);
1347#endif
1348
Yaowu Xuf883b422016-08-30 14:01:10 -07001349void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
Jingning Haneee43152016-12-05 09:58:45 -08001350 int plane, TX_SIZE tx_size, int has_eob, int aoff,
1351 int loff);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001352
Yaowu Xuc27fc142016-08-22 16:08:15 -07001353static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001354#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001355 // TODO(debargha): Should this be bsize < BLOCK_LARGEST?
1356 return (bsize >= BLOCK_8X8) && (bsize < BLOCK_64X64);
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001357#else
1358 (void)bsize;
1359 return 0;
1360#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001361}
1362
1363static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) {
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001364#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001365 return (mode >= NEARESTMV) && (mode <= NEWMV);
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001366#else
1367 (void)mode;
1368 return 0;
1369#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001370}
1371
1372static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) {
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001373#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001374 return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME);
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001375#else
1376 (void)rf;
1377 return 0;
1378#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001379}
1380
1381static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
1382 return is_interintra_allowed_bsize(mbmi->sb_type) &&
1383 is_interintra_allowed_mode(mbmi->mode) &&
1384 is_interintra_allowed_ref(mbmi->ref_frame);
1385}
1386
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001387static INLINE int is_interintra_allowed_bsize_group(int group) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001388 int i;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001389 for (i = 0; i < BLOCK_SIZES_ALL; i++) {
Urvang Joshicb586f32016-09-20 11:36:33 -07001390 if (size_group_lookup[i] == group &&
1391 is_interintra_allowed_bsize((BLOCK_SIZE)i)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001392 return 1;
Urvang Joshicb586f32016-09-20 11:36:33 -07001393 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001394 }
1395 return 0;
1396}
1397
1398static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) {
1399 return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi);
1400}
Yaowu Xuc27fc142016-08-22 16:08:15 -07001401
Sarah Parker106b3cb2017-04-21 12:13:37 -07001402static INLINE int get_vartx_max_txsize(const MB_MODE_INFO *const mbmi,
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001403 BLOCK_SIZE bsize, int subsampled) {
Sarah Parker106b3cb2017-04-21 12:13:37 -07001404 (void)mbmi;
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001405 TX_SIZE max_txsize = max_txsize_rect_lookup[bsize];
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001406
1407#if CONFIG_EXT_PARTITION && CONFIG_TX64X64
1408 // The decoder is designed so that it can process 64x64 luma pixels at a
1409 // time. If this is a chroma plane with subsampling and bsize corresponds to
1410 // a subsampled BLOCK_128X128 then the lookup above will give TX_64X64. That
1411 // mustn't be used for the subsampled plane (because it would be bigger than
1412 // a 64x64 luma block) so we round down to TX_32X32.
Debargha Mukherjee1fa24462017-10-19 14:33:39 -07001413 if (subsampled && txsize_sqr_up_map[max_txsize] == TX_64X64) {
1414 max_txsize = TX_32X32;
1415 }
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001416#else
1417 (void)subsampled;
1418#endif
1419
1420 return max_txsize;
Sarah Parker106b3cb2017-04-21 12:13:37 -07001421}
Sarah Parker106b3cb2017-04-21 12:13:37 -07001422
Yue Chencb60b182016-10-13 15:18:22 -07001423#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
1424static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) {
Debargha Mukherjeec17a4432017-08-28 22:22:45 -07001425 return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Yue Chencb60b182016-10-13 15:18:22 -07001426}
1427
Yue Chen8636da62017-04-03 01:23:44 -07001428static INLINE int is_motion_variation_allowed_compound(
1429 const MB_MODE_INFO *mbmi) {
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +02001430#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu85b66462017-04-20 14:28:19 -07001431 if (!has_second_ref(mbmi) && !is_inter_singleref_comp_mode(mbmi->mode))
1432#else
Yue Chen8636da62017-04-03 01:23:44 -07001433 if (!has_second_ref(mbmi))
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +02001434#endif // CONFIG_COMPOUND_SINGLEREF
Yue Chen8636da62017-04-03 01:23:44 -07001435 return 1;
1436 else
1437 return 0;
1438}
1439
Yue Chen5329a2b2017-02-28 17:33:00 +08001440#if CONFIG_MOTION_VAR
Yue Chen1bd42be2017-03-15 18:07:04 -07001441// input: log2 of length, 0(4), 1(8), ...
1442static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };
1443
Yue Chen5329a2b2017-02-28 17:33:00 +08001444static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) {
Yue Chen1bd42be2017-03-15 18:07:04 -07001445 return !(mbmi->overlappable_neighbors[0] == 0 &&
1446 mbmi->overlappable_neighbors[1] == 0);
Yue Chen5329a2b2017-02-28 17:33:00 +08001447}
Wei-Ting Lin20885282017-08-28 17:18:18 -07001448#if CONFIG_NCOBMC_ADAPT_WEIGHT
1449static INLINE NCOBMC_MODE ncobmc_mode_allowed_bsize(BLOCK_SIZE bsize) {
1450 if (bsize < BLOCK_8X8 || bsize >= BLOCK_64X64)
1451 return NO_OVERLAP;
1452 else
1453 return MAX_NCOBMC_MODES;
1454}
1455#endif // CONFIG_NCOBMC_ADAPT_WEIGHT
1456#endif // CONFIG_MOTION_VAR
Yue Chen5329a2b2017-02-28 17:33:00 +08001457
Sarah Parker19234cc2017-03-10 16:43:25 -08001458static INLINE MOTION_MODE motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -07001459#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001460 int block, const WarpedMotionParams *gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001461#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001462#if CONFIG_WARPED_MOTION
1463 const MACROBLOCKD *xd,
1464#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001465 const MODE_INFO *mi) {
1466 const MB_MODE_INFO *mbmi = &mi->mbmi;
RogerZhou3b635242017-09-19 10:06:46 -07001467#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -07001468 if (xd->cur_frame_force_integer_mv == 0) {
RogerZhou3b635242017-09-19 10:06:46 -07001469#endif
Sarah Parker0eea89f2017-07-11 11:56:36 -07001470#if CONFIG_GLOBAL_MOTION
RogerZhou3b635242017-09-19 10:06:46 -07001471 const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype;
1472 if (is_global_mv_block(mi, block, gm_type)) return SIMPLE_TRANSLATION;
Sarah Parker0eea89f2017-07-11 11:56:36 -07001473#endif // CONFIG_GLOBAL_MOTION
RogerZhou3b635242017-09-19 10:06:46 -07001474#if CONFIG_AMVR
1475 }
1476#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001477 if (is_motion_variation_allowed_bsize(mbmi->sb_type) &&
Yue Chen8636da62017-04-03 01:23:44 -07001478 is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME &&
1479 is_motion_variation_allowed_compound(mbmi)) {
Yue Chen5329a2b2017-02-28 17:33:00 +08001480#if CONFIG_MOTION_VAR
1481 if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION;
1482#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001483#if CONFIG_WARPED_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001484 if (!has_second_ref(mbmi) && mbmi->num_proj_ref[0] >= 1 &&
Wei-Ting Lin20885282017-08-28 17:18:18 -07001485 !av1_is_scaled(&(xd->block_refs[0]->sf))) {
RogerZhou3b635242017-09-19 10:06:46 -07001486#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -07001487 if (xd->cur_frame_force_integer_mv) {
RogerZhou3b635242017-09-19 10:06:46 -07001488 return OBMC_CAUSAL;
1489 }
1490#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001491 return WARPED_CAUSAL;
Hui Su12231bd2017-09-07 18:01:15 -07001492 }
RogerZhou3b635242017-09-19 10:06:46 -07001493
Yue Chen69f18e12016-09-08 14:48:15 -07001494#endif // CONFIG_WARPED_MOTION
1495#if CONFIG_MOTION_VAR
Wei-Ting Lin20885282017-08-28 17:18:18 -07001496#if CONFIG_NCOBMC_ADAPT_WEIGHT
Hui Su12231bd2017-09-07 18:01:15 -07001497 if (ncobmc_mode_allowed_bsize(mbmi->sb_type) < NO_OVERLAP)
1498 return NCOBMC_ADAPT_WEIGHT;
1499 else
Wei-Ting Lin20885282017-08-28 17:18:18 -07001500#endif
Hui Su12231bd2017-09-07 18:01:15 -07001501 return OBMC_CAUSAL;
Yue Chen69f18e12016-09-08 14:48:15 -07001502#else
1503 return SIMPLE_TRANSLATION;
1504#endif // CONFIG_MOTION_VAR
1505 } else {
1506 return SIMPLE_TRANSLATION;
1507 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001508}
1509
Sarah Parker19234cc2017-03-10 16:43:25 -08001510static INLINE void assert_motion_mode_valid(MOTION_MODE mode,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001511#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001512 int block,
1513 const WarpedMotionParams *gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001514#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001515#if CONFIG_WARPED_MOTION
1516 const MACROBLOCKD *xd,
1517#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001518 const MODE_INFO *mi) {
1519 const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -07001520#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001521 block, gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001522#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001523#if CONFIG_WARPED_MOTION
1524 xd,
1525#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001526 mi);
Wei-Ting Lin20885282017-08-28 17:18:18 -07001527
Sarah Parker19234cc2017-03-10 16:43:25 -08001528 // Check that the input mode is not illegal
1529 if (last_motion_mode_allowed < mode)
1530 assert(0 && "Illegal motion mode selected");
1531}
1532
Yue Chencb60b182016-10-13 15:18:22 -07001533#if CONFIG_MOTION_VAR
Yaowu Xuc27fc142016-08-22 16:08:15 -07001534static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) {
1535 return (is_inter_block(mbmi));
1536}
Yue Chencb60b182016-10-13 15:18:22 -07001537#endif // CONFIG_MOTION_VAR
1538#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07001539
Hui Sue87fb232017-10-05 15:00:15 -07001540static INLINE int av1_allow_palette(int allow_screen_content_tools,
1541 BLOCK_SIZE sb_type) {
1542 return allow_screen_content_tools && sb_type >= BLOCK_8X8 &&
1543 sb_type <= BLOCK_LARGEST;
1544}
1545
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001546// Returns sub-sampled dimensions of the given block.
1547// The output values for 'rows_within_bounds' and 'cols_within_bounds' will
RogerZhou3b635242017-09-19 10:06:46 -07001548// differ from 'height' and 'width' when part of the block is outside the
1549// right
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001550// and/or bottom image boundary.
1551static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane,
1552 const MACROBLOCKD *xd, int *width,
1553 int *height,
1554 int *rows_within_bounds,
1555 int *cols_within_bounds) {
1556 const int block_height = block_size_high[bsize];
1557 const int block_width = block_size_wide[bsize];
1558 const int block_rows = (xd->mb_to_bottom_edge >= 0)
1559 ? block_height
1560 : (xd->mb_to_bottom_edge >> 3) + block_height;
1561 const int block_cols = (xd->mb_to_right_edge >= 0)
1562 ? block_width
1563 : (xd->mb_to_right_edge >> 3) + block_width;
1564 const struct macroblockd_plane *const pd = &xd->plane[plane];
1565 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0));
1566 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0));
1567 assert(block_width >= block_cols);
1568 assert(block_height >= block_rows);
1569 if (width) *width = block_width >> pd->subsampling_x;
1570 if (height) *height = block_height >> pd->subsampling_y;
1571 if (rows_within_bounds) *rows_within_bounds = block_rows >> pd->subsampling_y;
1572 if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x;
1573}
1574
Sarah Parkerefd8af22017-08-25 16:36:06 -07001575/* clang-format off */
1576typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS]
1577 [CDF_SIZE(PALETTE_COLORS)];
1578typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
1579 [PALETTE_COLORS];
1580/* clang-format on */
1581
1582typedef struct {
1583 int rows;
1584 int cols;
1585 int n_colors;
1586 int plane_width;
1587 int plane_height;
1588 uint8_t *color_map;
1589 MapCdf map_cdf;
1590 ColorCost color_cost;
1591} Av1ColorMapParam;
1592
Yue Chen19e7aa82016-11-30 14:05:39 -08001593#if CONFIG_GLOBAL_MOTION
1594static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) {
1595 const MODE_INFO *mi = xd->mi[0];
1596 const MB_MODE_INFO *const mbmi = &mi->mbmi;
1597 int ref;
Yue Chen19e7aa82016-11-30 14:05:39 -08001598
1599 // First check if all modes are ZEROMV
Debargha Mukherjeeedced252017-10-20 00:02:00 -07001600 if (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV) return 0;
Jingning Han3ca0e672017-04-14 19:48:05 -07001601
1602#if !GLOBAL_SUB8X8_USED
1603 if (mbmi->sb_type < BLOCK_8X8) return 0;
1604#endif
1605
Yue Chen19e7aa82016-11-30 14:05:39 -08001606 // Now check if all global motion is non translational
1607 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
1608 if (xd->global_motion[mbmi->ref_frame[ref]].wmtype <= TRANSLATION) return 0;
1609 }
1610 return 1;
1611}
1612#endif // CONFIG_GLOBAL_MOTION
1613
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001614static INLINE PLANE_TYPE get_plane_type(int plane) {
Luc Trudeau005feb62017-02-22 13:34:01 -05001615 return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
1616}
1617
Angie Chiang155bf9a2017-08-06 19:52:57 -07001618static INLINE void transpose_uint8(uint8_t *dst, int dst_stride,
1619 const uint8_t *src, int src_stride, int w,
1620 int h) {
1621 int r, c;
1622 for (r = 0; r < h; ++r)
1623 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1624}
1625
1626static INLINE void transpose_uint16(uint16_t *dst, int dst_stride,
1627 const uint16_t *src, int src_stride, int w,
1628 int h) {
1629 int r, c;
1630 for (r = 0; r < h; ++r)
1631 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1632}
1633
1634static INLINE void transpose_int16(int16_t *dst, int dst_stride,
1635 const int16_t *src, int src_stride, int w,
1636 int h) {
1637 int r, c;
1638 for (r = 0; r < h; ++r)
1639 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1640}
1641
1642static INLINE void transpose_int32(int32_t *dst, int dst_stride,
1643 const int32_t *src, int src_stride, int w,
1644 int h) {
1645 int r, c;
1646 for (r = 0; r < h; ++r)
1647 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1648}
1649
Yaowu Xuc27fc142016-08-22 16:08:15 -07001650#ifdef __cplusplus
1651} // extern "C"
1652#endif
1653
Yaowu Xuf883b422016-08-30 14:01:10 -07001654#endif // AV1_COMMON_BLOCKD_H_