[cvs] / xvidcore / src / motion / motion.h Repository:
ViewVC logotype

Diff of /xvidcore/src/motion/motion.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13.2.4, Wed Oct 30 18:01:34 2002 UTC revision 1.15, Sat Sep 7 09:12:21 2002 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  -  Motion sad header  -   *  - Motion Estimation header -
5     *
6     *  Copyright(C) 2002 Christoph Lampert <gruel@web.de>
7   *   *
8   *  This program is an implementation of a part of one or more MPEG-4   *  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   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
# Line 36  Line 38 
38  #include "../portab.h"  #include "../portab.h"
39  #include "../global.h"  #include "../global.h"
40    
41    /* hard coded motion search parameters for motion_est and smp_motion_est */
42    
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  // fast ((A)/2)*2
70  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)
71    
72  #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )  #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )
73  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
74    
75  static const uint32_t roundtab[16] =  /* default methods of Search, will be changed to function variable */
76                  { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };  
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   * modified rounding tables   * Calculate the min/max range (in halfpixels)
91   * original tables see ISO spec tables 7-6 -> 7-9   * relative to the _MACROBLOCK_ position
92   */   */
93    
94  /* K = 4 */  static void __inline
95  static const uint32_t roundtab_76[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 };  get_range(int32_t * const min_dx,
96  /* K = 2 */                    int32_t * const max_dx,
97  static const uint32_t roundtab_78[8] = { 0, 0, 1, 1, 0, 0, 0, 1  };                    int32_t * const min_dy,
98  /* K = 1 */                    int32_t * const max_dy,
99  static const uint32_t roundtab_79[4] = { 0, 1, 0, 0 };                    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  /*  /*
# Line 89  Line 159 
159                  return refh + (int) ((x * block + (dx - 1) / 2) + (y * block +                  return refh + (int) ((x * block + (dx - 1) / 2) + (y * block +
160                                                                                                          dy / 2) * stride);                                                                                                          dy / 2) * stride);
161          default:          default:
162            case 3:
163                  return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block +                  return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block +
164                                                                                                           (dy - 1) / 2) * stride);                                                                                                           (dy - 1) / 2) * stride);
165          }          }
# Line 123  Line 194 
194                  return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +                  return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +
195                                                                                                                   (mv->y) / 2) * stride);                                                                                                                   (mv->y) / 2) * stride);
196          default:          default:
197            case 3:
198                  return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +                  return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +
199                                                                                                                    ((mv->y) -                                                                                                                    ((mv->y) -
200                                                                                                                     1) / 2) * stride);                                                                                                                     1) / 2) * stride);
# Line 130  Line 202 
202    
203  }  }
204    
 void MotionEstimationBVOP(MBParam * const pParam,  
                                                   FRAMEINFO * const frame,  
                                                   // forward (past) reference  
                                                   const int32_t time_bp,  
                                                   const int32_t time_pp,  
                                                   const MACROBLOCK * const f_mbs,  
                                                   const IMAGE * const f_ref,  
                                                   const IMAGE * const f_refH,  
                                                   const IMAGE * const f_refV,  
                                                   const IMAGE * const f_refHV,  
                                                   // backward (future) reference  
                                                   const MACROBLOCK * const b_mbs,  
                                                   const IMAGE * const b_ref,  
                                                   const IMAGE * const b_refH,  
                                                   const IMAGE * const b_refV,  
                                                   const IMAGE * const b_refHV);  
   
 void MBMotionCompensationBVOP(MBParam * pParam,  
                                                           MACROBLOCK * const mb,  
                                                           const uint32_t i,  
                                                           const uint32_t j,  
                                                           IMAGE * const cur,  
                                                           const IMAGE * const f_ref,  
                                                           const IMAGE * const f_refh,  
                                                           const IMAGE * const f_refv,  
                                                           const IMAGE * const f_refhv,  
                                                           const IMAGE * const b_ref,  
                                                           const IMAGE * const b_refh,  
                                                           const IMAGE * const b_refv,  
                                                           const IMAGE * const b_refhv,  
                                                           int16_t * dct_codes);  
205    
206  void  static __inline const uint8_t *
207  MotionEstimationHinted( MBParam * const pParam,  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,                                                  FRAMEINFO * const current,
344                                                  FRAMEINFO * const reference,                                                  FRAMEINFO * const reference,
345                                                  const IMAGE * const pRefH,                                                  const IMAGE * const pRefH,
346                                                  const IMAGE * const pRefV,                                                  const IMAGE * const pRefV,
347                                                  const IMAGE * const pRefHV);                                   const IMAGE * const pRefHV,
348                                     const uint32_t iLimit);
349    
350  int  #ifdef _SMP
351  MEanalysis(     const IMAGE * const pRef,  bool
352                          const IMAGE * const pCurrent,  SMP_MotionEstimation(MBParam * const pParam,
353                          MBParam * const pParam,                                   FRAMEINFO * const current,
354                          MACROBLOCK * const pMBs,                                   FRAMEINFO * const reference,
355                          const uint32_t iFcode);                                   const IMAGE * const pRefH,
356                                     const IMAGE * const pRefV,
357  int                                   const IMAGE * const pRefHV,
358  FindFcode(      const MBParam * const pParam,                                   const uint32_t iLimit);
359                          const FRAMEINFO * const current);  #endif
360    
361    typedef int32_t(Halfpel8_RefineFunc) (const uint8_t * const pRef,
362                                          const uint8_t * const pRefH,
363                                          const uint8_t * const pRefV,
364                                          const uint8_t * const pRefHV,
365                                          const uint8_t * const cur,
366                                          const int x,
367                                          const int y,
368                                          VECTOR * const currMV,
369                                          int32_t iMinSAD,
370                                               const int center_x,
371                                               const int center_y,
372                                          const int32_t min_dx,
373                                          const int32_t max_dx,
374                                          const int32_t min_dy,
375                                          const int32_t max_dy,
376                                          const int32_t iFcode,
377                                          const int32_t iQuant,
378                                          const int32_t iEdgedWidth);
379    
380    typedef Halfpel8_RefineFunc *Halfpel8_RefineFuncPtr;
381    extern Halfpel8_RefineFuncPtr Halfpel8_Refine;
382    Halfpel8_RefineFunc Halfpel8_Refine_c;
383    Halfpel8_RefineFunc Halfpel8_Refine_ia64;
384    
385    
386  #endif                                                  /* _MOTION_H_ */  #endif                                                  /* _MOTION_H_ */

Legend:
Removed from v.1.13.2.4  
changed lines
  Added in v.1.15

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4