Parent Directory | Revision Log
Revision 326 - (view) (download)
1 : | chl | 326 | /************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - Motion sad header - | ||
5 : | * | ||
6 : | * This program is free software; you can redistribute it and/or modify | ||
7 : | * it under the terms of the GNU General Public License as published by | ||
8 : | * the Free Software Foundation; either version 2 of the License, or | ||
9 : | * (at your option) any later version. | ||
10 : | * | ||
11 : | * This program is distributed in the hope that it will be useful, | ||
12 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 : | * GNU General Public License for more details. | ||
15 : | * | ||
16 : | * You should have received a copy of the GNU General Public License | ||
17 : | * along with this program; if not, write to the Free Software | ||
18 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 : | * | ||
20 : | * $Id: motion.h,v 1.13 2002-07-21 23:34:08 chl Exp $ | ||
21 : | * | ||
22 : | ***************************************************************************/ | ||
23 : | |||
24 : | #ifndef _MOTION_H_ | ||
25 : | #define _MOTION_H_ | ||
26 : | |||
27 : | #include "../portab.h" | ||
28 : | #include "../global.h" | ||
29 : | |||
30 : | /* hard coded motion search parameters for motion_est and smp_motion_est */ | ||
31 : | |||
32 : | // very large value | ||
33 : | #define MV_MAX_ERROR (4096 * 256) | ||
34 : | |||
35 : | // stop search if sdelta < THRESHOLD | ||
36 : | #define MV16_THRESHOLD 192 | ||
37 : | #define MV8_THRESHOLD 56 | ||
38 : | |||
39 : | #define NEIGH_MOVE_THRESH 0 | ||
40 : | // how much a block's MV must differ from his neighbour | ||
41 : | // to be search for INTER4V. The more, the faster... | ||
42 : | |||
43 : | /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */ | ||
44 : | /* nb = vop pixels * 2^(bpp-8) */ | ||
45 : | #define MV16_00_BIAS (128+1) | ||
46 : | #define MV8_00_BIAS (0) | ||
47 : | |||
48 : | /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */ | ||
49 : | #define MV16_INTER_BIAS 512 | ||
50 : | |||
51 : | /* Parameters which control inter/inter4v decision */ | ||
52 : | #define IMV16X16 5 | ||
53 : | |||
54 : | /* vector map (vlc delta size) smoother parameters */ | ||
55 : | #define NEIGH_TEND_16X16 2 | ||
56 : | #define NEIGH_TEND_8X8 2 | ||
57 : | |||
58 : | // fast ((A)/2)*2 | ||
59 : | #define EVEN(A) (((A)<0?(A)+1:(A)) & ~1) | ||
60 : | |||
61 : | #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) ) | ||
62 : | #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) | ||
63 : | |||
64 : | /* default methods of Search, will be changed to function variable */ | ||
65 : | |||
66 : | #ifndef SEARCH16 | ||
67 : | #define SEARCH16 PMVfastSearch16 | ||
68 : | //#define SEARCH16 FullSearch16 | ||
69 : | //#define SEARCH16 EPZSSearch16 | ||
70 : | #endif | ||
71 : | |||
72 : | #ifndef SEARCH8 | ||
73 : | #define SEARCH8 PMVfastSearch8 | ||
74 : | //#define SEARCH8 EPZSSearch8 | ||
75 : | #endif | ||
76 : | |||
77 : | |||
78 : | /* | ||
79 : | * Calculate the min/max range (in halfpixels) | ||
80 : | * relative to the _MACROBLOCK_ position | ||
81 : | */ | ||
82 : | |||
83 : | static void __inline | ||
84 : | get_range(int32_t * const min_dx, | ||
85 : | int32_t * const max_dx, | ||
86 : | int32_t * const min_dy, | ||
87 : | int32_t * const max_dy, | ||
88 : | const uint32_t x, | ||
89 : | const uint32_t y, | ||
90 : | const uint32_t block_sz, /* block dimension, 8 or 16 */ | ||
91 : | |||
92 : | const uint32_t width, | ||
93 : | const uint32_t height, | ||
94 : | const uint32_t fcode) | ||
95 : | { | ||
96 : | |||
97 : | const int search_range = 32 << (fcode - 1); | ||
98 : | const int high = search_range - 1; | ||
99 : | const int low = -search_range; | ||
100 : | |||
101 : | /* convert full-pixel measurements to half pixel */ | ||
102 : | const int hp_width = 2 * width; | ||
103 : | const int hp_height = 2 * height; | ||
104 : | const int hp_edge = 2 * block_sz; | ||
105 : | |||
106 : | /* we need _right end_ of block, not x-coordinate */ | ||
107 : | const int hp_x = 2 * (x) * block_sz; | ||
108 : | |||
109 : | /* same for _bottom end_ */ | ||
110 : | const int hp_y = 2 * (y) * block_sz; | ||
111 : | |||
112 : | *max_dx = MIN(high, hp_width - hp_x); | ||
113 : | *max_dy = MIN(high, hp_height - hp_y); | ||
114 : | *min_dx = MAX(low, -(hp_edge + hp_x)); | ||
115 : | *min_dy = MAX(low, -(hp_edge + hp_y)); | ||
116 : | |||
117 : | } | ||
118 : | |||
119 : | |||
120 : | /* | ||
121 : | * getref: calculate reference image pointer | ||
122 : | * the decision to use interpolation h/v/hv or the normal image is | ||
123 : | * based on dx & dy. | ||
124 : | */ | ||
125 : | |||
126 : | static __inline const uint8_t * | ||
127 : | get_ref(const uint8_t * const refn, | ||
128 : | const uint8_t * const refh, | ||
129 : | const uint8_t * const refv, | ||
130 : | const uint8_t * const refhv, | ||
131 : | const uint32_t x, | ||
132 : | const uint32_t y, | ||
133 : | const uint32_t block, /* block dimension, 8 or 16 */ | ||
134 : | |||
135 : | const int32_t dx, | ||
136 : | const int32_t dy, | ||
137 : | const uint32_t stride) | ||
138 : | { | ||
139 : | |||
140 : | |||
141 : | switch (((dx & 1) << 1) + (dy & 1)) { /* ((dx%2)?2:0)+((dy%2)?1:0) */ | ||
142 : | case 0: | ||
143 : | return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); | ||
144 : | case 1: | ||
145 : | return refv + (int) ((x * block + dx / 2) + (y * block + | ||
146 : | (dy - 1) / 2) * stride); | ||
147 : | case 2: | ||
148 : | return refh + (int) ((x * block + (dx - 1) / 2) + (y * block + | ||
149 : | dy / 2) * stride); | ||
150 : | default: | ||
151 : | case 3: | ||
152 : | return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block + | ||
153 : | (dy - 1) / 2) * stride); | ||
154 : | } | ||
155 : | |||
156 : | } | ||
157 : | |||
158 : | |||
159 : | /* This is somehow a copy of get_ref, but with MV instead of X,Y */ | ||
160 : | |||
161 : | static __inline const uint8_t * | ||
162 : | get_ref_mv(const uint8_t * const refn, | ||
163 : | const uint8_t * const refh, | ||
164 : | const uint8_t * const refv, | ||
165 : | const uint8_t * const refhv, | ||
166 : | const uint32_t x, | ||
167 : | const uint32_t y, | ||
168 : | const uint32_t block, /* block dimension, 8 or 16 */ | ||
169 : | |||
170 : | const VECTOR * mv, /* measured in half-pel! */ | ||
171 : | |||
172 : | const uint32_t stride) | ||
173 : | { | ||
174 : | |||
175 : | switch ((((mv->x) & 1) << 1) + ((mv->y) & 1)) { | ||
176 : | case 0: | ||
177 : | return refn + (int) ((x * block + (mv->x) / 2) + (y * block + | ||
178 : | (mv->y) / 2) * stride); | ||
179 : | case 1: | ||
180 : | return refv + (int) ((x * block + (mv->x) / 2) + (y * block + | ||
181 : | ((mv->y) - 1) / 2) * stride); | ||
182 : | case 2: | ||
183 : | return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block + | ||
184 : | (mv->y) / 2) * stride); | ||
185 : | default: | ||
186 : | case 3: | ||
187 : | return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block + | ||
188 : | ((mv->y) - | ||
189 : | 1) / 2) * stride); | ||
190 : | } | ||
191 : | |||
192 : | } | ||
193 : | |||
194 : | |||
195 : | static __inline const uint8_t * | ||
196 : | get_iref(const uint8_t * const ref, | ||
197 : | const uint32_t x, | ||
198 : | const uint32_t y, | ||
199 : | const uint32_t block, /* block dimension, 8 or 16 */ | ||
200 : | |||
201 : | const int32_t dx, | ||
202 : | const int32_t dy, | ||
203 : | const uint32_t stride) | ||
204 : | { | ||
205 : | return ref + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); | ||
206 : | } | ||
207 : | |||
208 : | static __inline const uint8_t * | ||
209 : | get_iref_mv(const uint8_t * const ref, | ||
210 : | const uint32_t x, | ||
211 : | const uint32_t y, | ||
212 : | const uint32_t block, /* block dimension, 8 or 16 */ | ||
213 : | |||
214 : | const VECTOR * mv, /* as usual measured in half-pel */ | ||
215 : | |||
216 : | const uint32_t stride) | ||
217 : | { | ||
218 : | return ref + (int) ((x * block + (mv->x) / 2) + (y * block + (mv->y) / 2) * stride); | ||
219 : | } | ||
220 : | |||
221 : | |||
222 : | /* prototypes for MainSearch functions, i.e. Diamondsearch, FullSearch or whatever */ | ||
223 : | |||
224 : | typedef int32_t(MainSearch16Func) (const uint8_t * const pRef, | ||
225 : | const uint8_t * const pRefH, | ||
226 : | const uint8_t * const pRefV, | ||
227 : | const uint8_t * const pRefHV, | ||
228 : | const uint8_t * const cur, | ||
229 : | const int x, | ||
230 : | const int y, | ||
231 : | const int start_x, | ||
232 : | const int start_y, | ||
233 : | int iMinSAD, | ||
234 : | VECTOR * const currMV, | ||
235 : | const int center_x, | ||
236 : | const int center_y, | ||
237 : | const int32_t min_dx, | ||
238 : | const int32_t max_dx, | ||
239 : | const int32_t min_dy, | ||
240 : | const int32_t max_dy, | ||
241 : | const int32_t iEdgedWidth, | ||
242 : | const int32_t iDiamondSize, | ||
243 : | const int32_t iFcode, | ||
244 : | const int32_t iQuant, | ||
245 : | int iFound); | ||
246 : | |||
247 : | typedef MainSearch16Func *MainSearch16FuncPtr; | ||
248 : | |||
249 : | |||
250 : | typedef int32_t(MainSearch8Func) (const uint8_t * const pRef, | ||
251 : | const uint8_t * const pRefH, | ||
252 : | const uint8_t * const pRefV, | ||
253 : | const uint8_t * const pRefHV, | ||
254 : | const uint8_t * const cur, | ||
255 : | const int x, | ||
256 : | const int y, | ||
257 : | const int start_x, | ||
258 : | const int start_y, | ||
259 : | int iMinSAD, | ||
260 : | VECTOR * const currMV, | ||
261 : | const int center_x, | ||
262 : | const int center_y, | ||
263 : | const int32_t min_dx, | ||
264 : | const int32_t max_dx, | ||
265 : | const int32_t min_dy, | ||
266 : | const int32_t max_dy, | ||
267 : | const int32_t iEdgedWidth, | ||
268 : | const int32_t iDiamondSize, | ||
269 : | const int32_t iFcode, | ||
270 : | const int32_t iQuant, | ||
271 : | int iFound); | ||
272 : | |||
273 : | typedef MainSearch8Func *MainSearch8FuncPtr; | ||
274 : | |||
275 : | |||
276 : | /* prototypes for MotionEstimation functions, i.e. PMVfast, EPZS or whatever */ | ||
277 : | |||
278 : | typedef int32_t(Search16Func) ( const uint8_t * const pRef, | ||
279 : | const uint8_t * const pRefH, | ||
280 : | const uint8_t * const pRefV, | ||
281 : | const uint8_t * const pRefHV, | ||
282 : | const IMAGE * const pCur, | ||
283 : | const int x, | ||
284 : | const int y, | ||
285 : | const int start_x, | ||
286 : | const int start_y, | ||
287 : | const int center_x, | ||
288 : | const int center_y, | ||
289 : | const uint32_t MotionFlags, | ||
290 : | const uint32_t iQuant, | ||
291 : | const uint32_t iFcode, | ||
292 : | const MBParam * const pParam, | ||
293 : | const MACROBLOCK * const pMBs, | ||
294 : | const MACROBLOCK * const prevMBs, | ||
295 : | VECTOR * const currMV, | ||
296 : | VECTOR * const currPMV); | ||
297 : | |||
298 : | typedef Search16Func *Search16FuncPtr; | ||
299 : | |||
300 : | typedef int32_t(Search8Func) ( const uint8_t * const pRef, | ||
301 : | const uint8_t * const pRefH, | ||
302 : | const uint8_t * const pRefV, | ||
303 : | const uint8_t * const pRefHV, | ||
304 : | const IMAGE * const pCur, | ||
305 : | const int x, | ||
306 : | const int y, | ||
307 : | const int start_x, | ||
308 : | const int start_y, | ||
309 : | const int center_x, | ||
310 : | const int center_y, | ||
311 : | const uint32_t MotionFlags, | ||
312 : | const uint32_t iQuant, | ||
313 : | const uint32_t iFcode, | ||
314 : | const MBParam * const pParam, | ||
315 : | const MACROBLOCK * const pMBs, | ||
316 : | const MACROBLOCK * const prevMBs, | ||
317 : | VECTOR * const currMV, | ||
318 : | VECTOR * const currPMV); | ||
319 : | |||
320 : | typedef Search8Func *Search8FuncPtr; | ||
321 : | |||
322 : | Search16Func PMVfastSearch16; | ||
323 : | Search16Func EPZSSearch16; | ||
324 : | Search16Func PMVfastIntSearch16; | ||
325 : | |||
326 : | Search8Func PMVfastSearch8; | ||
327 : | Search8Func EPZSSearch8; | ||
328 : | |||
329 : | |||
330 : | bool | ||
331 : | MotionEstimation(MBParam * const pParam, | ||
332 : | FRAMEINFO * const current, | ||
333 : | FRAMEINFO * const reference, | ||
334 : | const IMAGE * const pRefH, | ||
335 : | const IMAGE * const pRefV, | ||
336 : | const IMAGE * const pRefHV, | ||
337 : | const uint32_t iLimit); | ||
338 : | |||
339 : | #ifdef _SMP | ||
340 : | bool | ||
341 : | SMP_MotionEstimation(MBParam * const pParam, | ||
342 : | FRAMEINFO * const current, | ||
343 : | FRAMEINFO * const reference, | ||
344 : | const IMAGE * const pRefH, | ||
345 : | const IMAGE * const pRefV, | ||
346 : | const IMAGE * const pRefHV, | ||
347 : | const uint32_t iLimit); | ||
348 : | #endif | ||
349 : | |||
350 : | |||
351 : | void MotionEstimationBVOP(MBParam * const pParam, | ||
352 : | FRAMEINFO * const frame, | ||
353 : | // forward (past) reference | ||
354 : | const int32_t time_bp, | ||
355 : | const int32_t time_pp, | ||
356 : | const MACROBLOCK * const f_mbs, | ||
357 : | const IMAGE * const f_ref, | ||
358 : | const IMAGE * const f_refH, | ||
359 : | const IMAGE * const f_refV, | ||
360 : | const IMAGE * const f_refHV, | ||
361 : | // backward (future) reference | ||
362 : | const MACROBLOCK * const b_mbs, | ||
363 : | const IMAGE * const b_ref, | ||
364 : | const IMAGE * const b_refH, | ||
365 : | const IMAGE * const b_refV, | ||
366 : | const IMAGE * const b_refHV); | ||
367 : | |||
368 : | void MBMotionCompensationBVOP(MBParam * pParam, | ||
369 : | MACROBLOCK * const mb, | ||
370 : | const uint32_t i, | ||
371 : | const uint32_t j, | ||
372 : | IMAGE * const cur, | ||
373 : | const IMAGE * const f_ref, | ||
374 : | const IMAGE * const f_refh, | ||
375 : | const IMAGE * const f_refv, | ||
376 : | const IMAGE * const f_refhv, | ||
377 : | const IMAGE * const b_ref, | ||
378 : | const IMAGE * const b_refh, | ||
379 : | const IMAGE * const b_refv, | ||
380 : | const IMAGE * const b_refhv, | ||
381 : | int16_t * dct_codes); | ||
382 : | |||
383 : | |||
384 : | |||
385 : | typedef int32_t(Halfpel8_RefineFunc) (const uint8_t * const pRef, | ||
386 : | const uint8_t * const pRefH, | ||
387 : | const uint8_t * const pRefV, | ||
388 : | const uint8_t * const pRefHV, | ||
389 : | const uint8_t * const cur, | ||
390 : | const int x, | ||
391 : | const int y, | ||
392 : | VECTOR * const currMV, | ||
393 : | int32_t iMinSAD, | ||
394 : | const int center_x, | ||
395 : | const int center_y, | ||
396 : | const int32_t min_dx, | ||
397 : | const int32_t max_dx, | ||
398 : | const int32_t min_dy, | ||
399 : | const int32_t max_dy, | ||
400 : | const int32_t iFcode, | ||
401 : | const int32_t iQuant, | ||
402 : | const int32_t iEdgedWidth); | ||
403 : | |||
404 : | typedef Halfpel8_RefineFunc *Halfpel8_RefineFuncPtr; | ||
405 : | extern Halfpel8_RefineFuncPtr Halfpel8_Refine; | ||
406 : | Halfpel8_RefineFunc Halfpel8_Refine_c; | ||
407 : | Halfpel8_RefineFunc Halfpel8_Refine_ia64; | ||
408 : | |||
409 : | |||
410 : | #endif /* _MOTION_H_ */ |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |