Merge "VP9: Eliminate up_available and left_available"
[aom.git] / vp8 / common / blockd.h
blob192108a06dba852431bef80fa09b7f6a6caeda04
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 #ifndef VP8_COMMON_BLOCKD_H_
13 #define VP8_COMMON_BLOCKD_H_
15 void vpx_log(const char *format, ...);
17 #include "vpx_config.h"
18 #include "vpx_scale/yv12config.h"
19 #include "mv.h"
20 #include "treecoder.h"
21 #include "vpx_ports/mem.h"
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 /*#define DCPRED 1*/
28 #define DCPREDSIMTHRESH 0
29 #define DCPREDCNTTHRESH 3
31 #define MB_FEATURE_TREE_PROBS 3
32 #define MAX_MB_SEGMENTS 4
34 #define MAX_REF_LF_DELTAS 4
35 #define MAX_MODE_LF_DELTAS 4
37 /* Segment Feature Masks */
38 #define SEGMENT_DELTADATA 0
39 #define SEGMENT_ABSDATA 1
41 typedef struct
43 int r, c;
44 } POS;
46 #define PLANE_TYPE_Y_NO_DC 0
47 #define PLANE_TYPE_Y2 1
48 #define PLANE_TYPE_UV 2
49 #define PLANE_TYPE_Y_WITH_DC 3
52 typedef char ENTROPY_CONTEXT;
53 typedef struct
55 ENTROPY_CONTEXT y1[4];
56 ENTROPY_CONTEXT u[2];
57 ENTROPY_CONTEXT v[2];
58 ENTROPY_CONTEXT y2;
59 } ENTROPY_CONTEXT_PLANES;
61 extern const unsigned char vp8_block2left[25];
62 extern const unsigned char vp8_block2above[25];
64 #define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \
65 Dest = (A)+(B);
68 typedef enum
70 KEY_FRAME = 0,
71 INTER_FRAME = 1
72 } FRAME_TYPE;
74 typedef enum
76 DC_PRED, /* average of above and left pixels */
77 V_PRED, /* vertical prediction */
78 H_PRED, /* horizontal prediction */
79 TM_PRED, /* Truemotion prediction */
80 B_PRED, /* block based prediction, each block has its own prediction mode */
82 NEARESTMV,
83 NEARMV,
84 ZEROMV,
85 NEWMV,
86 SPLITMV,
88 MB_MODE_COUNT
89 } MB_PREDICTION_MODE;
91 /* Macroblock level features */
92 typedef enum
94 MB_LVL_ALT_Q = 0, /* Use alternate Quantizer .... */
95 MB_LVL_ALT_LF = 1, /* Use alternate loop filter value... */
96 MB_LVL_MAX = 2 /* Number of MB level features supported */
98 } MB_LVL_FEATURES;
100 /* Segment Feature Masks */
101 #define SEGMENT_ALTQ 0x01
102 #define SEGMENT_ALT_LF 0x02
104 #define VP8_YMODES (B_PRED + 1)
105 #define VP8_UV_MODES (TM_PRED + 1)
107 #define VP8_MVREFS (1 + SPLITMV - NEARESTMV)
109 typedef enum
111 B_DC_PRED, /* average of above and left pixels */
112 B_TM_PRED,
114 B_VE_PRED, /* vertical prediction */
115 B_HE_PRED, /* horizontal prediction */
117 B_LD_PRED,
118 B_RD_PRED,
120 B_VR_PRED,
121 B_VL_PRED,
122 B_HD_PRED,
123 B_HU_PRED,
125 LEFT4X4,
126 ABOVE4X4,
127 ZERO4X4,
128 NEW4X4,
130 B_MODE_COUNT
131 } B_PREDICTION_MODE;
133 #define VP8_BINTRAMODES (B_HU_PRED + 1) /* 10 */
134 #define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
136 /* For keyframes, intra block modes are predicted by the (already decoded)
137 modes for the Y blocks to the left and above us; for interframes, there
138 is a single probability table. */
140 union b_mode_info
142 B_PREDICTION_MODE as_mode;
143 int_mv mv;
146 typedef enum
148 INTRA_FRAME = 0,
149 LAST_FRAME = 1,
150 GOLDEN_FRAME = 2,
151 ALTREF_FRAME = 3,
152 MAX_REF_FRAMES = 4
153 } MV_REFERENCE_FRAME;
155 typedef struct
157 uint8_t mode, uv_mode;
158 uint8_t ref_frame;
159 uint8_t is_4x4;
160 int_mv mv;
162 uint8_t partitioning;
163 uint8_t mb_skip_coeff; /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
164 uint8_t need_to_clamp_mvs;
165 uint8_t segment_id; /* Which set of segmentation parameters should be used for this MB */
166 } MB_MODE_INFO;
168 typedef struct modeinfo
170 MB_MODE_INFO mbmi;
171 union b_mode_info bmi[16];
172 } MODE_INFO;
174 #if CONFIG_MULTI_RES_ENCODING
175 /* The mb-level information needed to be stored for higher-resolution encoder */
176 typedef struct
178 MB_PREDICTION_MODE mode;
179 MV_REFERENCE_FRAME ref_frame;
180 int_mv mv;
181 int dissim; /* dissimilarity level of the macroblock */
182 } LOWER_RES_MB_INFO;
184 /* The frame-level information needed to be stored for higher-resolution
185 * encoder */
186 typedef struct
188 FRAME_TYPE frame_type;
189 int is_frame_dropped;
190 // The frame rate for the lowest resolution.
191 double low_res_framerate;
192 /* The frame number of each reference frames */
193 unsigned int low_res_ref_frames[MAX_REF_FRAMES];
194 // The video frame counter value for the key frame, for lowest resolution.
195 unsigned int key_frame_counter_value;
196 LOWER_RES_MB_INFO *mb_info;
197 } LOWER_RES_FRAME_INFO;
198 #endif
200 typedef struct blockd
202 short *qcoeff;
203 short *dqcoeff;
204 unsigned char *predictor;
205 short *dequant;
207 int offset;
208 char *eob;
210 union b_mode_info bmi;
211 } BLOCKD;
213 typedef void (*vp8_subpix_fn_t)(unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch);
215 typedef struct macroblockd
217 DECLARE_ALIGNED(16, unsigned char, predictor[384]);
218 DECLARE_ALIGNED(16, short, qcoeff[400]);
219 DECLARE_ALIGNED(16, short, dqcoeff[400]);
220 DECLARE_ALIGNED(16, char, eobs[25]);
222 DECLARE_ALIGNED(16, short, dequant_y1[16]);
223 DECLARE_ALIGNED(16, short, dequant_y1_dc[16]);
224 DECLARE_ALIGNED(16, short, dequant_y2[16]);
225 DECLARE_ALIGNED(16, short, dequant_uv[16]);
227 /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */
228 BLOCKD block[25];
229 int fullpixel_mask;
231 YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
232 YV12_BUFFER_CONFIG dst;
234 MODE_INFO *mode_info_context;
235 int mode_info_stride;
237 FRAME_TYPE frame_type;
239 int up_available;
240 int left_available;
242 unsigned char *recon_above[3];
243 unsigned char *recon_left[3];
244 int recon_left_stride[2];
246 /* Y,U,V,Y2 */
247 ENTROPY_CONTEXT_PLANES *above_context;
248 ENTROPY_CONTEXT_PLANES *left_context;
250 /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */
251 unsigned char segmentation_enabled;
253 /* 0 (do not update) 1 (update) the macroblock segmentation map. */
254 unsigned char update_mb_segmentation_map;
256 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
257 unsigned char update_mb_segmentation_data;
259 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
260 unsigned char mb_segement_abs_delta;
262 /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */
263 /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */
264 vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS]; /* Probability Tree used to code Segment number */
266 signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; /* Segment parameters */
268 /* mode_based Loop filter adjustment */
269 unsigned char mode_ref_lf_delta_enabled;
270 unsigned char mode_ref_lf_delta_update;
272 /* Delta values have the range +/- MAX_LOOP_FILTER */
273 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */
274 signed char ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */
275 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */
276 signed char mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */
278 /* Distance of MB away from frame edges */
279 int mb_to_left_edge;
280 int mb_to_right_edge;
281 int mb_to_top_edge;
282 int mb_to_bottom_edge;
286 vp8_subpix_fn_t subpixel_predict;
287 vp8_subpix_fn_t subpixel_predict8x4;
288 vp8_subpix_fn_t subpixel_predict8x8;
289 vp8_subpix_fn_t subpixel_predict16x16;
291 void *current_bc;
293 int corrupted;
295 #if ARCH_X86 || ARCH_X86_64
296 /* This is an intermediate buffer currently used in sub-pixel motion search
297 * to keep a copy of the reference area. This buffer can be used for other
298 * purpose.
300 DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]);
301 #endif
302 } MACROBLOCKD;
305 extern void vp8_build_block_doffsets(MACROBLOCKD *x);
306 extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
308 #ifdef __cplusplus
309 } // extern "C"
310 #endif
312 #endif // VP8_COMMON_BLOCKD_H_