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.
12 #ifndef __INC_BLOCKD_H
13 #define __INC_BLOCKD_H
15 void vpx_log(const char *format, ...);
17 #include "vpx_config.h"
18 #include "vpx_scale/yv12config.h"
20 #include "treecoder.h"
22 #include "vpx_ports/mem.h"
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
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;
55 ENTROPY_CONTEXT y1[4];
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) \
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 */
91 /* Macroblock level features */
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 */
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)
111 B_DC_PRED, /* average of above and left pixels */
114 B_VE_PRED, /* vertical prediction */
115 B_HE_PRED, /* horizontal prediction */
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. */
142 B_PREDICTION_MODE as_mode;
153 } MV_REFERENCE_FRAME;
157 MB_PREDICTION_MODE mode, uv_mode;
158 MV_REFERENCE_FRAME ref_frame;
161 unsigned char partitioning;
162 unsigned char mb_skip_coeff; /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
163 unsigned char need_to_clamp_mvs;
164 unsigned char segment_id; /* Which set of segmentation parameters should be used for this MB */
170 union b_mode_info bmi[16];
173 #if CONFIG_MULTI_RES_ENCODING
174 /* The information needed to be stored for higher-resolution encoder */
177 MB_PREDICTION_MODE mode;
178 MV_REFERENCE_FRAME ref_frame;
180 //union b_mode_info bmi[16];
181 int dissim; // dissimilarity level of the macroblock
189 unsigned char *predictor;
193 /* 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries */
194 unsigned char **base_pre;
198 unsigned char **base_dst;
204 union b_mode_info bmi;
207 typedef struct MacroBlockD
209 DECLARE_ALIGNED(16, short, diff[400]); /* from idct diff */
210 DECLARE_ALIGNED(16, unsigned char, predictor[384]);
211 DECLARE_ALIGNED(16, short, qcoeff[400]);
212 DECLARE_ALIGNED(16, short, dqcoeff[400]);
213 DECLARE_ALIGNED(16, char, eobs[25]);
215 /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */
219 YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
220 YV12_BUFFER_CONFIG dst;
222 MODE_INFO *mode_info_context;
223 int mode_info_stride;
225 FRAME_TYPE frame_type;
231 ENTROPY_CONTEXT_PLANES *above_context;
232 ENTROPY_CONTEXT_PLANES *left_context;
234 /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */
235 unsigned char segmentation_enabled;
237 /* 0 (do not update) 1 (update) the macroblock segmentation map. */
238 unsigned char update_mb_segmentation_map;
240 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
241 unsigned char update_mb_segmentation_data;
243 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
244 unsigned char mb_segement_abs_delta;
246 /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */
247 /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */
248 vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS]; /* Probability Tree used to code Segment number */
250 signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; /* Segment parameters */
252 /* mode_based Loop filter adjustment */
253 unsigned char mode_ref_lf_delta_enabled;
254 unsigned char mode_ref_lf_delta_update;
256 /* Delta values have the range +/- MAX_LOOP_FILTER */
257 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */
258 signed char ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */
259 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */
260 signed char mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */
262 /* Distance of MB away from frame edges */
264 int mb_to_right_edge;
266 int mb_to_bottom_edge;
268 int ref_frame_cost[MAX_REF_FRAMES];
271 unsigned int frames_since_golden;
272 unsigned int frames_till_alt_ref_frame;
273 vp8_subpix_fn_t subpixel_predict;
274 vp8_subpix_fn_t subpixel_predict8x4;
275 vp8_subpix_fn_t subpixel_predict8x8;
276 vp8_subpix_fn_t subpixel_predict16x16;
282 #if ARCH_X86 || ARCH_X86_64
283 /* This is an intermediate buffer currently used in sub-pixel motion search
284 * to keep a copy of the reference area. This buffer can be used for other
287 DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]);
290 #if CONFIG_RUNTIME_CPU_DETECT
291 struct VP8_COMMON_RTCD *rtcd;
296 extern void vp8_build_block_doffsets(MACROBLOCKD *x);
297 extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
299 #endif /* __INC_BLOCKD_H */