blob: d011e1b2ca30bfe3780bf606e65f7b2995556dba [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
Debargha Mukherjee891a8772017-11-22 10:09:37 -080042// Disables vartx transform split for chroma
Debargha Mukherjee19619882017-11-22 13:13:14 -080043// There are two possible options:
44// 1: Always choose chroma tx_size to be the largest allowed for the PU
45// 2: If the luma tranform size is split at least one level, split the
46// chroma by one level, otherwise use the largest allowed transform size for
47// chroma.
Debargha Mukherjee891a8772017-11-22 10:09:37 -080048#define DISABLE_VARTX_FOR_CHROMA 1
49
Zoe Liu104d62e2017-12-07 12:44:45 -080050#if CONFIG_EXT_SKIP && CONFIG_JNT_COMP
51// NOTE: To explore whether weighted-compound prediction to be considered.
52#define SKIP_MODE_WITH_JNT_COMP 0
53#endif // CONFIG_EXT_SKIP && CONFIG_JNT_COMP
54
Sarah Parkerb9f757c2017-01-06 17:12:24 -080055// SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS
56typedef enum {
Yaowu Xuf35f5272017-05-10 08:00:02 -070057#if COMPOUND_SEGMENT_TYPE == 0
Sarah Parkerb9f757c2017-01-06 17:12:24 -080058 UNIFORM_45 = 0,
59 UNIFORM_45_INV,
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080060#elif COMPOUND_SEGMENT_TYPE == 1
Sarah Parker7bb84f32017-05-09 15:17:46 -070061 DIFFWTD_38 = 0,
62 DIFFWTD_38_INV,
Yaowu Xuf35f5272017-05-10 08:00:02 -070063#endif // COMPOUND_SEGMENT_TYPE
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080064 SEG_MASK_TYPES,
65} SEG_MASK_TYPE;
66
Yaowu Xuc27fc142016-08-22 16:08:15 -070067typedef enum {
68 KEY_FRAME = 0,
69 INTER_FRAME = 1,
Soo-Chul Han65c00ae2017-09-07 13:12:35 -040070#if CONFIG_OBU
71 INTRA_ONLY_FRAME = 2, // replaces intra-only
72 S_FRAME = 3,
73#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070074 FRAME_TYPES,
75} FRAME_TYPE;
76
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070077static INLINE int is_comp_ref_allowed(BLOCK_SIZE bsize) {
78 (void)bsize;
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070079 return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Debargha Mukherjee0f248c42017-09-07 12:40:18 -070080}
81
Yaowu Xuc27fc142016-08-22 16:08:15 -070082static INLINE int is_inter_mode(PREDICTION_MODE mode) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070083 return mode >= NEARESTMV && mode <= NEW_NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -070084}
85
David Barkerac37fa32016-12-02 12:30:21 +000086typedef struct {
87 uint8_t *plane[MAX_MB_PLANE];
88 int stride[MAX_MB_PLANE];
89} BUFFER_SET;
90
Yaowu Xuc27fc142016-08-22 16:08:15 -070091static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -070092 return mode >= NEARESTMV && mode <= NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -070093}
Zoe Liu85b66462017-04-20 14:28:19 -070094static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) {
95 return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV;
96}
Yaowu Xuc27fc142016-08-22 16:08:15 -070097
98static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -070099 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800100 MB_MODE_COUNT, // DC_PRED
101 MB_MODE_COUNT, // V_PRED
102 MB_MODE_COUNT, // H_PRED
103 MB_MODE_COUNT, // D45_PRED
104 MB_MODE_COUNT, // D135_PRED
105 MB_MODE_COUNT, // D117_PRED
106 MB_MODE_COUNT, // D153_PRED
107 MB_MODE_COUNT, // D207_PRED
108 MB_MODE_COUNT, // D63_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800109 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700110 MB_MODE_COUNT, // SMOOTH_V_PRED
111 MB_MODE_COUNT, // SMOOTH_H_PRED
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700112 MB_MODE_COUNT, // PAETH_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800113 MB_MODE_COUNT, // NEARESTMV
114 MB_MODE_COUNT, // NEARMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700115 MB_MODE_COUNT, // GLOBALMV
Urvang Joshi102245d2016-11-28 13:05:36 -0800116 MB_MODE_COUNT, // NEWMV
Sebastien Alaiwan34d55662017-11-15 09:36:03 +0100117 NEARESTMV, // NEAREST_NEARESTMV
118 NEARMV, // NEAR_NEARMV
119 NEARESTMV, // NEAREST_NEWMV
120 NEWMV, // NEW_NEARESTMV
121 NEARMV, // NEAR_NEWMV
122 NEWMV, // NEW_NEARMV
123 GLOBALMV, // GLOBAL_GLOBALMV
124 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700125 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700126 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700127 assert(is_inter_compound_mode(mode));
128 return lut[mode];
129}
130
131static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700132 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800133 MB_MODE_COUNT, // DC_PRED
134 MB_MODE_COUNT, // V_PRED
135 MB_MODE_COUNT, // H_PRED
136 MB_MODE_COUNT, // D45_PRED
137 MB_MODE_COUNT, // D135_PRED
138 MB_MODE_COUNT, // D117_PRED
139 MB_MODE_COUNT, // D153_PRED
140 MB_MODE_COUNT, // D207_PRED
141 MB_MODE_COUNT, // D63_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800142 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700143 MB_MODE_COUNT, // SMOOTH_V_PRED
144 MB_MODE_COUNT, // SMOOTH_H_PRED
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700145 MB_MODE_COUNT, // PAETH_PRED
Urvang Joshi102245d2016-11-28 13:05:36 -0800146 MB_MODE_COUNT, // NEARESTMV
147 MB_MODE_COUNT, // NEARMV
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700148 MB_MODE_COUNT, // GLOBALMV
Urvang Joshi102245d2016-11-28 13:05:36 -0800149 MB_MODE_COUNT, // NEWMV
Sebastien Alaiwan34d55662017-11-15 09:36:03 +0100150 NEARESTMV, // NEAREST_NEARESTMV
151 NEARMV, // NEAR_NEARMV
152 NEWMV, // NEAREST_NEWMV
153 NEARESTMV, // NEW_NEARESTMV
154 NEWMV, // NEAR_NEWMV
155 NEARMV, // NEW_NEARMV
156 GLOBALMV, // GLOBAL_GLOBALMV
157 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700158 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700159 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700160 assert(is_inter_compound_mode(mode));
161 return lut[mode];
162}
163
David Barker3dfba992017-04-03 16:10:09 +0100164static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700165 return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV ||
166 mode == NEW_NEARMV);
David Barker3dfba992017-04-03 16:10:09 +0100167}
168
Yaowu Xuc27fc142016-08-22 16:08:15 -0700169static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700170 return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV ||
171 mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700172}
Sarah Parker6fdc8532016-11-16 17:47:13 -0800173
Sarah Parker2e604882017-01-17 17:31:25 -0800174static INLINE int use_masked_motion_search(COMPOUND_TYPE type) {
175 return (type == COMPOUND_WEDGE);
176}
177
Sarah Parker6fdc8532016-11-16 17:47:13 -0800178static INLINE int is_masked_compound_type(COMPOUND_TYPE type) {
Sarah Parker569edda2016-12-14 14:57:38 -0800179 return (type == COMPOUND_WEDGE || type == COMPOUND_SEG);
Sarah Parker6fdc8532016-11-16 17:47:13 -0800180}
Zoe Liu85b66462017-04-20 14:28:19 -0700181
Yaowu Xuc27fc142016-08-22 16:08:15 -0700182/* For keyframes, intra block modes are predicted by the (already decoded)
183 modes for the Y blocks to the left and above us; for interframes, there
184 is a single probability table. */
185
Yaowu Xuc27fc142016-08-22 16:08:15 -0700186typedef int8_t MV_REFERENCE_FRAME;
187
188typedef struct {
189 // Number of base colors for Y (0) and UV (1)
190 uint8_t palette_size[2];
hui sufa4ff852017-05-15 12:20:50 -0700191 // Value of base colors for Y, U, and V
Yaowu Xuc27fc142016-08-22 16:08:15 -0700192 uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700193} PALETTE_MODE_INFO;
194
hui su5db97432016-10-14 16:10:14 -0700195#if CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196typedef struct {
Yue Chenb0571872017-12-18 18:12:59 -0800197 uint8_t use_filter_intra;
198 FILTER_INTRA_MODE filter_intra_mode;
hui su5db97432016-10-14 16:10:14 -0700199} FILTER_INTRA_MODE_INFO;
Yue Chen57b8ff62017-10-10 23:37:31 -0700200
201static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = {
Yue Chenda2eefc2017-11-16 15:25:28 -0800202 DC_PRED, V_PRED, H_PRED, D153_PRED, DC_PRED
Yue Chen57b8ff62017-10-10 23:37:31 -0700203};
hui su5db97432016-10-14 16:10:14 -0700204#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700205
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800206#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800207#define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE)
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800208#endif
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800209
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800210typedef struct RD_STATS {
211 int rate;
212 int64_t dist;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700213 // Please be careful of using rdcost, it's not guaranteed to be set all the
214 // time.
215 // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In
216 // these functions, make sure rdcost is always up-to-date according to
217 // rate/dist.
Angie Chiang2a2a7dd2017-04-25 16:08:47 -0700218 int64_t rdcost;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800219 int64_t sse;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700220 int skip; // sse should equal to dist when skip == 1
Jingning Han3bce7542017-07-25 10:53:57 -0700221 int64_t ref_rdcost;
222 int zero_rate;
Jingning Han1a7f0a82017-07-27 09:48:05 -0700223 uint8_t invalid_rate;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800224#if CONFIG_RD_DEBUG
225 int txb_coeff_cost[MAX_MB_PLANE];
226 int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE]
227 [TXB_COEFF_COST_MAP_SIZE];
Angie Chiang3963d632016-11-10 18:41:40 -0800228#endif // CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800229} RD_STATS;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800230
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000231// This struct is used to group function args that are commonly
232// sent together in functions related to interinter compound modes
Sarah Parker6fdc8532016-11-16 17:47:13 -0800233typedef struct {
Sarah Parker6fdc8532016-11-16 17:47:13 -0800234 int wedge_index;
235 int wedge_sign;
Sarah Parkerb9f757c2017-01-06 17:12:24 -0800236 SEG_MASK_TYPE mask_type;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000237 uint8_t *seg_mask;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000238 COMPOUND_TYPE interinter_compound_type;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800239} INTERINTER_COMPOUND_DATA;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800240
Yaowu Xuc27fc142016-08-22 16:08:15 -0700241// This structure now relates to 8x8 block regions.
Luc Trudeauf5334002017-04-25 12:21:26 -0400242typedef struct MB_MODE_INFO {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700243 // Common for both INTER and INTRA blocks
244 BLOCK_SIZE sb_type;
245 PREDICTION_MODE mode;
246 TX_SIZE tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700247 // TODO(jingning): This effectively assigned a separate entry for each
248 // 8x8 block. Apparently it takes much more space than needed.
249 TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE];
Jingning Hane67b38a2016-11-04 10:30:00 -0700250 TX_SIZE min_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700251 int8_t skip;
Zoe Liuf704a1c2017-10-02 16:55:59 -0700252#if CONFIG_EXT_SKIP
253 int8_t skip_mode;
254#endif // CONFIG_EXT_SKIP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700255 int8_t segment_id;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700256 int8_t seg_id_predicted; // valid only when temporal_update is enabled
257
258 // Only for INTRA blocks
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400259 UV_PREDICTION_MODE uv_mode;
Urvang Joshic6300aa2017-06-01 14:46:23 -0700260
Yaowu Xuc27fc142016-08-22 16:08:15 -0700261 PALETTE_MODE_INFO palette_mode_info;
Alex Converse28744302017-04-13 14:46:22 -0700262#if CONFIG_INTRABC
263 uint8_t use_intrabc;
264#endif // CONFIG_INTRABC
Yaowu Xuc27fc142016-08-22 16:08:15 -0700265
Rupert Swarbrick27e90292017-09-28 17:46:50 +0100266 // Only for INTER blocks
267 InterpFilters interp_filters;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700268 MV_REFERENCE_FRAME ref_frame[2];
269 TX_TYPE tx_type;
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700270#if CONFIG_TXK_SEL
Angie Chiang808d8592017-04-06 18:36:55 -0700271 TX_TYPE txk_type[MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)];
272#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700273
hui su5db97432016-10-14 16:10:14 -0700274#if CONFIG_FILTER_INTRA
275 FILTER_INTRA_MODE_INFO filter_intra_mode_info;
276#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700277#if CONFIG_EXT_INTRA
hui sueda3d762016-12-06 16:58:23 -0800278 // The actual prediction angle is the base angle + (angle_delta * step).
Yaowu Xuc27fc142016-08-22 16:08:15 -0700279 int8_t angle_delta[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700280#endif // CONFIG_EXT_INTRA
281
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000282 // interintra members
Yaowu Xuc27fc142016-08-22 16:08:15 -0700283 INTERINTRA_MODE interintra_mode;
284 // TODO(debargha): Consolidate these flags
285 int use_wedge_interintra;
286 int interintra_wedge_index;
287 int interintra_wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000288 // interinter members
289 COMPOUND_TYPE interinter_compound_type;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000290 int wedge_index;
291 int wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000292 SEG_MASK_TYPE mask_type;
Yue Chencb60b182016-10-13 15:18:22 -0700293 MOTION_MODE motion_mode;
Yunqing Wang3afbf3f2017-11-21 20:16:18 -0800294#if CONFIG_EXT_WARPED_MOTION
295 int wm_ctx;
296#endif // CONFIG_EXT_WARPED_MOTION
Yue Chen5329a2b2017-02-28 17:33:00 +0800297 int overlappable_neighbors[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700298 int_mv mv[2];
299 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700300 uint8_t ref_mv_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700301#if CONFIG_EXT_PARTITION_TYPES
302 PARTITION_TYPE partition;
303#endif
304#if CONFIG_NEW_QUANT
305 int dq_off_index;
306 int send_dq_bit;
307#endif // CONFIG_NEW_QUANT
308 /* deringing gain *per-superblock* */
Jean-Marc Valin5f5c1322017-03-21 16:20:21 -0400309 int8_t cdef_strength;
Arild Fuldseth07441162016-08-15 15:07:52 +0200310 int current_q_index;
Fangwen Fu231fe422017-04-24 17:52:29 -0700311#if CONFIG_EXT_DELTA_Q
312 int current_delta_lf_from_base;
Cheng Chena97394f2017-09-27 15:05:14 -0700313#if CONFIG_LOOPFILTER_LEVEL
314 int curr_delta_lf[FRAME_LF_COUNT];
315#endif // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu231fe422017-04-24 17:52:29 -0700316#endif
Angie Chiangd4022822016-11-02 18:30:25 -0700317#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800318 RD_STATS rd_stats;
Angie Chiangd4022822016-11-02 18:30:25 -0700319 int mi_row;
320 int mi_col;
321#endif
Yue Chen69f18e12016-09-08 14:48:15 -0700322 int num_proj_ref[2];
323 WarpedMotionParams wm_params[2];
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800324
Luc Trudeauf5334002017-04-25 12:21:26 -0400325#if CONFIG_CFL
326 // Index of the alpha Cb and alpha Cr combination
Luc Trudeaua9bd85f2017-05-11 14:37:56 -0400327 int cfl_alpha_idx;
David Michael Barrf6eaa152017-07-19 19:42:28 +0900328 // Joint sign of alpha Cb and alpha Cr
329 int cfl_alpha_signs;
Luc Trudeauf5334002017-04-25 12:21:26 -0400330#endif
331
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800332 BOUNDARY_TYPE boundary_info;
Cheng Chenf572cd32017-08-25 18:34:51 -0700333#if CONFIG_LPF_SB
Cheng Chen765e34e2017-12-11 11:43:35 -0800334#if CONFIG_LOOPFILTER_LEVEL
335 // 0: y plane vert, 1: y plane horz, 2: u plane, 3: v plane
336 uint8_t filt_lvl[4];
337 int reuse_sb_lvl[4];
338 int sign[4];
339 int delta[4];
340#else
Cheng Chenf572cd32017-08-25 18:34:51 -0700341 uint8_t filt_lvl;
Cheng Chen41d37c22017-09-08 19:00:21 -0700342 int reuse_sb_lvl;
343 int sign;
344 int delta;
Cheng Chen765e34e2017-12-11 11:43:35 -0800345#endif // CONFIG_LOOPFILTER_LEVEL
346#endif // CONFIG_LPF_SB
Cheng Chenca6958c2017-10-10 14:00:50 -0700347
348#if CONFIG_JNT_COMP
349 int compound_idx;
Cheng Chen33a13d92017-11-28 16:49:59 -0800350 int comp_group_idx;
Cheng Chenca6958c2017-10-10 14:00:50 -0700351#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700352} MB_MODE_INFO;
353
Jingning Han2fac8a42017-12-14 16:26:00 -0800354typedef struct MODE_INFO { MB_MODE_INFO mbmi; } MODE_INFO;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700355
Alex Converse28744302017-04-13 14:46:22 -0700356#if CONFIG_INTRABC
Hui Su27df8342017-11-07 15:16:05 -0800357#define NO_FILTER_FOR_IBC 1 // Disable in-loop filters for frame with intrabc
358
Alex Converse28744302017-04-13 14:46:22 -0700359static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) {
360 return mbmi->use_intrabc;
361}
362#endif
363
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400364#if CONFIG_CFL
365static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) {
Luc Trudeau5d5078e2017-12-13 16:43:16 -0500366 assert(mode < UV_INTRA_MODES);
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400367 static const PREDICTION_MODE uv2y[UV_INTRA_MODES] = {
Urvang Joshib7301cd2017-11-09 15:08:56 -0800368 DC_PRED, // UV_DC_PRED
369 V_PRED, // UV_V_PRED
370 H_PRED, // UV_H_PRED
371 D45_PRED, // UV_D45_PRED
372 D135_PRED, // UV_D135_PRED
373 D117_PRED, // UV_D117_PRED
374 D153_PRED, // UV_D153_PRED
375 D207_PRED, // UV_D207_PRED
376 D63_PRED, // UV_D63_PRED
377 SMOOTH_PRED, // UV_SMOOTH_PRED
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400378 SMOOTH_V_PRED, // UV_SMOOTH_V_PRED
379 SMOOTH_H_PRED, // UV_SMOOTH_H_PRED
Urvang Joshi96d1c0a2017-10-10 13:15:32 -0700380 PAETH_PRED, // UV_PAETH_PRED
Luc Trudeau6e1cd782017-06-21 13:52:36 -0400381 DC_PRED, // CFL_PRED
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400382 };
383 return uv2y[mode];
384}
385#else
386static INLINE PREDICTION_MODE get_uv_mode(PREDICTION_MODE mode) { return mode; }
387#endif // CONFIG_CFL
388
Yaowu Xuc27fc142016-08-22 16:08:15 -0700389static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
Alex Converse28744302017-04-13 14:46:22 -0700390#if CONFIG_INTRABC
391 if (is_intrabc_block(mbmi)) return 1;
392#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700393 return mbmi->ref_frame[0] > INTRA_FRAME;
394}
395
396static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
397 return mbmi->ref_frame[1] > INTRA_FRAME;
398}
399
Zoe Liuc082bbc2017-05-17 13:31:37 -0700400#if CONFIG_EXT_COMP_REFS
401static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) {
402 return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^
403 (mbmi->ref_frame[1] >= BWDREF_FRAME)));
404}
405
406static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) {
407 static const MV_REFERENCE_FRAME lut[] = {
408 LAST_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700409 LAST_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700410 LAST_FRAME, // LAST_GOLDEN_FRAMES,
411 BWDREF_FRAME, // BWDREF_ALTREF_FRAMES,
412 };
413 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
414 return lut[ref_idx];
415}
416
417static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) {
418 static const MV_REFERENCE_FRAME lut[] = {
419 LAST2_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700420 LAST3_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700421 GOLDEN_FRAME, // LAST_GOLDEN_FRAMES,
422 ALTREF_FRAME, // BWDREF_ALTREF_FRAMES,
423 };
424 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
425 return lut[ref_idx];
426}
427#endif // CONFIG_EXT_COMP_REFS
428
Jingning Han9010e202017-12-14 14:48:09 -0800429PREDICTION_MODE av1_left_block_mode(const MODE_INFO *left_mi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700430
Jingning Han9010e202017-12-14 14:48:09 -0800431PREDICTION_MODE av1_above_block_mode(const MODE_INFO *above_mi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700432
Luc Trudeau2eb9b842017-12-13 11:19:16 -0500433static INLINE int is_global_mv_block(const MODE_INFO *mi,
Sarah Parker19234cc2017-03-10 16:43:25 -0800434 TransformationType type) {
Luc Trudeau2eb9b842017-12-13 11:19:16 -0500435 const MB_MODE_INFO *const mbmi = &mi->mbmi;
436 const PREDICTION_MODE mode = mbmi->mode;
Sarah Parker19234cc2017-03-10 16:43:25 -0800437#if GLOBAL_SUB8X8_USED
438 const int block_size_allowed = 1;
439#else
Luc Trudeau2eb9b842017-12-13 11:19:16 -0500440 const BLOCK_SIZE bsize = mbmi->sb_type;
Debargha Mukherjeec17a4432017-08-28 22:22:45 -0700441 const int block_size_allowed =
442 AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Sarah Parker19234cc2017-03-10 16:43:25 -0800443#endif // GLOBAL_SUB8X8_USED
Sarah Parker2b9ec2e2017-10-30 17:34:08 -0700444 return (mode == GLOBALMV || mode == GLOBAL_GLOBALMV) && type > TRANSLATION &&
Sarah Parker19234cc2017-03-10 16:43:25 -0800445 block_size_allowed;
Sarah Parker19234cc2017-03-10 16:43:25 -0800446}
Sarah Parker19234cc2017-03-10 16:43:25 -0800447
Angie Chiang5b5f4df2017-12-06 10:41:12 -0800448#if CONFIG_MISMATCH_DEBUG
449static INLINE void mi_to_pixel_loc(int *pixel_c, int *pixel_r, int mi_col,
450 int mi_row, int tx_blk_col, int tx_blk_row,
451 int subsampling_x, int subsampling_y) {
452 *pixel_c = ((mi_col >> subsampling_x) << MI_SIZE_LOG2) +
453 (tx_blk_col << tx_size_wide_log2[0]);
454 *pixel_r = ((mi_row >> subsampling_y) << MI_SIZE_LOG2) +
455 (tx_blk_row << tx_size_high_log2[0]);
456}
457#endif
458
Yaowu Xuc27fc142016-08-22 16:08:15 -0700459enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 };
460
461struct buf_2d {
462 uint8_t *buf;
463 uint8_t *buf0;
464 int width;
465 int height;
466 int stride;
467};
468
469typedef struct macroblockd_plane {
470 tran_low_t *dqcoeff;
471 PLANE_TYPE plane_type;
472 int subsampling_x;
473 int subsampling_y;
474 struct buf_2d dst;
475 struct buf_2d pre[2];
476 ENTROPY_CONTEXT *above_context;
477 ENTROPY_CONTEXT *left_context;
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400478
479 // The dequantizers below are true dequntizers used only in the
480 // dequantization process. They have the same coefficient
481 // shift/scale as TX.
482 int16_t seg_dequant_QTX[MAX_SEGMENTS][2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700483#if CONFIG_NEW_QUANT
Sarah Parker6b56e992017-12-07 11:51:04 -0800484 dequant_val_type_nuq seg_dequant_nuq_QTX[MAX_SEGMENTS][QUANT_PROFILES][2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700485#endif
486 uint8_t *color_index_map;
487
Jingning Hanc47fe6c2016-10-21 16:40:47 -0700488 // block size in pixels
489 uint8_t width, height;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700490
491#if CONFIG_AOM_QM
Thomas Daviesdd3cf832017-10-20 15:49:57 +0100492 qm_val_t *seg_iqmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
493 qm_val_t *seg_qmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700494#endif
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400495
496 // the 'dequantizers' below are not literal dequantizer values.
497 // They're used by encoder RDO to generate ad-hoc lambda values.
498 // They use a hardwired Q3 coeff shift and do not necessarily match
499 // the TX scale in use.
500 const int16_t *dequant_Q3;
Yushin Cho77bba8d2016-11-04 16:36:56 -0700501
Yushin Chod0b77ac2017-10-20 17:33:16 -0700502#if CONFIG_DIST_8X8
Yushin Cho77bba8d2016-11-04 16:36:56 -0700503 DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]);
Yushin Chob7b60c52017-07-14 16:18:52 -0700504#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700505} MACROBLOCKD_PLANE;
506
Jingning Han3468df12016-12-05 17:53:16 -0800507#define BLOCK_OFFSET(x, i) \
508 ((x) + (i) * (1 << (tx_size_wide_log2[0] + tx_size_high_log2[0])))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700509
510typedef struct RefBuffer {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700511 int idx;
512 YV12_BUFFER_CONFIG *buf;
513 struct scale_factors sf;
514} RefBuffer;
515
Rupert Swarbrick6c545212017-09-01 17:17:25 +0100516#if CONFIG_LOOP_RESTORATION
517typedef struct {
518 DECLARE_ALIGNED(16, InterpKernel, vfilter);
519 DECLARE_ALIGNED(16, InterpKernel, hfilter);
520} WienerInfo;
521
522typedef struct {
523 int ep;
524 int xqd[2];
525} SgrprojInfo;
526#endif // CONFIG_LOOP_RESTORATION
527
David Michael Barr5b2021e2017-08-17 18:12:39 +0900528#if CONFIG_CFL
Hui Su9fa96232017-10-23 15:46:04 -0700529#if CONFIG_DEBUG
Luc Trudeau03b7e7d2017-09-19 13:20:52 -0400530#define CFL_SUB8X8_VAL_MI_SIZE (4)
531#define CFL_SUB8X8_VAL_MI_SQUARE \
532 (CFL_SUB8X8_VAL_MI_SIZE * CFL_SUB8X8_VAL_MI_SIZE)
Hui Su9fa96232017-10-23 15:46:04 -0700533#endif // CONFIG_DEBUG
Luc Trudeaue425f472017-12-08 14:48:46 -0500534#define CFL_MAX_BLOCK_SIZE (BLOCK_32X32)
Luc Trudeau467205a2017-12-12 23:23:47 -0500535#define CFL_BUF_LINE (32)
536#define CFL_BUF_SQUARE (CFL_BUF_LINE * CFL_BUF_LINE)
David Michael Barr5b2021e2017-08-17 18:12:39 +0900537typedef struct cfl_ctx {
Luc Trudeau4e26d662017-09-11 13:08:40 -0400538 // The CfL prediction buffer is used in two steps:
539 // 1. Stores Q3 reconstructed luma pixels
540 // (only Q2 is required, but Q3 is used to avoid shifts)
541 // 2. Stores Q3 AC contributions (step1 - tx block avg)
Luc Trudeau467205a2017-12-12 23:23:47 -0500542 int16_t pred_buf_q3[CFL_BUF_SQUARE];
543
544 // Cache the DC_PRED when performing RDO, so it does not have to be recomputed
545 // for every scaling parameter
546 int dc_pred_is_cached[CFL_PRED_PLANES];
547 // The DC_PRED cache is disable when decoding
548 int use_dc_pred_cache;
549 // Only cache the first row of the DC_PRED
550 int16_t dc_pred_cache[CFL_PRED_PLANES][CFL_BUF_LINE];
David Michael Barr5b2021e2017-08-17 18:12:39 +0900551
Luc Trudeau4e26d662017-09-11 13:08:40 -0400552 // Height and width currently used in the CfL prediction buffer.
553 int buf_height, buf_width;
David Michael Barr5b2021e2017-08-17 18:12:39 +0900554
David Michael Barr5b2021e2017-08-17 18:12:39 +0900555 int are_parameters_computed;
556
557 // Chroma subsampling
558 int subsampling_x, subsampling_y;
559
David Michael Barr5b2021e2017-08-17 18:12:39 +0900560 int mi_row, mi_col;
561
562 // Whether the reconstructed luma pixels need to be stored
563 int store_y;
564
David Michael Barr1f8d0952017-10-11 17:46:39 +0900565#if CONFIG_DEBUG
566 int rate;
567#endif // CONFIG_DEBUG
568
David Michael Barr5b2021e2017-08-17 18:12:39 +0900569 int is_chroma_reference;
Hui Su9fa96232017-10-23 15:46:04 -0700570#if CONFIG_DEBUG
Luc Trudeauc7af36d2017-10-11 21:01:00 -0400571 // Validation buffer is usually 2x2, except for 16x4 and 4x16 in that case it
572 // is 4x2 and 2x4 respectively. To simplify accessing the buffer we use a
573 // stride of CFL_SUB8X8_VAL_MI_SIZE resulting in a square of 16.
574 uint16_t sub8x8_val[CFL_SUB8X8_VAL_MI_SQUARE];
575 uint16_t store_counter;
576 uint16_t last_compute_counter;
Hui Su9fa96232017-10-23 15:46:04 -0700577#endif // CONFIG_DEBUG
David Michael Barr5b2021e2017-08-17 18:12:39 +0900578} CFL_CTX;
579#endif // CONFIG_CFL
580
Cheng Chenf78632e2017-10-20 15:30:51 -0700581#if CONFIG_JNT_COMP
582typedef struct jnt_comp_params {
Cheng Chen8263f802017-11-14 15:50:00 -0800583 int use_jnt_comp_avg;
Cheng Chenf78632e2017-10-20 15:30:51 -0700584 int fwd_offset;
585 int bck_offset;
586} JNT_COMP_PARAMS;
587#endif // CONFIG_JNT_COMP
588
Yaowu Xuc27fc142016-08-22 16:08:15 -0700589typedef struct macroblockd {
590 struct macroblockd_plane plane[MAX_MB_PLANE];
591 uint8_t bmode_blocks_wl;
592 uint8_t bmode_blocks_hl;
593
594 FRAME_COUNTS *counts;
595 TileInfo tile;
596
597 int mi_stride;
598
599 MODE_INFO **mi;
600 MODE_INFO *left_mi;
601 MODE_INFO *above_mi;
602 MB_MODE_INFO *left_mbmi;
603 MB_MODE_INFO *above_mbmi;
604
605 int up_available;
606 int left_available;
Jingning Han3da18d62017-05-02 12:43:58 -0700607 int chroma_up_available;
608 int chroma_left_available;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700609
Rupert Swarbrick57486c52017-08-14 10:53:49 +0100610 /* Distance of MB away from frame edges in subpixels (1/8th pixel) */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700611 int mb_to_left_edge;
612 int mb_to_right_edge;
613 int mb_to_top_edge;
614 int mb_to_bottom_edge;
615
616 FRAME_CONTEXT *fc;
617
618 /* pointers to reference frames */
Urvang Joshi52648442016-10-13 17:27:51 -0700619 const RefBuffer *block_refs[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700620
621 /* pointer to current frame */
622 const YV12_BUFFER_CONFIG *cur_buf;
623
Alex Conversee816b312017-05-01 09:51:24 -0700624#if CONFIG_INTRABC
625 /* Scale of the current frame with respect to itself */
626 struct scale_factors sf_identity;
627#endif
628
Yaowu Xuc27fc142016-08-22 16:08:15 -0700629 ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
630 ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE];
631
632 PARTITION_CONTEXT *above_seg_context;
633 PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE];
634
Yaowu Xuc27fc142016-08-22 16:08:15 -0700635 TXFM_CONTEXT *above_txfm_context;
636 TXFM_CONTEXT *left_txfm_context;
Jingning Han331662e2017-05-30 17:03:32 -0700637 TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700638
Rupert Swarbrick6c545212017-09-01 17:17:25 +0100639#if CONFIG_LOOP_RESTORATION
640 WienerInfo wiener_info[MAX_MB_PLANE];
641 SgrprojInfo sgrproj_info[MAX_MB_PLANE];
642#endif // CONFIG_LOOP_RESTORATION
643
Jingning Hanff6ee6a2016-12-07 09:55:21 -0800644 // block dimension in the unit of mode_info.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700645 uint8_t n8_w, n8_h;
646
Yaowu Xuc27fc142016-08-22 16:08:15 -0700647 uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
648 CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
649 uint8_t is_sec_rect;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700650
Thomas Daviesf77d4ad2017-01-10 18:55:42 +0000651 FRAME_CONTEXT *tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700652 /* Bit depth: 8, 10, 12 */
653 int bd;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700654
Debargha Mukherjee3c42c092016-09-29 09:17:36 -0700655 int qindex[MAX_SEGMENTS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700656 int lossless[MAX_SEGMENTS];
657 int corrupted;
RogerZhou3b635242017-09-19 10:06:46 -0700658#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -0700659 int cur_frame_force_integer_mv;
RogerZhou3b635242017-09-19 10:06:46 -0700660// same with that in AV1_COMMON
661#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700662 struct aom_internal_error_info *error_info;
Luc Trudeauf3bf8b12017-12-08 14:38:41 -0500663 const WarpedMotionParams *global_motion;
Arild Fuldseth07441162016-08-15 15:07:52 +0200664 int prev_qindex;
665 int delta_qindex;
666 int current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -0700667#if CONFIG_EXT_DELTA_Q
668 // Since actual frame level loop filtering level value is not available
669 // at the beginning of the tile (only available during actual filtering)
670 // at encoder side.we record the delta_lf (against the frame level loop
671 // filtering level) and code the delta between previous superblock's delta
672 // lf and current delta lf. It is equivalent to the delta between previous
673 // superblock's actual lf and current lf.
674 int prev_delta_lf_from_base;
675 int current_delta_lf_from_base;
Cheng Chena97394f2017-09-27 15:05:14 -0700676#if CONFIG_LOOPFILTER_LEVEL
677 // For this experiment, we have four frame filter levels for different plane
678 // and direction. So, to support the per superblock update, we need to add
679 // a few more params as below.
680 // 0: delta loop filter level for y plane vertical
681 // 1: delta loop filter level for y plane horizontal
682 // 2: delta loop filter level for u plane
683 // 3: delta loop filter level for v plane
684 // To make it consistent with the reference to each filter level in segment,
685 // we need to -1, since
686 // SEG_LVL_ALT_LF_Y_V = 1;
687 // SEG_LVL_ALT_LF_Y_H = 2;
688 // SEG_LVL_ALT_LF_U = 3;
689 // SEG_LVL_ALT_LF_V = 4;
690 int prev_delta_lf[FRAME_LF_COUNT];
691 int curr_delta_lf[FRAME_LF_COUNT];
692#endif // CONFIG_LOOPFILTER_LEVEL
Fangwen Fu231fe422017-04-24 17:52:29 -0700693#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400694
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000695 DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]);
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000696
Luc Trudeauf8164152017-04-11 16:20:51 -0400697#if CONFIG_CFL
Luc Trudeau1e84af52017-11-25 15:00:28 -0500698 CFL_CTX cfl;
Luc Trudeauf8164152017-04-11 16:20:51 -0400699#endif
Cheng Chenf78632e2017-10-20 15:30:51 -0700700
701#if CONFIG_JNT_COMP
702 JNT_COMP_PARAMS jcp_param;
703#endif
Zoe Liu104d62e2017-12-07 12:44:45 -0800704
705#if CONFIG_EXT_SKIP
706 int all_one_sided_refs;
707#endif // CONFIG_EXT_SKIP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700708} MACROBLOCKD;
709
Yi Luo51281092017-06-26 16:36:15 -0700710static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) {
711 return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0;
712}
713
Yaowu Xuc27fc142016-08-22 16:08:15 -0700714static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize,
715 PARTITION_TYPE partition) {
716 if (partition == PARTITION_INVALID)
Urvang Joshicb586f32016-09-20 11:36:33 -0700717 return BLOCK_INVALID;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700718 else
719 return subsize_lookup[partition][bsize];
720}
721
Luc Trudeau9cea9932017-12-13 21:14:13 -0500722static TX_TYPE intra_mode_to_tx_type_context(const MB_MODE_INFO *mbmi,
723 PLANE_TYPE plane_type) {
724 static const TX_TYPE _intra_mode_to_tx_type_context[INTRA_MODES] = {
725 DCT_DCT, // DC
726 ADST_DCT, // V
727 DCT_ADST, // H
728 DCT_DCT, // D45
729 ADST_ADST, // D135
730 ADST_DCT, // D117
731 DCT_ADST, // D153
732 DCT_ADST, // D207
733 ADST_DCT, // D63
734 ADST_ADST, // SMOOTH
735 ADST_DCT, // SMOOTH_V
736 DCT_ADST, // SMOOTH_H
737 ADST_ADST, // PAETH
738 };
739 return plane_type == PLANE_TYPE_Y
740 ? _intra_mode_to_tx_type_context[mbmi->mode]
741 : _intra_mode_to_tx_type_context[get_uv_mode(mbmi->uv_mode)];
742}
Yaowu Xuc27fc142016-08-22 16:08:15 -0700743
Jingning Hanb83e64b2017-03-01 14:52:04 -0800744#define USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 1
Debargha Mukherjee5a488a62016-11-22 22:24:10 -0800745
Sarah Parker076437f2017-03-14 17:39:53 -0700746static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; }
Sarah Parker076437f2017-03-14 17:39:53 -0700747
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100748static INLINE int block_signals_txsize(BLOCK_SIZE bsize) {
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100749 return bsize > BLOCK_4X4;
Rupert Swarbrickfcff0b22017-10-05 09:26:04 +0100750}
751
Yaowu Xuc27fc142016-08-22 16:08:15 -0700752#define ALLOW_INTRA_EXT_TX 1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700753
Hui Suddbcde22017-09-18 17:22:02 -0700754// Number of transform types in each set type
755static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = {
Sarah Parkercec7ba12017-11-03 16:46:09 -0700756 1, 2, 5, 7, 7, 10, 12, 16, 16,
Hui Suddbcde22017-09-18 17:22:02 -0700757};
758
Hui Su4a9be2a2017-09-19 14:41:49 -0700759static const int av1_ext_tx_set_idx_to_type[2][AOMMAX(EXT_TX_SETS_INTRA,
760 EXT_TX_SETS_INTER)] = {
761 {
762 // Intra
Sarah Parkercec7ba12017-11-03 16:46:09 -0700763 EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT,
764#if EXT_TX_16X16_SET == 0
765 EXT_TX_SET_DTT4_IDTX_1DDCT_16X16,
766#else
767 EXT_TX_SET_DTT4_IDTX,
768#endif // EXT_TX_16X16_SET
Hui Su4a9be2a2017-09-19 14:41:49 -0700769 },
770 {
771 // Inter
Sarah Parker9d8222b2017-11-19 19:08:55 -0800772 EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16,
Sarah Parkercec7ba12017-11-03 16:46:09 -0700773#if EXT_TX_16X16_SET == 0
774 EXT_TX_SET_ALL16_16X16,
775#elif EXT_TX_16X16_SET == 1
Sarah Parker9d8222b2017-11-19 19:08:55 -0800776 EXT_TX_SET_DTT9_IDTX_1DDCT,
777#else
778 EXT_TX_SET_DTT9_IDTX,
Sarah Parkercec7ba12017-11-03 16:46:09 -0700779#endif // EXT_TX_16X16_SET
Hui Su4a9be2a2017-09-19 14:41:49 -0700780 EXT_TX_SET_DCT_IDTX,
Sarah Parkercec7ba12017-11-03 16:46:09 -0700781 },
Hui Suddbcde22017-09-18 17:22:02 -0700782};
783
Hui Suddbcde22017-09-18 17:22:02 -0700784static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = {
785 {
786 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
787 },
788 {
789 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
790 },
791 {
792 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
793 },
794 {
795 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
796 },
797 {
Sarah Parkercec7ba12017-11-03 16:46:09 -0700798 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
799 },
800 {
Sarah Parker9d8222b2017-11-19 19:08:55 -0800801 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
802 },
803 {
Hui Suddbcde22017-09-18 17:22:02 -0700804 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
805 },
806 {
807 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
808 },
Sarah Parkercec7ba12017-11-03 16:46:09 -0700809 {
810 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
811 },
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800812};
813
814static INLINE TxSetType get_ext_tx_set_type(TX_SIZE tx_size, BLOCK_SIZE bs,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800815 int is_inter, int use_reduced_set) {
Yue Chen56e226e2017-05-02 16:21:40 -0700816 const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
817 const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size];
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -0700818#if USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Jingning Han1a00cff2016-12-28 14:53:14 -0800819 (void)bs;
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700820 if (tx_size_sqr_up > TX_32X32) return EXT_TX_SET_DCTONLY;
Jingning Han1a00cff2016-12-28 14:53:14 -0800821#else
Debargha Mukherjee570423c2017-10-01 00:35:20 -0700822 if (tx_size_sqr_up > TX_32X32 || bs < BLOCK_8X8) return EXT_TX_SET_DCTONLY;
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -0700823#endif // USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Sarah Parker5effe3f2017-02-23 12:49:10 -0800824 if (use_reduced_set)
825 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX;
Nathan E. Eggef621a4f2017-12-08 09:02:09 -0500826#if CONFIG_DAALA_TX_DST32
Nathan E. Eggef73e47e2017-10-22 06:41:55 -0400827 if (tx_size_sqr_up > TX_32X32)
828 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
829 if (is_inter)
830 return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT
831 : EXT_TX_SET_ALL16);
832 else
833 return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT4_IDTX
834 : EXT_TX_SET_DTT4_IDTX_1DDCT);
835#endif
Yue Chen56e226e2017-05-02 16:21:40 -0700836 if (tx_size_sqr_up == TX_32X32)
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800837 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
838 if (is_inter)
Sarah Parkercec7ba12017-11-03 16:46:09 -0700839 return (tx_size_sqr == TX_16X16 ?
840#if EXT_TX_16X16_SET == 0
841 EXT_TX_SET_ALL16_16X16
842#elif EXT_TX_16X16_SET == 1
843 EXT_TX_SET_DTT9_IDTX_1DDCT
Sarah Parker9d8222b2017-11-19 19:08:55 -0800844#else
Sarah Parkercec7ba12017-11-03 16:46:09 -0700845 EXT_TX_SET_DTT9_IDTX
846#endif // EXT_TX_16X16_SET
847 : EXT_TX_SET_ALL16);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800848 else
Sarah Parkercec7ba12017-11-03 16:46:09 -0700849 return (tx_size_sqr == TX_16X16 ?
850#if EXT_TX_16X16_SET == 0
851 EXT_TX_SET_DTT4_IDTX_1DDCT_16X16
852#else
853 EXT_TX_SET_DTT4_IDTX
854#endif // EXT_TX_16X16_SET
Yue Chen56e226e2017-05-02 16:21:40 -0700855 : EXT_TX_SET_DTT4_IDTX_1DDCT);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800856}
857
Hui Su4a9be2a2017-09-19 14:41:49 -0700858// Maps tx set types to the indices.
859static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = {
860 {
861 // Intra
Sarah Parkercec7ba12017-11-03 16:46:09 -0700862 0, -1,
863#if EXT_TX_16X16_SET == 0
Sarah Parker9d8222b2017-11-19 19:08:55 -0800864 -1, 2,
865#else
866 2, -1,
Sarah Parkercec7ba12017-11-03 16:46:09 -0700867#endif // EXT_TX_16X16_SET
868 1, -1, -1, -1, -1,
869 },
870 {
871 // Inter
872 0, 3, -1, -1, -1,
873#if EXT_TX_16X16_SET == 0
874 -1, -1, 2,
875#elif EXT_TX_16X16_SET == 1
876 -1, 2, -1,
877#else
878 2, -1, -1,
879#endif // EXT_TX_16X16_SET
Sarah Parker9d8222b2017-11-19 19:08:55 -0800880 1,
Hui Su4a9be2a2017-09-19 14:41:49 -0700881 },
882};
883
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800884static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800885 int use_reduced_set) {
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800886 const TxSetType set_type =
Sarah Parker5effe3f2017-02-23 12:49:10 -0800887 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Hui Su4a9be2a2017-09-19 14:41:49 -0700888 return ext_tx_set_index[is_inter][set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700889}
890
Sarah Parkere68a3e42017-02-16 14:03:24 -0800891static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800892 int use_reduced_set) {
893 const int set_type =
894 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Hui Suddbcde22017-09-18 17:22:02 -0700895 return av1_num_ext_tx_set[set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700896}
897
Yaowu Xuc27fc142016-08-22 16:08:15 -0700898static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100899 static const char LUT[BLOCK_SIZES_ALL] = {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700900 0, // BLOCK_4X4
901 1, // BLOCK_4X8
902 1, // BLOCK_8X4
903 0, // BLOCK_8X8
904 1, // BLOCK_8X16
905 1, // BLOCK_16X8
906 0, // BLOCK_16X16
907 1, // BLOCK_16X32
908 1, // BLOCK_32X16
909 0, // BLOCK_32X32
Debargha Mukherjee1a86b012017-10-02 23:58:11 -0700910 1, // BLOCK_32X64
911 1, // BLOCK_64X32
Yaowu Xuc27fc142016-08-22 16:08:15 -0700912 0, // BLOCK_64X64
913#if CONFIG_EXT_PARTITION
914 0, // BLOCK_64X128
915 0, // BLOCK_128X64
916 0, // BLOCK_128X128
917#endif // CONFIG_EXT_PARTITION
Debargha Mukherjeed2cfbef2017-12-03 16:15:27 -0800918 1, // BLOCK_4X16
919 1, // BLOCK_16X4
920 1, // BLOCK_8X32
921 1, // BLOCK_32X8
922 1, // BLOCK_16X64
923 1, // BLOCK_64X16
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100924#if CONFIG_EXT_PARTITION
Debargha Mukherjeed2cfbef2017-12-03 16:15:27 -0800925 1, // BLOCK_32X128
926 1, // BLOCK_128X32
Rupert Swarbrick2fa6e1c2017-09-11 12:38:10 +0100927#endif // CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700928 };
929
930 return LUT[bsize];
931}
932
Yue Chen49587a72016-09-28 17:09:47 -0700933static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd,
934 const MB_MODE_INFO *mbmi) {
Urvang Joshifeb925f2016-12-05 10:37:29 -0800935 return is_rect_tx_allowed_bsize(mbmi->sb_type) &&
Yue Chen49587a72016-09-28 17:09:47 -0700936 !xd->lossless[mbmi->segment_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700937}
Yue Chen56e226e2017-05-02 16:21:40 -0700938
Yue Chen0797a202017-10-27 17:24:56 -0700939static INLINE TX_SIZE get_max_rect_tx_size(BLOCK_SIZE bsize, int is_inter) {
Debargha Mukherjeee4e18fc2017-12-06 23:43:24 -0800940 return max_txsize_rect_lookup[is_inter][bsize];
Yue Chen0797a202017-10-27 17:24:56 -0700941}
942
Yaowu Xuc27fc142016-08-22 16:08:15 -0700943static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode,
944 int is_inter) {
945 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
Yue Chen0797a202017-10-27 17:24:56 -0700946 const TX_SIZE max_rect_tx_size = get_max_rect_tx_size(bsize, is_inter);
Urvang Joshifeb925f2016-12-05 10:37:29 -0800947 (void)is_inter;
Urvang Joshifeb925f2016-12-05 10:37:29 -0800948 if (bsize == BLOCK_4X4)
949 return AOMMIN(max_txsize_lookup[bsize], largest_tx_size);
Urvang Joshifeb925f2016-12-05 10:37:29 -0800950 if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size)
951 return max_rect_tx_size;
952 else
953 return largest_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700954}
955
hui su5db97432016-10-14 16:10:14 -0700956#if CONFIG_EXT_INTRA
hui su5db97432016-10-14 16:10:14 -0700957extern const int16_t dr_intra_derivative[90];
hui su02c79742017-05-16 17:19:04 -0700958static const uint8_t mode_to_angle_map[] = {
Urvang Joshib7301cd2017-11-09 15:08:56 -0800959 0, 90, 180, 45, 135, 113, 157, 203, 67, 0, 0, 0, 0,
hui su5db97432016-10-14 16:10:14 -0700960};
Yaowu Xuc27fc142016-08-22 16:08:15 -0700961#endif // CONFIG_EXT_INTRA
962
Yue Chen1a5ab9f2017-12-14 14:53:51 -0800963#if CONFIG_FILTER_INTRA
Yue Chen1a5ab9f2017-12-14 14:53:51 -0800964static INLINE int av1_filter_intra_allowed_txsize(TX_SIZE tx) {
Yue Chen1a5ab9f2017-12-14 14:53:51 -0800965 if (tx == TX_INVALID) return 0;
966
Yue Chen1a5ab9f2017-12-14 14:53:51 -0800967 return tx_size_wide[tx] <= 32 && tx_size_high[tx] <= 32;
Yue Chen1a5ab9f2017-12-14 14:53:51 -0800968}
969
970static INLINE TX_SIZE av1_max_tx_size_for_filter_intra(BLOCK_SIZE bsize,
971 TX_MODE tx_mode) {
972 const TX_SIZE max_tx_size = tx_size_from_tx_mode(bsize, tx_mode, 0);
973
974 if (tx_mode != TX_MODE_SELECT) return max_tx_size;
975
976 int depth = 0;
977 TX_SIZE tx_size = max_tx_size;
978 while (depth < MAX_TX_DEPTH && tx_size != TX_4X4) {
979 if (av1_filter_intra_allowed_txsize(tx_size)) return tx_size;
980 depth++;
981 tx_size = sub_tx_size_map[0][tx_size];
982 }
983 return TX_INVALID;
984}
985#endif
986
Monty Montgomerycb55dad2017-07-11 16:59:52 -0400987#if CONFIG_DCT_ONLY
988#define FIXED_TX_TYPE 1
989#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700990#define FIXED_TX_TYPE 0
Monty Montgomerycb55dad2017-07-11 16:59:52 -0400991#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700992
Angie Chiang752ccce2017-04-09 13:41:13 -0700993// Converts block_index for given transform size to index of the block in raster
994// order.
995static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size,
996 int block_idx) {
997 // For transform size 4x8, the possible block_idx values are 0 & 2, because
998 // block_idx values are incremented in steps of size 'tx_width_unit x
999 // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to
1000 // block number 1 in raster order, inside an 8x8 MI block.
1001 // For any other transform size, the two indices are equivalent.
1002 return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx;
1003}
1004
1005// Inverse of above function.
1006// Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now.
1007static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size,
1008 int raster_order) {
1009 assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4);
1010 // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4.
1011 return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0;
1012}
1013
Yaowu Xuc27fc142016-08-22 16:08:15 -07001014static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type,
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001015 const MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001016 TX_SIZE tx_size) {
1017 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1018
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001019 if (CONFIG_DCT_ONLY || is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07001020 xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32)
1021 return DCT_DCT;
1022
Luc Trudeau9cea9932017-12-13 21:14:13 -05001023 return intra_mode_to_tx_type_context(mbmi, plane_type);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001024}
1025
Sarah Parker90024e42017-10-06 16:50:47 -07001026static INLINE BLOCK_SIZE
1027get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) {
1028 return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y];
1029}
1030
hui su45b64752017-07-12 16:54:35 -07001031static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type,
Jingning Han19b5c8f2017-07-06 15:10:12 -07001032 const MACROBLOCKD *xd, int blk_row,
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001033 int blk_col, TX_SIZE tx_size) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001034 const MODE_INFO *const mi = xd->mi[0];
1035 const MB_MODE_INFO *const mbmi = &mi->mbmi;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001036 (void)blk_row;
1037 (void)blk_col;
Sebastien Alaiwan3bac9922017-11-02 12:34:41 +01001038#if CONFIG_INTRABC && (CONFIG_TXK_SEL)
Alex Conversedaa15e42017-05-02 14:27:16 -07001039 // TODO(aconverse@google.com): Handle INTRABC + EXT_TX + TXK_SEL
Alex Converse28744302017-04-13 14:46:22 -07001040 if (is_intrabc_block(mbmi)) return DCT_DCT;
Sebastien Alaiwan3bac9922017-11-02 12:34:41 +01001041#endif // CONFIG_INTRABC && (CONFIG_TXK_SEL)
hui su45b64752017-07-12 16:54:35 -07001042
Sarah Parker90024e42017-10-06 16:50:47 -07001043 const struct macroblockd_plane *const pd = &xd->plane[plane_type];
1044 const BLOCK_SIZE plane_bsize = get_plane_block_size(mbmi->sb_type, pd);
1045 // TODO(sarahparker) This assumes reduced_tx_set_used == 0. I will do a
1046 // follow up refactor to make the actual value of reduced_tx_set_used
1047 // within this function.
1048 const TxSetType tx_set_type =
1049 get_ext_tx_set_type(tx_size, plane_bsize, is_inter_block(mbmi), 0);
1050 if (is_inter_block(mbmi) && !av1_ext_tx_used[tx_set_type][mbmi->tx_type])
1051 return DCT_DCT;
Sarah Parker90024e42017-10-06 16:50:47 -07001052
hui su45b64752017-07-12 16:54:35 -07001053#if CONFIG_TXK_SEL
1054 TX_TYPE tx_type;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001055 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] >= TX_32X32) {
hui su45b64752017-07-12 16:54:35 -07001056 tx_type = DCT_DCT;
1057 } else {
Angie Chiangbce07f12017-12-01 16:34:31 -08001058 if (plane_type == PLANE_TYPE_Y) {
1059 tx_type = mbmi->txk_type[(blk_row << MAX_MIB_SIZE_LOG2) + blk_col];
1060 } else if (is_inter_block(mbmi)) {
1061 // scale back to y plane's coordinate
1062 blk_row <<= pd->subsampling_y;
1063 blk_col <<= pd->subsampling_x;
1064 tx_type = mbmi->txk_type[(blk_row << MAX_MIB_SIZE_LOG2) + blk_col];
1065 } else {
1066 // In intra mode, uv planes don't share the same prediction mode as y
1067 // plane, so the tx_type should not be shared
Luc Trudeau9cea9932017-12-13 21:14:13 -05001068 tx_type = intra_mode_to_tx_type_context(mbmi, PLANE_TYPE_UV);
Angie Chiangbce07f12017-12-01 16:34:31 -08001069 }
hui su45b64752017-07-12 16:54:35 -07001070 }
Angie Chiang840c66e2017-12-11 16:43:38 -08001071 assert(tx_type < TX_TYPES);
Angie Chiang2ac18682017-12-01 18:02:59 -08001072 if (!av1_ext_tx_used[tx_set_type][tx_type]) return DCT_DCT;
hui su45b64752017-07-12 16:54:35 -07001073 return tx_type;
1074#endif // CONFIG_TXK_SEL
1075
James Zern7cdaa602017-04-20 20:12:46 -07001076#if FIXED_TX_TYPE
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001077 return get_default_tx_type(plane_type, xd, tx_size);
hui su45b64752017-07-12 16:54:35 -07001078#endif // FIXED_TX_TYPE
1079
Nathan E. Eggef621a4f2017-12-08 09:02:09 -05001080#if CONFIG_DAALA_TX_DST32
Nathan E. Egge856d1792017-10-26 17:55:20 -04001081 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32)
1082#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001083 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 ||
1084 (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi)))
Nathan E. Egge856d1792017-10-26 17:55:20 -04001085#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001086 return DCT_DCT;
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001087 if (plane_type == PLANE_TYPE_Y) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001088#if !ALLOW_INTRA_EXT_TX
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001089 if (is_inter_block(mbmi))
Yaowu Xuc27fc142016-08-22 16:08:15 -07001090#endif // ALLOW_INTRA_EXT_TX
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001091 return mbmi->tx_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001092 }
1093
Debargha Mukherjee6ea917e2017-10-19 09:31:29 -07001094 if (is_inter_block(mbmi)) {
1095 // UV Inter only
1096 return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32)
1097 ? DCT_DCT
1098 : mbmi->tx_type;
1099 }
1100
Sarah Parker90024e42017-10-06 16:50:47 -07001101 // UV Intra only
Luc Trudeau9cea9932017-12-13 21:14:13 -05001102 const TX_TYPE intra_type = intra_mode_to_tx_type_context(mbmi, PLANE_TYPE_UV);
Sarah Parker90024e42017-10-06 16:50:47 -07001103 if (!av1_ext_tx_used[tx_set_type][intra_type]) return DCT_DCT;
1104 return intra_type;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001105}
1106
Yaowu Xuf883b422016-08-30 14:01:10 -07001107void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001108
Debargha Mukherjee0fa057f2017-12-06 17:06:29 -08001109static INLINE int bsize_to_max_depth(BLOCK_SIZE bsize, int is_inter) {
1110 TX_SIZE tx_size = get_max_rect_tx_size(bsize, is_inter);
1111 int depth = 0;
1112 while (depth < MAX_TX_DEPTH && tx_size != TX_4X4) {
1113 depth++;
Debargha Mukherjeee4e18fc2017-12-06 23:43:24 -08001114 tx_size = sub_tx_size_map[is_inter][tx_size];
Debargha Mukherjee0fa057f2017-12-06 17:06:29 -08001115 }
1116 return depth;
Jingning Han4e1737a2016-10-25 16:05:02 -07001117}
1118
Debargha Mukherjeee4e18fc2017-12-06 23:43:24 -08001119static INLINE int bsize_to_tx_size_cat(BLOCK_SIZE bsize, int is_inter) {
1120 TX_SIZE tx_size = get_max_rect_tx_size(bsize, is_inter);
1121 assert(tx_size != TX_4X4);
1122 int depth = 0;
1123 while (tx_size != TX_4X4) {
1124 depth++;
1125 tx_size = sub_tx_size_map[is_inter][tx_size];
1126 assert(depth < 10);
1127 }
1128 assert(depth <= MAX_TX_CATS);
1129 return depth - 1;
1130}
1131
Debargha Mukherjee0fa057f2017-12-06 17:06:29 -08001132static INLINE int tx_size_to_depth(TX_SIZE tx_size, BLOCK_SIZE bsize,
1133 int is_inter) {
1134 TX_SIZE ctx_size = get_max_rect_tx_size(bsize, is_inter);
1135 int depth = 0;
1136 while (tx_size != ctx_size) {
1137 depth++;
Debargha Mukherjeee4e18fc2017-12-06 23:43:24 -08001138 ctx_size = sub_tx_size_map[is_inter][ctx_size];
Debargha Mukherjee0fa057f2017-12-06 17:06:29 -08001139 assert(depth <= MAX_TX_DEPTH);
1140 }
1141 return depth;
Debargha Mukherjee6147b1b2017-11-08 08:31:09 -08001142}
1143
Debargha Mukherjee0fa057f2017-12-06 17:06:29 -08001144static INLINE TX_SIZE depth_to_tx_size(int depth, BLOCK_SIZE bsize,
1145 int is_inter) {
1146 TX_SIZE max_tx_size = get_max_rect_tx_size(bsize, is_inter);
1147 TX_SIZE tx_size = max_tx_size;
Debargha Mukherjeee4e18fc2017-12-06 23:43:24 -08001148 for (int d = 0; d < depth; ++d) tx_size = sub_tx_size_map[is_inter][tx_size];
Debargha Mukherjee0fa057f2017-12-06 17:06:29 -08001149 return tx_size;
Jingning Han4e1737a2016-10-25 16:05:02 -07001150}
1151
hui su0c6244b2017-07-12 17:11:43 -07001152static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi,
1153 const struct macroblockd_plane *pd) {
Luc Trudeaud1941f32017-11-22 14:17:21 -05001154#if CONFIG_CFL
1155 if (!is_inter_block(mbmi) && mbmi->uv_mode == UV_CFL_PRED) {
Debargha Mukherjee5d149e12017-12-14 12:49:51 -08001156 const BLOCK_SIZE plane_bsize = get_plane_block_size(mbmi->sb_type, pd);
Luc Trudeaud1941f32017-11-22 14:17:21 -05001157 assert(plane_bsize < BLOCK_SIZES_ALL);
1158 return max_txsize_rect_lookup[0][plane_bsize];
1159 }
1160#endif
hui su0c6244b2017-07-12 17:11:43 -07001161 const TX_SIZE uv_txsize =
1162 uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x]
1163 [pd->subsampling_y];
Debargha Mukherjee2f123402016-08-30 17:43:38 -07001164 assert(uv_txsize != TX_INVALID);
1165 return uv_txsize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001166}
1167
hui su0c6244b2017-07-12 17:11:43 -07001168static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) {
Angie Chiang80b82262017-02-24 11:39:47 -08001169 const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
hui su0c6244b2017-07-12 17:11:43 -07001170 if (plane == 0) return mbmi->tx_size;
Angie Chiang80b82262017-02-24 11:39:47 -08001171 const MACROBLOCKD_PLANE *pd = &xd->plane[plane];
hui su0c6244b2017-07-12 17:11:43 -07001172 return av1_get_uv_tx_size(mbmi, pd);
Angie Chiang80b82262017-02-24 11:39:47 -08001173}
1174
Timothy B. Terriberrya2d5cde2017-05-10 18:33:50 -07001175void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
1176 BLOCK_SIZE bsize);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001177
Rupert Swarbrick76405202017-11-07 16:35:55 +00001178#if CONFIG_LOOP_RESTORATION
1179void av1_reset_loop_restoration(MACROBLOCKD *xd);
1180#endif // CONFIG_LOOP_RESTORATION
1181
Yaowu Xuc27fc142016-08-22 16:08:15 -07001182typedef void (*foreach_transformed_block_visitor)(int plane, int block,
1183 int blk_row, int blk_col,
1184 BLOCK_SIZE plane_bsize,
1185 TX_SIZE tx_size, void *arg);
1186
Yaowu Xuf883b422016-08-30 14:01:10 -07001187void av1_foreach_transformed_block_in_plane(
Yaowu Xuc27fc142016-08-22 16:08:15 -07001188 const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
1189 foreach_transformed_block_visitor visit, void *arg);
1190
Angie Chiang0397eda2017-03-15 16:57:14 -07001191#if CONFIG_LV_MAP
1192void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
Jingning Han94652b82017-04-04 09:45:02 -07001193 BLOCK_SIZE bsize, int mi_row, int mi_col,
Angie Chiang0397eda2017-03-15 16:57:14 -07001194 foreach_transformed_block_visitor visit,
1195 void *arg);
1196#endif
1197
Yaowu Xuf883b422016-08-30 14:01:10 -07001198void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
Jingning Haneee43152016-12-05 09:58:45 -08001199 int plane, TX_SIZE tx_size, int has_eob, int aoff,
1200 int loff);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001201
Yaowu Xuc27fc142016-08-22 16:08:15 -07001202static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
Yue Chen9ddd4092017-10-30 16:13:39 -07001203 return (bsize >= BLOCK_8X8) && (bsize <= BLOCK_32X32);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001204}
1205
1206static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) {
1207 return (mode >= NEARESTMV) && (mode <= NEWMV);
1208}
1209
1210static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) {
1211 return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME);
1212}
1213
1214static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
1215 return is_interintra_allowed_bsize(mbmi->sb_type) &&
1216 is_interintra_allowed_mode(mbmi->mode) &&
1217 is_interintra_allowed_ref(mbmi->ref_frame);
1218}
1219
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001220static INLINE int is_interintra_allowed_bsize_group(int group) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001221 int i;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001222 for (i = 0; i < BLOCK_SIZES_ALL; i++) {
Urvang Joshicb586f32016-09-20 11:36:33 -07001223 if (size_group_lookup[i] == group &&
1224 is_interintra_allowed_bsize((BLOCK_SIZE)i)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001225 return 1;
Urvang Joshicb586f32016-09-20 11:36:33 -07001226 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001227 }
1228 return 0;
1229}
1230
1231static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) {
1232 return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi);
1233}
Yaowu Xuc27fc142016-08-22 16:08:15 -07001234
Debargha Mukherjee891a8772017-11-22 10:09:37 -08001235static INLINE int get_vartx_max_txsize(const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1236 int subsampled) {
1237 TX_SIZE max_txsize =
1238 xd->lossless[xd->mi[0]->mbmi.segment_id]
1239 ? TX_4X4
1240 : get_max_rect_tx_size(bsize, is_inter_block(&xd->mi[0]->mbmi));
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001241
1242#if CONFIG_EXT_PARTITION && CONFIG_TX64X64
1243 // The decoder is designed so that it can process 64x64 luma pixels at a
1244 // time. If this is a chroma plane with subsampling and bsize corresponds to
1245 // a subsampled BLOCK_128X128 then the lookup above will give TX_64X64. That
1246 // mustn't be used for the subsampled plane (because it would be bigger than
1247 // a 64x64 luma block) so we round down to TX_32X32.
Debargha Mukherjee1fa24462017-10-19 14:33:39 -07001248 if (subsampled && txsize_sqr_up_map[max_txsize] == TX_64X64) {
1249 max_txsize = TX_32X32;
1250 }
Rupert Swarbrick4e7b7d62017-09-28 17:30:44 +01001251#else
1252 (void)subsampled;
1253#endif
1254
1255 return max_txsize;
Sarah Parker106b3cb2017-04-21 12:13:37 -07001256}
Sarah Parker106b3cb2017-04-21 12:13:37 -07001257
Yue Chencb60b182016-10-13 15:18:22 -07001258static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) {
Debargha Mukherjeec17a4432017-08-28 22:22:45 -07001259 return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
Yue Chencb60b182016-10-13 15:18:22 -07001260}
1261
Yue Chen8636da62017-04-03 01:23:44 -07001262static INLINE int is_motion_variation_allowed_compound(
1263 const MB_MODE_INFO *mbmi) {
1264 if (!has_second_ref(mbmi))
1265 return 1;
1266 else
1267 return 0;
1268}
1269
Yue Chen1bd42be2017-03-15 18:07:04 -07001270// input: log2 of length, 0(4), 1(8), ...
1271static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };
1272
Yue Chen5329a2b2017-02-28 17:33:00 +08001273static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) {
Yue Chen1bd42be2017-03-15 18:07:04 -07001274 return !(mbmi->overlappable_neighbors[0] == 0 &&
1275 mbmi->overlappable_neighbors[1] == 0);
Yue Chen5329a2b2017-02-28 17:33:00 +08001276}
Yue Chen5329a2b2017-02-28 17:33:00 +08001277
Sebastien Alaiwan48795802017-10-30 12:07:13 +01001278static INLINE MOTION_MODE
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001279motion_mode_allowed(const WarpedMotionParams *gm_params, const MACROBLOCKD *xd,
1280 const MODE_INFO *mi) {
Sarah Parker19234cc2017-03-10 16:43:25 -08001281 const MB_MODE_INFO *mbmi = &mi->mbmi;
RogerZhou3b635242017-09-19 10:06:46 -07001282#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -07001283 if (xd->cur_frame_force_integer_mv == 0) {
RogerZhou3b635242017-09-19 10:06:46 -07001284#endif
RogerZhou3b635242017-09-19 10:06:46 -07001285 const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype;
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001286 if (is_global_mv_block(mi, gm_type)) return SIMPLE_TRANSLATION;
RogerZhou3b635242017-09-19 10:06:46 -07001287#if CONFIG_AMVR
1288 }
1289#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001290 if (is_motion_variation_allowed_bsize(mbmi->sb_type) &&
Yue Chen8636da62017-04-03 01:23:44 -07001291 is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME &&
1292 is_motion_variation_allowed_compound(mbmi)) {
Yue Chen5329a2b2017-02-28 17:33:00 +08001293 if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION;
Zoe Liu70539b12017-12-02 19:03:36 -08001294 assert(!has_second_ref(mbmi));
1295 if (mbmi->num_proj_ref[0] >= 1 &&
Wei-Ting Lin20885282017-08-28 17:18:18 -07001296 !av1_is_scaled(&(xd->block_refs[0]->sf))) {
RogerZhou3b635242017-09-19 10:06:46 -07001297#if CONFIG_AMVR
RogerZhou10a03802017-10-26 11:49:48 -07001298 if (xd->cur_frame_force_integer_mv) {
RogerZhou3b635242017-09-19 10:06:46 -07001299 return OBMC_CAUSAL;
1300 }
1301#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001302 return WARPED_CAUSAL;
Hui Su12231bd2017-09-07 18:01:15 -07001303 }
Yue Chen80daf0c2017-11-02 17:14:18 -07001304 return OBMC_CAUSAL;
Yue Chen69f18e12016-09-08 14:48:15 -07001305 } else {
1306 return SIMPLE_TRANSLATION;
1307 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001308}
1309
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001310static INLINE void assert_motion_mode_valid(MOTION_MODE mode,
Sarah Parker19234cc2017-03-10 16:43:25 -08001311 const WarpedMotionParams *gm_params,
Yue Chen52c51732017-07-11 15:08:30 -07001312 const MACROBLOCKD *xd,
Sarah Parker19234cc2017-03-10 16:43:25 -08001313 const MODE_INFO *mi) {
Sebastien Alaiwan48795802017-10-30 12:07:13 +01001314 const MOTION_MODE last_motion_mode_allowed =
Luc Trudeau2eb9b842017-12-13 11:19:16 -05001315 motion_mode_allowed(gm_params, xd, mi);
Wei-Ting Lin20885282017-08-28 17:18:18 -07001316
Sarah Parker19234cc2017-03-10 16:43:25 -08001317 // Check that the input mode is not illegal
1318 if (last_motion_mode_allowed < mode)
1319 assert(0 && "Illegal motion mode selected");
1320}
1321
Yaowu Xuc27fc142016-08-22 16:08:15 -07001322static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) {
1323 return (is_inter_block(mbmi));
1324}
Yaowu Xuc27fc142016-08-22 16:08:15 -07001325
Hui Sue87fb232017-10-05 15:00:15 -07001326static INLINE int av1_allow_palette(int allow_screen_content_tools,
1327 BLOCK_SIZE sb_type) {
1328 return allow_screen_content_tools && sb_type >= BLOCK_8X8 &&
Hui Su473cf892017-11-08 18:14:31 -08001329 sb_type <= BLOCK_64X64;
Hui Sue87fb232017-10-05 15:00:15 -07001330}
1331
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001332// Returns sub-sampled dimensions of the given block.
1333// The output values for 'rows_within_bounds' and 'cols_within_bounds' will
RogerZhou3b635242017-09-19 10:06:46 -07001334// differ from 'height' and 'width' when part of the block is outside the
1335// right
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001336// and/or bottom image boundary.
1337static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane,
1338 const MACROBLOCKD *xd, int *width,
1339 int *height,
1340 int *rows_within_bounds,
1341 int *cols_within_bounds) {
1342 const int block_height = block_size_high[bsize];
1343 const int block_width = block_size_wide[bsize];
1344 const int block_rows = (xd->mb_to_bottom_edge >= 0)
1345 ? block_height
1346 : (xd->mb_to_bottom_edge >> 3) + block_height;
1347 const int block_cols = (xd->mb_to_right_edge >= 0)
1348 ? block_width
1349 : (xd->mb_to_right_edge >> 3) + block_width;
1350 const struct macroblockd_plane *const pd = &xd->plane[plane];
1351 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0));
1352 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0));
1353 assert(block_width >= block_cols);
1354 assert(block_height >= block_rows);
1355 if (width) *width = block_width >> pd->subsampling_x;
1356 if (height) *height = block_height >> pd->subsampling_y;
1357 if (rows_within_bounds) *rows_within_bounds = block_rows >> pd->subsampling_y;
1358 if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x;
1359}
1360
Sarah Parkerefd8af22017-08-25 16:36:06 -07001361/* clang-format off */
1362typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS]
1363 [CDF_SIZE(PALETTE_COLORS)];
1364typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
1365 [PALETTE_COLORS];
1366/* clang-format on */
1367
1368typedef struct {
1369 int rows;
1370 int cols;
1371 int n_colors;
1372 int plane_width;
1373 int plane_height;
1374 uint8_t *color_map;
1375 MapCdf map_cdf;
1376 ColorCost color_cost;
1377} Av1ColorMapParam;
1378
Yue Chen19e7aa82016-11-30 14:05:39 -08001379static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) {
1380 const MODE_INFO *mi = xd->mi[0];
1381 const MB_MODE_INFO *const mbmi = &mi->mbmi;
1382 int ref;
Yue Chen19e7aa82016-11-30 14:05:39 -08001383
Sarah Parker2b9ec2e2017-10-30 17:34:08 -07001384 // First check if all modes are GLOBALMV
1385 if (mbmi->mode != GLOBALMV && mbmi->mode != GLOBAL_GLOBALMV) return 0;
Jingning Han3ca0e672017-04-14 19:48:05 -07001386
1387#if !GLOBAL_SUB8X8_USED
1388 if (mbmi->sb_type < BLOCK_8X8) return 0;
1389#endif
1390
Yue Chen19e7aa82016-11-30 14:05:39 -08001391 // Now check if all global motion is non translational
1392 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
1393 if (xd->global_motion[mbmi->ref_frame[ref]].wmtype <= TRANSLATION) return 0;
1394 }
1395 return 1;
1396}
Yue Chen19e7aa82016-11-30 14:05:39 -08001397
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001398static INLINE PLANE_TYPE get_plane_type(int plane) {
Luc Trudeau005feb62017-02-22 13:34:01 -05001399 return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
1400}
1401
Angie Chiang155bf9a2017-08-06 19:52:57 -07001402static INLINE void transpose_uint8(uint8_t *dst, int dst_stride,
1403 const uint8_t *src, int src_stride, int w,
1404 int h) {
1405 int r, c;
1406 for (r = 0; r < h; ++r)
1407 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1408}
1409
1410static INLINE void transpose_uint16(uint16_t *dst, int dst_stride,
1411 const uint16_t *src, int src_stride, int w,
1412 int h) {
1413 int r, c;
1414 for (r = 0; r < h; ++r)
1415 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1416}
1417
1418static INLINE void transpose_int16(int16_t *dst, int dst_stride,
1419 const int16_t *src, int src_stride, int w,
1420 int h) {
1421 int r, c;
1422 for (r = 0; r < h; ++r)
1423 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1424}
1425
1426static INLINE void transpose_int32(int32_t *dst, int dst_stride,
1427 const int32_t *src, int src_stride, int w,
1428 int h) {
1429 int r, c;
1430 for (r = 0; r < h; ++r)
1431 for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c];
1432}
1433
Urvang Joshi80893152017-10-27 11:51:14 -07001434static INLINE int av1_get_max_eob(TX_SIZE tx_size) {
Urvang Joshi80893152017-10-27 11:51:14 -07001435#if CONFIG_TX64X64 && !CONFIG_DAALA_TX
Urvang Joshi030cea92017-12-05 15:27:09 -08001436 if (tx_size == TX_64X64 || tx_size == TX_64X32 || tx_size == TX_32X64) {
1437 return 1024;
1438 }
1439 if (tx_size == TX_16X64 || tx_size == TX_64X16) {
1440 return 512;
1441 }
Urvang Joshi80893152017-10-27 11:51:14 -07001442#endif // CONFIG_TX64X64 && !CONFIG_DAALA_TX
Urvang Joshi030cea92017-12-05 15:27:09 -08001443 return tx_size_2d[tx_size];
Urvang Joshi80893152017-10-27 11:51:14 -07001444}
1445
Debargha Mukherjee695abd72017-12-16 10:15:45 -08001446static INLINE TX_SIZE av1_get_adjusted_tx_size(TX_SIZE tx_size) {
1447#if CONFIG_TX64X64
1448 if (tx_size == TX_64X64 || tx_size == TX_64X32 || tx_size == TX_32X64) {
1449 return TX_32X32;
1450 }
1451 if (tx_size == TX_16X64) {
1452 return TX_16X32;
1453 }
1454 if (tx_size == TX_64X16) {
1455 return TX_32X16;
1456 }
1457#endif // CONFIG_TX64X64
1458 return tx_size;
1459}
1460
Yaowu Xuc27fc142016-08-22 16:08:15 -07001461#ifdef __cplusplus
1462} // extern "C"
1463#endif
1464
Yaowu Xuf883b422016-08-30 14:01:10 -07001465#endif // AV1_COMMON_BLOCKD_H_