[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, Sun Jul 21 23:34:08 2002 UTC revision 1.20, Wed Feb 19 20:12:43 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  -  Motion sad header  -   *  -  Motion sad header  -
5   *   *
6     *  This program is an implementation of a part of one or more MPEG-4
7     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
8     *  to use this software module in hardware or software products are
9     *  advised that its use may infringe existing patents or copyrights, and
10     *  any such use would be at such party's own risk.  The original
11     *  developer of this software module and his/her company, and subsequent
12     *  editors and their companies, will have no liability for use of this
13     *  software or modifications or derivatives thereof.
14     *
15   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
16   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
17   *  the Free Software Foundation; either version 2 of the License, or   *  the Free Software Foundation; either version 2 of the License, or
# Line 27  Line 36 
36  #include "../portab.h"  #include "../portab.h"
37  #include "../global.h"  #include "../global.h"
38    
 /* hard coded motion search parameters for motion_est and smp_motion_est */  
   
 // very large value  
 #define MV_MAX_ERROR    (4096 * 256)  
   
 // stop search if sdelta < THRESHOLD  
 #define MV16_THRESHOLD  192  
 #define MV8_THRESHOLD   56  
   
 #define NEIGH_MOVE_THRESH 0  
 // how much a block's MV must differ from his neighbour  
 // to be search for INTER4V. The more, the faster...  
   
 /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */  
 /* nb  = vop pixels * 2^(bpp-8) */  
 #define MV16_00_BIAS    (128+1)  
 #define MV8_00_BIAS     (0)  
   
 /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  
 #define MV16_INTER_BIAS 512  
   
 /* Parameters which control inter/inter4v decision */  
 #define IMV16X16                        5  
   
 /* vector map (vlc delta size) smoother parameters */  
 #define NEIGH_TEND_16X16        2  
 #define NEIGH_TEND_8X8          2  
   
39  // fast ((A)/2)*2  // fast ((A)/2)*2
40  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)
41    
42  #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )  #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )
43  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
44    
45  /* default methods of Search, will be changed to function variable */  /*****************************************************************************
46     * Modified rounding tables -- defined in motion_est.c
47  #ifndef SEARCH16   * Original tables see ISO spec tables 7-6 -> 7-9
48  #define SEARCH16        PMVfastSearch16   ****************************************************************************/
49  //#define SEARCH16  FullSearch16  
50  //#define SEARCH16  EPZSSearch16  extern const uint32_t roundtab[16];
51  #endif  
52    /* K = 4 */
53  #ifndef SEARCH8  extern const uint32_t roundtab_76[16];
54  #define SEARCH8         PMVfastSearch8  /* K = 2 */
55  //#define SEARCH8   EPZSSearch8  extern const uint32_t roundtab_78[8];
56  #endif  /* K = 1 */
57    extern const uint32_t roundtab_79[4];
   
 /*  
  * Calculate the min/max range (in halfpixels)  
  * relative to the _MACROBLOCK_ position  
  */  
   
 static void __inline  
 get_range(int32_t * const min_dx,  
                   int32_t * const max_dx,  
                   int32_t * const min_dy,  
                   int32_t * const max_dy,  
                   const uint32_t x,  
                   const uint32_t y,  
                   const uint32_t block_sz,      /* block dimension, 8 or 16 */  
   
                   const uint32_t width,  
                   const uint32_t height,  
                   const uint32_t fcode)  
 {  
   
         const int search_range = 32 << (fcode - 1);  
         const int high = search_range - 1;  
         const int low = -search_range;  
   
         /* convert full-pixel measurements to half pixel */  
         const int hp_width = 2 * width;  
         const int hp_height = 2 * height;  
         const int hp_edge = 2 * block_sz;  
   
         /* we need _right end_ of block, not x-coordinate */  
         const int hp_x = 2 * (x) * block_sz;  
   
         /* same for _bottom end_ */  
         const int hp_y = 2 * (y) * block_sz;  
   
         *max_dx = MIN(high, hp_width - hp_x);  
         *max_dy = MIN(high, hp_height - hp_y);  
         *min_dx = MAX(low, -(hp_edge + hp_x));  
         *min_dy = MAX(low, -(hp_edge + hp_y));  
   
 }  
58    
59    
60  /*  /*
# Line 134  Line 74 
74    
75                  const int32_t dx,                  const int32_t dx,
76                  const int32_t dy,                  const int32_t dy,
77                  const uint32_t stride)                  const int32_t stride)
78  {  {
79    
80    
# Line 148  Line 88 
88                  return refh + (int) ((x * block + (dx - 1) / 2) + (y * block +                  return refh + (int) ((x * block + (dx - 1) / 2) + (y * block +
89                                                                                                          dy / 2) * stride);                                                                                                          dy / 2) * stride);
90          default:          default:
         case 3:  
91                  return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block +                  return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block +
92                                                                                                           (dy - 1) / 2) * stride);                                                                                                           (dy - 1) / 2) * stride);
93          }          }
# Line 169  Line 108 
108    
109                     const VECTOR * mv,   /* measured in half-pel! */                     const VECTOR * mv,   /* measured in half-pel! */
110    
111                     const uint32_t stride)                     const int32_t stride)
112  {  {
113    
114          switch ((((mv->x) & 1) << 1) + ((mv->y) & 1)) {          switch ((((mv->x) & 1) << 1) + ((mv->y) & 1)) {
# Line 183  Line 122 
122                  return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +                  return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +
123                                                                                                                   (mv->y) / 2) * stride);                                                                                                                   (mv->y) / 2) * stride);
124          default:          default:
         case 3:  
125                  return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +                  return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +
126                                                                                                                    ((mv->y) -                                                                                                                    ((mv->y) -
127                                                                                                                     1) / 2) * stride);                                                                                                                     1) / 2) * stride);
# Line 191  Line 129 
129    
130  }  }
131    
   
 static __inline const uint8_t *  
 get_iref(const uint8_t * const ref,  
                 const uint32_t x,  
                 const uint32_t y,  
                 const uint32_t block,   /* block dimension, 8 or 16 */  
   
                 const int32_t dx,  
                 const int32_t dy,  
                 const uint32_t stride)  
 {  
         return ref + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride);  
 }  
   
 static __inline const uint8_t *  
 get_iref_mv(const uint8_t * const ref,  
                    const uint32_t x,  
                    const uint32_t y,  
                    const uint32_t block,        /* block dimension, 8 or 16 */  
   
                    const VECTOR * mv,   /* as usual measured in half-pel */  
   
                    const uint32_t stride)  
 {  
         return ref + (int) ((x * block + (mv->x) / 2) + (y * block + (mv->y) / 2) * stride);  
 }  
   
   
 /* prototypes for MainSearch functions, i.e. Diamondsearch, FullSearch or whatever */  
   
 typedef int32_t(MainSearch16Func) (const uint8_t * const pRef,  
                                                                    const uint8_t * const pRefH,  
                                                                    const uint8_t * const pRefV,  
                                                                    const uint8_t * const pRefHV,  
                                                                    const uint8_t * const cur,  
                                                                    const int x,  
                                                                    const int y,  
                                                                    const int start_x,  
                                                                    const int start_y,  
                                                                    int iMinSAD,  
                                                                    VECTOR * const currMV,  
                                                                    const int center_x,  
                                                                    const int center_y,  
                                                                    const int32_t min_dx,  
                                                                    const int32_t max_dx,  
                                                                    const int32_t min_dy,  
                                                                    const int32_t max_dy,  
                                                                    const int32_t iEdgedWidth,  
                                                                    const int32_t iDiamondSize,  
                                                                    const int32_t iFcode,  
                                                                    const int32_t iQuant,  
                                                                    int iFound);  
   
 typedef MainSearch16Func *MainSearch16FuncPtr;  
   
   
 typedef int32_t(MainSearch8Func) (const uint8_t * const pRef,  
                                                                   const uint8_t * const pRefH,  
                                                                   const uint8_t * const pRefV,  
                                                                   const uint8_t * const pRefHV,  
                                                                   const uint8_t * const cur,  
                                                                   const int x,  
                                                                   const int y,  
                                                                    const int start_x,  
                                                                    const int start_y,  
                                                                    int iMinSAD,  
                                                                    VECTOR * const currMV,  
                                                                    const int center_x,  
                                                                    const int center_y,  
                                                                   const int32_t min_dx,  
                                                                   const int32_t max_dx,  
                                                                   const int32_t min_dy,  
                                                                   const int32_t max_dy,  
                                                                   const int32_t iEdgedWidth,  
                                                                   const int32_t iDiamondSize,  
                                                                   const int32_t iFcode,  
                                                                   const int32_t iQuant,  
                                                                   int iFound);  
   
 typedef MainSearch8Func *MainSearch8FuncPtr;  
   
   
 /* prototypes for MotionEstimation functions, i.e. PMVfast, EPZS or whatever */  
   
 typedef int32_t(Search16Func) ( const uint8_t * const pRef,  
                                                                 const uint8_t * const pRefH,  
                                                                 const uint8_t * const pRefV,  
                                                                 const uint8_t * const pRefHV,  
                                                                 const IMAGE * const pCur,  
                                                                 const int x,  
                                                                 const int y,  
                                                                 const int start_x,  
                                                                 const int start_y,  
                                                                 const int center_x,  
                                                                 const int center_y,  
                                                                 const uint32_t MotionFlags,  
                                                                 const uint32_t iQuant,  
                                                                 const uint32_t iFcode,  
                                                                 const MBParam * const pParam,  
                                                                 const MACROBLOCK * const pMBs,  
                                                                 const MACROBLOCK * const prevMBs,  
                                                                 VECTOR * const currMV,  
                                                                 VECTOR * const currPMV);  
   
 typedef Search16Func *Search16FuncPtr;  
   
 typedef int32_t(Search8Func) (  const uint8_t * const pRef,  
                                                                 const uint8_t * const pRefH,  
                                                                 const uint8_t * const pRefV,  
                                                                 const uint8_t * const pRefHV,  
                                                                 const IMAGE * const pCur,  
                                                                 const int x,  
                                                                 const int y,  
                                                                 const int start_x,  
                                                                 const int start_y,  
                                                                 const int center_x,  
                                                                 const int center_y,  
                                                                 const uint32_t MotionFlags,  
                                                                 const uint32_t iQuant,  
                                                                 const uint32_t iFcode,  
                                                                 const MBParam * const pParam,  
                                                                 const MACROBLOCK * const pMBs,  
                                                                 const MACROBLOCK * const prevMBs,  
                                                                 VECTOR * const currMV,  
                                                                 VECTOR * const currPMV);  
   
 typedef Search8Func *Search8FuncPtr;  
   
 Search16Func PMVfastSearch16;  
 Search16Func EPZSSearch16;  
 Search16Func PMVfastIntSearch16;  
   
 Search8Func     PMVfastSearch8;  
 Search8Func     EPZSSearch8;  
   
   
 bool  
 MotionEstimation(MBParam * const pParam,  
                                  FRAMEINFO * const current,  
                                  FRAMEINFO * const reference,  
                                  const IMAGE * const pRefH,  
                                  const IMAGE * const pRefV,  
                                  const IMAGE * const pRefHV,  
                                  const uint32_t iLimit);  
   
 #ifdef _SMP  
 bool  
 SMP_MotionEstimation(MBParam * const pParam,  
                                  FRAMEINFO * const current,  
                                  FRAMEINFO * const reference,  
                                  const IMAGE * const pRefH,  
                                  const IMAGE * const pRefV,  
                                  const IMAGE * const pRefHV,  
                                  const uint32_t iLimit);  
 #endif  
   
   
132  void MotionEstimationBVOP(MBParam * const pParam,  void MotionEstimationBVOP(MBParam * const pParam,
133                                                    FRAMEINFO * const frame,                                                    FRAMEINFO * const frame,
134                                                    // forward (past) reference                                                    // forward (past) reference
# Line 359  Line 140 
140                                                    const IMAGE * const f_refV,                                                    const IMAGE * const f_refV,
141                                                    const IMAGE * const f_refHV,                                                    const IMAGE * const f_refHV,
142                                                    // backward (future) reference                                                    // backward (future) reference
143                                                    const MACROBLOCK * const b_mbs,                                                    const FRAMEINFO * const b_reference,
144                                                    const IMAGE * const b_ref,                                                    const IMAGE * const b_ref,
145                                                    const IMAGE * const b_refH,                                                    const IMAGE * const b_refH,
146                                                    const IMAGE * const b_refV,                                                    const IMAGE * const b_refV,
# Line 381  Line 162 
162                                                            int16_t * dct_codes);                                                            int16_t * dct_codes);
163    
164    
165    /* GMC stuff. Maybe better put it into a separate file */
166    
167    void
168    generate_GMCparameters( const int num_wp,                               // [input]: number of warppoints
169                                                    const int res,                                  // [input]: resolution
170                                                    const WARPPOINTS *const warp,   // [input]: warp points
171                                                    const int width, const int height,      // [input]: without edges!
172                                                    GMC_DATA *const gmc);           // [output] precalculated parameters
173    
174    void
175    generate_GMCimage(      const GMC_DATA *const gmc_data,         // [input] precalculated data
176                                            const IMAGE *const pRef,                        // [input]
177                                            const int mb_width,
178                                            const int mb_height,
179                                            const int stride,
180                                            const int stride2,
181                                            const int fcode,                                        // [input] some parameters...
182                                            const int32_t quarterpel,                       // [input] for rounding avgMV
183                                            const int reduced_resolution,           // [input] ignored
184                                            const int32_t rounding,                 // [input] for rounding image data
185                                            MACROBLOCK *const pMBs,         // [output] average motion vectors
186                                            IMAGE *const pGMC);                     // [output] full warped image
187    
188    
189    VECTOR generate_GMCimageMB(     const GMC_DATA *const gmc_data,         /* [input] all precalc data */
190                                                            const IMAGE *const pRef,                        // [input]
191                                                            const int mi, const int mj,             /* [input] MB position  */
192                                                            const int stride,                                       /* [input] Lumi stride */
193                                                            const int stride2,                                      /* [input] chroma stride */
194                                                            const int quarterpel,                           /* [input] for rounding of AvgMV */
195                                                            const int rounding,
196                                                            IMAGE *const pGMC);                                     /* [outut] generate image */
197    
198    
199    
200    /* Hinted ME */
201    
202    void
203    MotionEstimationHinted( MBParam * const pParam,
204                                                    FRAMEINFO * const current,
205                                                    FRAMEINFO * const reference,
206                                                    const IMAGE * const pRefH,
207                                                    const IMAGE * const pRefV,
208                                                    const IMAGE * const pRefHV);
209    
210    int
211    MEanalysis(     const IMAGE * const pRef,
212                            FRAMEINFO * const Current,
213                            MBParam * const pParam,
214                            int maxIntra,
215                            int intraCount,
216                            int bCount);
217    
218    int
219    FindFcode(      const MBParam * const pParam,
220                            const FRAMEINFO * const current);
221    
222    
223  typedef int32_t(Halfpel8_RefineFunc) (const uint8_t * const pRef,  int d_amv_penalty(int x, int y, const VECTOR pred, const uint32_t iFcode, const int quant);
                                       const uint8_t * const pRefH,  
                                       const uint8_t * const pRefV,  
                                       const uint8_t * const pRefHV,  
                                       const uint8_t * const cur,  
                                       const int x,  
                                       const int y,  
                                       VECTOR * const currMV,  
                                       int32_t iMinSAD,  
                                            const int center_x,  
                                            const int center_y,  
                                       const int32_t min_dx,  
                                       const int32_t max_dx,  
                                       const int32_t min_dy,  
                                       const int32_t max_dy,  
                                       const int32_t iFcode,  
                                       const int32_t iQuant,  
                                       const int32_t iEdgedWidth);  
   
 typedef Halfpel8_RefineFunc *Halfpel8_RefineFuncPtr;  
 extern Halfpel8_RefineFuncPtr Halfpel8_Refine;  
 Halfpel8_RefineFunc Halfpel8_Refine_c;  
 Halfpel8_RefineFunc Halfpel8_Refine_ia64;  
224    
225    
226  #endif                                                  /* _MOTION_H_ */  #endif                                                  /* _MOTION_H_ */

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.20

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