1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_COMMON_BLOCKD_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_COMMON_BLOCKD_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/aom_dsp_common.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/mem.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom_scale/yv12config.h"
20*77c1e3ccSAndroid Build Coastguard Worker
21*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/common_data.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/quant_common.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/entropy.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/entropymode.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/mv.h"
26*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/scale.h"
27*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/seg_common.h"
28*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/tile_common.h"
29*77c1e3ccSAndroid Build Coastguard Worker
30*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
31*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
32*77c1e3ccSAndroid Build Coastguard Worker #endif
33*77c1e3ccSAndroid Build Coastguard Worker
34*77c1e3ccSAndroid Build Coastguard Worker #define USE_B_QUANT_NO_TRELLIS 1
35*77c1e3ccSAndroid Build Coastguard Worker
36*77c1e3ccSAndroid Build Coastguard Worker #define MAX_MB_PLANE 3
37*77c1e3ccSAndroid Build Coastguard Worker
38*77c1e3ccSAndroid Build Coastguard Worker #define MAX_DIFFWTD_MASK_BITS 1
39*77c1e3ccSAndroid Build Coastguard Worker
40*77c1e3ccSAndroid Build Coastguard Worker #define INTERINTRA_WEDGE_SIGN 0
41*77c1e3ccSAndroid Build Coastguard Worker
42*77c1e3ccSAndroid Build Coastguard Worker #define DEFAULT_INTER_TX_TYPE DCT_DCT
43*77c1e3ccSAndroid Build Coastguard Worker
44*77c1e3ccSAndroid Build Coastguard Worker #define MAX_PALETTE_BLOCK_WIDTH 64
45*77c1e3ccSAndroid Build Coastguard Worker
46*77c1e3ccSAndroid Build Coastguard Worker #define MAX_PALETTE_BLOCK_HEIGHT 64
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
49*77c1e3ccSAndroid Build Coastguard Worker
50*77c1e3ccSAndroid Build Coastguard Worker // DIFFWTD_MASK_TYPES should not surpass 1 << MAX_DIFFWTD_MASK_BITS
51*77c1e3ccSAndroid Build Coastguard Worker enum {
52*77c1e3ccSAndroid Build Coastguard Worker DIFFWTD_38 = 0,
53*77c1e3ccSAndroid Build Coastguard Worker DIFFWTD_38_INV,
54*77c1e3ccSAndroid Build Coastguard Worker DIFFWTD_MASK_TYPES,
55*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(DIFFWTD_MASK_TYPE);
56*77c1e3ccSAndroid Build Coastguard Worker
57*77c1e3ccSAndroid Build Coastguard Worker enum {
58*77c1e3ccSAndroid Build Coastguard Worker KEY_FRAME = 0,
59*77c1e3ccSAndroid Build Coastguard Worker INTER_FRAME = 1,
60*77c1e3ccSAndroid Build Coastguard Worker INTRA_ONLY_FRAME = 2, // replaces intra-only
61*77c1e3ccSAndroid Build Coastguard Worker S_FRAME = 3,
62*77c1e3ccSAndroid Build Coastguard Worker FRAME_TYPES,
63*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(FRAME_TYPE);
64*77c1e3ccSAndroid Build Coastguard Worker
is_comp_ref_allowed(BLOCK_SIZE bsize)65*77c1e3ccSAndroid Build Coastguard Worker static inline int is_comp_ref_allowed(BLOCK_SIZE bsize) {
66*77c1e3ccSAndroid Build Coastguard Worker return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
67*77c1e3ccSAndroid Build Coastguard Worker }
68*77c1e3ccSAndroid Build Coastguard Worker
is_inter_mode(PREDICTION_MODE mode)69*77c1e3ccSAndroid Build Coastguard Worker static inline int is_inter_mode(PREDICTION_MODE mode) {
70*77c1e3ccSAndroid Build Coastguard Worker return mode >= INTER_MODE_START && mode < INTER_MODE_END;
71*77c1e3ccSAndroid Build Coastguard Worker }
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
74*77c1e3ccSAndroid Build Coastguard Worker uint8_t *plane[MAX_MB_PLANE];
75*77c1e3ccSAndroid Build Coastguard Worker int stride[MAX_MB_PLANE];
76*77c1e3ccSAndroid Build Coastguard Worker } BUFFER_SET;
77*77c1e3ccSAndroid Build Coastguard Worker
is_inter_singleref_mode(PREDICTION_MODE mode)78*77c1e3ccSAndroid Build Coastguard Worker static inline int is_inter_singleref_mode(PREDICTION_MODE mode) {
79*77c1e3ccSAndroid Build Coastguard Worker return mode >= SINGLE_INTER_MODE_START && mode < SINGLE_INTER_MODE_END;
80*77c1e3ccSAndroid Build Coastguard Worker }
is_inter_compound_mode(PREDICTION_MODE mode)81*77c1e3ccSAndroid Build Coastguard Worker static inline int is_inter_compound_mode(PREDICTION_MODE mode) {
82*77c1e3ccSAndroid Build Coastguard Worker return mode >= COMP_INTER_MODE_START && mode < COMP_INTER_MODE_END;
83*77c1e3ccSAndroid Build Coastguard Worker }
84*77c1e3ccSAndroid Build Coastguard Worker
compound_ref0_mode(PREDICTION_MODE mode)85*77c1e3ccSAndroid Build Coastguard Worker static inline PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) {
86*77c1e3ccSAndroid Build Coastguard Worker static const PREDICTION_MODE lut[] = {
87*77c1e3ccSAndroid Build Coastguard Worker DC_PRED, // DC_PRED
88*77c1e3ccSAndroid Build Coastguard Worker V_PRED, // V_PRED
89*77c1e3ccSAndroid Build Coastguard Worker H_PRED, // H_PRED
90*77c1e3ccSAndroid Build Coastguard Worker D45_PRED, // D45_PRED
91*77c1e3ccSAndroid Build Coastguard Worker D135_PRED, // D135_PRED
92*77c1e3ccSAndroid Build Coastguard Worker D113_PRED, // D113_PRED
93*77c1e3ccSAndroid Build Coastguard Worker D157_PRED, // D157_PRED
94*77c1e3ccSAndroid Build Coastguard Worker D203_PRED, // D203_PRED
95*77c1e3ccSAndroid Build Coastguard Worker D67_PRED, // D67_PRED
96*77c1e3ccSAndroid Build Coastguard Worker SMOOTH_PRED, // SMOOTH_PRED
97*77c1e3ccSAndroid Build Coastguard Worker SMOOTH_V_PRED, // SMOOTH_V_PRED
98*77c1e3ccSAndroid Build Coastguard Worker SMOOTH_H_PRED, // SMOOTH_H_PRED
99*77c1e3ccSAndroid Build Coastguard Worker PAETH_PRED, // PAETH_PRED
100*77c1e3ccSAndroid Build Coastguard Worker NEARESTMV, // NEARESTMV
101*77c1e3ccSAndroid Build Coastguard Worker NEARMV, // NEARMV
102*77c1e3ccSAndroid Build Coastguard Worker GLOBALMV, // GLOBALMV
103*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEWMV
104*77c1e3ccSAndroid Build Coastguard Worker NEARESTMV, // NEAREST_NEARESTMV
105*77c1e3ccSAndroid Build Coastguard Worker NEARMV, // NEAR_NEARMV
106*77c1e3ccSAndroid Build Coastguard Worker NEARESTMV, // NEAREST_NEWMV
107*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEW_NEARESTMV
108*77c1e3ccSAndroid Build Coastguard Worker NEARMV, // NEAR_NEWMV
109*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEW_NEARMV
110*77c1e3ccSAndroid Build Coastguard Worker GLOBALMV, // GLOBAL_GLOBALMV
111*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEW_NEWMV
112*77c1e3ccSAndroid Build Coastguard Worker };
113*77c1e3ccSAndroid Build Coastguard Worker assert(NELEMENTS(lut) == MB_MODE_COUNT);
114*77c1e3ccSAndroid Build Coastguard Worker assert(is_inter_compound_mode(mode) || is_inter_singleref_mode(mode));
115*77c1e3ccSAndroid Build Coastguard Worker return lut[mode];
116*77c1e3ccSAndroid Build Coastguard Worker }
117*77c1e3ccSAndroid Build Coastguard Worker
compound_ref1_mode(PREDICTION_MODE mode)118*77c1e3ccSAndroid Build Coastguard Worker static inline PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) {
119*77c1e3ccSAndroid Build Coastguard Worker static const PREDICTION_MODE lut[] = {
120*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // DC_PRED
121*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // V_PRED
122*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // H_PRED
123*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // D45_PRED
124*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // D135_PRED
125*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // D113_PRED
126*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // D157_PRED
127*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // D203_PRED
128*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // D67_PRED
129*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // SMOOTH_PRED
130*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // SMOOTH_V_PRED
131*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // SMOOTH_H_PRED
132*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // PAETH_PRED
133*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // NEARESTMV
134*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // NEARMV
135*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // GLOBALMV
136*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_COUNT, // NEWMV
137*77c1e3ccSAndroid Build Coastguard Worker NEARESTMV, // NEAREST_NEARESTMV
138*77c1e3ccSAndroid Build Coastguard Worker NEARMV, // NEAR_NEARMV
139*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEAREST_NEWMV
140*77c1e3ccSAndroid Build Coastguard Worker NEARESTMV, // NEW_NEARESTMV
141*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEAR_NEWMV
142*77c1e3ccSAndroid Build Coastguard Worker NEARMV, // NEW_NEARMV
143*77c1e3ccSAndroid Build Coastguard Worker GLOBALMV, // GLOBAL_GLOBALMV
144*77c1e3ccSAndroid Build Coastguard Worker NEWMV, // NEW_NEWMV
145*77c1e3ccSAndroid Build Coastguard Worker };
146*77c1e3ccSAndroid Build Coastguard Worker assert(NELEMENTS(lut) == MB_MODE_COUNT);
147*77c1e3ccSAndroid Build Coastguard Worker assert(is_inter_compound_mode(mode));
148*77c1e3ccSAndroid Build Coastguard Worker return lut[mode];
149*77c1e3ccSAndroid Build Coastguard Worker }
150*77c1e3ccSAndroid Build Coastguard Worker
have_nearmv_in_inter_mode(PREDICTION_MODE mode)151*77c1e3ccSAndroid Build Coastguard Worker static inline int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
152*77c1e3ccSAndroid Build Coastguard Worker return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV ||
153*77c1e3ccSAndroid Build Coastguard Worker mode == NEW_NEARMV);
154*77c1e3ccSAndroid Build Coastguard Worker }
155*77c1e3ccSAndroid Build Coastguard Worker
have_newmv_in_inter_mode(PREDICTION_MODE mode)156*77c1e3ccSAndroid Build Coastguard Worker static inline int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
157*77c1e3ccSAndroid Build Coastguard Worker return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV ||
158*77c1e3ccSAndroid Build Coastguard Worker mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
159*77c1e3ccSAndroid Build Coastguard Worker }
160*77c1e3ccSAndroid Build Coastguard Worker
is_masked_compound_type(COMPOUND_TYPE type)161*77c1e3ccSAndroid Build Coastguard Worker static inline int is_masked_compound_type(COMPOUND_TYPE type) {
162*77c1e3ccSAndroid Build Coastguard Worker return (type == COMPOUND_WEDGE || type == COMPOUND_DIFFWTD);
163*77c1e3ccSAndroid Build Coastguard Worker }
164*77c1e3ccSAndroid Build Coastguard Worker
165*77c1e3ccSAndroid Build Coastguard Worker /* For keyframes, intra block modes are predicted by the (already decoded)
166*77c1e3ccSAndroid Build Coastguard Worker modes for the Y blocks to the left and above us; for interframes, there
167*77c1e3ccSAndroid Build Coastguard Worker is a single probability table. */
168*77c1e3ccSAndroid Build Coastguard Worker
169*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
170*77c1e3ccSAndroid Build Coastguard Worker // Value of base colors for Y, U, and V
171*77c1e3ccSAndroid Build Coastguard Worker uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
172*77c1e3ccSAndroid Build Coastguard Worker // Number of base colors for Y (0) and UV (1)
173*77c1e3ccSAndroid Build Coastguard Worker uint8_t palette_size[2];
174*77c1e3ccSAndroid Build Coastguard Worker } PALETTE_MODE_INFO;
175*77c1e3ccSAndroid Build Coastguard Worker
176*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
177*77c1e3ccSAndroid Build Coastguard Worker FILTER_INTRA_MODE filter_intra_mode;
178*77c1e3ccSAndroid Build Coastguard Worker uint8_t use_filter_intra;
179*77c1e3ccSAndroid Build Coastguard Worker } FILTER_INTRA_MODE_INFO;
180*77c1e3ccSAndroid Build Coastguard Worker
181*77c1e3ccSAndroid Build Coastguard Worker static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = {
182*77c1e3ccSAndroid Build Coastguard Worker DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED
183*77c1e3ccSAndroid Build Coastguard Worker };
184*77c1e3ccSAndroid Build Coastguard Worker
185*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RD_DEBUG
186*77c1e3ccSAndroid Build Coastguard Worker #define TXB_COEFF_COST_MAP_SIZE (MAX_MIB_SIZE)
187*77c1e3ccSAndroid Build Coastguard Worker #endif
188*77c1e3ccSAndroid Build Coastguard Worker
189*77c1e3ccSAndroid Build Coastguard Worker typedef struct RD_STATS {
190*77c1e3ccSAndroid Build Coastguard Worker int rate;
191*77c1e3ccSAndroid Build Coastguard Worker int zero_rate;
192*77c1e3ccSAndroid Build Coastguard Worker int64_t dist;
193*77c1e3ccSAndroid Build Coastguard Worker // Please be careful of using rdcost, it's not guaranteed to be set all the
194*77c1e3ccSAndroid Build Coastguard Worker // time.
195*77c1e3ccSAndroid Build Coastguard Worker // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In
196*77c1e3ccSAndroid Build Coastguard Worker // these functions, make sure rdcost is always up-to-date according to
197*77c1e3ccSAndroid Build Coastguard Worker // rate/dist.
198*77c1e3ccSAndroid Build Coastguard Worker int64_t rdcost;
199*77c1e3ccSAndroid Build Coastguard Worker int64_t sse;
200*77c1e3ccSAndroid Build Coastguard Worker uint8_t skip_txfm; // sse should equal to dist when skip_txfm == 1
201*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RD_DEBUG
202*77c1e3ccSAndroid Build Coastguard Worker int txb_coeff_cost[MAX_MB_PLANE];
203*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_RD_DEBUG
204*77c1e3ccSAndroid Build Coastguard Worker } RD_STATS;
205*77c1e3ccSAndroid Build Coastguard Worker
206*77c1e3ccSAndroid Build Coastguard Worker // This struct is used to group function args that are commonly
207*77c1e3ccSAndroid Build Coastguard Worker // sent together in functions related to interinter compound modes
208*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
209*77c1e3ccSAndroid Build Coastguard Worker uint8_t *seg_mask;
210*77c1e3ccSAndroid Build Coastguard Worker int8_t wedge_index;
211*77c1e3ccSAndroid Build Coastguard Worker int8_t wedge_sign;
212*77c1e3ccSAndroid Build Coastguard Worker DIFFWTD_MASK_TYPE mask_type;
213*77c1e3ccSAndroid Build Coastguard Worker COMPOUND_TYPE type;
214*77c1e3ccSAndroid Build Coastguard Worker } INTERINTER_COMPOUND_DATA;
215*77c1e3ccSAndroid Build Coastguard Worker
216*77c1e3ccSAndroid Build Coastguard Worker #define INTER_TX_SIZE_BUF_LEN 16
217*77c1e3ccSAndroid Build Coastguard Worker #define TXK_TYPE_BUF_LEN 64
218*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
219*77c1e3ccSAndroid Build Coastguard Worker
220*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Stores the prediction/txfm mode of the current coding block
221*77c1e3ccSAndroid Build Coastguard Worker */
222*77c1e3ccSAndroid Build Coastguard Worker typedef struct MB_MODE_INFO {
223*77c1e3ccSAndroid Build Coastguard Worker /*****************************************************************************
224*77c1e3ccSAndroid Build Coastguard Worker * \name General Info of the Coding Block
225*77c1e3ccSAndroid Build Coastguard Worker ****************************************************************************/
226*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
227*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The block size of the current coding block */
228*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE bsize;
229*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The partition type of the current coding block. */
230*77c1e3ccSAndroid Build Coastguard Worker PARTITION_TYPE partition;
231*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The prediction mode used */
232*77c1e3ccSAndroid Build Coastguard Worker PREDICTION_MODE mode;
233*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The UV mode when intra is used */
234*77c1e3ccSAndroid Build Coastguard Worker UV_PREDICTION_MODE uv_mode;
235*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The q index for the current coding block. */
236*77c1e3ccSAndroid Build Coastguard Worker int current_qindex;
237*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
238*77c1e3ccSAndroid Build Coastguard Worker
239*77c1e3ccSAndroid Build Coastguard Worker /*****************************************************************************
240*77c1e3ccSAndroid Build Coastguard Worker * \name Inter Mode Info
241*77c1e3ccSAndroid Build Coastguard Worker ****************************************************************************/
242*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
243*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The motion vectors used by the current inter mode */
244*77c1e3ccSAndroid Build Coastguard Worker int_mv mv[2];
245*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The reference frames for the MV */
246*77c1e3ccSAndroid Build Coastguard Worker MV_REFERENCE_FRAME ref_frame[2];
247*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Filter used in subpel interpolation. */
248*77c1e3ccSAndroid Build Coastguard Worker int_interpfilters interp_filters;
249*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The motion mode used by the inter prediction. */
250*77c1e3ccSAndroid Build Coastguard Worker MOTION_MODE motion_mode;
251*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Number of samples used by warp causal */
252*77c1e3ccSAndroid Build Coastguard Worker uint8_t num_proj_ref;
253*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The number of overlapped neighbors above/left for obmc/warp motion
254*77c1e3ccSAndroid Build Coastguard Worker * mode. */
255*77c1e3ccSAndroid Build Coastguard Worker uint8_t overlappable_neighbors;
256*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The parameters used in warp motion mode. */
257*77c1e3ccSAndroid Build Coastguard Worker WarpedMotionParams wm_params;
258*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The type of intra mode used by inter-intra */
259*77c1e3ccSAndroid Build Coastguard Worker INTERINTRA_MODE interintra_mode;
260*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The type of wedge used in interintra mode. */
261*77c1e3ccSAndroid Build Coastguard Worker int8_t interintra_wedge_index;
262*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Struct that stores the data used in interinter compound mode. */
263*77c1e3ccSAndroid Build Coastguard Worker INTERINTER_COMPOUND_DATA interinter_comp;
264*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
265*77c1e3ccSAndroid Build Coastguard Worker
266*77c1e3ccSAndroid Build Coastguard Worker /*****************************************************************************
267*77c1e3ccSAndroid Build Coastguard Worker * \name Intra Mode Info
268*77c1e3ccSAndroid Build Coastguard Worker ****************************************************************************/
269*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
270*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Directional mode delta: the angle is base angle + (angle_delta *
271*77c1e3ccSAndroid Build Coastguard Worker * step). */
272*77c1e3ccSAndroid Build Coastguard Worker int8_t angle_delta[PLANE_TYPES];
273*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The type of filter intra mode used (if applicable). */
274*77c1e3ccSAndroid Build Coastguard Worker FILTER_INTRA_MODE_INFO filter_intra_mode_info;
275*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Chroma from Luma: Joint sign of alpha Cb and alpha Cr */
276*77c1e3ccSAndroid Build Coastguard Worker int8_t cfl_alpha_signs;
277*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Chroma from Luma: Index of the alpha Cb and alpha Cr combination */
278*77c1e3ccSAndroid Build Coastguard Worker uint8_t cfl_alpha_idx;
279*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Stores the size and colors of palette mode */
280*77c1e3ccSAndroid Build Coastguard Worker PALETTE_MODE_INFO palette_mode_info;
281*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
282*77c1e3ccSAndroid Build Coastguard Worker
283*77c1e3ccSAndroid Build Coastguard Worker /*****************************************************************************
284*77c1e3ccSAndroid Build Coastguard Worker * \name Transform Info
285*77c1e3ccSAndroid Build Coastguard Worker ****************************************************************************/
286*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
287*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Whether to skip transforming and sending. */
288*77c1e3ccSAndroid Build Coastguard Worker uint8_t skip_txfm;
289*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Transform size when fixed size txfm is used (e.g. intra modes). */
290*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size;
291*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Transform size when recursive txfm tree is on. */
292*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE inter_tx_size[INTER_TX_SIZE_BUF_LEN];
293*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
294*77c1e3ccSAndroid Build Coastguard Worker
295*77c1e3ccSAndroid Build Coastguard Worker /*****************************************************************************
296*77c1e3ccSAndroid Build Coastguard Worker * \name Loop Filter Info
297*77c1e3ccSAndroid Build Coastguard Worker ****************************************************************************/
298*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
299*77c1e3ccSAndroid Build Coastguard Worker /*! \copydoc MACROBLOCKD::delta_lf_from_base */
300*77c1e3ccSAndroid Build Coastguard Worker int8_t delta_lf_from_base;
301*77c1e3ccSAndroid Build Coastguard Worker /*! \copydoc MACROBLOCKD::delta_lf */
302*77c1e3ccSAndroid Build Coastguard Worker int8_t delta_lf[FRAME_LF_COUNT];
303*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
304*77c1e3ccSAndroid Build Coastguard Worker
305*77c1e3ccSAndroid Build Coastguard Worker /*****************************************************************************
306*77c1e3ccSAndroid Build Coastguard Worker * \name Bitfield for Memory Reduction
307*77c1e3ccSAndroid Build Coastguard Worker ****************************************************************************/
308*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
309*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The segment id */
310*77c1e3ccSAndroid Build Coastguard Worker uint8_t segment_id : 3;
311*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Only valid when temporal update if off. */
312*77c1e3ccSAndroid Build Coastguard Worker uint8_t seg_id_predicted : 1;
313*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Which ref_mv to use */
314*77c1e3ccSAndroid Build Coastguard Worker uint8_t ref_mv_idx : 2;
315*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Inter skip mode */
316*77c1e3ccSAndroid Build Coastguard Worker uint8_t skip_mode : 1;
317*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Whether intrabc is used. */
318*77c1e3ccSAndroid Build Coastguard Worker uint8_t use_intrabc : 1;
319*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Indicates if masked compound is used(1) or not (0). */
320*77c1e3ccSAndroid Build Coastguard Worker uint8_t comp_group_idx : 1;
321*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Indicates whether dist_wtd_comp(0) is used or not (0). */
322*77c1e3ccSAndroid Build Coastguard Worker uint8_t compound_idx : 1;
323*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Whether to use interintra wedge */
324*77c1e3ccSAndroid Build Coastguard Worker uint8_t use_wedge_interintra : 1;
325*77c1e3ccSAndroid Build Coastguard Worker /*! \brief CDEF strength per BLOCK_64X64 */
326*77c1e3ccSAndroid Build Coastguard Worker int8_t cdef_strength : 4;
327*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
328*77c1e3ccSAndroid Build Coastguard Worker
329*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RD_DEBUG
330*77c1e3ccSAndroid Build Coastguard Worker /*! \brief RD info used for debugging */
331*77c1e3ccSAndroid Build Coastguard Worker RD_STATS rd_stats;
332*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The current row in unit of 4x4 blocks for debugging */
333*77c1e3ccSAndroid Build Coastguard Worker int mi_row;
334*77c1e3ccSAndroid Build Coastguard Worker /*! \brief The current col in unit of 4x4 blocks for debugging */
335*77c1e3ccSAndroid Build Coastguard Worker int mi_col;
336*77c1e3ccSAndroid Build Coastguard Worker #endif
337*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_INSPECTION
338*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Whether we are skipping the current rows or columns. */
339*77c1e3ccSAndroid Build Coastguard Worker int16_t tx_skip[TXK_TYPE_BUF_LEN];
340*77c1e3ccSAndroid Build Coastguard Worker #endif
341*77c1e3ccSAndroid Build Coastguard Worker } MB_MODE_INFO;
342*77c1e3ccSAndroid Build Coastguard Worker
343*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
344*77c1e3ccSAndroid Build Coastguard Worker
is_intrabc_block(const MB_MODE_INFO * mbmi)345*77c1e3ccSAndroid Build Coastguard Worker static inline int is_intrabc_block(const MB_MODE_INFO *mbmi) {
346*77c1e3ccSAndroid Build Coastguard Worker return mbmi->use_intrabc;
347*77c1e3ccSAndroid Build Coastguard Worker }
348*77c1e3ccSAndroid Build Coastguard Worker
get_uv_mode(UV_PREDICTION_MODE mode)349*77c1e3ccSAndroid Build Coastguard Worker static inline PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) {
350*77c1e3ccSAndroid Build Coastguard Worker assert(mode < UV_INTRA_MODES);
351*77c1e3ccSAndroid Build Coastguard Worker static const PREDICTION_MODE uv2y[] = {
352*77c1e3ccSAndroid Build Coastguard Worker DC_PRED, // UV_DC_PRED
353*77c1e3ccSAndroid Build Coastguard Worker V_PRED, // UV_V_PRED
354*77c1e3ccSAndroid Build Coastguard Worker H_PRED, // UV_H_PRED
355*77c1e3ccSAndroid Build Coastguard Worker D45_PRED, // UV_D45_PRED
356*77c1e3ccSAndroid Build Coastguard Worker D135_PRED, // UV_D135_PRED
357*77c1e3ccSAndroid Build Coastguard Worker D113_PRED, // UV_D113_PRED
358*77c1e3ccSAndroid Build Coastguard Worker D157_PRED, // UV_D157_PRED
359*77c1e3ccSAndroid Build Coastguard Worker D203_PRED, // UV_D203_PRED
360*77c1e3ccSAndroid Build Coastguard Worker D67_PRED, // UV_D67_PRED
361*77c1e3ccSAndroid Build Coastguard Worker SMOOTH_PRED, // UV_SMOOTH_PRED
362*77c1e3ccSAndroid Build Coastguard Worker SMOOTH_V_PRED, // UV_SMOOTH_V_PRED
363*77c1e3ccSAndroid Build Coastguard Worker SMOOTH_H_PRED, // UV_SMOOTH_H_PRED
364*77c1e3ccSAndroid Build Coastguard Worker PAETH_PRED, // UV_PAETH_PRED
365*77c1e3ccSAndroid Build Coastguard Worker DC_PRED, // UV_CFL_PRED
366*77c1e3ccSAndroid Build Coastguard Worker INTRA_INVALID, // UV_INTRA_MODES
367*77c1e3ccSAndroid Build Coastguard Worker INTRA_INVALID, // UV_MODE_INVALID
368*77c1e3ccSAndroid Build Coastguard Worker };
369*77c1e3ccSAndroid Build Coastguard Worker return uv2y[mode];
370*77c1e3ccSAndroid Build Coastguard Worker }
371*77c1e3ccSAndroid Build Coastguard Worker
is_inter_block(const MB_MODE_INFO * mbmi)372*77c1e3ccSAndroid Build Coastguard Worker static inline int is_inter_block(const MB_MODE_INFO *mbmi) {
373*77c1e3ccSAndroid Build Coastguard Worker return is_intrabc_block(mbmi) || mbmi->ref_frame[0] > INTRA_FRAME;
374*77c1e3ccSAndroid Build Coastguard Worker }
375*77c1e3ccSAndroid Build Coastguard Worker
has_second_ref(const MB_MODE_INFO * mbmi)376*77c1e3ccSAndroid Build Coastguard Worker static inline int has_second_ref(const MB_MODE_INFO *mbmi) {
377*77c1e3ccSAndroid Build Coastguard Worker return mbmi->ref_frame[1] > INTRA_FRAME;
378*77c1e3ccSAndroid Build Coastguard Worker }
379*77c1e3ccSAndroid Build Coastguard Worker
has_uni_comp_refs(const MB_MODE_INFO * mbmi)380*77c1e3ccSAndroid Build Coastguard Worker static inline int has_uni_comp_refs(const MB_MODE_INFO *mbmi) {
381*77c1e3ccSAndroid Build Coastguard Worker return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^
382*77c1e3ccSAndroid Build Coastguard Worker (mbmi->ref_frame[1] >= BWDREF_FRAME)));
383*77c1e3ccSAndroid Build Coastguard Worker }
384*77c1e3ccSAndroid Build Coastguard Worker
comp_ref0(int ref_idx)385*77c1e3ccSAndroid Build Coastguard Worker static inline MV_REFERENCE_FRAME comp_ref0(int ref_idx) {
386*77c1e3ccSAndroid Build Coastguard Worker static const MV_REFERENCE_FRAME lut[] = {
387*77c1e3ccSAndroid Build Coastguard Worker LAST_FRAME, // LAST_LAST2_FRAMES,
388*77c1e3ccSAndroid Build Coastguard Worker LAST_FRAME, // LAST_LAST3_FRAMES,
389*77c1e3ccSAndroid Build Coastguard Worker LAST_FRAME, // LAST_GOLDEN_FRAMES,
390*77c1e3ccSAndroid Build Coastguard Worker BWDREF_FRAME, // BWDREF_ALTREF_FRAMES,
391*77c1e3ccSAndroid Build Coastguard Worker LAST2_FRAME, // LAST2_LAST3_FRAMES
392*77c1e3ccSAndroid Build Coastguard Worker LAST2_FRAME, // LAST2_GOLDEN_FRAMES,
393*77c1e3ccSAndroid Build Coastguard Worker LAST3_FRAME, // LAST3_GOLDEN_FRAMES,
394*77c1e3ccSAndroid Build Coastguard Worker BWDREF_FRAME, // BWDREF_ALTREF2_FRAMES,
395*77c1e3ccSAndroid Build Coastguard Worker ALTREF2_FRAME, // ALTREF2_ALTREF_FRAMES,
396*77c1e3ccSAndroid Build Coastguard Worker };
397*77c1e3ccSAndroid Build Coastguard Worker assert(NELEMENTS(lut) == TOTAL_UNIDIR_COMP_REFS);
398*77c1e3ccSAndroid Build Coastguard Worker return lut[ref_idx];
399*77c1e3ccSAndroid Build Coastguard Worker }
400*77c1e3ccSAndroid Build Coastguard Worker
comp_ref1(int ref_idx)401*77c1e3ccSAndroid Build Coastguard Worker static inline MV_REFERENCE_FRAME comp_ref1(int ref_idx) {
402*77c1e3ccSAndroid Build Coastguard Worker static const MV_REFERENCE_FRAME lut[] = {
403*77c1e3ccSAndroid Build Coastguard Worker LAST2_FRAME, // LAST_LAST2_FRAMES,
404*77c1e3ccSAndroid Build Coastguard Worker LAST3_FRAME, // LAST_LAST3_FRAMES,
405*77c1e3ccSAndroid Build Coastguard Worker GOLDEN_FRAME, // LAST_GOLDEN_FRAMES,
406*77c1e3ccSAndroid Build Coastguard Worker ALTREF_FRAME, // BWDREF_ALTREF_FRAMES,
407*77c1e3ccSAndroid Build Coastguard Worker LAST3_FRAME, // LAST2_LAST3_FRAMES
408*77c1e3ccSAndroid Build Coastguard Worker GOLDEN_FRAME, // LAST2_GOLDEN_FRAMES,
409*77c1e3ccSAndroid Build Coastguard Worker GOLDEN_FRAME, // LAST3_GOLDEN_FRAMES,
410*77c1e3ccSAndroid Build Coastguard Worker ALTREF2_FRAME, // BWDREF_ALTREF2_FRAMES,
411*77c1e3ccSAndroid Build Coastguard Worker ALTREF_FRAME, // ALTREF2_ALTREF_FRAMES,
412*77c1e3ccSAndroid Build Coastguard Worker };
413*77c1e3ccSAndroid Build Coastguard Worker assert(NELEMENTS(lut) == TOTAL_UNIDIR_COMP_REFS);
414*77c1e3ccSAndroid Build Coastguard Worker return lut[ref_idx];
415*77c1e3ccSAndroid Build Coastguard Worker }
416*77c1e3ccSAndroid Build Coastguard Worker
417*77c1e3ccSAndroid Build Coastguard Worker PREDICTION_MODE av1_left_block_mode(const MB_MODE_INFO *left_mi);
418*77c1e3ccSAndroid Build Coastguard Worker
419*77c1e3ccSAndroid Build Coastguard Worker PREDICTION_MODE av1_above_block_mode(const MB_MODE_INFO *above_mi);
420*77c1e3ccSAndroid Build Coastguard Worker
is_global_mv_block(const MB_MODE_INFO * const mbmi,TransformationType type)421*77c1e3ccSAndroid Build Coastguard Worker static inline int is_global_mv_block(const MB_MODE_INFO *const mbmi,
422*77c1e3ccSAndroid Build Coastguard Worker TransformationType type) {
423*77c1e3ccSAndroid Build Coastguard Worker const PREDICTION_MODE mode = mbmi->mode;
424*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE bsize = mbmi->bsize;
425*77c1e3ccSAndroid Build Coastguard Worker const int block_size_allowed =
426*77c1e3ccSAndroid Build Coastguard Worker AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
427*77c1e3ccSAndroid Build Coastguard Worker return (mode == GLOBALMV || mode == GLOBAL_GLOBALMV) && type > TRANSLATION &&
428*77c1e3ccSAndroid Build Coastguard Worker block_size_allowed;
429*77c1e3ccSAndroid Build Coastguard Worker }
430*77c1e3ccSAndroid Build Coastguard Worker
431*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MISMATCH_DEBUG
mi_to_pixel_loc(int * pixel_c,int * pixel_r,int mi_col,int mi_row,int tx_blk_col,int tx_blk_row,int subsampling_x,int subsampling_y)432*77c1e3ccSAndroid Build Coastguard Worker static inline void mi_to_pixel_loc(int *pixel_c, int *pixel_r, int mi_col,
433*77c1e3ccSAndroid Build Coastguard Worker int mi_row, int tx_blk_col, int tx_blk_row,
434*77c1e3ccSAndroid Build Coastguard Worker int subsampling_x, int subsampling_y) {
435*77c1e3ccSAndroid Build Coastguard Worker *pixel_c = ((mi_col >> subsampling_x) << MI_SIZE_LOG2) +
436*77c1e3ccSAndroid Build Coastguard Worker (tx_blk_col << MI_SIZE_LOG2);
437*77c1e3ccSAndroid Build Coastguard Worker *pixel_r = ((mi_row >> subsampling_y) << MI_SIZE_LOG2) +
438*77c1e3ccSAndroid Build Coastguard Worker (tx_blk_row << MI_SIZE_LOG2);
439*77c1e3ccSAndroid Build Coastguard Worker }
440*77c1e3ccSAndroid Build Coastguard Worker #endif
441*77c1e3ccSAndroid Build Coastguard Worker
442*77c1e3ccSAndroid Build Coastguard Worker enum { MV_PRECISION_Q3, MV_PRECISION_Q4 } UENUM1BYTE(mv_precision);
443*77c1e3ccSAndroid Build Coastguard Worker
444*77c1e3ccSAndroid Build Coastguard Worker struct buf_2d {
445*77c1e3ccSAndroid Build Coastguard Worker uint8_t *buf;
446*77c1e3ccSAndroid Build Coastguard Worker uint8_t *buf0;
447*77c1e3ccSAndroid Build Coastguard Worker int width;
448*77c1e3ccSAndroid Build Coastguard Worker int height;
449*77c1e3ccSAndroid Build Coastguard Worker int stride;
450*77c1e3ccSAndroid Build Coastguard Worker };
451*77c1e3ccSAndroid Build Coastguard Worker
452*77c1e3ccSAndroid Build Coastguard Worker typedef struct eob_info {
453*77c1e3ccSAndroid Build Coastguard Worker uint16_t eob;
454*77c1e3ccSAndroid Build Coastguard Worker uint16_t max_scan_line;
455*77c1e3ccSAndroid Build Coastguard Worker } eob_info;
456*77c1e3ccSAndroid Build Coastguard Worker
457*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
458*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, tran_low_t, dqcoeff[MAX_MB_PLANE][MAX_SB_SQUARE]);
459*77c1e3ccSAndroid Build Coastguard Worker eob_info eob_data[MAX_MB_PLANE]
460*77c1e3ccSAndroid Build Coastguard Worker [MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)];
461*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
462*77c1e3ccSAndroid Build Coastguard Worker } CB_BUFFER;
463*77c1e3ccSAndroid Build Coastguard Worker
464*77c1e3ccSAndroid Build Coastguard Worker typedef struct macroblockd_plane {
465*77c1e3ccSAndroid Build Coastguard Worker PLANE_TYPE plane_type;
466*77c1e3ccSAndroid Build Coastguard Worker int subsampling_x;
467*77c1e3ccSAndroid Build Coastguard Worker int subsampling_y;
468*77c1e3ccSAndroid Build Coastguard Worker struct buf_2d dst;
469*77c1e3ccSAndroid Build Coastguard Worker struct buf_2d pre[2];
470*77c1e3ccSAndroid Build Coastguard Worker ENTROPY_CONTEXT *above_entropy_context;
471*77c1e3ccSAndroid Build Coastguard Worker ENTROPY_CONTEXT *left_entropy_context;
472*77c1e3ccSAndroid Build Coastguard Worker
473*77c1e3ccSAndroid Build Coastguard Worker // The dequantizers below are true dequantizers used only in the
474*77c1e3ccSAndroid Build Coastguard Worker // dequantization process. They have the same coefficient
475*77c1e3ccSAndroid Build Coastguard Worker // shift/scale as TX.
476*77c1e3ccSAndroid Build Coastguard Worker int16_t seg_dequant_QTX[MAX_SEGMENTS][2];
477*77c1e3ccSAndroid Build Coastguard Worker // Pointer to color index map of:
478*77c1e3ccSAndroid Build Coastguard Worker // - Current coding block, on encoder side.
479*77c1e3ccSAndroid Build Coastguard Worker // - Current superblock, on decoder side.
480*77c1e3ccSAndroid Build Coastguard Worker uint8_t *color_index_map;
481*77c1e3ccSAndroid Build Coastguard Worker
482*77c1e3ccSAndroid Build Coastguard Worker // block size in pixels
483*77c1e3ccSAndroid Build Coastguard Worker uint8_t width, height;
484*77c1e3ccSAndroid Build Coastguard Worker
485*77c1e3ccSAndroid Build Coastguard Worker qm_val_t *seg_iqmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
486*77c1e3ccSAndroid Build Coastguard Worker qm_val_t *seg_qmatrix[MAX_SEGMENTS][TX_SIZES_ALL];
487*77c1e3ccSAndroid Build Coastguard Worker } MACROBLOCKD_PLANE;
488*77c1e3ccSAndroid Build Coastguard Worker
489*77c1e3ccSAndroid Build Coastguard Worker #define BLOCK_OFFSET(i) ((i) << 4)
490*77c1e3ccSAndroid Build Coastguard Worker
491*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
492*77c1e3ccSAndroid Build Coastguard Worker
493*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Parameters related to Wiener Filter */
494*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
495*77c1e3ccSAndroid Build Coastguard Worker /*!
496*77c1e3ccSAndroid Build Coastguard Worker * Vertical filter kernel.
497*77c1e3ccSAndroid Build Coastguard Worker */
498*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(16, InterpKernel, vfilter);
499*77c1e3ccSAndroid Build Coastguard Worker
500*77c1e3ccSAndroid Build Coastguard Worker /*!
501*77c1e3ccSAndroid Build Coastguard Worker * Horizontal filter kernel.
502*77c1e3ccSAndroid Build Coastguard Worker */
503*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(16, InterpKernel, hfilter);
504*77c1e3ccSAndroid Build Coastguard Worker } WienerInfo;
505*77c1e3ccSAndroid Build Coastguard Worker
506*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Parameters related to Sgrproj Filter */
507*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
508*77c1e3ccSAndroid Build Coastguard Worker /*!
509*77c1e3ccSAndroid Build Coastguard Worker * Parameter index.
510*77c1e3ccSAndroid Build Coastguard Worker */
511*77c1e3ccSAndroid Build Coastguard Worker int ep;
512*77c1e3ccSAndroid Build Coastguard Worker
513*77c1e3ccSAndroid Build Coastguard Worker /*!
514*77c1e3ccSAndroid Build Coastguard Worker * Weights for linear combination of filtered versions
515*77c1e3ccSAndroid Build Coastguard Worker */
516*77c1e3ccSAndroid Build Coastguard Worker int xqd[2];
517*77c1e3ccSAndroid Build Coastguard Worker } SgrprojInfo;
518*77c1e3ccSAndroid Build Coastguard Worker
519*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
520*77c1e3ccSAndroid Build Coastguard Worker
521*77c1e3ccSAndroid Build Coastguard Worker #define CFL_MAX_BLOCK_SIZE (BLOCK_32X32)
522*77c1e3ccSAndroid Build Coastguard Worker #define CFL_BUF_LINE (32)
523*77c1e3ccSAndroid Build Coastguard Worker #define CFL_BUF_LINE_I128 (CFL_BUF_LINE >> 3)
524*77c1e3ccSAndroid Build Coastguard Worker #define CFL_BUF_LINE_I256 (CFL_BUF_LINE >> 4)
525*77c1e3ccSAndroid Build Coastguard Worker #define CFL_BUF_SQUARE (CFL_BUF_LINE * CFL_BUF_LINE)
526*77c1e3ccSAndroid Build Coastguard Worker typedef struct cfl_ctx {
527*77c1e3ccSAndroid Build Coastguard Worker // Q3 reconstructed luma pixels (only Q2 is required, but Q3 is used to avoid
528*77c1e3ccSAndroid Build Coastguard Worker // shifts)
529*77c1e3ccSAndroid Build Coastguard Worker uint16_t recon_buf_q3[CFL_BUF_SQUARE];
530*77c1e3ccSAndroid Build Coastguard Worker // Q3 AC contributions (reconstructed luma pixels - tx block avg)
531*77c1e3ccSAndroid Build Coastguard Worker int16_t ac_buf_q3[CFL_BUF_SQUARE];
532*77c1e3ccSAndroid Build Coastguard Worker
533*77c1e3ccSAndroid Build Coastguard Worker // Cache the DC_PRED when performing RDO, so it does not have to be recomputed
534*77c1e3ccSAndroid Build Coastguard Worker // for every scaling parameter
535*77c1e3ccSAndroid Build Coastguard Worker bool dc_pred_is_cached[CFL_PRED_PLANES];
536*77c1e3ccSAndroid Build Coastguard Worker // Whether the DC_PRED cache is enabled. The DC_PRED cache is disabled when
537*77c1e3ccSAndroid Build Coastguard Worker // decoding.
538*77c1e3ccSAndroid Build Coastguard Worker bool use_dc_pred_cache;
539*77c1e3ccSAndroid Build Coastguard Worker // Only cache the first row of the DC_PRED
540*77c1e3ccSAndroid Build Coastguard Worker int16_t dc_pred_cache[CFL_PRED_PLANES][CFL_BUF_LINE];
541*77c1e3ccSAndroid Build Coastguard Worker
542*77c1e3ccSAndroid Build Coastguard Worker // Height and width currently used in the CfL prediction buffer.
543*77c1e3ccSAndroid Build Coastguard Worker int buf_height, buf_width;
544*77c1e3ccSAndroid Build Coastguard Worker
545*77c1e3ccSAndroid Build Coastguard Worker int are_parameters_computed;
546*77c1e3ccSAndroid Build Coastguard Worker
547*77c1e3ccSAndroid Build Coastguard Worker // Chroma subsampling
548*77c1e3ccSAndroid Build Coastguard Worker int subsampling_x, subsampling_y;
549*77c1e3ccSAndroid Build Coastguard Worker
550*77c1e3ccSAndroid Build Coastguard Worker // Whether the reconstructed luma pixels need to be stored
551*77c1e3ccSAndroid Build Coastguard Worker int store_y;
552*77c1e3ccSAndroid Build Coastguard Worker } CFL_CTX;
553*77c1e3ccSAndroid Build Coastguard Worker
554*77c1e3ccSAndroid Build Coastguard Worker typedef struct dist_wtd_comp_params {
555*77c1e3ccSAndroid Build Coastguard Worker int use_dist_wtd_comp_avg;
556*77c1e3ccSAndroid Build Coastguard Worker int fwd_offset;
557*77c1e3ccSAndroid Build Coastguard Worker int bck_offset;
558*77c1e3ccSAndroid Build Coastguard Worker } DIST_WTD_COMP_PARAMS;
559*77c1e3ccSAndroid Build Coastguard Worker
560*77c1e3ccSAndroid Build Coastguard Worker struct scale_factors;
561*77c1e3ccSAndroid Build Coastguard Worker
562*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
563*77c1e3ccSAndroid Build Coastguard Worker
564*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Variables related to current coding block.
565*77c1e3ccSAndroid Build Coastguard Worker *
566*77c1e3ccSAndroid Build Coastguard Worker * This is a common set of variables used by both encoder and decoder.
567*77c1e3ccSAndroid Build Coastguard Worker * Most/all of the pointers are mere pointers to actual arrays are allocated
568*77c1e3ccSAndroid Build Coastguard Worker * elsewhere. This is mostly for coding convenience.
569*77c1e3ccSAndroid Build Coastguard Worker */
570*77c1e3ccSAndroid Build Coastguard Worker typedef struct macroblockd {
571*77c1e3ccSAndroid Build Coastguard Worker /**
572*77c1e3ccSAndroid Build Coastguard Worker * \name Position of current macroblock in mi units
573*77c1e3ccSAndroid Build Coastguard Worker */
574*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
575*77c1e3ccSAndroid Build Coastguard Worker int mi_row; /*!< Row position in mi units. */
576*77c1e3ccSAndroid Build Coastguard Worker int mi_col; /*!< Column position in mi units. */
577*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
578*77c1e3ccSAndroid Build Coastguard Worker
579*77c1e3ccSAndroid Build Coastguard Worker /*!
580*77c1e3ccSAndroid Build Coastguard Worker * Same as cm->mi_params.mi_stride, copied here for convenience.
581*77c1e3ccSAndroid Build Coastguard Worker */
582*77c1e3ccSAndroid Build Coastguard Worker int mi_stride;
583*77c1e3ccSAndroid Build Coastguard Worker
584*77c1e3ccSAndroid Build Coastguard Worker /*!
585*77c1e3ccSAndroid Build Coastguard Worker * True if current block transmits chroma information.
586*77c1e3ccSAndroid Build Coastguard Worker * More detail:
587*77c1e3ccSAndroid Build Coastguard Worker * Smallest supported block size for both luma and chroma plane is 4x4. Hence,
588*77c1e3ccSAndroid Build Coastguard Worker * in case of subsampled chroma plane (YUV 4:2:0 or YUV 4:2:2), multiple luma
589*77c1e3ccSAndroid Build Coastguard Worker * blocks smaller than 8x8 maybe combined into one chroma block.
590*77c1e3ccSAndroid Build Coastguard Worker * For example, for YUV 4:2:0, let's say an 8x8 area is split into four 4x4
591*77c1e3ccSAndroid Build Coastguard Worker * luma blocks. Then, a single chroma block of size 4x4 will cover the area of
592*77c1e3ccSAndroid Build Coastguard Worker * these four luma blocks. This is implemented in bitstream as follows:
593*77c1e3ccSAndroid Build Coastguard Worker * - There are four MB_MODE_INFO structs for the four luma blocks.
594*77c1e3ccSAndroid Build Coastguard Worker * - First 3 MB_MODE_INFO have is_chroma_ref = false, and so do not transmit
595*77c1e3ccSAndroid Build Coastguard Worker * any information for chroma planes.
596*77c1e3ccSAndroid Build Coastguard Worker * - Last block will have is_chroma_ref = true and transmits chroma
597*77c1e3ccSAndroid Build Coastguard Worker * information for the 4x4 chroma block that covers whole 8x8 area covered by
598*77c1e3ccSAndroid Build Coastguard Worker * four luma blocks.
599*77c1e3ccSAndroid Build Coastguard Worker * Similar logic applies for chroma blocks that cover 2 or 3 luma blocks.
600*77c1e3ccSAndroid Build Coastguard Worker */
601*77c1e3ccSAndroid Build Coastguard Worker bool is_chroma_ref;
602*77c1e3ccSAndroid Build Coastguard Worker
603*77c1e3ccSAndroid Build Coastguard Worker /*!
604*77c1e3ccSAndroid Build Coastguard Worker * Info specific to each plane.
605*77c1e3ccSAndroid Build Coastguard Worker */
606*77c1e3ccSAndroid Build Coastguard Worker struct macroblockd_plane plane[MAX_MB_PLANE];
607*77c1e3ccSAndroid Build Coastguard Worker
608*77c1e3ccSAndroid Build Coastguard Worker /*!
609*77c1e3ccSAndroid Build Coastguard Worker * Tile related info.
610*77c1e3ccSAndroid Build Coastguard Worker */
611*77c1e3ccSAndroid Build Coastguard Worker TileInfo tile;
612*77c1e3ccSAndroid Build Coastguard Worker
613*77c1e3ccSAndroid Build Coastguard Worker /*!
614*77c1e3ccSAndroid Build Coastguard Worker * Appropriate offset inside cm->mi_params.mi_grid_base based on current
615*77c1e3ccSAndroid Build Coastguard Worker * mi_row and mi_col.
616*77c1e3ccSAndroid Build Coastguard Worker */
617*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO **mi;
618*77c1e3ccSAndroid Build Coastguard Worker
619*77c1e3ccSAndroid Build Coastguard Worker /*!
620*77c1e3ccSAndroid Build Coastguard Worker * True if 4x4 block above the current block is available.
621*77c1e3ccSAndroid Build Coastguard Worker */
622*77c1e3ccSAndroid Build Coastguard Worker bool up_available;
623*77c1e3ccSAndroid Build Coastguard Worker /*!
624*77c1e3ccSAndroid Build Coastguard Worker * True if 4x4 block to the left of the current block is available.
625*77c1e3ccSAndroid Build Coastguard Worker */
626*77c1e3ccSAndroid Build Coastguard Worker bool left_available;
627*77c1e3ccSAndroid Build Coastguard Worker /*!
628*77c1e3ccSAndroid Build Coastguard Worker * True if the above chrome reference block is available.
629*77c1e3ccSAndroid Build Coastguard Worker */
630*77c1e3ccSAndroid Build Coastguard Worker bool chroma_up_available;
631*77c1e3ccSAndroid Build Coastguard Worker /*!
632*77c1e3ccSAndroid Build Coastguard Worker * True if the left chrome reference block is available.
633*77c1e3ccSAndroid Build Coastguard Worker */
634*77c1e3ccSAndroid Build Coastguard Worker bool chroma_left_available;
635*77c1e3ccSAndroid Build Coastguard Worker
636*77c1e3ccSAndroid Build Coastguard Worker /*!
637*77c1e3ccSAndroid Build Coastguard Worker * MB_MODE_INFO for 4x4 block to the left of the current block, if
638*77c1e3ccSAndroid Build Coastguard Worker * left_available == true; otherwise NULL.
639*77c1e3ccSAndroid Build Coastguard Worker */
640*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO *left_mbmi;
641*77c1e3ccSAndroid Build Coastguard Worker /*!
642*77c1e3ccSAndroid Build Coastguard Worker * MB_MODE_INFO for 4x4 block above the current block, if
643*77c1e3ccSAndroid Build Coastguard Worker * up_available == true; otherwise NULL.
644*77c1e3ccSAndroid Build Coastguard Worker */
645*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO *above_mbmi;
646*77c1e3ccSAndroid Build Coastguard Worker /*!
647*77c1e3ccSAndroid Build Coastguard Worker * Above chroma reference block if is_chroma_ref == true for the current block
648*77c1e3ccSAndroid Build Coastguard Worker * and chroma_up_available == true; otherwise NULL.
649*77c1e3ccSAndroid Build Coastguard Worker * See also: the special case logic when current chroma block covers more than
650*77c1e3ccSAndroid Build Coastguard Worker * one luma blocks in set_mi_row_col().
651*77c1e3ccSAndroid Build Coastguard Worker */
652*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO *chroma_left_mbmi;
653*77c1e3ccSAndroid Build Coastguard Worker /*!
654*77c1e3ccSAndroid Build Coastguard Worker * Left chroma reference block if is_chroma_ref == true for the current block
655*77c1e3ccSAndroid Build Coastguard Worker * and chroma_left_available == true; otherwise NULL.
656*77c1e3ccSAndroid Build Coastguard Worker * See also: the special case logic when current chroma block covers more than
657*77c1e3ccSAndroid Build Coastguard Worker * one luma blocks in set_mi_row_col().
658*77c1e3ccSAndroid Build Coastguard Worker */
659*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO *chroma_above_mbmi;
660*77c1e3ccSAndroid Build Coastguard Worker
661*77c1e3ccSAndroid Build Coastguard Worker /*!
662*77c1e3ccSAndroid Build Coastguard Worker * Appropriate offset based on current 'mi_row' and 'mi_col', inside
663*77c1e3ccSAndroid Build Coastguard Worker * 'tx_type_map' in one of 'CommonModeInfoParams', 'PICK_MODE_CONTEXT' or
664*77c1e3ccSAndroid Build Coastguard Worker * 'MACROBLOCK' structs.
665*77c1e3ccSAndroid Build Coastguard Worker */
666*77c1e3ccSAndroid Build Coastguard Worker uint8_t *tx_type_map;
667*77c1e3ccSAndroid Build Coastguard Worker /*!
668*77c1e3ccSAndroid Build Coastguard Worker * Stride for 'tx_type_map'. Note that this may / may not be same as
669*77c1e3ccSAndroid Build Coastguard Worker * 'mi_stride', depending on which actual array 'tx_type_map' points to.
670*77c1e3ccSAndroid Build Coastguard Worker */
671*77c1e3ccSAndroid Build Coastguard Worker int tx_type_map_stride;
672*77c1e3ccSAndroid Build Coastguard Worker
673*77c1e3ccSAndroid Build Coastguard Worker /**
674*77c1e3ccSAndroid Build Coastguard Worker * \name Distance of this macroblock from frame edges in 1/8th pixel units.
675*77c1e3ccSAndroid Build Coastguard Worker */
676*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
677*77c1e3ccSAndroid Build Coastguard Worker int mb_to_left_edge; /*!< Distance from left edge */
678*77c1e3ccSAndroid Build Coastguard Worker int mb_to_right_edge; /*!< Distance from right edge */
679*77c1e3ccSAndroid Build Coastguard Worker int mb_to_top_edge; /*!< Distance from top edge */
680*77c1e3ccSAndroid Build Coastguard Worker int mb_to_bottom_edge; /*!< Distance from bottom edge */
681*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
682*77c1e3ccSAndroid Build Coastguard Worker
683*77c1e3ccSAndroid Build Coastguard Worker /*!
684*77c1e3ccSAndroid Build Coastguard Worker * Scale factors for reference frames of the current block.
685*77c1e3ccSAndroid Build Coastguard Worker * These are pointers into 'cm->ref_scale_factors'.
686*77c1e3ccSAndroid Build Coastguard Worker */
687*77c1e3ccSAndroid Build Coastguard Worker const struct scale_factors *block_ref_scale_factors[2];
688*77c1e3ccSAndroid Build Coastguard Worker
689*77c1e3ccSAndroid Build Coastguard Worker /*!
690*77c1e3ccSAndroid Build Coastguard Worker * - On encoder side: points to cpi->source, which is the buffer containing
691*77c1e3ccSAndroid Build Coastguard Worker * the current *source* frame (maybe filtered).
692*77c1e3ccSAndroid Build Coastguard Worker * - On decoder side: points to cm->cur_frame->buf, which is the buffer into
693*77c1e3ccSAndroid Build Coastguard Worker * which current frame is being *decoded*.
694*77c1e3ccSAndroid Build Coastguard Worker */
695*77c1e3ccSAndroid Build Coastguard Worker const YV12_BUFFER_CONFIG *cur_buf;
696*77c1e3ccSAndroid Build Coastguard Worker
697*77c1e3ccSAndroid Build Coastguard Worker /*!
698*77c1e3ccSAndroid Build Coastguard Worker * Entropy contexts for the above blocks.
699*77c1e3ccSAndroid Build Coastguard Worker * above_entropy_context[i][j] corresponds to above entropy context for ith
700*77c1e3ccSAndroid Build Coastguard Worker * plane and jth mi column of this *frame*, wrt current 'mi_row'.
701*77c1e3ccSAndroid Build Coastguard Worker * These are pointers into 'cm->above_contexts.entropy'.
702*77c1e3ccSAndroid Build Coastguard Worker */
703*77c1e3ccSAndroid Build Coastguard Worker ENTROPY_CONTEXT *above_entropy_context[MAX_MB_PLANE];
704*77c1e3ccSAndroid Build Coastguard Worker /*!
705*77c1e3ccSAndroid Build Coastguard Worker * Entropy contexts for the left blocks.
706*77c1e3ccSAndroid Build Coastguard Worker * left_entropy_context[i][j] corresponds to left entropy context for ith
707*77c1e3ccSAndroid Build Coastguard Worker * plane and jth mi row of this *superblock*, wrt current 'mi_col'.
708*77c1e3ccSAndroid Build Coastguard Worker * Note: These contain actual data, NOT pointers.
709*77c1e3ccSAndroid Build Coastguard Worker */
710*77c1e3ccSAndroid Build Coastguard Worker ENTROPY_CONTEXT left_entropy_context[MAX_MB_PLANE][MAX_MIB_SIZE];
711*77c1e3ccSAndroid Build Coastguard Worker
712*77c1e3ccSAndroid Build Coastguard Worker /*!
713*77c1e3ccSAndroid Build Coastguard Worker * Partition contexts for the above blocks.
714*77c1e3ccSAndroid Build Coastguard Worker * above_partition_context[i] corresponds to above partition context for ith
715*77c1e3ccSAndroid Build Coastguard Worker * mi column of this *frame*, wrt current 'mi_row'.
716*77c1e3ccSAndroid Build Coastguard Worker * This is a pointer into 'cm->above_contexts.partition'.
717*77c1e3ccSAndroid Build Coastguard Worker */
718*77c1e3ccSAndroid Build Coastguard Worker PARTITION_CONTEXT *above_partition_context;
719*77c1e3ccSAndroid Build Coastguard Worker /*!
720*77c1e3ccSAndroid Build Coastguard Worker * Partition contexts for the left blocks.
721*77c1e3ccSAndroid Build Coastguard Worker * left_partition_context[i] corresponds to left partition context for ith
722*77c1e3ccSAndroid Build Coastguard Worker * mi row of this *superblock*, wrt current 'mi_col'.
723*77c1e3ccSAndroid Build Coastguard Worker * Note: These contain actual data, NOT pointers.
724*77c1e3ccSAndroid Build Coastguard Worker */
725*77c1e3ccSAndroid Build Coastguard Worker PARTITION_CONTEXT left_partition_context[MAX_MIB_SIZE];
726*77c1e3ccSAndroid Build Coastguard Worker
727*77c1e3ccSAndroid Build Coastguard Worker /*!
728*77c1e3ccSAndroid Build Coastguard Worker * Transform contexts for the above blocks.
729*77c1e3ccSAndroid Build Coastguard Worker * above_txfm_context[i] corresponds to above transform context for ith mi col
730*77c1e3ccSAndroid Build Coastguard Worker * from the current position (mi row and mi column) for this *frame*.
731*77c1e3ccSAndroid Build Coastguard Worker * This is a pointer into 'cm->above_contexts.txfm'.
732*77c1e3ccSAndroid Build Coastguard Worker */
733*77c1e3ccSAndroid Build Coastguard Worker TXFM_CONTEXT *above_txfm_context;
734*77c1e3ccSAndroid Build Coastguard Worker /*!
735*77c1e3ccSAndroid Build Coastguard Worker * Transform contexts for the left blocks.
736*77c1e3ccSAndroid Build Coastguard Worker * left_txfm_context[i] corresponds to left transform context for ith mi row
737*77c1e3ccSAndroid Build Coastguard Worker * from the current position (mi_row and mi_col) for this *superblock*.
738*77c1e3ccSAndroid Build Coastguard Worker * This is a pointer into 'left_txfm_context_buffer'.
739*77c1e3ccSAndroid Build Coastguard Worker */
740*77c1e3ccSAndroid Build Coastguard Worker TXFM_CONTEXT *left_txfm_context;
741*77c1e3ccSAndroid Build Coastguard Worker /*!
742*77c1e3ccSAndroid Build Coastguard Worker * left_txfm_context_buffer[i] is the left transform context for ith mi_row
743*77c1e3ccSAndroid Build Coastguard Worker * in this *superblock*.
744*77c1e3ccSAndroid Build Coastguard Worker * Behaves like an internal actual buffer which 'left_txt_context' points to,
745*77c1e3ccSAndroid Build Coastguard Worker * and never accessed directly except to fill in initial default values.
746*77c1e3ccSAndroid Build Coastguard Worker */
747*77c1e3ccSAndroid Build Coastguard Worker TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE];
748*77c1e3ccSAndroid Build Coastguard Worker
749*77c1e3ccSAndroid Build Coastguard Worker /**
750*77c1e3ccSAndroid Build Coastguard Worker * \name Default values for the two restoration filters for each plane.
751*77c1e3ccSAndroid Build Coastguard Worker * Default values for the two restoration filters for each plane.
752*77c1e3ccSAndroid Build Coastguard Worker * These values are used as reference values when writing the bitstream. That
753*77c1e3ccSAndroid Build Coastguard Worker * is, we transmit the delta between the actual values in
754*77c1e3ccSAndroid Build Coastguard Worker * cm->rst_info[plane].unit_info[unit_idx] and these reference values.
755*77c1e3ccSAndroid Build Coastguard Worker */
756*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
757*77c1e3ccSAndroid Build Coastguard Worker WienerInfo wiener_info[MAX_MB_PLANE]; /*!< Defaults for Wiener filter*/
758*77c1e3ccSAndroid Build Coastguard Worker SgrprojInfo sgrproj_info[MAX_MB_PLANE]; /*!< Defaults for SGR filter */
759*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
760*77c1e3ccSAndroid Build Coastguard Worker
761*77c1e3ccSAndroid Build Coastguard Worker /**
762*77c1e3ccSAndroid Build Coastguard Worker * \name Block dimensions in MB_MODE_INFO units.
763*77c1e3ccSAndroid Build Coastguard Worker */
764*77c1e3ccSAndroid Build Coastguard Worker /**@{*/
765*77c1e3ccSAndroid Build Coastguard Worker uint8_t width; /*!< Block width in MB_MODE_INFO units */
766*77c1e3ccSAndroid Build Coastguard Worker uint8_t height; /*!< Block height in MB_MODE_INFO units */
767*77c1e3ccSAndroid Build Coastguard Worker /**@}*/
768*77c1e3ccSAndroid Build Coastguard Worker
769*77c1e3ccSAndroid Build Coastguard Worker /*!
770*77c1e3ccSAndroid Build Coastguard Worker * Contains the motion vector candidates found during motion vector prediction
771*77c1e3ccSAndroid Build Coastguard Worker * process. ref_mv_stack[i] contains the candidates for ith type of
772*77c1e3ccSAndroid Build Coastguard Worker * reference frame (single/compound). The actual number of candidates found in
773*77c1e3ccSAndroid Build Coastguard Worker * ref_mv_stack[i] is stored in either dcb->ref_mv_count[i] (decoder side)
774*77c1e3ccSAndroid Build Coastguard Worker * or mbmi_ext->ref_mv_count[i] (encoder side).
775*77c1e3ccSAndroid Build Coastguard Worker */
776*77c1e3ccSAndroid Build Coastguard Worker CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
777*77c1e3ccSAndroid Build Coastguard Worker /*!
778*77c1e3ccSAndroid Build Coastguard Worker * weight[i][j] is the weight for ref_mv_stack[i][j] and used to compute the
779*77c1e3ccSAndroid Build Coastguard Worker * DRL (dynamic reference list) mode contexts.
780*77c1e3ccSAndroid Build Coastguard Worker */
781*77c1e3ccSAndroid Build Coastguard Worker uint16_t weight[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
782*77c1e3ccSAndroid Build Coastguard Worker
783*77c1e3ccSAndroid Build Coastguard Worker /*!
784*77c1e3ccSAndroid Build Coastguard Worker * True if this is the last vertical rectangular block in a VERTICAL or
785*77c1e3ccSAndroid Build Coastguard Worker * VERTICAL_4 partition.
786*77c1e3ccSAndroid Build Coastguard Worker */
787*77c1e3ccSAndroid Build Coastguard Worker bool is_last_vertical_rect;
788*77c1e3ccSAndroid Build Coastguard Worker /*!
789*77c1e3ccSAndroid Build Coastguard Worker * True if this is the 1st horizontal rectangular block in a HORIZONTAL or
790*77c1e3ccSAndroid Build Coastguard Worker * HORIZONTAL_4 partition.
791*77c1e3ccSAndroid Build Coastguard Worker */
792*77c1e3ccSAndroid Build Coastguard Worker bool is_first_horizontal_rect;
793*77c1e3ccSAndroid Build Coastguard Worker
794*77c1e3ccSAndroid Build Coastguard Worker /*!
795*77c1e3ccSAndroid Build Coastguard Worker * Counts of each reference frame in the above and left neighboring blocks.
796*77c1e3ccSAndroid Build Coastguard Worker * NOTE: Take into account both single and comp references.
797*77c1e3ccSAndroid Build Coastguard Worker */
798*77c1e3ccSAndroid Build Coastguard Worker uint8_t neighbors_ref_counts[REF_FRAMES];
799*77c1e3ccSAndroid Build Coastguard Worker
800*77c1e3ccSAndroid Build Coastguard Worker /*!
801*77c1e3ccSAndroid Build Coastguard Worker * Current CDFs of all the symbols for the current tile.
802*77c1e3ccSAndroid Build Coastguard Worker */
803*77c1e3ccSAndroid Build Coastguard Worker FRAME_CONTEXT *tile_ctx;
804*77c1e3ccSAndroid Build Coastguard Worker
805*77c1e3ccSAndroid Build Coastguard Worker /*!
806*77c1e3ccSAndroid Build Coastguard Worker * Bit depth: copied from cm->seq_params->bit_depth for convenience.
807*77c1e3ccSAndroid Build Coastguard Worker */
808*77c1e3ccSAndroid Build Coastguard Worker int bd;
809*77c1e3ccSAndroid Build Coastguard Worker
810*77c1e3ccSAndroid Build Coastguard Worker /*!
811*77c1e3ccSAndroid Build Coastguard Worker * Quantizer index for each segment (base qindex + delta for each segment).
812*77c1e3ccSAndroid Build Coastguard Worker */
813*77c1e3ccSAndroid Build Coastguard Worker int qindex[MAX_SEGMENTS];
814*77c1e3ccSAndroid Build Coastguard Worker /*!
815*77c1e3ccSAndroid Build Coastguard Worker * lossless[s] is true if segment 's' is coded losslessly.
816*77c1e3ccSAndroid Build Coastguard Worker */
817*77c1e3ccSAndroid Build Coastguard Worker int lossless[MAX_SEGMENTS];
818*77c1e3ccSAndroid Build Coastguard Worker /*!
819*77c1e3ccSAndroid Build Coastguard Worker * Q index for the coding blocks in this superblock will be stored in
820*77c1e3ccSAndroid Build Coastguard Worker * mbmi->current_qindex. Now, when cm->delta_q_info.delta_q_present_flag is
821*77c1e3ccSAndroid Build Coastguard Worker * true, mbmi->current_qindex is computed by taking 'current_base_qindex' as
822*77c1e3ccSAndroid Build Coastguard Worker * the base, and adding any transmitted delta qindex on top of it.
823*77c1e3ccSAndroid Build Coastguard Worker * Precisely, this is the latest qindex used by the first coding block of a
824*77c1e3ccSAndroid Build Coastguard Worker * non-skip superblock in the current tile; OR
825*77c1e3ccSAndroid Build Coastguard Worker * same as cm->quant_params.base_qindex (if not explicitly set yet).
826*77c1e3ccSAndroid Build Coastguard Worker * Note: This is 'CurrentQIndex' in the AV1 spec.
827*77c1e3ccSAndroid Build Coastguard Worker */
828*77c1e3ccSAndroid Build Coastguard Worker int current_base_qindex;
829*77c1e3ccSAndroid Build Coastguard Worker
830*77c1e3ccSAndroid Build Coastguard Worker /*!
831*77c1e3ccSAndroid Build Coastguard Worker * Same as cm->features.cur_frame_force_integer_mv.
832*77c1e3ccSAndroid Build Coastguard Worker */
833*77c1e3ccSAndroid Build Coastguard Worker int cur_frame_force_integer_mv;
834*77c1e3ccSAndroid Build Coastguard Worker
835*77c1e3ccSAndroid Build Coastguard Worker /*!
836*77c1e3ccSAndroid Build Coastguard Worker * Pointer to cm->error.
837*77c1e3ccSAndroid Build Coastguard Worker */
838*77c1e3ccSAndroid Build Coastguard Worker struct aom_internal_error_info *error_info;
839*77c1e3ccSAndroid Build Coastguard Worker
840*77c1e3ccSAndroid Build Coastguard Worker /*!
841*77c1e3ccSAndroid Build Coastguard Worker * Same as cm->global_motion.
842*77c1e3ccSAndroid Build Coastguard Worker */
843*77c1e3ccSAndroid Build Coastguard Worker const WarpedMotionParams *global_motion;
844*77c1e3ccSAndroid Build Coastguard Worker
845*77c1e3ccSAndroid Build Coastguard Worker /*!
846*77c1e3ccSAndroid Build Coastguard Worker * Since actual frame level loop filtering level value is not available
847*77c1e3ccSAndroid Build Coastguard Worker * at the beginning of the tile (only available during actual filtering)
848*77c1e3ccSAndroid Build Coastguard Worker * at encoder side.we record the delta_lf (against the frame level loop
849*77c1e3ccSAndroid Build Coastguard Worker * filtering level) and code the delta between previous superblock's delta
850*77c1e3ccSAndroid Build Coastguard Worker * lf and current delta lf. It is equivalent to the delta between previous
851*77c1e3ccSAndroid Build Coastguard Worker * superblock's actual lf and current lf.
852*77c1e3ccSAndroid Build Coastguard Worker */
853*77c1e3ccSAndroid Build Coastguard Worker int8_t delta_lf_from_base;
854*77c1e3ccSAndroid Build Coastguard Worker /*!
855*77c1e3ccSAndroid Build Coastguard Worker * We have four frame filter levels for different plane and direction. So, to
856*77c1e3ccSAndroid Build Coastguard Worker * support the per superblock update, we need to add a few more params:
857*77c1e3ccSAndroid Build Coastguard Worker * 0. delta loop filter level for y plane vertical
858*77c1e3ccSAndroid Build Coastguard Worker * 1. delta loop filter level for y plane horizontal
859*77c1e3ccSAndroid Build Coastguard Worker * 2. delta loop filter level for u plane
860*77c1e3ccSAndroid Build Coastguard Worker * 3. delta loop filter level for v plane
861*77c1e3ccSAndroid Build Coastguard Worker * To make it consistent with the reference to each filter level in segment,
862*77c1e3ccSAndroid Build Coastguard Worker * we need to -1, since
863*77c1e3ccSAndroid Build Coastguard Worker * - SEG_LVL_ALT_LF_Y_V = 1;
864*77c1e3ccSAndroid Build Coastguard Worker * - SEG_LVL_ALT_LF_Y_H = 2;
865*77c1e3ccSAndroid Build Coastguard Worker * - SEG_LVL_ALT_LF_U = 3;
866*77c1e3ccSAndroid Build Coastguard Worker * - SEG_LVL_ALT_LF_V = 4;
867*77c1e3ccSAndroid Build Coastguard Worker */
868*77c1e3ccSAndroid Build Coastguard Worker int8_t delta_lf[FRAME_LF_COUNT];
869*77c1e3ccSAndroid Build Coastguard Worker /*!
870*77c1e3ccSAndroid Build Coastguard Worker * cdef_transmitted[i] is true if CDEF strength for ith CDEF unit in the
871*77c1e3ccSAndroid Build Coastguard Worker * current superblock has already been read from (decoder) / written to
872*77c1e3ccSAndroid Build Coastguard Worker * (encoder) the bitstream; and false otherwise.
873*77c1e3ccSAndroid Build Coastguard Worker * More detail:
874*77c1e3ccSAndroid Build Coastguard Worker * 1. CDEF strength is transmitted only once per CDEF unit, in the 1st
875*77c1e3ccSAndroid Build Coastguard Worker * non-skip coding block. So, we need this array to keep track of whether CDEF
876*77c1e3ccSAndroid Build Coastguard Worker * strengths for the given CDEF units have been transmitted yet or not.
877*77c1e3ccSAndroid Build Coastguard Worker * 2. Superblock size can be either 128x128 or 64x64, but CDEF unit size is
878*77c1e3ccSAndroid Build Coastguard Worker * fixed to be 64x64. So, there may be 4 CDEF units within a superblock (if
879*77c1e3ccSAndroid Build Coastguard Worker * superblock size is 128x128). Hence the array size is 4.
880*77c1e3ccSAndroid Build Coastguard Worker * 3. In the current implementation, CDEF strength for this CDEF unit is
881*77c1e3ccSAndroid Build Coastguard Worker * stored in the MB_MODE_INFO of the 1st block in this CDEF unit (inside
882*77c1e3ccSAndroid Build Coastguard Worker * cm->mi_params.mi_grid_base).
883*77c1e3ccSAndroid Build Coastguard Worker */
884*77c1e3ccSAndroid Build Coastguard Worker bool cdef_transmitted[4];
885*77c1e3ccSAndroid Build Coastguard Worker
886*77c1e3ccSAndroid Build Coastguard Worker /*!
887*77c1e3ccSAndroid Build Coastguard Worker * Mask for this block used for compound prediction.
888*77c1e3ccSAndroid Build Coastguard Worker */
889*77c1e3ccSAndroid Build Coastguard Worker uint8_t *seg_mask;
890*77c1e3ccSAndroid Build Coastguard Worker
891*77c1e3ccSAndroid Build Coastguard Worker /*!
892*77c1e3ccSAndroid Build Coastguard Worker * CFL (chroma from luma) related parameters.
893*77c1e3ccSAndroid Build Coastguard Worker */
894*77c1e3ccSAndroid Build Coastguard Worker CFL_CTX cfl;
895*77c1e3ccSAndroid Build Coastguard Worker
896*77c1e3ccSAndroid Build Coastguard Worker /*!
897*77c1e3ccSAndroid Build Coastguard Worker * Offset to plane[p].color_index_map.
898*77c1e3ccSAndroid Build Coastguard Worker * Currently:
899*77c1e3ccSAndroid Build Coastguard Worker * - On encoder side, this is always 0 as 'color_index_map' is allocated per
900*77c1e3ccSAndroid Build Coastguard Worker * *coding block* there.
901*77c1e3ccSAndroid Build Coastguard Worker * - On decoder side, this may be non-zero, as 'color_index_map' is a (static)
902*77c1e3ccSAndroid Build Coastguard Worker * memory pointing to the base of a *superblock* there, and we need an offset
903*77c1e3ccSAndroid Build Coastguard Worker * to it to get the color index map for current coding block.
904*77c1e3ccSAndroid Build Coastguard Worker */
905*77c1e3ccSAndroid Build Coastguard Worker uint16_t color_index_map_offset[2];
906*77c1e3ccSAndroid Build Coastguard Worker
907*77c1e3ccSAndroid Build Coastguard Worker /*!
908*77c1e3ccSAndroid Build Coastguard Worker * Temporary buffer used for convolution in case of compound reference only
909*77c1e3ccSAndroid Build Coastguard Worker * for (weighted or uniform) averaging operation.
910*77c1e3ccSAndroid Build Coastguard Worker * There are pointers to actual buffers allocated elsewhere: e.g.
911*77c1e3ccSAndroid Build Coastguard Worker * - In decoder, 'pbi->td.tmp_conv_dst' or
912*77c1e3ccSAndroid Build Coastguard Worker * 'pbi->thread_data[t].td->xd.tmp_conv_dst' and
913*77c1e3ccSAndroid Build Coastguard Worker * - In encoder, 'x->tmp_conv_dst' or
914*77c1e3ccSAndroid Build Coastguard Worker * 'cpi->tile_thr_data[t].td->mb.tmp_conv_dst'.
915*77c1e3ccSAndroid Build Coastguard Worker */
916*77c1e3ccSAndroid Build Coastguard Worker CONV_BUF_TYPE *tmp_conv_dst;
917*77c1e3ccSAndroid Build Coastguard Worker /*!
918*77c1e3ccSAndroid Build Coastguard Worker * Temporary buffers used to build OBMC prediction by above (index 0) and left
919*77c1e3ccSAndroid Build Coastguard Worker * (index 1) predictors respectively.
920*77c1e3ccSAndroid Build Coastguard Worker * tmp_obmc_bufs[i][p * MAX_SB_SQUARE] is the buffer used for plane 'p'.
921*77c1e3ccSAndroid Build Coastguard Worker * There are pointers to actual buffers allocated elsewhere: e.g.
922*77c1e3ccSAndroid Build Coastguard Worker * - In decoder, 'pbi->td.tmp_obmc_bufs' or
923*77c1e3ccSAndroid Build Coastguard Worker * 'pbi->thread_data[t].td->xd.tmp_conv_dst' and
924*77c1e3ccSAndroid Build Coastguard Worker * -In encoder, 'x->tmp_pred_bufs' or
925*77c1e3ccSAndroid Build Coastguard Worker * 'cpi->tile_thr_data[t].td->mb.tmp_pred_bufs'.
926*77c1e3ccSAndroid Build Coastguard Worker */
927*77c1e3ccSAndroid Build Coastguard Worker uint8_t *tmp_obmc_bufs[2];
928*77c1e3ccSAndroid Build Coastguard Worker } MACROBLOCKD;
929*77c1e3ccSAndroid Build Coastguard Worker
930*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
931*77c1e3ccSAndroid Build Coastguard Worker
is_cur_buf_hbd(const MACROBLOCKD * xd)932*77c1e3ccSAndroid Build Coastguard Worker static inline int is_cur_buf_hbd(const MACROBLOCKD *xd) {
933*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
934*77c1e3ccSAndroid Build Coastguard Worker return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0;
935*77c1e3ccSAndroid Build Coastguard Worker #else
936*77c1e3ccSAndroid Build Coastguard Worker (void)xd;
937*77c1e3ccSAndroid Build Coastguard Worker return 0;
938*77c1e3ccSAndroid Build Coastguard Worker #endif
939*77c1e3ccSAndroid Build Coastguard Worker }
940*77c1e3ccSAndroid Build Coastguard Worker
get_buf_by_bd(const MACROBLOCKD * xd,uint8_t * buf16)941*77c1e3ccSAndroid Build Coastguard Worker static inline uint8_t *get_buf_by_bd(const MACROBLOCKD *xd, uint8_t *buf16) {
942*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
943*77c1e3ccSAndroid Build Coastguard Worker return (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)
944*77c1e3ccSAndroid Build Coastguard Worker ? CONVERT_TO_BYTEPTR(buf16)
945*77c1e3ccSAndroid Build Coastguard Worker : buf16;
946*77c1e3ccSAndroid Build Coastguard Worker #else
947*77c1e3ccSAndroid Build Coastguard Worker (void)xd;
948*77c1e3ccSAndroid Build Coastguard Worker return buf16;
949*77c1e3ccSAndroid Build Coastguard Worker #endif
950*77c1e3ccSAndroid Build Coastguard Worker }
951*77c1e3ccSAndroid Build Coastguard Worker
952*77c1e3ccSAndroid Build Coastguard Worker typedef struct BitDepthInfo {
953*77c1e3ccSAndroid Build Coastguard Worker int bit_depth;
954*77c1e3ccSAndroid Build Coastguard Worker /*! Is the image buffer high bit depth?
955*77c1e3ccSAndroid Build Coastguard Worker * Low bit depth buffer uses uint8_t.
956*77c1e3ccSAndroid Build Coastguard Worker * High bit depth buffer uses uint16_t.
957*77c1e3ccSAndroid Build Coastguard Worker * Equivalent to cm->seq_params->use_highbitdepth
958*77c1e3ccSAndroid Build Coastguard Worker */
959*77c1e3ccSAndroid Build Coastguard Worker int use_highbitdepth_buf;
960*77c1e3ccSAndroid Build Coastguard Worker } BitDepthInfo;
961*77c1e3ccSAndroid Build Coastguard Worker
get_bit_depth_info(const MACROBLOCKD * xd)962*77c1e3ccSAndroid Build Coastguard Worker static inline BitDepthInfo get_bit_depth_info(const MACROBLOCKD *xd) {
963*77c1e3ccSAndroid Build Coastguard Worker BitDepthInfo bit_depth_info;
964*77c1e3ccSAndroid Build Coastguard Worker bit_depth_info.bit_depth = xd->bd;
965*77c1e3ccSAndroid Build Coastguard Worker bit_depth_info.use_highbitdepth_buf = is_cur_buf_hbd(xd);
966*77c1e3ccSAndroid Build Coastguard Worker assert(IMPLIES(!bit_depth_info.use_highbitdepth_buf,
967*77c1e3ccSAndroid Build Coastguard Worker bit_depth_info.bit_depth == 8));
968*77c1e3ccSAndroid Build Coastguard Worker return bit_depth_info;
969*77c1e3ccSAndroid Build Coastguard Worker }
970*77c1e3ccSAndroid Build Coastguard Worker
get_sqr_bsize_idx(BLOCK_SIZE bsize)971*77c1e3ccSAndroid Build Coastguard Worker static inline int get_sqr_bsize_idx(BLOCK_SIZE bsize) {
972*77c1e3ccSAndroid Build Coastguard Worker switch (bsize) {
973*77c1e3ccSAndroid Build Coastguard Worker case BLOCK_4X4: return 0;
974*77c1e3ccSAndroid Build Coastguard Worker case BLOCK_8X8: return 1;
975*77c1e3ccSAndroid Build Coastguard Worker case BLOCK_16X16: return 2;
976*77c1e3ccSAndroid Build Coastguard Worker case BLOCK_32X32: return 3;
977*77c1e3ccSAndroid Build Coastguard Worker case BLOCK_64X64: return 4;
978*77c1e3ccSAndroid Build Coastguard Worker case BLOCK_128X128: return 5;
979*77c1e3ccSAndroid Build Coastguard Worker default: return SQR_BLOCK_SIZES;
980*77c1e3ccSAndroid Build Coastguard Worker }
981*77c1e3ccSAndroid Build Coastguard Worker }
982*77c1e3ccSAndroid Build Coastguard Worker
983*77c1e3ccSAndroid Build Coastguard Worker // For a square block size 'bsize', returns the size of the sub-blocks used by
984*77c1e3ccSAndroid Build Coastguard Worker // the given partition type. If the partition produces sub-blocks of different
985*77c1e3ccSAndroid Build Coastguard Worker // sizes, then the function returns the largest sub-block size.
986*77c1e3ccSAndroid Build Coastguard Worker // Implements the Partition_Subsize lookup table in the spec (Section 9.3.
987*77c1e3ccSAndroid Build Coastguard Worker // Conversion tables).
988*77c1e3ccSAndroid Build Coastguard Worker // Note: the input block size should be square.
989*77c1e3ccSAndroid Build Coastguard Worker // Otherwise it's considered invalid.
get_partition_subsize(BLOCK_SIZE bsize,PARTITION_TYPE partition)990*77c1e3ccSAndroid Build Coastguard Worker static inline BLOCK_SIZE get_partition_subsize(BLOCK_SIZE bsize,
991*77c1e3ccSAndroid Build Coastguard Worker PARTITION_TYPE partition) {
992*77c1e3ccSAndroid Build Coastguard Worker if (partition == PARTITION_INVALID) {
993*77c1e3ccSAndroid Build Coastguard Worker return BLOCK_INVALID;
994*77c1e3ccSAndroid Build Coastguard Worker } else {
995*77c1e3ccSAndroid Build Coastguard Worker const int sqr_bsize_idx = get_sqr_bsize_idx(bsize);
996*77c1e3ccSAndroid Build Coastguard Worker return sqr_bsize_idx >= SQR_BLOCK_SIZES
997*77c1e3ccSAndroid Build Coastguard Worker ? BLOCK_INVALID
998*77c1e3ccSAndroid Build Coastguard Worker : subsize_lookup[partition][sqr_bsize_idx];
999*77c1e3ccSAndroid Build Coastguard Worker }
1000*77c1e3ccSAndroid Build Coastguard Worker }
1001*77c1e3ccSAndroid Build Coastguard Worker
intra_mode_to_tx_type(const MB_MODE_INFO * mbmi,PLANE_TYPE plane_type)1002*77c1e3ccSAndroid Build Coastguard Worker static TX_TYPE intra_mode_to_tx_type(const MB_MODE_INFO *mbmi,
1003*77c1e3ccSAndroid Build Coastguard Worker PLANE_TYPE plane_type) {
1004*77c1e3ccSAndroid Build Coastguard Worker static const TX_TYPE _intra_mode_to_tx_type[INTRA_MODES] = {
1005*77c1e3ccSAndroid Build Coastguard Worker DCT_DCT, // DC_PRED
1006*77c1e3ccSAndroid Build Coastguard Worker ADST_DCT, // V_PRED
1007*77c1e3ccSAndroid Build Coastguard Worker DCT_ADST, // H_PRED
1008*77c1e3ccSAndroid Build Coastguard Worker DCT_DCT, // D45_PRED
1009*77c1e3ccSAndroid Build Coastguard Worker ADST_ADST, // D135_PRED
1010*77c1e3ccSAndroid Build Coastguard Worker ADST_DCT, // D113_PRED
1011*77c1e3ccSAndroid Build Coastguard Worker DCT_ADST, // D157_PRED
1012*77c1e3ccSAndroid Build Coastguard Worker DCT_ADST, // D203_PRED
1013*77c1e3ccSAndroid Build Coastguard Worker ADST_DCT, // D67_PRED
1014*77c1e3ccSAndroid Build Coastguard Worker ADST_ADST, // SMOOTH_PRED
1015*77c1e3ccSAndroid Build Coastguard Worker ADST_DCT, // SMOOTH_V_PRED
1016*77c1e3ccSAndroid Build Coastguard Worker DCT_ADST, // SMOOTH_H_PRED
1017*77c1e3ccSAndroid Build Coastguard Worker ADST_ADST, // PAETH_PRED
1018*77c1e3ccSAndroid Build Coastguard Worker };
1019*77c1e3ccSAndroid Build Coastguard Worker const PREDICTION_MODE mode =
1020*77c1e3ccSAndroid Build Coastguard Worker (plane_type == PLANE_TYPE_Y) ? mbmi->mode : get_uv_mode(mbmi->uv_mode);
1021*77c1e3ccSAndroid Build Coastguard Worker assert(mode < INTRA_MODES);
1022*77c1e3ccSAndroid Build Coastguard Worker return _intra_mode_to_tx_type[mode];
1023*77c1e3ccSAndroid Build Coastguard Worker }
1024*77c1e3ccSAndroid Build Coastguard Worker
is_rect_tx(TX_SIZE tx_size)1025*77c1e3ccSAndroid Build Coastguard Worker static inline int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; }
1026*77c1e3ccSAndroid Build Coastguard Worker
block_signals_txsize(BLOCK_SIZE bsize)1027*77c1e3ccSAndroid Build Coastguard Worker static inline int block_signals_txsize(BLOCK_SIZE bsize) {
1028*77c1e3ccSAndroid Build Coastguard Worker return bsize > BLOCK_4X4;
1029*77c1e3ccSAndroid Build Coastguard Worker }
1030*77c1e3ccSAndroid Build Coastguard Worker
1031*77c1e3ccSAndroid Build Coastguard Worker // Number of transform types in each set type
1032*77c1e3ccSAndroid Build Coastguard Worker static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = {
1033*77c1e3ccSAndroid Build Coastguard Worker 1, 2, 5, 7, 12, 16,
1034*77c1e3ccSAndroid Build Coastguard Worker };
1035*77c1e3ccSAndroid Build Coastguard Worker
1036*77c1e3ccSAndroid Build Coastguard Worker static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = {
1037*77c1e3ccSAndroid Build Coastguard Worker { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1038*77c1e3ccSAndroid Build Coastguard Worker { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
1039*77c1e3ccSAndroid Build Coastguard Worker { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
1040*77c1e3ccSAndroid Build Coastguard Worker { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 },
1041*77c1e3ccSAndroid Build Coastguard Worker { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
1042*77c1e3ccSAndroid Build Coastguard Worker { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
1043*77c1e3ccSAndroid Build Coastguard Worker };
1044*77c1e3ccSAndroid Build Coastguard Worker
1045*77c1e3ccSAndroid Build Coastguard Worker // The bitmask corresponds to the transform types as defined in
1046*77c1e3ccSAndroid Build Coastguard Worker // enums.h TX_TYPE enumeration type. Setting the bit 0 means to disable
1047*77c1e3ccSAndroid Build Coastguard Worker // the use of the corresponding transform type in that table.
1048*77c1e3ccSAndroid Build Coastguard Worker // The av1_derived_intra_tx_used_flag table is used when
1049*77c1e3ccSAndroid Build Coastguard Worker // use_reduced_intra_txset is set to 2, where one only searches
1050*77c1e3ccSAndroid Build Coastguard Worker // the transform types derived from residual statistics.
1051*77c1e3ccSAndroid Build Coastguard Worker static const uint16_t av1_derived_intra_tx_used_flag[INTRA_MODES] = {
1052*77c1e3ccSAndroid Build Coastguard Worker 0x0209, // DC_PRED: 0000 0010 0000 1001
1053*77c1e3ccSAndroid Build Coastguard Worker 0x0403, // V_PRED: 0000 0100 0000 0011
1054*77c1e3ccSAndroid Build Coastguard Worker 0x0805, // H_PRED: 0000 1000 0000 0101
1055*77c1e3ccSAndroid Build Coastguard Worker 0x020F, // D45_PRED: 0000 0010 0000 1111
1056*77c1e3ccSAndroid Build Coastguard Worker 0x0009, // D135_PRED: 0000 0000 0000 1001
1057*77c1e3ccSAndroid Build Coastguard Worker 0x0009, // D113_PRED: 0000 0000 0000 1001
1058*77c1e3ccSAndroid Build Coastguard Worker 0x0009, // D157_PRED: 0000 0000 0000 1001
1059*77c1e3ccSAndroid Build Coastguard Worker 0x0805, // D203_PRED: 0000 1000 0000 0101
1060*77c1e3ccSAndroid Build Coastguard Worker 0x0403, // D67_PRED: 0000 0100 0000 0011
1061*77c1e3ccSAndroid Build Coastguard Worker 0x0205, // SMOOTH_PRED: 0000 0010 0000 1001
1062*77c1e3ccSAndroid Build Coastguard Worker 0x0403, // SMOOTH_V_PRED: 0000 0100 0000 0011
1063*77c1e3ccSAndroid Build Coastguard Worker 0x0805, // SMOOTH_H_PRED: 0000 1000 0000 0101
1064*77c1e3ccSAndroid Build Coastguard Worker 0x0209, // PAETH_PRED: 0000 0010 0000 1001
1065*77c1e3ccSAndroid Build Coastguard Worker };
1066*77c1e3ccSAndroid Build Coastguard Worker
1067*77c1e3ccSAndroid Build Coastguard Worker static const uint16_t av1_reduced_intra_tx_used_flag[INTRA_MODES] = {
1068*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // DC_PRED: 0000 1000 0000 1111
1069*77c1e3ccSAndroid Build Coastguard Worker 0x040F, // V_PRED: 0000 0100 0000 1111
1070*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // H_PRED: 0000 1000 0000 1111
1071*77c1e3ccSAndroid Build Coastguard Worker 0x020F, // D45_PRED: 0000 0010 0000 1111
1072*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // D135_PRED: 0000 1000 0000 1111
1073*77c1e3ccSAndroid Build Coastguard Worker 0x040F, // D113_PRED: 0000 0100 0000 1111
1074*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // D157_PRED: 0000 1000 0000 1111
1075*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // D203_PRED: 0000 1000 0000 1111
1076*77c1e3ccSAndroid Build Coastguard Worker 0x040F, // D67_PRED: 0000 0100 0000 1111
1077*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // SMOOTH_PRED: 0000 1000 0000 1111
1078*77c1e3ccSAndroid Build Coastguard Worker 0x040F, // SMOOTH_V_PRED: 0000 0100 0000 1111
1079*77c1e3ccSAndroid Build Coastguard Worker 0x080F, // SMOOTH_H_PRED: 0000 1000 0000 1111
1080*77c1e3ccSAndroid Build Coastguard Worker 0x0C0E, // PAETH_PRED: 0000 1100 0000 1110
1081*77c1e3ccSAndroid Build Coastguard Worker };
1082*77c1e3ccSAndroid Build Coastguard Worker
1083*77c1e3ccSAndroid Build Coastguard Worker static const uint16_t av1_ext_tx_used_flag[EXT_TX_SET_TYPES] = {
1084*77c1e3ccSAndroid Build Coastguard Worker 0x0001, // 0000 0000 0000 0001
1085*77c1e3ccSAndroid Build Coastguard Worker 0x0201, // 0000 0010 0000 0001
1086*77c1e3ccSAndroid Build Coastguard Worker 0x020F, // 0000 0010 0000 1111
1087*77c1e3ccSAndroid Build Coastguard Worker 0x0E0F, // 0000 1110 0000 1111
1088*77c1e3ccSAndroid Build Coastguard Worker 0x0FFF, // 0000 1111 1111 1111
1089*77c1e3ccSAndroid Build Coastguard Worker 0xFFFF, // 1111 1111 1111 1111
1090*77c1e3ccSAndroid Build Coastguard Worker };
1091*77c1e3ccSAndroid Build Coastguard Worker
1092*77c1e3ccSAndroid Build Coastguard Worker static const TxSetType av1_ext_tx_set_lookup[2][2] = {
1093*77c1e3ccSAndroid Build Coastguard Worker { EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX },
1094*77c1e3ccSAndroid Build Coastguard Worker { EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT },
1095*77c1e3ccSAndroid Build Coastguard Worker };
1096*77c1e3ccSAndroid Build Coastguard Worker
av1_get_ext_tx_set_type(TX_SIZE tx_size,int is_inter,int use_reduced_set)1097*77c1e3ccSAndroid Build Coastguard Worker static inline TxSetType av1_get_ext_tx_set_type(TX_SIZE tx_size, int is_inter,
1098*77c1e3ccSAndroid Build Coastguard Worker int use_reduced_set) {
1099*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
1100*77c1e3ccSAndroid Build Coastguard Worker if (tx_size_sqr_up > TX_32X32) return EXT_TX_SET_DCTONLY;
1101*77c1e3ccSAndroid Build Coastguard Worker if (tx_size_sqr_up == TX_32X32)
1102*77c1e3ccSAndroid Build Coastguard Worker return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
1103*77c1e3ccSAndroid Build Coastguard Worker if (use_reduced_set)
1104*77c1e3ccSAndroid Build Coastguard Worker return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX;
1105*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size];
1106*77c1e3ccSAndroid Build Coastguard Worker return av1_ext_tx_set_lookup[is_inter][tx_size_sqr == TX_16X16];
1107*77c1e3ccSAndroid Build Coastguard Worker }
1108*77c1e3ccSAndroid Build Coastguard Worker
1109*77c1e3ccSAndroid Build Coastguard Worker // Maps tx set types to the indices.
1110*77c1e3ccSAndroid Build Coastguard Worker static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = {
1111*77c1e3ccSAndroid Build Coastguard Worker { // Intra
1112*77c1e3ccSAndroid Build Coastguard Worker 0, -1, 2, 1, -1, -1 },
1113*77c1e3ccSAndroid Build Coastguard Worker { // Inter
1114*77c1e3ccSAndroid Build Coastguard Worker 0, 3, -1, -1, 2, 1 },
1115*77c1e3ccSAndroid Build Coastguard Worker };
1116*77c1e3ccSAndroid Build Coastguard Worker
get_ext_tx_set(TX_SIZE tx_size,int is_inter,int use_reduced_set)1117*77c1e3ccSAndroid Build Coastguard Worker static inline int get_ext_tx_set(TX_SIZE tx_size, int is_inter,
1118*77c1e3ccSAndroid Build Coastguard Worker int use_reduced_set) {
1119*77c1e3ccSAndroid Build Coastguard Worker const TxSetType set_type =
1120*77c1e3ccSAndroid Build Coastguard Worker av1_get_ext_tx_set_type(tx_size, is_inter, use_reduced_set);
1121*77c1e3ccSAndroid Build Coastguard Worker return ext_tx_set_index[is_inter][set_type];
1122*77c1e3ccSAndroid Build Coastguard Worker }
1123*77c1e3ccSAndroid Build Coastguard Worker
get_ext_tx_types(TX_SIZE tx_size,int is_inter,int use_reduced_set)1124*77c1e3ccSAndroid Build Coastguard Worker static inline int get_ext_tx_types(TX_SIZE tx_size, int is_inter,
1125*77c1e3ccSAndroid Build Coastguard Worker int use_reduced_set) {
1126*77c1e3ccSAndroid Build Coastguard Worker const int set_type =
1127*77c1e3ccSAndroid Build Coastguard Worker av1_get_ext_tx_set_type(tx_size, is_inter, use_reduced_set);
1128*77c1e3ccSAndroid Build Coastguard Worker return av1_num_ext_tx_set[set_type];
1129*77c1e3ccSAndroid Build Coastguard Worker }
1130*77c1e3ccSAndroid Build Coastguard Worker
1131*77c1e3ccSAndroid Build Coastguard Worker #define TXSIZEMAX(t1, t2) (tx_size_2d[(t1)] >= tx_size_2d[(t2)] ? (t1) : (t2))
1132*77c1e3ccSAndroid Build Coastguard Worker #define TXSIZEMIN(t1, t2) (tx_size_2d[(t1)] <= tx_size_2d[(t2)] ? (t1) : (t2))
1133*77c1e3ccSAndroid Build Coastguard Worker
tx_size_from_tx_mode(BLOCK_SIZE bsize,TX_MODE tx_mode)1134*77c1e3ccSAndroid Build Coastguard Worker static inline TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode) {
1135*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
1136*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize];
1137*77c1e3ccSAndroid Build Coastguard Worker if (bsize == BLOCK_4X4)
1138*77c1e3ccSAndroid Build Coastguard Worker return AOMMIN(max_txsize_lookup[bsize], largest_tx_size);
1139*77c1e3ccSAndroid Build Coastguard Worker if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size)
1140*77c1e3ccSAndroid Build Coastguard Worker return max_rect_tx_size;
1141*77c1e3ccSAndroid Build Coastguard Worker else
1142*77c1e3ccSAndroid Build Coastguard Worker return largest_tx_size;
1143*77c1e3ccSAndroid Build Coastguard Worker }
1144*77c1e3ccSAndroid Build Coastguard Worker
1145*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t mode_to_angle_map[INTRA_MODES] = {
1146*77c1e3ccSAndroid Build Coastguard Worker 0, 90, 180, 45, 135, 113, 157, 203, 67, 0, 0, 0, 0,
1147*77c1e3ccSAndroid Build Coastguard Worker };
1148*77c1e3ccSAndroid Build Coastguard Worker
1149*77c1e3ccSAndroid Build Coastguard Worker // Converts block_index for given transform size to index of the block in raster
1150*77c1e3ccSAndroid Build Coastguard Worker // order.
av1_block_index_to_raster_order(TX_SIZE tx_size,int block_idx)1151*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_block_index_to_raster_order(TX_SIZE tx_size,
1152*77c1e3ccSAndroid Build Coastguard Worker int block_idx) {
1153*77c1e3ccSAndroid Build Coastguard Worker // For transform size 4x8, the possible block_idx values are 0 & 2, because
1154*77c1e3ccSAndroid Build Coastguard Worker // block_idx values are incremented in steps of size 'tx_width_unit x
1155*77c1e3ccSAndroid Build Coastguard Worker // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to
1156*77c1e3ccSAndroid Build Coastguard Worker // block number 1 in raster order, inside an 8x8 MI block.
1157*77c1e3ccSAndroid Build Coastguard Worker // For any other transform size, the two indices are equivalent.
1158*77c1e3ccSAndroid Build Coastguard Worker return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx;
1159*77c1e3ccSAndroid Build Coastguard Worker }
1160*77c1e3ccSAndroid Build Coastguard Worker
1161*77c1e3ccSAndroid Build Coastguard Worker // Inverse of above function.
1162*77c1e3ccSAndroid Build Coastguard Worker // Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now.
av1_raster_order_to_block_index(TX_SIZE tx_size,int raster_order)1163*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_raster_order_to_block_index(TX_SIZE tx_size,
1164*77c1e3ccSAndroid Build Coastguard Worker int raster_order) {
1165*77c1e3ccSAndroid Build Coastguard Worker assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4);
1166*77c1e3ccSAndroid Build Coastguard Worker // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4.
1167*77c1e3ccSAndroid Build Coastguard Worker return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0;
1168*77c1e3ccSAndroid Build Coastguard Worker }
1169*77c1e3ccSAndroid Build Coastguard Worker
get_default_tx_type(PLANE_TYPE plane_type,const MACROBLOCKD * xd,TX_SIZE tx_size,int use_screen_content_tools)1170*77c1e3ccSAndroid Build Coastguard Worker static inline TX_TYPE get_default_tx_type(PLANE_TYPE plane_type,
1171*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd,
1172*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size,
1173*77c1e3ccSAndroid Build Coastguard Worker int use_screen_content_tools) {
1174*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const mbmi = xd->mi[0];
1175*77c1e3ccSAndroid Build Coastguard Worker
1176*77c1e3ccSAndroid Build Coastguard Worker if (is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y ||
1177*77c1e3ccSAndroid Build Coastguard Worker xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32 ||
1178*77c1e3ccSAndroid Build Coastguard Worker use_screen_content_tools)
1179*77c1e3ccSAndroid Build Coastguard Worker return DEFAULT_INTER_TX_TYPE;
1180*77c1e3ccSAndroid Build Coastguard Worker
1181*77c1e3ccSAndroid Build Coastguard Worker return intra_mode_to_tx_type(mbmi, plane_type);
1182*77c1e3ccSAndroid Build Coastguard Worker }
1183*77c1e3ccSAndroid Build Coastguard Worker
1184*77c1e3ccSAndroid Build Coastguard Worker // Implements the get_plane_residual_size() function in the spec (Section
1185*77c1e3ccSAndroid Build Coastguard Worker // 5.11.38. Get plane residual size function).
get_plane_block_size(BLOCK_SIZE bsize,int subsampling_x,int subsampling_y)1186*77c1e3ccSAndroid Build Coastguard Worker static inline BLOCK_SIZE get_plane_block_size(BLOCK_SIZE bsize,
1187*77c1e3ccSAndroid Build Coastguard Worker int subsampling_x,
1188*77c1e3ccSAndroid Build Coastguard Worker int subsampling_y) {
1189*77c1e3ccSAndroid Build Coastguard Worker assert(bsize < BLOCK_SIZES_ALL);
1190*77c1e3ccSAndroid Build Coastguard Worker assert(subsampling_x >= 0 && subsampling_x < 2);
1191*77c1e3ccSAndroid Build Coastguard Worker assert(subsampling_y >= 0 && subsampling_y < 2);
1192*77c1e3ccSAndroid Build Coastguard Worker return av1_ss_size_lookup[bsize][subsampling_x][subsampling_y];
1193*77c1e3ccSAndroid Build Coastguard Worker }
1194*77c1e3ccSAndroid Build Coastguard Worker
1195*77c1e3ccSAndroid Build Coastguard Worker /*
1196*77c1e3ccSAndroid Build Coastguard Worker * Logic to generate the lookup tables:
1197*77c1e3ccSAndroid Build Coastguard Worker *
1198*77c1e3ccSAndroid Build Coastguard Worker * TX_SIZE txs = max_txsize_rect_lookup[bsize];
1199*77c1e3ccSAndroid Build Coastguard Worker * for (int level = 0; level < MAX_VARTX_DEPTH - 1; ++level)
1200*77c1e3ccSAndroid Build Coastguard Worker * txs = sub_tx_size_map[txs];
1201*77c1e3ccSAndroid Build Coastguard Worker * const int tx_w_log2 = tx_size_wide_log2[txs] - MI_SIZE_LOG2;
1202*77c1e3ccSAndroid Build Coastguard Worker * const int tx_h_log2 = tx_size_high_log2[txs] - MI_SIZE_LOG2;
1203*77c1e3ccSAndroid Build Coastguard Worker * const int bw_uint_log2 = mi_size_wide_log2[bsize];
1204*77c1e3ccSAndroid Build Coastguard Worker * const int stride_log2 = bw_uint_log2 - tx_w_log2;
1205*77c1e3ccSAndroid Build Coastguard Worker */
av1_get_txb_size_index(BLOCK_SIZE bsize,int blk_row,int blk_col)1206*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_txb_size_index(BLOCK_SIZE bsize, int blk_row,
1207*77c1e3ccSAndroid Build Coastguard Worker int blk_col) {
1208*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t tw_w_log2_table[BLOCK_SIZES_ALL] = {
1209*77c1e3ccSAndroid Build Coastguard Worker 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 0, 1, 1, 2, 2, 3,
1210*77c1e3ccSAndroid Build Coastguard Worker };
1211*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t tw_h_log2_table[BLOCK_SIZES_ALL] = {
1212*77c1e3ccSAndroid Build Coastguard Worker 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 1, 0, 2, 1, 3, 2,
1213*77c1e3ccSAndroid Build Coastguard Worker };
1214*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t stride_log2_table[BLOCK_SIZES_ALL] = {
1215*77c1e3ccSAndroid Build Coastguard Worker 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 2, 2, 0, 1, 0, 1, 0, 1,
1216*77c1e3ccSAndroid Build Coastguard Worker };
1217*77c1e3ccSAndroid Build Coastguard Worker const int index =
1218*77c1e3ccSAndroid Build Coastguard Worker ((blk_row >> tw_h_log2_table[bsize]) << stride_log2_table[bsize]) +
1219*77c1e3ccSAndroid Build Coastguard Worker (blk_col >> tw_w_log2_table[bsize]);
1220*77c1e3ccSAndroid Build Coastguard Worker assert(index < INTER_TX_SIZE_BUF_LEN);
1221*77c1e3ccSAndroid Build Coastguard Worker return index;
1222*77c1e3ccSAndroid Build Coastguard Worker }
1223*77c1e3ccSAndroid Build Coastguard Worker
1224*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_INSPECTION
1225*77c1e3ccSAndroid Build Coastguard Worker /*
1226*77c1e3ccSAndroid Build Coastguard Worker * Here is the logic to generate the lookup tables:
1227*77c1e3ccSAndroid Build Coastguard Worker *
1228*77c1e3ccSAndroid Build Coastguard Worker * TX_SIZE txs = max_txsize_rect_lookup[bsize];
1229*77c1e3ccSAndroid Build Coastguard Worker * for (int level = 0; level < MAX_VARTX_DEPTH; ++level)
1230*77c1e3ccSAndroid Build Coastguard Worker * txs = sub_tx_size_map[txs];
1231*77c1e3ccSAndroid Build Coastguard Worker * const int tx_w_log2 = tx_size_wide_log2[txs] - MI_SIZE_LOG2;
1232*77c1e3ccSAndroid Build Coastguard Worker * const int tx_h_log2 = tx_size_high_log2[txs] - MI_SIZE_LOG2;
1233*77c1e3ccSAndroid Build Coastguard Worker * const int bw_uint_log2 = mi_size_wide_log2[bsize];
1234*77c1e3ccSAndroid Build Coastguard Worker * const int stride_log2 = bw_uint_log2 - tx_w_log2;
1235*77c1e3ccSAndroid Build Coastguard Worker */
av1_get_txk_type_index(BLOCK_SIZE bsize,int blk_row,int blk_col)1236*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_txk_type_index(BLOCK_SIZE bsize, int blk_row,
1237*77c1e3ccSAndroid Build Coastguard Worker int blk_col) {
1238*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t tw_w_log2_table[BLOCK_SIZES_ALL] = {
1239*77c1e3ccSAndroid Build Coastguard Worker 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2,
1240*77c1e3ccSAndroid Build Coastguard Worker };
1241*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t tw_h_log2_table[BLOCK_SIZES_ALL] = {
1242*77c1e3ccSAndroid Build Coastguard Worker 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2, 2,
1243*77c1e3ccSAndroid Build Coastguard Worker };
1244*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t stride_log2_table[BLOCK_SIZES_ALL] = {
1245*77c1e3ccSAndroid Build Coastguard Worker 0, 0, 1, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 3, 3, 0, 2, 0, 2, 0, 2,
1246*77c1e3ccSAndroid Build Coastguard Worker };
1247*77c1e3ccSAndroid Build Coastguard Worker const int index =
1248*77c1e3ccSAndroid Build Coastguard Worker ((blk_row >> tw_h_log2_table[bsize]) << stride_log2_table[bsize]) +
1249*77c1e3ccSAndroid Build Coastguard Worker (blk_col >> tw_w_log2_table[bsize]);
1250*77c1e3ccSAndroid Build Coastguard Worker assert(index < TXK_TYPE_BUF_LEN);
1251*77c1e3ccSAndroid Build Coastguard Worker return index;
1252*77c1e3ccSAndroid Build Coastguard Worker }
1253*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_INSPECTION
1254*77c1e3ccSAndroid Build Coastguard Worker
update_txk_array(MACROBLOCKD * const xd,int blk_row,int blk_col,TX_SIZE tx_size,TX_TYPE tx_type)1255*77c1e3ccSAndroid Build Coastguard Worker static inline void update_txk_array(MACROBLOCKD *const xd, int blk_row,
1256*77c1e3ccSAndroid Build Coastguard Worker int blk_col, TX_SIZE tx_size,
1257*77c1e3ccSAndroid Build Coastguard Worker TX_TYPE tx_type) {
1258*77c1e3ccSAndroid Build Coastguard Worker const int stride = xd->tx_type_map_stride;
1259*77c1e3ccSAndroid Build Coastguard Worker xd->tx_type_map[blk_row * stride + blk_col] = tx_type;
1260*77c1e3ccSAndroid Build Coastguard Worker
1261*77c1e3ccSAndroid Build Coastguard Worker const int txw = tx_size_wide_unit[tx_size];
1262*77c1e3ccSAndroid Build Coastguard Worker const int txh = tx_size_high_unit[tx_size];
1263*77c1e3ccSAndroid Build Coastguard Worker // The 16x16 unit is due to the constraint from tx_64x64 which sets the
1264*77c1e3ccSAndroid Build Coastguard Worker // maximum tx size for chroma as 32x32. Coupled with 4x1 transform block
1265*77c1e3ccSAndroid Build Coastguard Worker // size, the constraint takes effect in 32x16 / 16x32 size too. To solve
1266*77c1e3ccSAndroid Build Coastguard Worker // the intricacy, cover all the 16x16 units inside a 64 level transform.
1267*77c1e3ccSAndroid Build Coastguard Worker if (txw == tx_size_wide_unit[TX_64X64] ||
1268*77c1e3ccSAndroid Build Coastguard Worker txh == tx_size_high_unit[TX_64X64]) {
1269*77c1e3ccSAndroid Build Coastguard Worker const int tx_unit = tx_size_wide_unit[TX_16X16];
1270*77c1e3ccSAndroid Build Coastguard Worker for (int idy = 0; idy < txh; idy += tx_unit) {
1271*77c1e3ccSAndroid Build Coastguard Worker for (int idx = 0; idx < txw; idx += tx_unit) {
1272*77c1e3ccSAndroid Build Coastguard Worker xd->tx_type_map[(blk_row + idy) * stride + blk_col + idx] = tx_type;
1273*77c1e3ccSAndroid Build Coastguard Worker }
1274*77c1e3ccSAndroid Build Coastguard Worker }
1275*77c1e3ccSAndroid Build Coastguard Worker }
1276*77c1e3ccSAndroid Build Coastguard Worker }
1277*77c1e3ccSAndroid Build Coastguard Worker
av1_get_tx_type(const MACROBLOCKD * xd,PLANE_TYPE plane_type,int blk_row,int blk_col,TX_SIZE tx_size,int reduced_tx_set)1278*77c1e3ccSAndroid Build Coastguard Worker static inline TX_TYPE av1_get_tx_type(const MACROBLOCKD *xd,
1279*77c1e3ccSAndroid Build Coastguard Worker PLANE_TYPE plane_type, int blk_row,
1280*77c1e3ccSAndroid Build Coastguard Worker int blk_col, TX_SIZE tx_size,
1281*77c1e3ccSAndroid Build Coastguard Worker int reduced_tx_set) {
1282*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *const mbmi = xd->mi[0];
1283*77c1e3ccSAndroid Build Coastguard Worker if (xd->lossless[mbmi->segment_id] || txsize_sqr_up_map[tx_size] > TX_32X32) {
1284*77c1e3ccSAndroid Build Coastguard Worker return DCT_DCT;
1285*77c1e3ccSAndroid Build Coastguard Worker }
1286*77c1e3ccSAndroid Build Coastguard Worker
1287*77c1e3ccSAndroid Build Coastguard Worker TX_TYPE tx_type;
1288*77c1e3ccSAndroid Build Coastguard Worker if (plane_type == PLANE_TYPE_Y) {
1289*77c1e3ccSAndroid Build Coastguard Worker tx_type = xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col];
1290*77c1e3ccSAndroid Build Coastguard Worker } else {
1291*77c1e3ccSAndroid Build Coastguard Worker if (is_inter_block(mbmi)) {
1292*77c1e3ccSAndroid Build Coastguard Worker // scale back to y plane's coordinate
1293*77c1e3ccSAndroid Build Coastguard Worker const struct macroblockd_plane *const pd = &xd->plane[plane_type];
1294*77c1e3ccSAndroid Build Coastguard Worker blk_row <<= pd->subsampling_y;
1295*77c1e3ccSAndroid Build Coastguard Worker blk_col <<= pd->subsampling_x;
1296*77c1e3ccSAndroid Build Coastguard Worker tx_type = xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col];
1297*77c1e3ccSAndroid Build Coastguard Worker } else {
1298*77c1e3ccSAndroid Build Coastguard Worker // In intra mode, uv planes don't share the same prediction mode as y
1299*77c1e3ccSAndroid Build Coastguard Worker // plane, so the tx_type should not be shared
1300*77c1e3ccSAndroid Build Coastguard Worker tx_type = intra_mode_to_tx_type(mbmi, PLANE_TYPE_UV);
1301*77c1e3ccSAndroid Build Coastguard Worker }
1302*77c1e3ccSAndroid Build Coastguard Worker const TxSetType tx_set_type =
1303*77c1e3ccSAndroid Build Coastguard Worker av1_get_ext_tx_set_type(tx_size, is_inter_block(mbmi), reduced_tx_set);
1304*77c1e3ccSAndroid Build Coastguard Worker if (!av1_ext_tx_used[tx_set_type][tx_type]) tx_type = DCT_DCT;
1305*77c1e3ccSAndroid Build Coastguard Worker }
1306*77c1e3ccSAndroid Build Coastguard Worker assert(tx_type < TX_TYPES);
1307*77c1e3ccSAndroid Build Coastguard Worker assert(av1_ext_tx_used[av1_get_ext_tx_set_type(tx_size, is_inter_block(mbmi),
1308*77c1e3ccSAndroid Build Coastguard Worker reduced_tx_set)][tx_type]);
1309*77c1e3ccSAndroid Build Coastguard Worker return tx_type;
1310*77c1e3ccSAndroid Build Coastguard Worker }
1311*77c1e3ccSAndroid Build Coastguard Worker
1312*77c1e3ccSAndroid Build Coastguard Worker void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y,
1313*77c1e3ccSAndroid Build Coastguard Worker const int num_planes);
1314*77c1e3ccSAndroid Build Coastguard Worker
1315*77c1e3ccSAndroid Build Coastguard Worker /*
1316*77c1e3ccSAndroid Build Coastguard Worker * Logic to generate the lookup table:
1317*77c1e3ccSAndroid Build Coastguard Worker *
1318*77c1e3ccSAndroid Build Coastguard Worker * TX_SIZE tx_size = max_txsize_rect_lookup[bsize];
1319*77c1e3ccSAndroid Build Coastguard Worker * int depth = 0;
1320*77c1e3ccSAndroid Build Coastguard Worker * while (depth < MAX_TX_DEPTH && tx_size != TX_4X4) {
1321*77c1e3ccSAndroid Build Coastguard Worker * depth++;
1322*77c1e3ccSAndroid Build Coastguard Worker * tx_size = sub_tx_size_map[tx_size];
1323*77c1e3ccSAndroid Build Coastguard Worker * }
1324*77c1e3ccSAndroid Build Coastguard Worker */
bsize_to_max_depth(BLOCK_SIZE bsize)1325*77c1e3ccSAndroid Build Coastguard Worker static inline int bsize_to_max_depth(BLOCK_SIZE bsize) {
1326*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t bsize_to_max_depth_table[BLOCK_SIZES_ALL] = {
1327*77c1e3ccSAndroid Build Coastguard Worker 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1328*77c1e3ccSAndroid Build Coastguard Worker };
1329*77c1e3ccSAndroid Build Coastguard Worker return bsize_to_max_depth_table[bsize];
1330*77c1e3ccSAndroid Build Coastguard Worker }
1331*77c1e3ccSAndroid Build Coastguard Worker
1332*77c1e3ccSAndroid Build Coastguard Worker /*
1333*77c1e3ccSAndroid Build Coastguard Worker * Logic to generate the lookup table:
1334*77c1e3ccSAndroid Build Coastguard Worker *
1335*77c1e3ccSAndroid Build Coastguard Worker * TX_SIZE tx_size = max_txsize_rect_lookup[bsize];
1336*77c1e3ccSAndroid Build Coastguard Worker * assert(tx_size != TX_4X4);
1337*77c1e3ccSAndroid Build Coastguard Worker * int depth = 0;
1338*77c1e3ccSAndroid Build Coastguard Worker * while (tx_size != TX_4X4) {
1339*77c1e3ccSAndroid Build Coastguard Worker * depth++;
1340*77c1e3ccSAndroid Build Coastguard Worker * tx_size = sub_tx_size_map[tx_size];
1341*77c1e3ccSAndroid Build Coastguard Worker * }
1342*77c1e3ccSAndroid Build Coastguard Worker * assert(depth < 10);
1343*77c1e3ccSAndroid Build Coastguard Worker */
bsize_to_tx_size_cat(BLOCK_SIZE bsize)1344*77c1e3ccSAndroid Build Coastguard Worker static inline int bsize_to_tx_size_cat(BLOCK_SIZE bsize) {
1345*77c1e3ccSAndroid Build Coastguard Worker assert(bsize < BLOCK_SIZES_ALL);
1346*77c1e3ccSAndroid Build Coastguard Worker static const uint8_t bsize_to_tx_size_depth_table[BLOCK_SIZES_ALL] = {
1347*77c1e3ccSAndroid Build Coastguard Worker 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 2, 2, 3, 3, 4, 4,
1348*77c1e3ccSAndroid Build Coastguard Worker };
1349*77c1e3ccSAndroid Build Coastguard Worker const int depth = bsize_to_tx_size_depth_table[bsize];
1350*77c1e3ccSAndroid Build Coastguard Worker assert(depth <= MAX_TX_CATS);
1351*77c1e3ccSAndroid Build Coastguard Worker return depth - 1;
1352*77c1e3ccSAndroid Build Coastguard Worker }
1353*77c1e3ccSAndroid Build Coastguard Worker
depth_to_tx_size(int depth,BLOCK_SIZE bsize)1354*77c1e3ccSAndroid Build Coastguard Worker static inline TX_SIZE depth_to_tx_size(int depth, BLOCK_SIZE bsize) {
1355*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize];
1356*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size = max_tx_size;
1357*77c1e3ccSAndroid Build Coastguard Worker for (int d = 0; d < depth; ++d) tx_size = sub_tx_size_map[tx_size];
1358*77c1e3ccSAndroid Build Coastguard Worker return tx_size;
1359*77c1e3ccSAndroid Build Coastguard Worker }
1360*77c1e3ccSAndroid Build Coastguard Worker
av1_get_adjusted_tx_size(TX_SIZE tx_size)1361*77c1e3ccSAndroid Build Coastguard Worker static inline TX_SIZE av1_get_adjusted_tx_size(TX_SIZE tx_size) {
1362*77c1e3ccSAndroid Build Coastguard Worker switch (tx_size) {
1363*77c1e3ccSAndroid Build Coastguard Worker case TX_64X64:
1364*77c1e3ccSAndroid Build Coastguard Worker case TX_64X32:
1365*77c1e3ccSAndroid Build Coastguard Worker case TX_32X64: return TX_32X32;
1366*77c1e3ccSAndroid Build Coastguard Worker case TX_64X16: return TX_32X16;
1367*77c1e3ccSAndroid Build Coastguard Worker case TX_16X64: return TX_16X32;
1368*77c1e3ccSAndroid Build Coastguard Worker default: return tx_size;
1369*77c1e3ccSAndroid Build Coastguard Worker }
1370*77c1e3ccSAndroid Build Coastguard Worker }
1371*77c1e3ccSAndroid Build Coastguard Worker
av1_get_max_uv_txsize(BLOCK_SIZE bsize,int subsampling_x,int subsampling_y)1372*77c1e3ccSAndroid Build Coastguard Worker static inline TX_SIZE av1_get_max_uv_txsize(BLOCK_SIZE bsize, int subsampling_x,
1373*77c1e3ccSAndroid Build Coastguard Worker int subsampling_y) {
1374*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE plane_bsize =
1375*77c1e3ccSAndroid Build Coastguard Worker get_plane_block_size(bsize, subsampling_x, subsampling_y);
1376*77c1e3ccSAndroid Build Coastguard Worker assert(plane_bsize < BLOCK_SIZES_ALL);
1377*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE uv_tx = max_txsize_rect_lookup[plane_bsize];
1378*77c1e3ccSAndroid Build Coastguard Worker return av1_get_adjusted_tx_size(uv_tx);
1379*77c1e3ccSAndroid Build Coastguard Worker }
1380*77c1e3ccSAndroid Build Coastguard Worker
av1_get_tx_size(int plane,const MACROBLOCKD * xd)1381*77c1e3ccSAndroid Build Coastguard Worker static inline TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) {
1382*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *mbmi = xd->mi[0];
1383*77c1e3ccSAndroid Build Coastguard Worker if (xd->lossless[mbmi->segment_id]) return TX_4X4;
1384*77c1e3ccSAndroid Build Coastguard Worker if (plane == 0) return mbmi->tx_size;
1385*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD_PLANE *pd = &xd->plane[plane];
1386*77c1e3ccSAndroid Build Coastguard Worker return av1_get_max_uv_txsize(mbmi->bsize, pd->subsampling_x,
1387*77c1e3ccSAndroid Build Coastguard Worker pd->subsampling_y);
1388*77c1e3ccSAndroid Build Coastguard Worker }
1389*77c1e3ccSAndroid Build Coastguard Worker
1390*77c1e3ccSAndroid Build Coastguard Worker void av1_reset_entropy_context(MACROBLOCKD *xd, BLOCK_SIZE bsize,
1391*77c1e3ccSAndroid Build Coastguard Worker const int num_planes);
1392*77c1e3ccSAndroid Build Coastguard Worker
1393*77c1e3ccSAndroid Build Coastguard Worker void av1_reset_loop_filter_delta(MACROBLOCKD *xd, int num_planes);
1394*77c1e3ccSAndroid Build Coastguard Worker
1395*77c1e3ccSAndroid Build Coastguard Worker void av1_reset_loop_restoration(MACROBLOCKD *xd, const int num_planes);
1396*77c1e3ccSAndroid Build Coastguard Worker
1397*77c1e3ccSAndroid Build Coastguard Worker typedef void (*foreach_transformed_block_visitor)(int plane, int block,
1398*77c1e3ccSAndroid Build Coastguard Worker int blk_row, int blk_col,
1399*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE plane_bsize,
1400*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size, void *arg);
1401*77c1e3ccSAndroid Build Coastguard Worker
1402*77c1e3ccSAndroid Build Coastguard Worker void av1_set_entropy_contexts(const MACROBLOCKD *xd,
1403*77c1e3ccSAndroid Build Coastguard Worker struct macroblockd_plane *pd, int plane,
1404*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
1405*77c1e3ccSAndroid Build Coastguard Worker int has_eob, int aoff, int loff);
1406*77c1e3ccSAndroid Build Coastguard Worker
1407*77c1e3ccSAndroid Build Coastguard Worker #define MAX_INTERINTRA_SB_SQUARE 32 * 32
is_interintra_mode(const MB_MODE_INFO * mbmi)1408*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_mode(const MB_MODE_INFO *mbmi) {
1409*77c1e3ccSAndroid Build Coastguard Worker return (mbmi->ref_frame[0] > INTRA_FRAME &&
1410*77c1e3ccSAndroid Build Coastguard Worker mbmi->ref_frame[1] == INTRA_FRAME);
1411*77c1e3ccSAndroid Build Coastguard Worker }
1412*77c1e3ccSAndroid Build Coastguard Worker
is_interintra_allowed_bsize(const BLOCK_SIZE bsize)1413*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
1414*77c1e3ccSAndroid Build Coastguard Worker return (bsize >= BLOCK_8X8) && (bsize <= BLOCK_32X32);
1415*77c1e3ccSAndroid Build Coastguard Worker }
1416*77c1e3ccSAndroid Build Coastguard Worker
is_interintra_allowed_mode(const PREDICTION_MODE mode)1417*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_allowed_mode(const PREDICTION_MODE mode) {
1418*77c1e3ccSAndroid Build Coastguard Worker return (mode >= SINGLE_INTER_MODE_START) && (mode < SINGLE_INTER_MODE_END);
1419*77c1e3ccSAndroid Build Coastguard Worker }
1420*77c1e3ccSAndroid Build Coastguard Worker
is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2])1421*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) {
1422*77c1e3ccSAndroid Build Coastguard Worker return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME);
1423*77c1e3ccSAndroid Build Coastguard Worker }
1424*77c1e3ccSAndroid Build Coastguard Worker
is_interintra_allowed(const MB_MODE_INFO * mbmi)1425*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
1426*77c1e3ccSAndroid Build Coastguard Worker return is_interintra_allowed_bsize(mbmi->bsize) &&
1427*77c1e3ccSAndroid Build Coastguard Worker is_interintra_allowed_mode(mbmi->mode) &&
1428*77c1e3ccSAndroid Build Coastguard Worker is_interintra_allowed_ref(mbmi->ref_frame);
1429*77c1e3ccSAndroid Build Coastguard Worker }
1430*77c1e3ccSAndroid Build Coastguard Worker
is_interintra_allowed_bsize_group(int group)1431*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_allowed_bsize_group(int group) {
1432*77c1e3ccSAndroid Build Coastguard Worker int i;
1433*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < BLOCK_SIZES_ALL; i++) {
1434*77c1e3ccSAndroid Build Coastguard Worker if (size_group_lookup[i] == group &&
1435*77c1e3ccSAndroid Build Coastguard Worker is_interintra_allowed_bsize((BLOCK_SIZE)i)) {
1436*77c1e3ccSAndroid Build Coastguard Worker return 1;
1437*77c1e3ccSAndroid Build Coastguard Worker }
1438*77c1e3ccSAndroid Build Coastguard Worker }
1439*77c1e3ccSAndroid Build Coastguard Worker return 0;
1440*77c1e3ccSAndroid Build Coastguard Worker }
1441*77c1e3ccSAndroid Build Coastguard Worker
is_interintra_pred(const MB_MODE_INFO * mbmi)1442*77c1e3ccSAndroid Build Coastguard Worker static inline int is_interintra_pred(const MB_MODE_INFO *mbmi) {
1443*77c1e3ccSAndroid Build Coastguard Worker return mbmi->ref_frame[0] > INTRA_FRAME &&
1444*77c1e3ccSAndroid Build Coastguard Worker mbmi->ref_frame[1] == INTRA_FRAME && is_interintra_allowed(mbmi);
1445*77c1e3ccSAndroid Build Coastguard Worker }
1446*77c1e3ccSAndroid Build Coastguard Worker
get_vartx_max_txsize(const MACROBLOCKD * xd,BLOCK_SIZE bsize,int plane)1447*77c1e3ccSAndroid Build Coastguard Worker static inline int get_vartx_max_txsize(const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1448*77c1e3ccSAndroid Build Coastguard Worker int plane) {
1449*77c1e3ccSAndroid Build Coastguard Worker if (xd->lossless[xd->mi[0]->segment_id]) return TX_4X4;
1450*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE max_txsize = max_txsize_rect_lookup[bsize];
1451*77c1e3ccSAndroid Build Coastguard Worker if (plane == 0) return max_txsize; // luma
1452*77c1e3ccSAndroid Build Coastguard Worker return av1_get_adjusted_tx_size(max_txsize); // chroma
1453*77c1e3ccSAndroid Build Coastguard Worker }
1454*77c1e3ccSAndroid Build Coastguard Worker
is_motion_variation_allowed_bsize(BLOCK_SIZE bsize)1455*77c1e3ccSAndroid Build Coastguard Worker static inline int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) {
1456*77c1e3ccSAndroid Build Coastguard Worker assert(bsize < BLOCK_SIZES_ALL);
1457*77c1e3ccSAndroid Build Coastguard Worker return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8;
1458*77c1e3ccSAndroid Build Coastguard Worker }
1459*77c1e3ccSAndroid Build Coastguard Worker
is_motion_variation_allowed_compound(const MB_MODE_INFO * mbmi)1460*77c1e3ccSAndroid Build Coastguard Worker static inline int is_motion_variation_allowed_compound(
1461*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *mbmi) {
1462*77c1e3ccSAndroid Build Coastguard Worker return !has_second_ref(mbmi);
1463*77c1e3ccSAndroid Build Coastguard Worker }
1464*77c1e3ccSAndroid Build Coastguard Worker
1465*77c1e3ccSAndroid Build Coastguard Worker // input: log2 of length, 0(4), 1(8), ...
1466*77c1e3ccSAndroid Build Coastguard Worker static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };
1467*77c1e3ccSAndroid Build Coastguard Worker
check_num_overlappable_neighbors(const MB_MODE_INFO * mbmi)1468*77c1e3ccSAndroid Build Coastguard Worker static inline int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) {
1469*77c1e3ccSAndroid Build Coastguard Worker return mbmi->overlappable_neighbors != 0;
1470*77c1e3ccSAndroid Build Coastguard Worker }
1471*77c1e3ccSAndroid Build Coastguard Worker
motion_mode_allowed(const WarpedMotionParams * gm_params,const MACROBLOCKD * xd,const MB_MODE_INFO * mbmi,int allow_warped_motion)1472*77c1e3ccSAndroid Build Coastguard Worker static inline MOTION_MODE motion_mode_allowed(
1473*77c1e3ccSAndroid Build Coastguard Worker const WarpedMotionParams *gm_params, const MACROBLOCKD *xd,
1474*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *mbmi, int allow_warped_motion) {
1475*77c1e3ccSAndroid Build Coastguard Worker if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION;
1476*77c1e3ccSAndroid Build Coastguard Worker if (xd->cur_frame_force_integer_mv == 0) {
1477*77c1e3ccSAndroid Build Coastguard Worker const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype;
1478*77c1e3ccSAndroid Build Coastguard Worker if (is_global_mv_block(mbmi, gm_type)) return SIMPLE_TRANSLATION;
1479*77c1e3ccSAndroid Build Coastguard Worker }
1480*77c1e3ccSAndroid Build Coastguard Worker if (is_motion_variation_allowed_bsize(mbmi->bsize) &&
1481*77c1e3ccSAndroid Build Coastguard Worker is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME &&
1482*77c1e3ccSAndroid Build Coastguard Worker is_motion_variation_allowed_compound(mbmi)) {
1483*77c1e3ccSAndroid Build Coastguard Worker assert(!has_second_ref(mbmi));
1484*77c1e3ccSAndroid Build Coastguard Worker if (mbmi->num_proj_ref >= 1 && allow_warped_motion &&
1485*77c1e3ccSAndroid Build Coastguard Worker !xd->cur_frame_force_integer_mv &&
1486*77c1e3ccSAndroid Build Coastguard Worker !av1_is_scaled(xd->block_ref_scale_factors[0])) {
1487*77c1e3ccSAndroid Build Coastguard Worker return WARPED_CAUSAL;
1488*77c1e3ccSAndroid Build Coastguard Worker }
1489*77c1e3ccSAndroid Build Coastguard Worker return OBMC_CAUSAL;
1490*77c1e3ccSAndroid Build Coastguard Worker }
1491*77c1e3ccSAndroid Build Coastguard Worker return SIMPLE_TRANSLATION;
1492*77c1e3ccSAndroid Build Coastguard Worker }
1493*77c1e3ccSAndroid Build Coastguard Worker
is_neighbor_overlappable(const MB_MODE_INFO * mbmi)1494*77c1e3ccSAndroid Build Coastguard Worker static inline int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) {
1495*77c1e3ccSAndroid Build Coastguard Worker return (is_inter_block(mbmi));
1496*77c1e3ccSAndroid Build Coastguard Worker }
1497*77c1e3ccSAndroid Build Coastguard Worker
av1_allow_palette(int allow_screen_content_tools,BLOCK_SIZE sb_type)1498*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_allow_palette(int allow_screen_content_tools,
1499*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE sb_type) {
1500*77c1e3ccSAndroid Build Coastguard Worker assert(sb_type < BLOCK_SIZES_ALL);
1501*77c1e3ccSAndroid Build Coastguard Worker return allow_screen_content_tools &&
1502*77c1e3ccSAndroid Build Coastguard Worker block_size_wide[sb_type] <= MAX_PALETTE_BLOCK_WIDTH &&
1503*77c1e3ccSAndroid Build Coastguard Worker block_size_high[sb_type] <= MAX_PALETTE_BLOCK_HEIGHT &&
1504*77c1e3ccSAndroid Build Coastguard Worker sb_type >= BLOCK_8X8;
1505*77c1e3ccSAndroid Build Coastguard Worker }
1506*77c1e3ccSAndroid Build Coastguard Worker
1507*77c1e3ccSAndroid Build Coastguard Worker // Returns sub-sampled dimensions of the given block.
1508*77c1e3ccSAndroid Build Coastguard Worker // The output values for 'rows_within_bounds' and 'cols_within_bounds' will
1509*77c1e3ccSAndroid Build Coastguard Worker // differ from 'height' and 'width' when part of the block is outside the
1510*77c1e3ccSAndroid Build Coastguard Worker // right
1511*77c1e3ccSAndroid Build Coastguard Worker // and/or bottom image boundary.
av1_get_block_dimensions(BLOCK_SIZE bsize,int plane,const MACROBLOCKD * xd,int * width,int * height,int * rows_within_bounds,int * cols_within_bounds)1512*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane,
1513*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCKD *xd, int *width,
1514*77c1e3ccSAndroid Build Coastguard Worker int *height,
1515*77c1e3ccSAndroid Build Coastguard Worker int *rows_within_bounds,
1516*77c1e3ccSAndroid Build Coastguard Worker int *cols_within_bounds) {
1517*77c1e3ccSAndroid Build Coastguard Worker const int block_height = block_size_high[bsize];
1518*77c1e3ccSAndroid Build Coastguard Worker const int block_width = block_size_wide[bsize];
1519*77c1e3ccSAndroid Build Coastguard Worker const int block_rows = (xd->mb_to_bottom_edge >= 0)
1520*77c1e3ccSAndroid Build Coastguard Worker ? block_height
1521*77c1e3ccSAndroid Build Coastguard Worker : (xd->mb_to_bottom_edge >> 3) + block_height;
1522*77c1e3ccSAndroid Build Coastguard Worker const int block_cols = (xd->mb_to_right_edge >= 0)
1523*77c1e3ccSAndroid Build Coastguard Worker ? block_width
1524*77c1e3ccSAndroid Build Coastguard Worker : (xd->mb_to_right_edge >> 3) + block_width;
1525*77c1e3ccSAndroid Build Coastguard Worker const struct macroblockd_plane *const pd = &xd->plane[plane];
1526*77c1e3ccSAndroid Build Coastguard Worker assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0));
1527*77c1e3ccSAndroid Build Coastguard Worker assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0));
1528*77c1e3ccSAndroid Build Coastguard Worker assert(block_width >= block_cols);
1529*77c1e3ccSAndroid Build Coastguard Worker assert(block_height >= block_rows);
1530*77c1e3ccSAndroid Build Coastguard Worker const int plane_block_width = block_width >> pd->subsampling_x;
1531*77c1e3ccSAndroid Build Coastguard Worker const int plane_block_height = block_height >> pd->subsampling_y;
1532*77c1e3ccSAndroid Build Coastguard Worker // Special handling for chroma sub8x8.
1533*77c1e3ccSAndroid Build Coastguard Worker const int is_chroma_sub8_x = plane > 0 && plane_block_width < 4;
1534*77c1e3ccSAndroid Build Coastguard Worker const int is_chroma_sub8_y = plane > 0 && plane_block_height < 4;
1535*77c1e3ccSAndroid Build Coastguard Worker if (width) {
1536*77c1e3ccSAndroid Build Coastguard Worker *width = plane_block_width + 2 * is_chroma_sub8_x;
1537*77c1e3ccSAndroid Build Coastguard Worker assert(*width >= 0);
1538*77c1e3ccSAndroid Build Coastguard Worker }
1539*77c1e3ccSAndroid Build Coastguard Worker if (height) {
1540*77c1e3ccSAndroid Build Coastguard Worker *height = plane_block_height + 2 * is_chroma_sub8_y;
1541*77c1e3ccSAndroid Build Coastguard Worker assert(*height >= 0);
1542*77c1e3ccSAndroid Build Coastguard Worker }
1543*77c1e3ccSAndroid Build Coastguard Worker if (rows_within_bounds) {
1544*77c1e3ccSAndroid Build Coastguard Worker *rows_within_bounds =
1545*77c1e3ccSAndroid Build Coastguard Worker (block_rows >> pd->subsampling_y) + 2 * is_chroma_sub8_y;
1546*77c1e3ccSAndroid Build Coastguard Worker assert(*rows_within_bounds >= 0);
1547*77c1e3ccSAndroid Build Coastguard Worker }
1548*77c1e3ccSAndroid Build Coastguard Worker if (cols_within_bounds) {
1549*77c1e3ccSAndroid Build Coastguard Worker *cols_within_bounds =
1550*77c1e3ccSAndroid Build Coastguard Worker (block_cols >> pd->subsampling_x) + 2 * is_chroma_sub8_x;
1551*77c1e3ccSAndroid Build Coastguard Worker assert(*cols_within_bounds >= 0);
1552*77c1e3ccSAndroid Build Coastguard Worker }
1553*77c1e3ccSAndroid Build Coastguard Worker }
1554*77c1e3ccSAndroid Build Coastguard Worker
1555*77c1e3ccSAndroid Build Coastguard Worker /* clang-format off */
1556*77c1e3ccSAndroid Build Coastguard Worker // Pointer to a three-dimensional array whose first dimension is PALETTE_SIZES.
1557*77c1e3ccSAndroid Build Coastguard Worker typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS]
1558*77c1e3ccSAndroid Build Coastguard Worker [CDF_SIZE(PALETTE_COLORS)];
1559*77c1e3ccSAndroid Build Coastguard Worker // Pointer to a const three-dimensional array whose first dimension is
1560*77c1e3ccSAndroid Build Coastguard Worker // PALETTE_SIZES.
1561*77c1e3ccSAndroid Build Coastguard Worker typedef const int (*ColorCost)[PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS];
1562*77c1e3ccSAndroid Build Coastguard Worker /* clang-format on */
1563*77c1e3ccSAndroid Build Coastguard Worker
1564*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
1565*77c1e3ccSAndroid Build Coastguard Worker int rows;
1566*77c1e3ccSAndroid Build Coastguard Worker int cols;
1567*77c1e3ccSAndroid Build Coastguard Worker int n_colors;
1568*77c1e3ccSAndroid Build Coastguard Worker int plane_width;
1569*77c1e3ccSAndroid Build Coastguard Worker int plane_height;
1570*77c1e3ccSAndroid Build Coastguard Worker uint8_t *color_map;
1571*77c1e3ccSAndroid Build Coastguard Worker MapCdf map_cdf;
1572*77c1e3ccSAndroid Build Coastguard Worker ColorCost color_cost;
1573*77c1e3ccSAndroid Build Coastguard Worker } Av1ColorMapParam;
1574*77c1e3ccSAndroid Build Coastguard Worker
is_nontrans_global_motion(const MACROBLOCKD * xd,const MB_MODE_INFO * mbmi)1575*77c1e3ccSAndroid Build Coastguard Worker static inline int is_nontrans_global_motion(const MACROBLOCKD *xd,
1576*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO *mbmi) {
1577*77c1e3ccSAndroid Build Coastguard Worker int ref;
1578*77c1e3ccSAndroid Build Coastguard Worker
1579*77c1e3ccSAndroid Build Coastguard Worker // First check if all modes are GLOBALMV
1580*77c1e3ccSAndroid Build Coastguard Worker if (mbmi->mode != GLOBALMV && mbmi->mode != GLOBAL_GLOBALMV) return 0;
1581*77c1e3ccSAndroid Build Coastguard Worker
1582*77c1e3ccSAndroid Build Coastguard Worker if (AOMMIN(mi_size_wide[mbmi->bsize], mi_size_high[mbmi->bsize]) < 2)
1583*77c1e3ccSAndroid Build Coastguard Worker return 0;
1584*77c1e3ccSAndroid Build Coastguard Worker
1585*77c1e3ccSAndroid Build Coastguard Worker // Now check if all global motion is non translational
1586*77c1e3ccSAndroid Build Coastguard Worker for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
1587*77c1e3ccSAndroid Build Coastguard Worker if (xd->global_motion[mbmi->ref_frame[ref]].wmtype == TRANSLATION) return 0;
1588*77c1e3ccSAndroid Build Coastguard Worker }
1589*77c1e3ccSAndroid Build Coastguard Worker return 1;
1590*77c1e3ccSAndroid Build Coastguard Worker }
1591*77c1e3ccSAndroid Build Coastguard Worker
get_plane_type(int plane)1592*77c1e3ccSAndroid Build Coastguard Worker static inline PLANE_TYPE get_plane_type(int plane) {
1593*77c1e3ccSAndroid Build Coastguard Worker return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
1594*77c1e3ccSAndroid Build Coastguard Worker }
1595*77c1e3ccSAndroid Build Coastguard Worker
av1_get_max_eob(TX_SIZE tx_size)1596*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_get_max_eob(TX_SIZE tx_size) {
1597*77c1e3ccSAndroid Build Coastguard Worker if (tx_size == TX_64X64 || tx_size == TX_64X32 || tx_size == TX_32X64) {
1598*77c1e3ccSAndroid Build Coastguard Worker return 1024;
1599*77c1e3ccSAndroid Build Coastguard Worker }
1600*77c1e3ccSAndroid Build Coastguard Worker if (tx_size == TX_16X64 || tx_size == TX_64X16) {
1601*77c1e3ccSAndroid Build Coastguard Worker return 512;
1602*77c1e3ccSAndroid Build Coastguard Worker }
1603*77c1e3ccSAndroid Build Coastguard Worker return tx_size_2d[tx_size];
1604*77c1e3ccSAndroid Build Coastguard Worker }
1605*77c1e3ccSAndroid Build Coastguard Worker
1606*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
1607*77c1e3ccSAndroid Build Coastguard Worker
1608*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
1609*77c1e3ccSAndroid Build Coastguard Worker } // extern "C"
1610*77c1e3ccSAndroid Build Coastguard Worker #endif
1611*77c1e3ccSAndroid Build Coastguard Worker
1612*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AV1_COMMON_BLOCKD_H_
1613