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