1 /*
2 * Copyright(c) 2019 Intel Corporation
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
10 */
11
12 #ifndef EbBlockStructures_h
13 #define EbBlockStructures_h
14
15 #include "EbDefinitions.h"
16 #include "EbSegmentationParams.h"
17 #include "EbAv1Structs.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #define MAX_TILE_WIDTH (4096) // Max Tile width in pixels
24 #define MAX_TILE_AREA (4096 * 2304) // Maximum tile area in pixels
25
26 typedef struct MV {
27 int16_t row;
28 int16_t col;
29 } MV;
30
31 typedef union IntMv {
32 uint32_t as_int;
33 MV as_mv;
34 } IntMv; /* facilitates faster equality tests and copies */
35
36 typedef struct mv32 {
37 int32_t row;
38 int32_t col;
39 } MV32;
40
41 #define GET_MV_RAWPEL(x) (((x) + 3 + ((x) >= 0)) >> 3)
42 #define GET_MV_SUBPEL(x) ((x)*8)
43
44 // The motion vector in units of full pixel
45 typedef struct fullpel_mv {
46 int16_t row;
47 int16_t col;
48 } FULLPEL_MV;
49 static const MV kZeroMv = {0, 0};
50 static const FULLPEL_MV kZeroFullMv = {0, 0};
is_zero_mv(const MV * mv)51 static INLINE int is_zero_mv(const MV *mv) { return *((const uint32_t *)mv) == 0; }
52
is_equal_mv(const MV * a,const MV * b)53 static INLINE int is_equal_mv(const MV *a, const MV *b) {
54 return *((const uint32_t *)a) == *((const uint32_t *)b);
55 }
56
get_fullmv_from_mv(const MV * subpel_mv)57 static AOM_INLINE FULLPEL_MV get_fullmv_from_mv(const MV *subpel_mv) {
58 const FULLPEL_MV full_mv = {(int16_t)GET_MV_RAWPEL(subpel_mv->row),
59 (int16_t)GET_MV_RAWPEL(subpel_mv->col)};
60 return full_mv;
61 }
62
get_mv_from_fullmv(const FULLPEL_MV * full_mv)63 static AOM_INLINE MV get_mv_from_fullmv(const FULLPEL_MV *full_mv) {
64 const MV subpel_mv = {(int16_t)GET_MV_SUBPEL(full_mv->row),
65 (int16_t)GET_MV_SUBPEL(full_mv->col)};
66 return subpel_mv;
67 }
68
69 typedef struct OisMbResults {
70 int64_t intra_cost;
71 int32_t intra_mode;
72 } OisMbResults;
73 typedef struct CandidateMv {
74 IntMv this_mv;
75 IntMv comp_mv;
76 int32_t weight;
77 } CandidateMv;
78
79 typedef struct TileInfo {
80 int32_t mi_row_start, mi_row_end;
81 int32_t mi_col_start, mi_col_end;
82 int32_t tg_horz_boundary;
83 int32_t tile_row;
84 int32_t tile_col;
85 int32_t tile_rs_index; //tile index in raster order
86 } TileInfo;
87
88 #define INTER_TX_SIZE_BUF_LEN 16
89 #define TXK_TYPE_BUF_LEN 64
90
91 typedef struct FilterIntraModeInfo {
92 /*!< Specifies the type of intra filtering, and can represent any of the following:
93 * FILTER_DC_PRED, FILTER_V_PRED, FILTER_H_PRED, FILTER_D157_PRED, FILTER_PAETH_PRED */
94 FilterIntraMode filter_intra_mode;
95
96 /*!< This bit specifies whether or not intra filtering can be used. */
97 uint8_t use_filter_intra;
98 } FilterIntraModeInfo_t;
99
100 typedef struct InterIntraModeParams {
101 /*!< Specifies the type of intra prediction to be used */
102 InterIntraMode interintra_mode;
103
104 /*!< equal to 1 specifies that wedge blending should be used.
105 * wedge_interintra equal to 0 specifies that intra blending should be used. */
106 uint8_t wedge_interintra;
107
108 /*!< Used to derive the direction and offset of the wedge mask used during blending. */
109 uint8_t interintra_wedge_index;
110
111 /*!< Specifies the sign of the wedge blend. */
112 // int interintra_wedge_sign; Always 0
113 } InterIntraModeParams;
114
115 typedef struct BlockModeInfo {
116 // Common for both INTER and INTRA blocks
117 BlockSize sb_type;
118 PredictionMode mode;
119 int8_t skip;
120
121 PartitionType partition;
122
123 /*!< 1 indicates that this block will use some default settings and skip mode info.
124 * 0 indicates that the mode info is not skipped. */
125 int8_t skip_mode;
126
127 /*!< Specifies which segment is associated with the current intra block being decoded. */
128 int8_t segment_id;
129
130 /*!< Equal to 1 specifies that the segment_id is taken from the segmentation map. */
131 int8_t seg_id_predicted;
132
133 /*!< For Lossy mode : Specifies number of TUs in a block for each plane
134 For Lossless mode: Specifies number of TUs for a block of size other than
135 128x128, 128x64, 64x128 and 64x64 - computed based on blocksize */
136 uint8_t num_tus[MAX_MB_PLANE - 1];
137
138 /*!< Offset of first transform info from strat of SB pointer for each plane */
139 uint16_t first_txb_offset[MAX_MB_PLANE - 1];
140
141 // Only for INTRA blocks
142 UvPredictionMode uv_mode;
143
144 uint8_t use_intrabc;
145
146 // Only for INTER blocks
147
148 MvReferenceFrame ref_frame[2];
149 IntMv mv[2];
150
151 uint16_t ref_mv_idx;
152
153 // interinter members
154
155 InterIntraModeParams interintra_mode_params;
156
157 /*!< Specifies the type of motion compensation to perform. */
158 MotionMode motion_mode;
159
160 InterIntraMode is_inter_intra;
161
162 /*!< 0 indicates that a distance based weighted scheme should be used for blending.
163 * 1 indicates that the averaging scheme should be used for blending.*/
164 uint8_t compound_idx;
165
166 InterInterCompoundData inter_inter_compound;
167 FilterIntraModeInfo_t filter_intra_mode_info;
168
169 /*!< Specifies how the motion vector used by inter prediction is obtained when using compound prediction. */
170 uint8_t compound_mode;
171
172 /*!< Specifies the type of filter used in inter prediction. Values 0..3 are allowed
173 * with the same interpretation as for interpolation_filter. One filter type is specified
174 * for the vertical filter direction and one for the horizontal filter direction.*/
175 uint32_t interp_filters;
176
177 /*!< Index of the alpha Cb and alpha Cr combination */
178 uint8_t cfl_alpha_idx;
179
180 /*!< Contains the sign of the alpha values for U and V packed together into a single syntax element. */
181 uint8_t cfl_alpha_signs;
182
183 /*!< The actual prediction angle is the base angle + (angle_delta * step). */
184 int8_t angle_delta[PLANE_TYPES];
185
186 // Number of base colors for Y (0) and UV (1)
187 uint8_t palette_size[MAX_MB_PLANE - 1];
188
189 /*mi_row & mi_col wrt a super block*/
190 int8_t mi_row_in_sb;
191 int8_t mi_col_in_sb;
192
193 #if MODE_INFO_DBG
194 int32_t mi_row;
195 int32_t mi_col;
196 #endif
197 } BlockModeInfo;
198
199 typedef struct MbModeInfo {
200 #if CONFIG_RD_DEBUG
201 RD_STATS rd_stats;
202 int32_t mi_row;
203 int32_t mi_col;
204 #endif
205 EbWarpedMotionParams wm_params;
206 int32_t comp_group_idx;
207
208 int8_t cdef_strength;
209 TxSize tx_size;
210 uint8_t tx_depth;
211 BlockModeInfo block_mi;
212 PaletteModeInfo palette_mode_info;
213 } MbModeInfo;
214
215 void svt_av1_tile_set_col(TileInfo *tile, const TilesInfo *tiles_info, int32_t mi_cols, int col);
216 void svt_av1_tile_set_row(TileInfo *tile, TilesInfo *tiles_info, int32_t mi_rows, int row);
217
tile_log2(int32_t blk_size,int32_t target)218 static INLINE int32_t tile_log2(int32_t blk_size, int32_t target) {
219 int32_t k;
220 for (k = 0; (blk_size << k) < target; k++) {}
221 return k;
222 }
223
224 #ifdef __cplusplus
225 }
226 #endif
227 #endif // EbBlockStructures_h
228