[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.18, Tue Nov 26 23:44:10 2002 UTC revision 1.27, Fri Dec 24 13:21:35 2010 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Motion Estimation header -   *  - Motion module header -
5   *   *
6   *  Copyright(C) 2002 Christoph Lampert <gruel@web.de>   *  Copyright(C) 2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net>
7     *               2002 Michael Militzer <michael@xvid.org>
8   *   *
  *  This file is part of XviD, a free MPEG-4 video encoder/decoder  
9   *   *
10   *  XviD is free software; you can redistribute it and/or modify it   *  This program is free software ; you can redistribute it and/or modify
11   *  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
12   *  the Free Software Foundation; either version 2 of the License, or   *  the Free Software Foundation; either version 2 of the License, or
13   *  (at your option) any later version.   *  (at your option) any later version.
14   *   *
# Line 21  Line 21 
21   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23   *   *
  *  Under section 8 of the GNU General Public License, the copyright  
  *  holders of XVID explicitly forbid distribution in the following  
  *  countries:  
  *  
  *    - Japan  
  *    - United States of America  
  *  
  *  Linking XviD statically or dynamically with other modules is making a  
  *  combined work based on XviD.  Thus, the terms and conditions of the  
  *  GNU General Public License cover the whole combination.  
  *  
  *  As a special exception, the copyright holders of XviD give you  
  *  permission to link XviD with independent modules that communicate with  
  *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the  
  *  license terms of these independent modules, and to copy and distribute  
  *  the resulting combined work under terms of your choice, provided that  
  *  every copy of the combined work is accompanied by a complete copy of  
  *  the source code of XviD (the version of XviD used to produce the  
  *  combined work), being distributed under the terms of the GNU General  
  *  Public License plus this exception.  An independent module is a module  
  *  which is not derived from or based on XviD.  
  *  
  *  Note that people who make modified versions of XviD are not obligated  
  *  to grant this special exception for their modified versions; it is  
  *  their choice whether to do so.  The GNU General Public License gives  
  *  permission to release a modified version without this exception; this  
  *  exception also makes it possible to release a modified version which  
  *  carries forward this exception.  
  *  
24   * $Id$   * $Id$
25   *   *
26   ***************************************************************************/   ***************************************************************************/
# Line 60  Line 31 
31  #include "../portab.h"  #include "../portab.h"
32  #include "../global.h"  #include "../global.h"
33    
34  /* hard coded motion search parameters for motion_est */  /*****************************************************************************
35     * Modified rounding tables -- defined in estimation_common.c
36  /* very large value */   * Original tables see ISO spec tables 7-6 -> 7-9
37  #define MV_MAX_ERROR    (4096 * 256)   ****************************************************************************/
38    
39  /* stop search if sdelta < THRESHOLD */  extern const uint32_t roundtab[16];
40  #define MV16_THRESHOLD  192  /* K = 4 */
41  #define MV8_THRESHOLD   56  extern const uint32_t roundtab_76[16];
42    /* K = 2 */
43  #define NEIGH_MOVE_THRESH 0  extern const uint32_t roundtab_78[8];
44  /* how much a block's MV must differ from his neighbour  */  /* K = 1 */
45  /* to be search for INTER4V. The more, the faster... */  extern const uint32_t roundtab_79[4];
   
 /* 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  
   
 /* fast ((A)/2)*2 */  
 #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)  
   
 #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )  
 #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  
   
 /* default methods of Search, will be changed to function variable */  
   
 #ifndef SEARCH16  
 #define SEARCH16        PMVfastSearch16  
 /*#define SEARCH16  FullSearch16 */  
 /*#define SEARCH16  EPZSSearch16 */  
 #endif  
   
 #ifndef SEARCH8  
 #define SEARCH8         PMVfastSearch8  
 /*#define SEARCH8   EPZSSearch8 */  
 #endif  
   
   
 /*  
  * 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));  
   
 }  
   
   
 /*  
  * getref: calculate reference image pointer  
  * the decision to use interpolation h/v/hv or the normal image is  
  * based on dx & dy.  
  */  
   
 static __inline const uint8_t *  
 get_ref(const uint8_t * const refn,  
                 const uint8_t * const refh,  
                 const uint8_t * const refv,  
                 const uint8_t * const refhv,  
                 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)  
 {  
   
   
         switch (((dx & 1) << 1) + (dy & 1)) {   /* ((dx%2)?2:0)+((dy%2)?1:0) */  
         case 0:  
                 return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride);  
         case 1:  
                 return refv + (int) ((x * block + dx / 2) + (y * block +  
                                                                                           (dy - 1) / 2) * stride);  
         case 2:  
                 return refh + (int) ((x * block + (dx - 1) / 2) + (y * block +  
                                                                                                         dy / 2) * stride);  
         default:  
         case 3:  
                 return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block +  
                                                                                                          (dy - 1) / 2) * stride);  
         }  
   
 }  
   
   
 /* This is somehow a copy of get_ref, but with MV instead of X,Y */  
   
 static __inline const uint8_t *  
 get_ref_mv(const uint8_t * const refn,  
                    const uint8_t * const refh,  
                    const uint8_t * const refv,  
                    const uint8_t * const refhv,  
                    const uint32_t x,  
                    const uint32_t y,  
                    const uint32_t block,        /* block dimension, 8 or 16 */  
   
                    const VECTOR * mv,   /* measured in half-pel! */  
   
                    const uint32_t stride)  
 {  
   
         switch ((((mv->x) & 1) << 1) + ((mv->y) & 1)) {  
         case 0:  
                 return refn + (int) ((x * block + (mv->x) / 2) + (y * block +  
                                                                                                    (mv->y) / 2) * stride);  
         case 1:  
                 return refv + (int) ((x * block + (mv->x) / 2) + (y * block +  
                                                                                                    ((mv->y) - 1) / 2) * stride);  
         case 2:  
                 return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +  
                                                                                                                  (mv->y) / 2) * stride);  
         default:  
         case 3:  
                 return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block +  
                                                                                                                   ((mv->y) -  
                                                                                                                    1) / 2) * stride);  
         }  
   
 }  
   
   
 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;  
46    
 Search8Func     PMVfastSearch8;  
 Search8Func     EPZSSearch8;  
47    
48    /** MotionEstimation **/
49    
50  bool  void MotionEstimation(MBParam * const pParam,
 MotionEstimation(MBParam * const pParam,  
51                                   FRAMEINFO * const current,                                   FRAMEINFO * const current,
52                                   FRAMEINFO * const reference,                                   FRAMEINFO * const reference,
53                                   const IMAGE * const pRefH,                                   const IMAGE * const pRefH,
54                                   const IMAGE * const pRefV,                                   const IMAGE * const pRefV,
55                                   const IMAGE * const pRefHV,                                   const IMAGE * const pRefHV,
56                                   const uint32_t iLimit);                                          const IMAGE * const pGMC,
57                                            const uint32_t iLimit,
58                                            const int num_slices);
59    
60    void
61    MotionEstimationBVOP(MBParam * const pParam,
62                                                    FRAMEINFO * const frame,
63                                                    const int32_t time_bp,
64                                                    const int32_t time_pp,
65                                                    const MACROBLOCK * const f_mbs,
66                                                    const IMAGE * const f_ref,
67                                                    const IMAGE * const f_refH,
68                                                    const IMAGE * const f_refV,
69                                                    const IMAGE * const f_refHV,
70                                                    const FRAMEINFO * const b_reference,
71                                                    const IMAGE * const b_ref,
72                                                    const IMAGE * const b_refH,
73                                                    const IMAGE * const b_refV,
74                                                    const IMAGE * const b_refHV,
75                                                    const int num_slices);
76    
77    void
78    GMEanalysis(const MBParam * const pParam,
79                            const FRAMEINFO * const current,
80                            const FRAMEINFO * const reference,
81                            const IMAGE * const pRefH,
82                            const IMAGE * const pRefV,
83                            const IMAGE * const pRefHV,
84                            const int num_slices);
85    
86    WARPPOINTS
87    GlobalMotionEst(MACROBLOCK * const pMBs,
88                                    const MBParam * const pParam,
89                                    const FRAMEINFO * const current,
90                                    const FRAMEINFO * const reference,
91                                    const IMAGE * const pRefH,
92                                    const IMAGE * const pRefV,
93                                    const IMAGE * const pRefHV,
94                                    const int num_slices);
95    
96    int
97    GlobalMotionEstRefine(
98                                    WARPPOINTS *const startwp,
99                                    MACROBLOCK * const pMBs,
100                                    const MBParam * const pParam,
101                                    const FRAMEINFO * const current,
102                                    const FRAMEINFO * const reference,
103                                    const IMAGE * const pCurr,
104                                    const IMAGE * const pRef,
105                                    const IMAGE * const pRefH,
106                                    const IMAGE * const pRefV,
107                                    const IMAGE * const pRefHV);
108    
109  typedef int32_t(Halfpel8_RefineFunc) (const uint8_t * const pRef,  int
110                                        const uint8_t * const pRefH,  globalSAD(const WARPPOINTS *const wp,
111                                        const uint8_t * const pRefV,                    const MBParam * const pParam,
112                                        const uint8_t * const pRefHV,                    const MACROBLOCK * const pMBs,
113                                        const uint8_t * const cur,                    const FRAMEINFO * const current,
114                                        const int x,                    const IMAGE * const pRef,
115                                        const int y,                    const IMAGE * const pCurr,
116                                        VECTOR * const currMV,                    uint8_t *const GMCblock);
                                       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;  
117    
118    
119    int
120    MEanalysis(     const IMAGE * const pRef,
121                            const FRAMEINFO * const Current,
122                            const MBParam * const pParam,
123                            const int maxIntra,
124                            const int intraCount,
125                            const int bCount,
126                            const int b_thresh,
127                            const MACROBLOCK * const prev_mbs);
128    
129    /** MotionCompensation **/
130    
131    void
132    MBMotionCompensation(MACROBLOCK * const mb,
133                                            const uint32_t i,
134                                            const uint32_t j,
135                                            const IMAGE * const ref,
136                                            const IMAGE * const refh,
137                                            const IMAGE * const refv,
138                                            const IMAGE * const refhv,
139                                            const IMAGE * const refGMC,
140                                            IMAGE * const cur,
141                                            int16_t * dct_codes,
142                                            const uint32_t width,
143                                            const uint32_t height,
144                                            const uint32_t edged_width,
145                                            const int32_t quarterpel,
146                                            const int32_t rounding,
147                                            const uint8_t * const tmp);
148    
149    void
150    MBMotionCompensationBVOP(MBParam * pParam,
151                                                            MACROBLOCK * const mb,
152                                                            const uint32_t i,
153                                                            const uint32_t j,
154                                                            IMAGE * const cur,
155                                                            const IMAGE * const f_ref,
156                                                            const IMAGE * const f_refh,
157                                                            const IMAGE * const f_refv,
158                                                            const IMAGE * const f_refhv,
159                                                            const IMAGE * const b_ref,
160                                                            const IMAGE * const b_refh,
161                                                            const IMAGE * const b_refv,
162                                                            const IMAGE * const b_refhv,
163                                                            int16_t * dct_codes,
164                                                            const uint8_t * const tmp);
165    
166  #endif                                                  /* _MOTION_H_ */  #endif                                                  /* _MOTION_H_ */

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.27

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