blob: b8d8533606d08fc5d0cdfc3d38a399fb75174309 [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// Set COMPOUND_SEGMENT_TYPE to one of the three
37// 0: Uniform
38// 1: Difference weighted
39#define COMPOUND_SEGMENT_TYPE 1
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080040#define MAX_SEG_MASK_BITS 1
Yaowu Xuf35f5272017-05-10 08:00:02 -070041
Sarah Parkerb9f757c2017-01-06 17:12:24 -080042// SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS
43typedef enum {
Yaowu Xuf35f5272017-05-10 08:00:02 -070044#if COMPOUND_SEGMENT_TYPE == 0
Sarah Parkerb9f757c2017-01-06 17:12:24 -080045 UNIFORM_45 = 0,
46 UNIFORM_45_INV,
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080047#elif COMPOUND_SEGMENT_TYPE == 1
Sarah Parker7bb84f32017-05-09 15:17:46 -070048 DIFFWTD_38 = 0,
49 DIFFWTD_38_INV,
Yaowu Xuf35f5272017-05-10 08:00:02 -070050#endif // COMPOUND_SEGMENT_TYPE
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080051 SEG_MASK_TYPES,
52} SEG_MASK_TYPE;
53
Yaowu Xuc27fc142016-08-22 16:08:15 -070054typedef enum {
55 KEY_FRAME = 0,
56 INTER_FRAME = 1,
Soo-Chul Han65c00ae2017-09-07 13:12:35 -040057#if CONFIG_OBU
58 INTRA_ONLY_FRAME = 2, // replaces intra-only
59 S_FRAME = 3,
60#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070061 FRAME_TYPES,
62} FRAME_TYPE;
63
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070064static INLINE int is_comp_ref_allowed(BLOCK_SIZE bsize) {
65 (void)bsize;
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070066 return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070067}
68
Yaowu Xuc27fc142016-08-22 16:08:15 -070069static INLINE int is_inter_mode(PREDICTION_MODE mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 return mode >= NEARESTMV && mode <= NEW_NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -070071}
72
David Barkerac37fa32016-12-02 12:30:21 +000073typedef struct {
74 uint8_t *plane[MAX_MB_PLANE];
75 int stride[MAX_MB_PLANE];
76} BUFFER_SET;
77
Yaowu Xuc27fc142016-08-22 16:08:15 -070078static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -070079 return mode >= NEARESTMV && mode <= NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -070080}
Zoe Liu85b66462017-04-20 14:28:19 -070081static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) {
82 return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV;
83}
Zoe Liu239f06b2017-04-20 13:10:55 -070084#if CONFIG_COMPOUND_SINGLEREF
85static INLINE int is_inter_singleref_comp_mode(PREDICTION_MODE mode) {
86 return mode >= SR_NEAREST_NEARMV && mode <= SR_NEW_NEWMV;
87}
Zoe Liu85b66462017-04-20 14:28:19 -070088static INLINE int is_inter_anyref_comp_mode(PREDICTION_MODE mode) {
89 return is_inter_compound_mode(mode) || is_inter_singleref_comp_mode(mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -070090}
Zoe Liu85b66462017-04-20 14:28:19 -070091#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -070092
93static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -070094 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -080095 MB_MODE_COUNT, // DC_PRED
96 MB_MODE_COUNT, // V_PRED
97 MB_MODE_COUNT, // H_PRED
98 MB_MODE_COUNT, // D45_PRED
99 MB_MODE_COUNT, // D135_PRED
100 MB_MODE_COUNT, // D117_PRED
101 MB_MODE_COUNT, // D153_PRED
102 MB_MODE_COUNT, // D207_PRED
103 MB_MODE_COUNT, // D63_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800104 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700105 MB_MODE_COUNT, // SMOOTH_V_PRED
106 MB_MODE_COUNT, // SMOOTH_H_PRED
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700107 MB_MODE_COUNT, // PAETH_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800108 MB_MODE_COUNT, // NEARESTMV
109 MB_MODE_COUNT, // NEARMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700110 MB_MODE_COUNT, // GLOBALMV
Urvang Joshi102245d2016-11-28 13:05:36 -0800111 MB_MODE_COUNT, // NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700112#if CONFIG_COMPOUND_SINGLEREF
113 NEARESTMV, // SR_NEAREST_NEARMV
Zoe Liu85b66462017-04-20 14:28:19 -0700114 // NEARESTMV, // SR_NEAREST_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700115 NEARMV, // SR_NEAR_NEWMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700116 GLOBALMV, // SR_ZERO_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700117 NEWMV, // SR_NEW_NEWMV
118#endif // CONFIG_COMPOUND_SINGLEREF
119 NEARESTMV, // NEAREST_NEARESTMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700120 NEARMV, // NEAR_NEARMV
121 NEARESTMV, // NEAREST_NEWMV
122 NEWMV, // NEW_NEARESTMV
123 NEARMV, // NEAR_NEWMV
124 NEWMV, // NEW_NEARMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700125 GLOBALMV, // GLOBAL_GLOBALMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700126 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700127 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700128 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Zoe Liu85b66462017-04-20 14:28:19 -0700129#if CONFIG_COMPOUND_SINGLEREF
130 assert(is_inter_anyref_comp_mode(mode));
131#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700132 assert(is_inter_compound_mode(mode));
Zoe Liu85b66462017-04-20 14:28:19 -0700133#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700134 return lut[mode];
135}
136
137static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700138 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800139 MB_MODE_COUNT, // DC_PRED
140 MB_MODE_COUNT, // V_PRED
141 MB_MODE_COUNT, // H_PRED
142 MB_MODE_COUNT, // D45_PRED
143 MB_MODE_COUNT, // D135_PRED
144 MB_MODE_COUNT, // D117_PRED
145 MB_MODE_COUNT, // D153_PRED
146 MB_MODE_COUNT, // D207_PRED
147 MB_MODE_COUNT, // D63_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800148 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700149 MB_MODE_COUNT, // SMOOTH_V_PRED
150 MB_MODE_COUNT, // SMOOTH_H_PRED
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700151 MB_MODE_COUNT, // PAETH_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800152 MB_MODE_COUNT, // NEARESTMV
153 MB_MODE_COUNT, // NEARMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700154 MB_MODE_COUNT, // GLOBALMV
Urvang Joshi102245d2016-11-28 13:05:36 -0800155 MB_MODE_COUNT, // NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700156#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu85b66462017-04-20 14:28:19 -0700157 NEARMV, // SR_NEAREST_NEARMV
158 // NEWMV, // SR_NEAREST_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700159 NEWMV, // SR_NEAR_NEWMV
160 NEWMV, // SR_ZERO_NEWMV
161 NEWMV, // SR_NEW_NEWMV
162#endif // CONFIG_COMPOUND_SINGLEREF
163 NEARESTMV, // NEAREST_NEARESTMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700164 NEARMV, // NEAR_NEARMV
165 NEWMV, // NEAREST_NEWMV
166 NEARESTMV, // NEW_NEARESTMV
167 NEWMV, // NEAR_NEWMV
168 NEARMV, // NEW_NEARMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700169 GLOBALMV, // GLOBAL_GLOBALMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700170 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700171 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700172 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Zoe Liu85b66462017-04-20 14:28:19 -0700173#if CONFIG_COMPOUND_SINGLEREF
174 assert(is_inter_anyref_comp_mode(mode));
175#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700176 assert(is_inter_compound_mode(mode));
Zoe Liu85b66462017-04-20 14:28:19 -0700177#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700178 return lut[mode];
179}
180
David Barker3dfba992017-04-03 16:10:09 +0100181static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700182 return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -0700183#if CONFIG_COMPOUND_SINGLEREF
184 mode == SR_NEAREST_NEARMV || mode == SR_NEAR_NEWMV ||
185#endif // CONFIG_COMPOUND_SINGLEREF
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700186 mode == NEW_NEARMV);
David Barker3dfba992017-04-03 16:10:09 +0100187}
188
Yaowu Xuc27fc142016-08-22 16:08:15 -0700189static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700190 return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -0700191#if CONFIG_COMPOUND_SINGLEREF
192 /* mode == SR_NEAREST_NEWMV || */ mode == SR_NEAR_NEWMV ||
193 mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV ||
194#endif // CONFIG_COMPOUND_SINGLEREF
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700195 mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196}
Sarah Parker6fdc8532016-11-16 17:47:13 -0800197
Sarah Parker2e604882017-01-17 17:31:25 -0800198static INLINE int use_masked_motion_search(COMPOUND_TYPE type) {
199 return (type == COMPOUND_WEDGE);
200}
201
Sarah Parker6fdc8532016-11-16 17:47:13 -0800202static INLINE int is_masked_compound_type(COMPOUND_TYPE type) {
Sarah Parker569edda2016-12-14 14:57:38 -0800203 return (type == COMPOUND_WEDGE || type == COMPOUND_SEG);
Sarah Parker6fdc8532016-11-16 17:47:13 -0800204}
Zoe Liu85b66462017-04-20 14:28:19 -0700205
Yaowu Xuc27fc142016-08-22 16:08:15 -0700206/* For keyframes, intra block modes are predicted by the (already decoded)
207 modes for the Y blocks to the left and above us; for interframes, there
208 is a single probability table. */
209
210typedef struct {
211 PREDICTION_MODE as_mode;
212 int_mv as_mv[2]; // first, second inter predictor motion vectors
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -0700213 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700214 int_mv ref_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700215} b_mode_info;
216
217typedef int8_t MV_REFERENCE_FRAME;
218
219typedef struct {
220 // Number of base colors for Y (0) and UV (1)
221 uint8_t palette_size[2];
hui sufa4ff852017-05-15 12:20:50 -0700222 // Value of base colors for Y, U, and V
Yaowu Xuc27fc142016-08-22 16:08:15 -0700223 uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700224} PALETTE_MODE_INFO;
225
hui su5db97432016-10-14 16:10:14 -0700226#if CONFIG_FILTER_INTRA
Yue Chen8d8638a2017-02-21 13:28:16 +0800227#define USE_3TAP_INTRA_FILTER 1 // 0: 4-tap; 1: 3-tap
Yaowu Xuc27fc142016-08-22 16:08:15 -0700228typedef struct {
229 // 1: an ext intra mode is used; 0: otherwise.
hui su5db97432016-10-14 16:10:14 -0700230 uint8_t use_filter_intra_mode[PLANE_TYPES];
231 FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES];
232} FILTER_INTRA_MODE_INFO;
Yue Chen57b8ff62017-10-10 23:37:31 -0700233
234static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = {
235 DC_PRED, V_PRED, H_PRED, D117_PRED, D153_PRED, DC_PRED
236};
Yue Chen95e13e22017-11-01 23:56:35 -0700237
238#define DISABLE_SUB8X8_FILTER_INTRA 1
239
240static INLINE int av1_filter_intra_allowed_bsize(BLOCK_SIZE bs) {
241 (void)bs;
242#if DISABLE_SUB8X8_FILTER_INTRA
243 return block_size_wide[bs] >= 8 && block_size_high[bs] >= 8;
244#else
245 return 1;
246#endif
247}
248
249static INLINE int av1_filter_intra_allowed_txsize(TX_SIZE tx) {
250 (void)tx;
251#if DISABLE_SUB8X8_FILTER_INTRA
252 return tx_size_wide[tx] >= 8 && tx_size_high[tx] >= 8;
253#else
254 return 1;
255#endif
256}
hui su5db97432016-10-14 16:10:14 -0700257#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700258
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800259#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800260#define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE)
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800261#endif
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800262
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800263typedef struct RD_STATS {
264 int rate;
265 int64_t dist;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700266 // Please be careful of using rdcost, it's not guaranteed to be set all the
267 // time.
268 // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In
269 // these functions, make sure rdcost is always up-to-date according to
270 // rate/dist.
Angie Chiang2a2a7dd2017-04-25 16:08:47 -0700271 int64_t rdcost;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800272 int64_t sse;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700273 int skip; // sse should equal to dist when skip == 1
Jingning Han3bce7542017-07-25 10:53:57 -0700274 int64_t ref_rdcost;
275 int zero_rate;
Jingning Han1a7f0a82017-07-27 09:48:05 -0700276 uint8_t invalid_rate;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800277#if CONFIG_RD_DEBUG
278 int txb_coeff_cost[MAX_MB_PLANE];
279 int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE]
280 [TXB_COEFF_COST_MAP_SIZE];
Angie Chiang3963d632016-11-10 18:41:40 -0800281#endif // CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800282} RD_STATS;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800283
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000284// This struct is used to group function args that are commonly
285// sent together in functions related to interinter compound modes
Sarah Parker6fdc8532016-11-16 17:47:13 -0800286typedef struct {
Sarah Parker6fdc8532016-11-16 17:47:13 -0800287 int wedge_index;
288 int wedge_sign;
Sarah Parkerb9f757c2017-01-06 17:12:24 -0800289 SEG_MASK_TYPE mask_type;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000290 uint8_t *seg_mask;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000291 COMPOUND_TYPE interinter_compound_type;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800292} INTERINTER_COMPOUND_DATA;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800293
Yaowu Xuc27fc142016-08-22 16:08:15 -0700294// This structure now relates to 8x8 block regions.
Luc Trudeauf5334002017-04-25 12:21:26 -0400295typedef struct MB_MODE_INFO {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700296 // Common for both INTER and INTRA blocks
297 BLOCK_SIZE sb_type;
298 PREDICTION_MODE mode;
299 TX_SIZE tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700300 // TODO(jingning): This effectively assigned a separate entry for each
301 // 8x8 block. Apparently it takes much more space than needed.
302 TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE];
Jingning Hane67b38a2016-11-04 10:30:00 -0700303 TX_SIZE min_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700304 int8_t skip;
Zoe Liuf704a1c2017-10-02 16:55:59 -0700305#if CONFIG_EXT_SKIP
306 int8_t skip_mode;
307#endif // CONFIG_EXT_SKIP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700308 int8_t segment_id;
Rostislav Pehlivanovf624dd52017-10-24 16:46:09 +0100309#if CONFIG_Q_SEGMENTATION
310 int8_t q_segment_id;
311#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700312 int8_t seg_id_predicted; // valid only when temporal_update is enabled
313
Sarah Parkerc5ccd4c2017-08-03 11:27:50 -0700314#if CONFIG_MRC_TX
315 int valid_mrc_mask;
316#endif // CONFIG_MRC_TX
317
Yaowu Xuc27fc142016-08-22 16:08:15 -0700318 // Only for INTRA blocks
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400319 UV_PREDICTION_MODE uv_mode;
Urvang Joshic6300aa2017-06-01 14:46:23 -0700320
Yaowu Xuc27fc142016-08-22 16:08:15 -0700321 PALETTE_MODE_INFO palette_mode_info;
Alex Converse28744302017-04-13 14:46:22 -0700322#if CONFIG_INTRABC
323 uint8_t use_intrabc;
324#endif // CONFIG_INTRABC
Yaowu Xuc27fc142016-08-22 16:08:15 -0700325
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100326 // Only for INTER blocks
327 InterpFilters interp_filters;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700328 MV_REFERENCE_FRAME ref_frame[2];
329 TX_TYPE tx_type;
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700330#if CONFIG_TXK_SEL
Angie Chiang808d8592017-04-06 18:36:55 -0700331 TX_TYPE txk_type[MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)];
332#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700333
hui su5db97432016-10-14 16:10:14 -0700334#if CONFIG_FILTER_INTRA
335 FILTER_INTRA_MODE_INFO filter_intra_mode_info;
336#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700337#if CONFIG_EXT_INTRA
hui sueda3d762016-12-06 16:58:23 -0800338 // The actual prediction angle is the base angle + (angle_delta * step).
Yaowu Xuc27fc142016-08-22 16:08:15 -0700339 int8_t angle_delta[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340#endif // CONFIG_EXT_INTRA
341
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000342 // interintra members
Yaowu Xuc27fc142016-08-22 16:08:15 -0700343 INTERINTRA_MODE interintra_mode;
344 // TODO(debargha): Consolidate these flags
345 int use_wedge_interintra;
346 int interintra_wedge_index;
347 int interintra_wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000348 // interinter members
349 COMPOUND_TYPE interinter_compound_type;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000350 int wedge_index;
351 int wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000352 SEG_MASK_TYPE mask_type;
Yue Chencb60b182016-10-13 15:18:22 -0700353 MOTION_MODE motion_mode;
Yue Chen5329a2b2017-02-28 17:33:00 +0800354 int overlappable_neighbors[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700355 int_mv mv[2];
356 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700357 uint8_t ref_mv_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700358#if CONFIG_EXT_PARTITION_TYPES
359 PARTITION_TYPE partition;
360#endif
361#if CONFIG_NEW_QUANT
362 int dq_off_index;
363 int send_dq_bit;
364#endif // CONFIG_NEW_QUANT
365 /* deringing gain *per-superblock* */
Jean-Marc Valin5f5c1322017-03-21 16:20:21 -0400366 int8_t cdef_strength;
Arild Fuldseth07441162016-08-15 15:07:52 +0200367 int current_q_index;
Fangwen Fu231fe422017-04-24 17:52:29 -0700368#if CONFIG_EXT_DELTA_Q
369 int current_delta_lf_from_base;
Cheng Chena97394f2017-09-27 15:05:14 -0700370#if CONFIG_LOOPFILTER_LEVEL
371 int curr_delta_lf[FRAME_LF_COUNT];
372#endif // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu231fe422017-04-24 17:52:29 -0700373#endif
Angie Chiangd4022822016-11-02 18:30:25 -0700374#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800375 RD_STATS rd_stats;
Angie Chiangd4022822016-11-02 18:30:25 -0700376 int mi_row;
377 int mi_col;
378#endif
Yue Chen69f18e12016-09-08 14:48:15 -0700379 int num_proj_ref[2];
380 WarpedMotionParams wm_params[2];
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800381
Luc Trudeauf5334002017-04-25 12:21:26 -0400382#if CONFIG_CFL
383 // Index of the alpha Cb and alpha Cr combination
Luc Trudeaua9bd85f2017-05-11 14:37:56 -0400384 int cfl_alpha_idx;
David Michael Barrf6eaa152017-07-19 19:42:28 +0900385 // Joint sign of alpha Cb and alpha Cr
386 int cfl_alpha_signs;
Luc Trudeauf5334002017-04-25 12:21:26 -0400387#endif
388
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800389 BOUNDARY_TYPE boundary_info;
Cheng Chenf572cd32017-08-25 18:34:51 -0700390#if CONFIG_LPF_SB
391 uint8_t filt_lvl;
Cheng Chen41d37c22017-09-08 19:00:21 -0700392 int reuse_sb_lvl;
393 int sign;
394 int delta;
Cheng Chenf572cd32017-08-25 18:34:51 -0700395#endif
Cheng Chenca6958c2017-10-10 14:00:50 -0700396
397#if CONFIG_JNT_COMP
398 int compound_idx;
399#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700400} MB_MODE_INFO;
401
402typedef struct MODE_INFO {
403 MB_MODE_INFO mbmi;
404 b_mode_info bmi[4];
405} MODE_INFO;
406
Alex Converse28744302017-04-13 14:46:22 -0700407#if CONFIG_INTRABC
Hui Su27df8342017-11-07 15:16:05 -0800408#define NO_FILTER_FOR_IBC 1 // Disable in-loop filters for frame with intrabc
409
Alex Converse28744302017-04-13 14:46:22 -0700410static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) {
411 return mbmi->use_intrabc;
412}
413#endif
414
Yaowu Xuc27fc142016-08-22 16:08:15 -0700415static INLINE PREDICTION_MODE get_y_mode(const MODE_INFO *mi, int block) {
Jingning Hand7d20472016-12-14 11:13:48 -0800416 (void)block;
417 return mi->mbmi.mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700418}
419
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400420#if CONFIG_CFL
421static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) {
422 static const PREDICTION_MODE uv2y[UV_INTRA_MODES] = {
Urvang Joshib7301cd2017-11-09 15:08:56 -0800423 DC_PRED, // UV_DC_PRED
424 V_PRED, // UV_V_PRED
425 H_PRED, // UV_H_PRED
426 D45_PRED, // UV_D45_PRED
427 D135_PRED, // UV_D135_PRED
428 D117_PRED, // UV_D117_PRED
429 D153_PRED, // UV_D153_PRED
430 D207_PRED, // UV_D207_PRED
431 D63_PRED, // UV_D63_PRED
432 SMOOTH_PRED, // UV_SMOOTH_PRED
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400433 SMOOTH_V_PRED, // UV_SMOOTH_V_PRED
434 SMOOTH_H_PRED, // UV_SMOOTH_H_PRED
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700435 PAETH_PRED, // UV_PAETH_PRED
Luc Trudeau6e1cd782017-06-21 13:52:36 -0400436 DC_PRED, // CFL_PRED
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400437 };
438 return uv2y[mode];
439}
440#else
441static INLINE PREDICTION_MODE get_uv_mode(PREDICTION_MODE mode) { return mode; }
442#endif // CONFIG_CFL
443
Yaowu Xuc27fc142016-08-22 16:08:15 -0700444static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
Alex Converse28744302017-04-13 14:46:22 -0700445#if CONFIG_INTRABC
446 if (is_intrabc_block(mbmi)) return 1;
447#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700448 return mbmi->ref_frame[0] > INTRA_FRAME;
449}
450
451static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
452 return mbmi->ref_frame[1] > INTRA_FRAME;
453}
454
Zoe Liuc082bbc2017-05-17 13:31:37 -0700455#if CONFIG_EXT_COMP_REFS
456static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) {
457 return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^
458 (mbmi->ref_frame[1] >= BWDREF_FRAME)));
459}
460
461static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) {
462 static const MV_REFERENCE_FRAME lut[] = {
463 LAST_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700464 LAST_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700465 LAST_FRAME, // LAST_GOLDEN_FRAMES,
466 BWDREF_FRAME, // BWDREF_ALTREF_FRAMES,
467 };
468 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
469 return lut[ref_idx];
470}
471
472static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) {
473 static const MV_REFERENCE_FRAME lut[] = {
474 LAST2_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700475 LAST3_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700476 GOLDEN_FRAME, // LAST_GOLDEN_FRAMES,
477 ALTREF_FRAME, // BWDREF_ALTREF_FRAMES,
478 };
479 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
480 return lut[ref_idx];
481}
482#endif // CONFIG_EXT_COMP_REFS
483
Yaowu Xuf883b422016-08-30 14:01:10 -0700484PREDICTION_MODE av1_left_block_mode(const MODE_INFO *cur_mi,
485 const MODE_INFO *left_mi, int b);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700486
Yaowu Xuf883b422016-08-30 14:01:10 -0700487PREDICTION_MODE av1_above_block_mode(const MODE_INFO *cur_mi,
488 const MODE_INFO *above_mi, int b);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700489
Sarah Parker19234cc2017-03-10 16:43:25 -0800490static INLINE int is_global_mv_block(const MODE_INFO *mi, int block,
491 TransformationType type) {
492 PREDICTION_MODE mode = get_y_mode(mi, block);
493#if GLOBAL_SUB8X8_USED
494 const int block_size_allowed = 1;
495#else
496 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
Debargha Mukherjeec17a4432017-08-28 22:22:45 -0700497 const int block_size_allowed =
498 AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Sarah Parker19234cc2017-03-10 16:43:25 -0800499#endif // GLOBAL_SUB8X8_USED
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700500 return (mode == GLOBALMV || mode == GLOBAL_GLOBALMV) && type > TRANSLATION &&
Sarah Parker19234cc2017-03-10 16:43:25 -0800501 block_size_allowed;
Sarah Parker19234cc2017-03-10 16:43:25 -0800502}
Sarah Parker19234cc2017-03-10 16:43:25 -0800503
Yaowu Xuc27fc142016-08-22 16:08:15 -0700504enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 };
505
506struct buf_2d {
507 uint8_t *buf;
508 uint8_t *buf0;
509 int width;
510 int height;
511 int stride;
512};
513
514typedef struct macroblockd_plane {
515 tran_low_t *dqcoeff;
516 PLANE_TYPE plane_type;
517 int subsampling_x;
518 int subsampling_y;
519 struct buf_2d dst;
520 struct buf_2d pre[2];
521 ENTROPY_CONTEXT *above_context;
522 ENTROPY_CONTEXT *left_context;
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400523
524 // The dequantizers below are true dequntizers used only in the
525 // dequantization process. They have the same coefficient
526 // shift/scale as TX.
527 int16_t seg_dequant_QTX[MAX_SEGMENTS][2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700528#if CONFIG_NEW_QUANT
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400529 dequant_val_type_nuq seg_dequant_nuq_QTX[MAX_SEGMENTS][QUANT_PROFILES]
530 [COEF_BANDS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700531#endif
532 uint8_t *color_index_map;
533
534 // number of 4x4s in current block
535 uint16_t n4_w, n4_h;
536 // log2 of n4_w, n4_h
537 uint8_t n4_wl, n4_hl;
Jingning Hanc47fe6c2016-10-21 16:40:47 -0700538 // block size in pixels
539 uint8_t width, height;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700540
541#if CONFIG_AOM_QM
Thomas Daviesdd3cf832017-10-20 15:49:57 +0100542 qm_val_t *seg_iqmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
543 qm_val_t *seg_qmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700544#endif
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400545
546 // the 'dequantizers' below are not literal dequantizer values.
547 // They're used by encoder RDO to generate ad-hoc lambda values.
548 // They use a hardwired Q3 coeff shift and do not necessarily match
549 // the TX scale in use.
550 const int16_t *dequant_Q3;
Yushin Cho77bba8d2016-11-04 16:36:56 -0700551
Yushin Chod0b77ac2017-10-20 17:33:16 -0700552#if CONFIG_DIST_8X8
Yushin Cho77bba8d2016-11-04 16:36:56 -0700553 DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]);
Yushin Chob7b60c52017-07-14 16:18:52 -0700554#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700555} MACROBLOCKD_PLANE;
556
Jingning Han3468df12016-12-05 17:53:16 -0800557#define BLOCK_OFFSET(x, i) \
558 ((x) + (i) * (1 << (tx_size_wide_log2[0] + tx_size_high_log2[0])))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700559
560typedef struct RefBuffer {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700561 int idx;
562 YV12_BUFFER_CONFIG *buf;
563 struct scale_factors sf;
564} RefBuffer;
565
Yi Luo2ab63cb2017-05-11 16:44:22 -0700566#if CONFIG_ADAPT_SCAN
567typedef int16_t EobThresholdMD[TX_TYPES][EOB_THRESHOLD_NUM];
568#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400569
Rupert Swarbrick6c545212017-09-01 17:17:25 +0100570#if CONFIG_LOOP_RESTORATION
571typedef struct {
572 DECLARE_ALIGNED(16, InterpKernel, vfilter);
573 DECLARE_ALIGNED(16, InterpKernel, hfilter);
574} WienerInfo;
575
576typedef struct {
577 int ep;
578 int xqd[2];
579} SgrprojInfo;
580#endif // CONFIG_LOOP_RESTORATION
581
David Michael Barr5b2021e2017-08-17 18:12:39 +0900582#if CONFIG_CFL
Hui Su9fa96232017-10-23 15:46:04 -0700583#if CONFIG_DEBUG
Luc Trudeau03b7e7d2017-09-19 13:20:52 -0400584#define CFL_SUB8X8_VAL_MI_SIZE (4)
585#define CFL_SUB8X8_VAL_MI_SQUARE \
586 (CFL_SUB8X8_VAL_MI_SIZE * CFL_SUB8X8_VAL_MI_SIZE)
Hui Su9fa96232017-10-23 15:46:04 -0700587#endif // CONFIG_DEBUG
David Michael Barr5b2021e2017-08-17 18:12:39 +0900588typedef struct cfl_ctx {
Luc Trudeau4e26d662017-09-11 13:08:40 -0400589 // The CfL prediction buffer is used in two steps:
590 // 1. Stores Q3 reconstructed luma pixels
591 // (only Q2 is required, but Q3 is used to avoid shifts)
592 // 2. Stores Q3 AC contributions (step1 - tx block avg)
593 int16_t pred_buf_q3[MAX_SB_SQUARE];
David Michael Barr5b2021e2017-08-17 18:12:39 +0900594
Luc Trudeau4e26d662017-09-11 13:08:40 -0400595 // Height and width currently used in the CfL prediction buffer.
596 int buf_height, buf_width;
David Michael Barr5b2021e2017-08-17 18:12:39 +0900597
598 // Height and width of the chroma prediction block currently associated with
599 // this context
600 int uv_height, uv_width;
601
David Michael Barr5b2021e2017-08-17 18:12:39 +0900602 int are_parameters_computed;
603
604 // Chroma subsampling
605 int subsampling_x, subsampling_y;
606
David Michael Barr5b2021e2017-08-17 18:12:39 +0900607 int mi_row, mi_col;
608
609 // Whether the reconstructed luma pixels need to be stored
610 int store_y;
611
David Michael Barr1f8d0952017-10-11 17:46:39 +0900612#if CONFIG_DEBUG
613 int rate;
614#endif // CONFIG_DEBUG
615
David Michael Barr5b2021e2017-08-17 18:12:39 +0900616 int is_chroma_reference;
Hui Su9fa96232017-10-23 15:46:04 -0700617#if CONFIG_DEBUG
Luc Trudeauc7af36d2017-10-11 21:01:00 -0400618 // Validation buffer is usually 2x2, except for 16x4 and 4x16 in that case it
619 // is 4x2 and 2x4 respectively. To simplify accessing the buffer we use a
620 // stride of CFL_SUB8X8_VAL_MI_SIZE resulting in a square of 16.
621 uint16_t sub8x8_val[CFL_SUB8X8_VAL_MI_SQUARE];
622 uint16_t store_counter;
623 uint16_t last_compute_counter;
Hui Su9fa96232017-10-23 15:46:04 -0700624#endif // CONFIG_DEBUG
David Michael Barr5b2021e2017-08-17 18:12:39 +0900625} CFL_CTX;
626#endif // CONFIG_CFL
627
Cheng Chenf78632e2017-10-20 15:30:51 -0700628#if CONFIG_JNT_COMP
629typedef struct jnt_comp_params {
630 int fwd_offset;
631 int bck_offset;
632} JNT_COMP_PARAMS;
633#endif // CONFIG_JNT_COMP
634
Yaowu Xuc27fc142016-08-22 16:08:15 -0700635typedef struct macroblockd {
636 struct macroblockd_plane plane[MAX_MB_PLANE];
637 uint8_t bmode_blocks_wl;
638 uint8_t bmode_blocks_hl;
639
640 FRAME_COUNTS *counts;
641 TileInfo tile;
642
643 int mi_stride;
644
645 MODE_INFO **mi;
646 MODE_INFO *left_mi;
647 MODE_INFO *above_mi;
648 MB_MODE_INFO *left_mbmi;
649 MB_MODE_INFO *above_mbmi;
650
651 int up_available;
652 int left_available;
Jingning Han3da18d62017-05-02 12:43:58 -0700653 int chroma_up_available;
654 int chroma_left_available;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700655
Yaowu Xuf883b422016-08-30 14:01:10 -0700656 const aom_prob (*partition_probs)[PARTITION_TYPES - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700657
Rupert Swarbrick57486c52017-08-14 10:53:49 +0100658 /* Distance of MB away from frame edges in subpixels (1/8th pixel) */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700659 int mb_to_left_edge;
660 int mb_to_right_edge;
661 int mb_to_top_edge;
662 int mb_to_bottom_edge;
663
664 FRAME_CONTEXT *fc;
665
666 /* pointers to reference frames */
Urvang Joshi52648442016-10-13 17:27:51 -0700667 const RefBuffer *block_refs[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700668
669 /* pointer to current frame */
670 const YV12_BUFFER_CONFIG *cur_buf;
671
Alex Conversee816b312017-05-01 09:51:24 -0700672#if CONFIG_INTRABC
673 /* Scale of the current frame with respect to itself */
674 struct scale_factors sf_identity;
675#endif
676
Yaowu Xuc27fc142016-08-22 16:08:15 -0700677 ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
678 ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE];
679
680 PARTITION_CONTEXT *above_seg_context;
681 PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE];
682
Yaowu Xuc27fc142016-08-22 16:08:15 -0700683 TXFM_CONTEXT *above_txfm_context;
684 TXFM_CONTEXT *left_txfm_context;
Jingning Han331662e2017-05-30 17:03:32 -0700685 TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700686
Rupert Swarbrick6c545212017-09-01 17:17:25 +0100687#if CONFIG_LOOP_RESTORATION
688 WienerInfo wiener_info[MAX_MB_PLANE];
689 SgrprojInfo sgrproj_info[MAX_MB_PLANE];
690#endif // CONFIG_LOOP_RESTORATION
691
Jingning Hanff6ee6a2016-12-07 09:55:21 -0800692 // block dimension in the unit of mode_info.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700693 uint8_t n8_w, n8_h;
694
Yaowu Xuc27fc142016-08-22 16:08:15 -0700695 uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
696 CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
697 uint8_t is_sec_rect;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700698
Thomas Daviesf77d4ad2017-01-10 18:55:42 +0000699 FRAME_CONTEXT *tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700700 /* Bit depth: 8, 10, 12 */
701 int bd;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700702
Debargha Mukherjee3c42c092016-09-29 09:17:36 -0700703 int qindex[MAX_SEGMENTS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700704 int lossless[MAX_SEGMENTS];
705 int corrupted;
RogerZhou3b635242017-09-19 10:06:46 -0700706#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -0700707 int cur_frame_force_integer_mv;
RogerZhou3b635242017-09-19 10:06:46 -0700708// same with that in AV1_COMMON
709#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700710 struct aom_internal_error_info *error_info;
David Barkercf3d0b02016-11-10 10:14:49 +0000711 WarpedMotionParams *global_motion;
Arild Fuldseth07441162016-08-15 15:07:52 +0200712 int prev_qindex;
713 int delta_qindex;
714 int current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -0700715#if CONFIG_EXT_DELTA_Q
716 // Since actual frame level loop filtering level value is not available
717 // at the beginning of the tile (only available during actual filtering)
718 // at encoder side.we record the delta_lf (against the frame level loop
719 // filtering level) and code the delta between previous superblock's delta
720 // lf and current delta lf. It is equivalent to the delta between previous
721 // superblock's actual lf and current lf.
722 int prev_delta_lf_from_base;
723 int current_delta_lf_from_base;
Cheng Chena97394f2017-09-27 15:05:14 -0700724#if CONFIG_LOOPFILTER_LEVEL
725 // For this experiment, we have four frame filter levels for different plane
726 // and direction. So, to support the per superblock update, we need to add
727 // a few more params as below.
728 // 0: delta loop filter level for y plane vertical
729 // 1: delta loop filter level for y plane horizontal
730 // 2: delta loop filter level for u plane
731 // 3: delta loop filter level for v plane
732 // To make it consistent with the reference to each filter level in segment,
733 // we need to -1, since
734 // SEG_LVL_ALT_LF_Y_V = 1;
735 // SEG_LVL_ALT_LF_Y_H = 2;
736 // SEG_LVL_ALT_LF_U = 3;
737 // SEG_LVL_ALT_LF_V = 4;
738 int prev_delta_lf[FRAME_LF_COUNT];
739 int curr_delta_lf[FRAME_LF_COUNT];
740#endif // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu231fe422017-04-24 17:52:29 -0700741#endif
Yi Luof8e87b42017-04-14 17:20:27 -0700742#if CONFIG_ADAPT_SCAN
743 const EobThresholdMD *eob_threshold_md;
744#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400745
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000746 DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]);
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000747
Sarah Parker5c6744b2017-08-25 17:27:45 -0700748#if CONFIG_MRC_TX
749 uint8_t *mrc_mask;
750#endif // CONFIG_MRC_TX
751
Luc Trudeauf8164152017-04-11 16:20:51 -0400752#if CONFIG_CFL
753 CFL_CTX *cfl;
754#endif
Cheng Chenf78632e2017-10-20 15:30:51 -0700755
756#if CONFIG_JNT_COMP
757 JNT_COMP_PARAMS jcp_param;
758#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700759} MACROBLOCKD;
760
Yi Luo51281092017-06-26 16:36:15 -0700761static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) {
762 return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0;
763}
764
Yaowu Xuc27fc142016-08-22 16:08:15 -0700765static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize,
766 PARTITION_TYPE partition) {
767 if (partition == PARTITION_INVALID)
Urvang Joshicb586f32016-09-20 11:36:33 -0700768 return BLOCK_INVALID;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700769 else
770 return subsize_lookup[partition][bsize];
771}
772
773static const TX_TYPE intra_mode_to_tx_type_context[INTRA_MODES] = {
774 DCT_DCT, // DC
775 ADST_DCT, // V
776 DCT_ADST, // H
777 DCT_DCT, // D45
778 ADST_ADST, // D135
779 ADST_DCT, // D117
780 DCT_ADST, // D153
781 DCT_ADST, // D207
782 ADST_DCT, // D63
Urvang Joshi6be4a542016-11-03 15:24:05 -0700783 ADST_ADST, // SMOOTH
Urvang Joshie6ca8e82017-03-15 14:57:41 -0700784 ADST_DCT, // SMOOTH_V
785 DCT_ADST, // SMOOTH_H
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700786 ADST_ADST, // PAETH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700787};
788
Jingning Hanb83e64b2017-03-01 14:52:04 -0800789#define USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 1
Debargha Mukherjee5a488a62016-11-22 22:24:10 -0800790
Sarah Parker076437f2017-03-14 17:39:53 -0700791static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; }
Sarah Parker076437f2017-03-14 17:39:53 -0700792
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100793static INLINE int block_signals_txsize(BLOCK_SIZE bsize) {
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100794 return bsize > BLOCK_4X4;
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100795}
796
Sarah Parker2e08d962017-08-01 19:51:20 -0700797#if CONFIG_MRC_TX
798#define USE_MRC_INTRA 0
799#define USE_MRC_INTER 1
Sarah Parker99e7daa2017-08-29 10:30:13 -0700800#define SIGNAL_MRC_MASK_INTRA (USE_MRC_INTRA && 0)
801#define SIGNAL_MRC_MASK_INTER (USE_MRC_INTER && 1)
802#define SIGNAL_ANY_MRC_MASK (SIGNAL_MRC_MASK_INTRA || SIGNAL_MRC_MASK_INTER)
Sarah Parker2e08d962017-08-01 19:51:20 -0700803#endif // CONFIG_MRC_TX
804
Yaowu Xuc27fc142016-08-22 16:08:15 -0700805#define ALLOW_INTRA_EXT_TX 1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700806
Hui Suddbcde22017-09-18 17:22:02 -0700807// Number of transform types in each set type
808static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = {
809 1, 2,
Sarah Parker53f93db2017-07-11 17:20:04 -0700810#if CONFIG_MRC_TX
Hui Suddbcde22017-09-18 17:22:02 -0700811 2, 3,
812#endif // CONFIG_MRC_TX
813 5, 7, 12, 16,
814};
815
Hui Su4a9be2a2017-09-19 14:41:49 -0700816static const int av1_ext_tx_set_idx_to_type[2][AOMMAX(EXT_TX_SETS_INTRA,
817 EXT_TX_SETS_INTER)] = {
818 {
819 // Intra
820 EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX,
Hui Suddbcde22017-09-18 17:22:02 -0700821#if CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700822 EXT_TX_SET_MRC_DCT,
Hui Suddbcde22017-09-18 17:22:02 -0700823#endif // CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700824 },
825 {
826 // Inter
827 EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT,
828 EXT_TX_SET_DCT_IDTX,
Hui Suddbcde22017-09-18 17:22:02 -0700829#if CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700830 EXT_TX_SET_MRC_DCT_IDTX,
Sarah Parker53f93db2017-07-11 17:20:04 -0700831#endif // CONFIG_MRC_TX
Hui Su4a9be2a2017-09-19 14:41:49 -0700832 }
Hui Suddbcde22017-09-18 17:22:02 -0700833};
834
Hui Suddbcde22017-09-18 17:22:02 -0700835#if CONFIG_MRC_TX
836static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = {
837 {
838 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
839 },
840 {
841 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
842 },
843 {
844 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
845 },
846 {
847 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
848 },
849 {
850 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
851 },
852 {
853 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
854 },
855 {
856 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
857 },
858 {
859 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
860 },
861};
862#else // CONFIG_MRC_TX
863static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = {
864 {
865 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
866 },
867 {
868 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
869 },
870 {
871 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
872 },
873 {
874 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
875 },
876 {
877 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
878 },
879 {
880 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
881 },
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800882};
Sarah Parker53f93db2017-07-11 17:20:04 -0700883#endif // CONFIG_MRC_TX
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800884
885static INLINE TxSetType get_ext_tx_set_type(TX_SIZE tx_size, BLOCK_SIZE bs,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800886 int is_inter, int use_reduced_set) {
Yue Chen56e226e2017-05-02 16:21:40 -0700887 const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
888 const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size];
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -0700889#if USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Jingning Han1a00cff2016-12-28 14:53:14 -0800890 (void)bs;
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700891 if (tx_size_sqr_up > TX_32X32) return EXT_TX_SET_DCTONLY;
Jingning Han1a00cff2016-12-28 14:53:14 -0800892#else
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700893 if (tx_size_sqr_up > TX_32X32 || bs < BLOCK_8X8) return EXT_TX_SET_DCTONLY;
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -0700894#endif // USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Sarah Parker5effe3f2017-02-23 12:49:10 -0800895 if (use_reduced_set)
896 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX;
Sarah Parker53f93db2017-07-11 17:20:04 -0700897#if CONFIG_MRC_TX
Sarah Parker2e08d962017-08-01 19:51:20 -0700898 if (tx_size == TX_32X32) {
899 if (is_inter && USE_MRC_INTER)
900 return EXT_TX_SET_MRC_DCT_IDTX;
901 else if (!is_inter && USE_MRC_INTRA)
902 return EXT_TX_SET_MRC_DCT;
903 }
Sarah Parker53f93db2017-07-11 17:20:04 -0700904#endif // CONFIG_MRC_TX
Nathan E. Eggef73e47e2017-10-22 06:41:55 -0400905#if CONFIG_DAALA_TX32
906 if (tx_size_sqr_up > TX_32X32)
907 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
908 if (is_inter)
909 return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT
910 : EXT_TX_SET_ALL16);
911 else
912 return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT4_IDTX
913 : EXT_TX_SET_DTT4_IDTX_1DDCT);
914#endif
Yue Chen56e226e2017-05-02 16:21:40 -0700915 if (tx_size_sqr_up == TX_32X32)
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800916 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
917 if (is_inter)
Yue Chen56e226e2017-05-02 16:21:40 -0700918 return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT
919 : EXT_TX_SET_ALL16);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800920 else
Yue Chen56e226e2017-05-02 16:21:40 -0700921 return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT4_IDTX
922 : EXT_TX_SET_DTT4_IDTX_1DDCT);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800923}
924
Hui Su4a9be2a2017-09-19 14:41:49 -0700925// Maps tx set types to the indices.
926static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = {
927 {
928 // Intra
929 0, -1,
930#if CONFIG_MRC_TX
931 3, -1,
932#endif // CONFIG_MRC_TX
933 2, 1, -1, -1,
934 },
935 {
936 // Inter
937 0, 3,
938#if CONFIG_MRC_TX
939 -1, 4,
940#endif // CONFIG_MRC_TX
941 -1, -1, 2, 1,
942 },
943};
944
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800945static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800946 int use_reduced_set) {
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800947 const TxSetType set_type =
Sarah Parker5effe3f2017-02-23 12:49:10 -0800948 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Hui Su4a9be2a2017-09-19 14:41:49 -0700949 return ext_tx_set_index[is_inter][set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700950}
951
Sarah Parkere68a3e42017-02-16 14:03:24 -0800952static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800953 int use_reduced_set) {
954 const int set_type =
955 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Hui Suddbcde22017-09-18 17:22:02 -0700956 return av1_num_ext_tx_set[set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700957}
958
Yaowu Xuc27fc142016-08-22 16:08:15 -0700959static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100960 static const char LUT[BLOCK_SIZES_ALL] = {
Jingning Hanf4e097b2017-01-20 09:23:58 -0800961 0, // BLOCK_2X2
962 0, // BLOCK_2X4
963 0, // BLOCK_4X2
Yaowu Xuc27fc142016-08-22 16:08:15 -0700964 0, // BLOCK_4X4
965 1, // BLOCK_4X8
966 1, // BLOCK_8X4
967 0, // BLOCK_8X8
968 1, // BLOCK_8X16
969 1, // BLOCK_16X8
970 0, // BLOCK_16X16
971 1, // BLOCK_16X32
972 1, // BLOCK_32X16
973 0, // BLOCK_32X32
Debargha Mukherjee1a86b012017-10-02 23:58:11 -0700974 1, // BLOCK_32X64
975 1, // BLOCK_64X32
Yaowu Xuc27fc142016-08-22 16:08:15 -0700976 0, // BLOCK_64X64
977#if CONFIG_EXT_PARTITION
978 0, // BLOCK_64X128
979 0, // BLOCK_128X64
980 0, // BLOCK_128X128
981#endif // CONFIG_EXT_PARTITION
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100982 0, // BLOCK_4X16
983 0, // BLOCK_16X4
984 0, // BLOCK_8X32
985 0, // BLOCK_32X8
Rupert Swarbrick72678572017-08-02 12:05:26 +0100986 0, // BLOCK_16X64
987 0, // BLOCK_64X16
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100988#if CONFIG_EXT_PARTITION
989 0, // BLOCK_32X128
990 0, // BLOCK_128X32
991#endif // CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700992 };
993
994 return LUT[bsize];
995}
996
Yue Chen49587a72016-09-28 17:09:47 -0700997static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd,
998 const MB_MODE_INFO *mbmi) {
Urvang Joshifeb925f2016-12-05 10:37:29 -0800999 return is_rect_tx_allowed_bsize(mbmi->sb_type) &&
Yue Chen49587a72016-09-28 17:09:47 -07001000 !xd->lossless[mbmi->segment_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001001}
Yue Chen56e226e2017-05-02 16:21:40 -07001002
Sebastien Alaiwanfb838772017-10-24 12:02:54 +02001003#if CONFIG_RECT_TX_EXT
Yue Chen56e226e2017-05-02 16:21:40 -07001004static INLINE int is_quarter_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001005 static const char LUT_QTTX[BLOCK_SIZES_ALL] = {
Yue Chen56e226e2017-05-02 16:21:40 -07001006 0, // BLOCK_2X2
1007 0, // BLOCK_2X4
1008 0, // BLOCK_4X2
Yue Chen56e226e2017-05-02 16:21:40 -07001009 0, // BLOCK_4X4
1010 0, // BLOCK_4X8
1011 0, // BLOCK_8X4
1012 0, // BLOCK_8X8
1013 1, // BLOCK_8X16
1014 1, // BLOCK_16X8
1015 0, // BLOCK_16X16
1016 0, // BLOCK_16X32
1017 0, // BLOCK_32X16
1018 0, // BLOCK_32X32
1019 0, // BLOCK_32X64
1020 0, // BLOCK_64X32
1021 0, // BLOCK_64X64
1022#if CONFIG_EXT_PARTITION
1023 0, // BLOCK_64X128
1024 0, // BLOCK_128X64
1025 0, // BLOCK_128X128
1026#endif // CONFIG_EXT_PARTITION
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001027 0, // BLOCK_4X16
1028 0, // BLOCK_16X4
1029 0, // BLOCK_8X32
1030 0, // BLOCK_32X8
Rupert Swarbrick72678572017-08-02 12:05:26 +01001031 0, // BLOCK_16X64
1032 0, // BLOCK_64X16
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +01001033#if CONFIG_EXT_PARTITION
1034 0, // BLOCK_32X128
1035 0, // BLOCK_128X32
1036#endif // CONFIG_EXT_PARTITION
Yue Chen56e226e2017-05-02 16:21:40 -07001037 };
1038
1039 return LUT_QTTX[bsize];
1040}
1041
1042static INLINE int is_quarter_tx_allowed(const MACROBLOCKD *xd,
1043 const MB_MODE_INFO *mbmi,
1044 int is_inter) {
1045 return is_quarter_tx_allowed_bsize(mbmi->sb_type) && is_inter &&
1046 !xd->lossless[mbmi->segment_id];
1047}
Yue Chend6bdd462017-07-19 16:05:43 -07001048#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001049
1050static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode,
1051 int is_inter) {
1052 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
Urvang Joshifeb925f2016-12-05 10:37:29 -08001053 const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize];
Urvang Joshifeb925f2016-12-05 10:37:29 -08001054 (void)is_inter;
Urvang Joshifeb925f2016-12-05 10:37:29 -08001055 if (bsize == BLOCK_4X4)
1056 return AOMMIN(max_txsize_lookup[bsize], largest_tx_size);
Urvang Joshifeb925f2016-12-05 10:37:29 -08001057 if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size)
1058 return max_rect_tx_size;
1059 else
1060 return largest_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001061}
1062
hui su5db97432016-10-14 16:10:14 -07001063#if CONFIG_EXT_INTRA
hui su5db97432016-10-14 16:10:14 -07001064extern const int16_t dr_intra_derivative[90];
hui su02c79742017-05-16 17:19:04 -07001065static const uint8_t mode_to_angle_map[] = {
Urvang Joshib7301cd2017-11-09 15:08:56 -08001066 0, 90, 180, 45, 135, 113, 157, 203, 67, 0, 0, 0, 0,
hui su5db97432016-10-14 16:10:14 -07001067};
Yaowu Xuc27fc142016-08-22 16:08:15 -07001068#endif // CONFIG_EXT_INTRA
1069
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001070#if CONFIG_DCT_ONLY
1071#define FIXED_TX_TYPE 1
1072#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001073#define FIXED_TX_TYPE 0
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001074#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001075
Angie Chiang752ccce2017-04-09 13:41:13 -07001076// Converts block_index for given transform size to index of the block in raster
1077// order.
1078static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size,
1079 int block_idx) {
1080 // For transform size 4x8, the possible block_idx values are 0 & 2, because
1081 // block_idx values are incremented in steps of size 'tx_width_unit x
1082 // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to
1083 // block number 1 in raster order, inside an 8x8 MI block.
1084 // For any other transform size, the two indices are equivalent.
1085 return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx;
1086}
1087
1088// Inverse of above function.
1089// Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now.
1090static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size,
1091 int raster_order) {
1092 assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4);
1093 // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4.
1094 return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0;
1095}
1096
Yaowu Xuc27fc142016-08-22 16:08:15 -07001097static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type,
1098 const MACROBLOCKD *xd, int block_idx,
1099 TX_SIZE tx_size) {
1100 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1101
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001102 if (CONFIG_DCT_ONLY || is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07001103 xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32)
1104 return DCT_DCT;
1105
1106 return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y
1107 ? get_y_mode(xd->mi[0], block_idx)
Luc Trudeaud6d9eee2017-07-12 12:36:50 -04001108 : get_uv_mode(mbmi->uv_mode)];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001109}
1110
Sarah Parker90024e42017-10-06 16:50:47 -07001111static INLINE BLOCK_SIZE
1112get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) {
1113 return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y];
1114}
1115
hui su45b64752017-07-12 16:54:35 -07001116static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type,
Jingning Han19b5c8f2017-07-06 15:10:12 -07001117 const MACROBLOCKD *xd, int blk_row,
1118 int blk_col, int block, TX_SIZE tx_size) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001119 const MODE_INFO *const mi = xd->mi[0];
1120 const MB_MODE_INFO *const mbmi = &mi->mbmi;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001121 (void)blk_row;
1122 (void)blk_col;
Sebastien Alaiwan3bac9922017-11-02 12:34:41 +01001123#if CONFIG_INTRABC && (CONFIG_TXK_SEL)
Alex Conversedaa15e42017-05-02 14:27:16 -07001124 // TODO(aconverse@google.com): Handle INTRABC + EXT_TX + TXK_SEL
Alex Converse28744302017-04-13 14:46:22 -07001125 if (is_intrabc_block(mbmi)) return DCT_DCT;
Sebastien Alaiwan3bac9922017-11-02 12:34:41 +01001126#endif // CONFIG_INTRABC && (CONFIG_TXK_SEL)
hui su45b64752017-07-12 16:54:35 -07001127
Sarah Parker90024e42017-10-06 16:50:47 -07001128 const struct macroblockd_plane *const pd = &xd->plane[plane_type];
1129 const BLOCK_SIZE plane_bsize = get_plane_block_size(mbmi->sb_type, pd);
1130 // TODO(sarahparker) This assumes reduced_tx_set_used == 0. I will do a
1131 // follow up refactor to make the actual value of reduced_tx_set_used
1132 // within this function.
1133 const TxSetType tx_set_type =
1134 get_ext_tx_set_type(tx_size, plane_bsize, is_inter_block(mbmi), 0);
1135 if (is_inter_block(mbmi) && !av1_ext_tx_used[tx_set_type][mbmi->tx_type])
1136 return DCT_DCT;
Sarah Parker90024e42017-10-06 16:50:47 -07001137
hui su45b64752017-07-12 16:54:35 -07001138#if CONFIG_TXK_SEL
1139 TX_TYPE tx_type;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001140 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] >= TX_32X32) {
hui su45b64752017-07-12 16:54:35 -07001141 tx_type = DCT_DCT;
1142 } else {
Jingning Han19b5c8f2017-07-06 15:10:12 -07001143 if (plane_type == PLANE_TYPE_Y)
1144 tx_type = mbmi->txk_type[(blk_row << 4) + blk_col];
1145 else if (is_inter_block(mbmi))
1146 tx_type = mbmi->txk_type[(blk_row << 5) + (blk_col << 1)];
1147 else
1148 tx_type = intra_mode_to_tx_type_context[mbmi->uv_mode];
hui su45b64752017-07-12 16:54:35 -07001149 }
1150 assert(tx_type >= DCT_DCT && tx_type < TX_TYPES);
Sarah Parker90024e42017-10-06 16:50:47 -07001151 if (is_inter_block(mbmi) && !av1_ext_tx_used[tx_set_type][tx_type])
1152 return DCT_DCT;
hui su45b64752017-07-12 16:54:35 -07001153 return tx_type;
1154#endif // CONFIG_TXK_SEL
1155
James Zern7cdaa602017-04-20 20:12:46 -07001156#if FIXED_TX_TYPE
Angie Chiangc2ebfbf2017-04-15 13:56:58 -07001157 const int block_raster_idx = av1_block_index_to_raster_order(tx_size, block);
James Zern7cdaa602017-04-20 20:12:46 -07001158 return get_default_tx_type(plane_type, xd, block_raster_idx, tx_size);
hui su45b64752017-07-12 16:54:35 -07001159#endif // FIXED_TX_TYPE
1160
Sarah Parker53f93db2017-07-11 17:20:04 -07001161#if CONFIG_MRC_TX
1162 if (mbmi->tx_type == MRC_DCT) {
Sarah Parker2e08d962017-08-01 19:51:20 -07001163 assert(((is_inter_block(mbmi) && USE_MRC_INTER) ||
1164 (!is_inter_block(mbmi) && USE_MRC_INTRA)) &&
1165 "INVALID BLOCK TYPE FOR MRC_DCT");
Sarah Parker53f93db2017-07-11 17:20:04 -07001166 if (plane_type == PLANE_TYPE_Y) {
1167 assert(tx_size == TX_32X32);
1168 return mbmi->tx_type;
1169 }
1170 return DCT_DCT;
1171 }
1172#endif // CONFIG_MRC_TX
Nathan E. Egge856d1792017-10-26 17:55:20 -04001173#if CONFIG_DAALA_TX32
1174 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32)
1175#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001176 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 ||
1177 (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi)))
Nathan E. Egge856d1792017-10-26 17:55:20 -04001178#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001179 return DCT_DCT;
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001180 if (plane_type == PLANE_TYPE_Y) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001181#if !ALLOW_INTRA_EXT_TX
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001182 if (is_inter_block(mbmi))
Yaowu Xuc27fc142016-08-22 16:08:15 -07001183#endif // ALLOW_INTRA_EXT_TX
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001184 return mbmi->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001185 }
1186
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001187 if (is_inter_block(mbmi)) {
1188 // UV Inter only
1189 return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32)
1190 ? DCT_DCT
1191 : mbmi->tx_type;
1192 }
1193
Sarah Parker90024e42017-10-06 16:50:47 -07001194 // UV Intra only
Thomas Daedeb7e72f32017-04-26 13:40:31 -07001195 (void)block;
Sarah Parker90024e42017-10-06 16:50:47 -07001196 TX_TYPE intra_type =
1197 intra_mode_to_tx_type_context[get_uv_mode(mbmi->uv_mode)];
1198 if (!av1_ext_tx_used[tx_set_type][intra_type]) return DCT_DCT;
1199 return intra_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001200}
1201
Yaowu Xuf883b422016-08-30 14:01:10 -07001202void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001203
Debargha Mukherjee6147b1b2017-11-08 08:31:09 -08001204static INLINE int tx_size_cat_to_max_depth(int tx_size_cat) {
1205 return AOMMIN(tx_size_cat + 1, MAX_TX_DEPTH);
Jingning Han4e1737a2016-10-25 16:05:02 -07001206}
1207
Debargha Mukherjee6147b1b2017-11-08 08:31:09 -08001208static INLINE int tx_size_to_depth(TX_SIZE tx_size, int tx_size_cat) {
1209 return (int)(tx_size_cat + 1 - (int)tx_size);
1210}
1211
1212static INLINE TX_SIZE depth_to_tx_size(int depth, int tx_size_cat) {
1213 assert(tx_size_cat + 1 - depth >= 0 && tx_size_cat + 1 - depth < TX_SIZES);
1214 return (TX_SIZE)(tx_size_cat + 1 - depth);
Jingning Han4e1737a2016-10-25 16:05:02 -07001215}
1216
hui su0c6244b2017-07-12 17:11:43 -07001217static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi,
1218 const struct macroblockd_plane *pd) {
hui su0c6244b2017-07-12 17:11:43 -07001219 const TX_SIZE uv_txsize =
1220 uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x]
1221 [pd->subsampling_y];
Debargha Mukherjee2f123402016-08-30 17:43:38 -07001222 assert(uv_txsize != TX_INVALID);
1223 return uv_txsize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001224}
1225
hui su0c6244b2017-07-12 17:11:43 -07001226static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) {
Angie Chiang80b82262017-02-24 11:39:47 -08001227 const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
hui su0c6244b2017-07-12 17:11:43 -07001228 if (plane == 0) return mbmi->tx_size;
Angie Chiang80b82262017-02-24 11:39:47 -08001229 const MACROBLOCKD_PLANE *pd = &xd->plane[plane];
hui su0c6244b2017-07-12 17:11:43 -07001230 return av1_get_uv_tx_size(mbmi, pd);
Angie Chiang80b82262017-02-24 11:39:47 -08001231}
1232
Timothy B. Terriberrya2d5cde2017-05-10 18:33:50 -07001233void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
1234 BLOCK_SIZE bsize);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001235
Rupert Swarbrick76405202017-11-07 16:35:55 +00001236#if CONFIG_LOOP_RESTORATION
1237void av1_reset_loop_restoration(MACROBLOCKD *xd);
1238#endif // CONFIG_LOOP_RESTORATION
1239
Yaowu Xuc27fc142016-08-22 16:08:15 -07001240typedef void (*foreach_transformed_block_visitor)(int plane, int block,
1241 int blk_row, int blk_col,
1242 BLOCK_SIZE plane_bsize,
1243 TX_SIZE tx_size, void *arg);
1244
Yaowu Xuf883b422016-08-30 14:01:10 -07001245void av1_foreach_transformed_block_in_plane(
Yaowu Xuc27fc142016-08-22 16:08:15 -07001246 const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
1247 foreach_transformed_block_visitor visit, void *arg);
1248
Angie Chiang0397eda2017-03-15 16:57:14 -07001249#if CONFIG_LV_MAP
1250void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
Jingning Han94652b82017-04-04 09:45:02 -07001251 BLOCK_SIZE bsize, int mi_row, int mi_col,
Angie Chiang0397eda2017-03-15 16:57:14 -07001252 foreach_transformed_block_visitor visit,
1253 void *arg);
1254#endif
1255
Yaowu Xuf883b422016-08-30 14:01:10 -07001256void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
Jingning Haneee43152016-12-05 09:58:45 -08001257 int plane, TX_SIZE tx_size, int has_eob, int aoff,
1258 int loff);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001259
Yaowu Xuc27fc142016-08-22 16:08:15 -07001260static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
Yue Chen9ddd4092017-10-30 16:13:39 -07001261 return (bsize >= BLOCK_8X8) && (bsize <= BLOCK_32X32);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001262}
1263
1264static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) {
1265 return (mode >= NEARESTMV) && (mode <= NEWMV);
1266}
1267
1268static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) {
1269 return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME);
1270}
1271
1272static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
1273 return is_interintra_allowed_bsize(mbmi->sb_type) &&
1274 is_interintra_allowed_mode(mbmi->mode) &&
1275 is_interintra_allowed_ref(mbmi->ref_frame);
1276}
1277
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001278static INLINE int is_interintra_allowed_bsize_group(int group) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001279 int i;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001280 for (i = 0; i < BLOCK_SIZES_ALL; i++) {
Urvang Joshicb586f32016-09-20 11:36:33 -07001281 if (size_group_lookup[i] == group &&
1282 is_interintra_allowed_bsize((BLOCK_SIZE)i)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001283 return 1;
Urvang Joshicb586f32016-09-20 11:36:33 -07001284 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001285 }
1286 return 0;
1287}
1288
1289static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) {
1290 return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi);
1291}
Yaowu Xuc27fc142016-08-22 16:08:15 -07001292
Sarah Parker106b3cb2017-04-21 12:13:37 -07001293static INLINE int get_vartx_max_txsize(const MB_MODE_INFO *const mbmi,
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001294 BLOCK_SIZE bsize, int subsampled) {
Sarah Parker106b3cb2017-04-21 12:13:37 -07001295 (void)mbmi;
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001296 TX_SIZE max_txsize = max_txsize_rect_lookup[bsize];
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001297
1298#if CONFIG_EXT_PARTITION && CONFIG_TX64X64
1299 // The decoder is designed so that it can process 64x64 luma pixels at a
1300 // time. If this is a chroma plane with subsampling and bsize corresponds to
1301 // a subsampled BLOCK_128X128 then the lookup above will give TX_64X64. That
1302 // mustn't be used for the subsampled plane (because it would be bigger than
1303 // a 64x64 luma block) so we round down to TX_32X32.
Debargha Mukherjee1fa24462017-10-19 14:33:39 -07001304 if (subsampled && txsize_sqr_up_map[max_txsize] == TX_64X64) {
1305 max_txsize = TX_32X32;
1306 }
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001307#else
1308 (void)subsampled;
1309#endif
1310
1311 return max_txsize;
Sarah Parker106b3cb2017-04-21 12:13:37 -07001312}
Sarah Parker106b3cb2017-04-21 12:13:37 -07001313
Yue Chencb60b182016-10-13 15:18:22 -07001314static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) {
Debargha Mukherjeec17a4432017-08-28 22:22:45 -07001315 return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Yue Chencb60b182016-10-13 15:18:22 -07001316}
1317
Yue Chen8636da62017-04-03 01:23:44 -07001318static INLINE int is_motion_variation_allowed_compound(
1319 const MB_MODE_INFO *mbmi) {
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +02001320#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu85b66462017-04-20 14:28:19 -07001321 if (!has_second_ref(mbmi) && !is_inter_singleref_comp_mode(mbmi->mode))
1322#else
Yue Chen8636da62017-04-03 01:23:44 -07001323 if (!has_second_ref(mbmi))
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +02001324#endif // CONFIG_COMPOUND_SINGLEREF
Yue Chen8636da62017-04-03 01:23:44 -07001325 return 1;
1326 else
1327 return 0;
1328}
1329
Yue Chen1bd42be2017-03-15 18:07:04 -07001330// input: log2 of length, 0(4), 1(8), ...
1331static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };
1332
Yue Chen5329a2b2017-02-28 17:33:00 +08001333static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) {
Yue Chen1bd42be2017-03-15 18:07:04 -07001334 return !(mbmi->overlappable_neighbors[0] == 0 &&
1335 mbmi->overlappable_neighbors[1] == 0);
Yue Chen5329a2b2017-02-28 17:33:00 +08001336}
Yue Chen5329a2b2017-02-28 17:33:00 +08001337
Sebastien Alaiwan48795802017-10-30 12:07:13 +01001338static INLINE MOTION_MODE
1339motion_mode_allowed(int block, const WarpedMotionParams *gm_params,
Sebastien Alaiwan1f56b8e2017-10-31 17:37:16 +01001340 const MACROBLOCKD *xd, const MODE_INFO *mi) {
Sarah Parker19234cc2017-03-10 16:43:25 -08001341 const MB_MODE_INFO *mbmi = &mi->mbmi;
RogerZhou3b635242017-09-19 10:06:46 -07001342#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -07001343 if (xd->cur_frame_force_integer_mv == 0) {
RogerZhou3b635242017-09-19 10:06:46 -07001344#endif
RogerZhou3b635242017-09-19 10:06:46 -07001345 const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype;
1346 if (is_global_mv_block(mi, block, gm_type)) return SIMPLE_TRANSLATION;
RogerZhou3b635242017-09-19 10:06:46 -07001347#if CONFIG_AMVR
1348 }
1349#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001350 if (is_motion_variation_allowed_bsize(mbmi->sb_type) &&
Yue Chen8636da62017-04-03 01:23:44 -07001351 is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME &&
1352 is_motion_variation_allowed_compound(mbmi)) {
Yue Chen5329a2b2017-02-28 17:33:00 +08001353 if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION;
Yue Chen52c51732017-07-11 15:08:30 -07001354 if (!has_second_ref(mbmi) && mbmi->num_proj_ref[0] >= 1 &&
Wei-Ting Lin20885282017-08-28 17:18:18 -07001355 !av1_is_scaled(&(xd->block_refs[0]->sf))) {
RogerZhou3b635242017-09-19 10:06:46 -07001356#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -07001357 if (xd->cur_frame_force_integer_mv) {
RogerZhou3b635242017-09-19 10:06:46 -07001358 return OBMC_CAUSAL;
1359 }
1360#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001361 return WARPED_CAUSAL;
Hui Su12231bd2017-09-07 18:01:15 -07001362 }
Yue Chen80daf0c2017-11-02 17:14:18 -07001363 return OBMC_CAUSAL;
Yue Chen69f18e12016-09-08 14:48:15 -07001364 } else {
1365 return SIMPLE_TRANSLATION;
1366 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001367}
1368
Sebastien Alaiwan48795802017-10-30 12:07:13 +01001369static INLINE void assert_motion_mode_valid(MOTION_MODE mode, int block,
Sarah Parker19234cc2017-03-10 16:43:25 -08001370 const WarpedMotionParams *gm_params,
Yue Chen52c51732017-07-11 15:08:30 -07001371 const MACROBLOCKD *xd,
Sarah Parker19234cc2017-03-10 16:43:25 -08001372 const MODE_INFO *mi) {
Sebastien Alaiwan48795802017-10-30 12:07:13 +01001373 const MOTION_MODE last_motion_mode_allowed =
Sebastien Alaiwan1f56b8e2017-10-31 17:37:16 +01001374 motion_mode_allowed(block, gm_params, xd, mi);
Wei-Ting Lin20885282017-08-28 17:18:18 -07001375
Sarah Parker19234cc2017-03-10 16:43:25 -08001376 // Check that the input mode is not illegal
1377 if (last_motion_mode_allowed < mode)
1378 assert(0 && "Illegal motion mode selected");
1379}
1380
Yaowu Xuc27fc142016-08-22 16:08:15 -07001381static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) {
1382 return (is_inter_block(mbmi));
1383}
Yaowu Xuc27fc142016-08-22 16:08:15 -07001384
Hui Sue87fb232017-10-05 15:00:15 -07001385static INLINE int av1_allow_palette(int allow_screen_content_tools,
1386 BLOCK_SIZE sb_type) {
1387 return allow_screen_content_tools && sb_type >= BLOCK_8X8 &&
Hui Su473cf892017-11-08 18:14:31 -08001388 sb_type <= BLOCK_64X64;
Hui Sue87fb232017-10-05 15:00:15 -07001389}
1390
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001391// Returns sub-sampled dimensions of the given block.
1392// The output values for 'rows_within_bounds' and 'cols_within_bounds' will
RogerZhou3b635242017-09-19 10:06:46 -07001393// differ from 'height' and 'width' when part of the block is outside the
1394// right
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001395// and/or bottom image boundary.
1396static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane,
1397 const MACROBLOCKD *xd, int *width,
1398 int *height,
1399 int *rows_within_bounds,
1400 int *cols_within_bounds) {
1401 const int block_height = block_size_high[bsize];
1402 const int block_width = block_size_wide[bsize];
1403 const int block_rows = (xd->mb_to_bottom_edge >= 0)
1404 ? block_height
1405 : (xd->mb_to_bottom_edge >> 3) + block_height;
1406 const int block_cols = (xd->mb_to_right_edge >= 0)
1407 ? block_width
1408 : (xd->mb_to_right_edge >> 3) + block_width;
1409 const struct macroblockd_plane *const pd = &xd->plane[plane];
1410 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0));
1411 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0));
1412 assert(block_width >= block_cols);
1413 assert(block_height >= block_rows);
1414 if (width) *width = block_width >> pd->subsampling_x;
1415 if (height) *height = block_height >> pd->subsampling_y;
1416 if (rows_within_bounds) *rows_within_bounds = block_rows >> pd->subsampling_y;
1417 if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x;
1418}
1419
Sarah Parkerefd8af22017-08-25 16:36:06 -07001420/* clang-format off */
1421typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS]
1422 [CDF_SIZE(PALETTE_COLORS)];
1423typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
1424 [PALETTE_COLORS];
1425/* clang-format on */
1426
1427typedef struct {
1428 int rows;
1429 int cols;
1430 int n_colors;
1431 int plane_width;
1432 int plane_height;
1433 uint8_t *color_map;
1434 MapCdf map_cdf;
1435 ColorCost color_cost;
1436} Av1ColorMapParam;
1437
Yue Chen19e7aa82016-11-30 14:05:39 -08001438static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) {
1439 const MODE_INFO *mi = xd->mi[0];
1440 const MB_MODE_INFO *const mbmi = &mi->mbmi;
1441 int ref;
Yue Chen19e7aa82016-11-30 14:05:39 -08001442
Sarah Parker2b9ec2e2017-10-30 17:34:08 -07001443 // First check if all modes are GLOBALMV
1444 if (mbmi->mode != GLOBALMV && mbmi->mode != GLOBAL_GLOBALMV) return 0;
Jingning Han3ca0e672017-04-14 19:48:05 -07001445
1446#if !GLOBAL_SUB8X8_USED
1447 if (mbmi->sb_type < BLOCK_8X8) return 0;
1448#endif
1449
Yue Chen19e7aa82016-11-30 14:05:39 -08001450 // Now check if all global motion is non translational
1451 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
1452 if (xd->global_motion[mbmi->ref_frame[ref]].wmtype <= TRANSLATION) return 0;
1453 }
1454 return 1;
1455}
Yue Chen19e7aa82016-11-30 14:05:39 -08001456
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001457static INLINE PLANE_TYPE get_plane_type(int plane) {
Luc Trudeau005feb62017-02-22 13:34:01 -05001458 return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
1459}
1460
Angie Chiang155bf9a2017-08-06 19:52:57 -07001461static INLINE void transpose_uint8(uint8_t *dst, int dst_stride,
1462 const uint8_t *src, int src_stride, int w,
1463 int h) {
1464 int r, c;
1465 for (r = 0; r < h; ++r)
1466 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1467}
1468
1469static INLINE void transpose_uint16(uint16_t *dst, int dst_stride,
1470 const uint16_t *src, int src_stride, int w,
1471 int h) {
1472 int r, c;
1473 for (r = 0; r < h; ++r)
1474 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1475}
1476
1477static INLINE void transpose_int16(int16_t *dst, int dst_stride,
1478 const int16_t *src, int src_stride, int w,
1479 int h) {
1480 int r, c;
1481 for (r = 0; r < h; ++r)
1482 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1483}
1484
1485static INLINE void transpose_int32(int32_t *dst, int dst_stride,
1486 const int32_t *src, int src_stride, int w,
1487 int h) {
1488 int r, c;
1489 for (r = 0; r < h; ++r)
1490 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1491}
1492
Yaowu Xuc27fc142016-08-22 16:08:15 -07001493#ifdef __cplusplus
1494} // extern "C"
1495#endif
1496
Yaowu Xuf883b422016-08-30 14:01:10 -07001497#endif // AV1_COMMON_BLOCKD_H_