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

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

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

revision 1.1.2.4, Sat Oct 5 21:37:44 2002 UTC revision 1.6, Tue Apr 8 11:12:07 2003 UTC
# Line 35  Line 35 
35    
36  #include "../portab.h"  #include "../portab.h"
37  #include "../global.h"  #include "../global.h"
38    #include "../image/reduced.h"
39    
40  /* hard coded motion search parameters for motion_est and smp_motion_est */  /* hard coded motion search parameters for motion_est and smp_motion_est */
41    
# Line 44  Line 45 
45  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
46  #define MV16_INTER_BIAS 512  #define MV16_INTER_BIAS 512
47    
48    /* vector map (vlc delta size) smoother parameters ! float !*/
49    #define NEIGH_TEND_16X16        10.5
50    #define NEIGH_TEND_8X8          40.0
51    #define NEIGH_8X8_BIAS          30
52    
53  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
54  #define IMV16X16                        2  #define IMV16X16                        2
55    
 /* vector map (vlc delta size) smoother parameters ! float !*/  
 #define NEIGH_TEND_16X16        4.0  
 #define NEIGH_TEND_8X8          7.0  
   
56  static const int lambda_vec16[32] =  static const int lambda_vec16[32] =
57          {     0    ,(int)(1.00235 * NEIGH_TEND_16X16 + 0.5),          {     0    ,(int)(1.00235 * NEIGH_TEND_16X16 + 0.5),
58          (int)(1.15582*NEIGH_TEND_16X16 + 0.5), (int)(1.31976*NEIGH_TEND_16X16 + 0.5),          (int)(1.15582*NEIGH_TEND_16X16 + 0.5), (int)(1.31976*NEIGH_TEND_16X16 + 0.5),
# Line 88  Line 90 
90          (int)(29.6436*NEIGH_TEND_8X8 + 0.5), (int)(36.4949*NEIGH_TEND_8X8 + 0.5)        };          (int)(29.6436*NEIGH_TEND_8X8 + 0.5), (int)(36.4949*NEIGH_TEND_8X8 + 0.5)        };
91    
92  // mv.length table  // mv.length table
93  static const uint32_t mvtab[33] = {  static const int mvtab[64] = {
94          1, 2, 3, 4, 6, 7, 7, 7,          1, 2, 3, 4, 6, 7, 7, 7,
95          9, 9, 9, 10, 10, 10, 10, 10,          9, 9, 9, 10, 10, 10, 10, 10,
96          10, 10, 10, 10, 10, 10, 10, 10,          10, 10, 10, 10, 10, 10, 10, 10,
97          10, 11, 11, 11, 11, 11, 11, 12, 12                  10, 11, 11, 11, 11, 11, 11, 12,
98  };                  12, 12, 12, 12, 12, 12, 12, 12,
99                    12, 12, 12, 12, 12, 12, 12, 12,
100                    12, 12, 12, 12, 12, 12, 12, 12, 12 };
101    
102  static const int DQtab[4] = {  static const int DQtab[4] = {
103          -1, -2, 1, 2          -1, -2, 1, 2
104  };  };
105    
106    #define RRV_MV_SCALEDOWN(a)     ( (a)>=0 ? (a+1)/2 : (a-1)/2 )
107    
108  typedef struct  typedef struct
109          {          {
# Line 106  Line 111 
111                  int max_dx, min_dx, max_dy, min_dy;                  int max_dx, min_dx, max_dy, min_dy;
112                  uint32_t rounding;                  uint32_t rounding;
113                  VECTOR predMV;                  VECTOR predMV;
                 VECTOR predQMV;  
114                  VECTOR *currentMV;                  VECTOR *currentMV;
115                  VECTOR *currentQMV;                  VECTOR *currentQMV;
116                  int32_t *iMinSAD;                  int32_t *iMinSAD;
117                  const uint8_t * Ref;          const uint8_t * RefP[6]; // N, V, H, HV, cU, cV
118                  const uint8_t * RefH;          const uint8_t * CurU;
119                  const uint8_t * RefV;          const uint8_t * CurV;
120                  const uint8_t * RefHV;          uint8_t * RefQ;
                 const uint8_t * RefQ;  
121                  const uint8_t * Cur;                  const uint8_t * Cur;
122                  uint32_t iQuant;          uint32_t lambda16;
123            uint32_t lambda8;
124                  uint32_t iEdgedWidth;                  uint32_t iEdgedWidth;
125                  uint32_t iFcode;                  uint32_t iFcode;
126                  int * temp;                  int * temp;
127  //fields for interpolate and direct mode          int qpel, qpel_precision;
128                  const uint8_t *bRef;          int chroma;
129                  const uint8_t *bRefH;          int rrv;
130                  const uint8_t *bRefV;  //fields for interpolate and direct modes
131                  const uint8_t *bRefHV;          const uint8_t * b_RefP[6]; // N, V, H, HV, cU, cV
132                  VECTOR bpredMV;                  VECTOR bpredMV;
133                  uint32_t bFcode;                  uint32_t bFcode;
134  // fields for direct mode  // fields for direct mode
135                  VECTOR directmvF[4];                  VECTOR directmvF[4];
136                  VECTOR directmvB[4];                  VECTOR directmvB[4];
137                  const VECTOR * referencemv;                  const VECTOR * referencemv;
138          }  // _BITS stuff
139          SearchData;          int16_t * dctSpace;
140    
141    } SearchData;
142    
143    
144  typedef void(CheckFunc)(const int x, const int y,  typedef void(CheckFunc)(const int x, const int y,
145                                                  const int Direction, int * const dir,                                                  const int Direction, int * const dir,
146                                                  const SearchData * const Data);                                                  const SearchData * const Data);
   
 static CheckFunc CheckCandidate16, CheckCandidate16no4v, CheckCandidateInt,  
                         CheckCandidateDirect, CheckCandidateDirectno4v,  
                         CheckCandidate8;  
147  CheckFunc *CheckCandidate;  CheckFunc *CheckCandidate;
148    
149  /*  /*
150   * Calculate the min/max range (in halfpixels)   * Calculate the min/max range
151   * relative to the _MACROBLOCK_ position   * relative to the _MACROBLOCK_ position
152   */   */
153  static void __inline  static void __inline
# Line 155  Line 157 
157                    int32_t * const max_dy,                    int32_t * const max_dy,
158                    const uint32_t x,                    const uint32_t x,
159                    const uint32_t y,                    const uint32_t y,
160                    const uint32_t block_sz,      /* block dimension, 8 or 16 */                    uint32_t block_sz, /* block dimension, 8 or 16 */
161                    const uint32_t width,                    const uint32_t width,
162                    const uint32_t height,                    const uint32_t height,
163                    const uint32_t fcode,                    const uint32_t fcode,
164                    const uint32_t quarterpel)                    const int qpel, /* 1 if the resulting range should be in qpel precision; otherwise 0 */
165                      const int rrv)
166  {  {
167            int k, m = qpel ? 4 : 2;
168            const int search_range = 32 << (fcode - 1);
169            int high = search_range - 1;
170            int low = -search_range;
171    
172            if (rrv) {
173                    high = RRV_MV_SCALEUP(high);
174                    low = RRV_MV_SCALEUP(low);
175                    block_sz *= 2;
176            }
177    
178          int k;          k = m * (int)(width - x * block_sz);
         const int search_range = 32 << (fcode - 1 - quarterpel);  
         const int high = search_range - 1;  
         const int low = -search_range;  
   
         k = 2 * (int)(width - x*block_sz);  
179          *max_dx = MIN(high, k);          *max_dx = MIN(high, k);
180          k = 2 * (int)(height -  y*block_sz);          k = m * (int)(height -  y * block_sz);
181          *max_dy = MIN(high, k);          *max_dy = MIN(high, k);
182    
183          k = -2 * (int)((x+1) * block_sz);          k = -m * (int)((x+1) * block_sz);
184          *min_dx = MAX(low, k);          *min_dx = MAX(low, k);
185          k = -2 * (int)((y+1) * block_sz);          k = -m * (int)((y+1) * block_sz);
186          *min_dy = MAX(low, k);          *min_dy = MAX(low, k);
   
187  }  }
188    
   
189  typedef void MainSearchFunc(int x, int y, const SearchData * const Data, int bDirection);  typedef void MainSearchFunc(int x, int y, const SearchData * const Data, int bDirection);
190    
191  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;
# Line 203  Line 209 
209                                   const uint32_t iLimit);                                   const uint32_t iLimit);
210    
211  static void  static void
212  SearchP(const uint8_t * const pRef,  SearchP(const IMAGE * const pRef,
213                  const uint8_t * const pRefH,                  const uint8_t * const pRefH,
214                  const uint8_t * const pRefV,                  const uint8_t * const pRefV,
215                  const uint8_t * const pRefHV,                  const uint8_t * const pRefHV,
                 const uint8_t * const pRefQ,  
216                  const IMAGE * const pCur,                  const IMAGE * const pCur,
217                  const int x,                  const int x,
218                  const int y,                  const int y,
219                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
220                    const uint32_t GlobalFlags,
221                  const uint32_t iQuant,                  const uint32_t iQuant,
222                  SearchData * const Data,                  SearchData * const Data,
223                  const MBParam * const pParam,                  const MBParam * const pParam,
# Line 221  Line 227 
227                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
228    
229    
230  #ifdef _SMP  static WARPPOINTS
231  bool  GlobalMotionEst(const MACROBLOCK * const pMBs,
232  SMP_MotionEstimation(MBParam * const pParam,                                  const MBParam * const pParam,
233                                   FRAMEINFO * const current,                                  const FRAMEINFO * const current,
234                                   FRAMEINFO * const reference,                                  const FRAMEINFO * const reference,
235                                   const IMAGE * const pRefH,                                   const IMAGE * const pRefH,
236                                   const IMAGE * const pRefV,                                   const IMAGE * const pRefV,
237                                   const IMAGE * const pRefHV,                                  const IMAGE * const pRefHV      );
238                                   const uint32_t iLimit);  
239  #endif  #define iDiamondSize 2
240    
241    static __inline uint32_t
242    MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags)
243    {
244            uint32_t Flags = MotionFlags;
245    
246            if (!(GlobalFlags & XVID_MODEDECISION_BITS))
247                    Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS);
248    
249            if (Flags & EXTSEARCH_BITS)
250                    Flags |= HALFPELREFINE16_BITS;
251    
252            if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)
253                    Flags |= HALFPELREFINE8_BITS;
254    
255            if (Flags & HALFPELREFINE16_BITS)
256                    Flags |= QUARTERPELREFINE16_BITS;
257    
258            if (Flags & HALFPELREFINE8_BITS) {
259                    Flags |= QUARTERPELREFINE8_BITS;
260                    Flags &= ~PMV_HALFPELREFINE8;
261            }
262    
263            if (Flags & QUARTERPELREFINE8_BITS)
264                    Flags &= ~PMV_QUARTERPELREFINE8;
265    
266            if (!(GlobalFlags & XVID_QUARTERPEL))
267                    Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);
268    
269            if (!(GlobalFlags & XVID_HALFPEL))
270                    Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS);
271    
272            if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED))
273                    Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);
274    
275            return Flags;
276    }
277    
278    /* BITS mode decision and search */
279    
280    #include "../bitstream/zigzag.h"
281    #include "../quant/quant_mpeg4.h"
282    #include "../quant/quant_h263.h"
283    #include "../bitstream/vlc_codes.h"
284    
285    static int
286    CountMBBitsInter(SearchData * const Data,
287                                    const MACROBLOCK * const pMBs, const int x, const int y,
288                                    const MBParam * const pParam,
289                                    const uint32_t MotionFlags);
290    
291    static int
292    CountMBBitsInter4v(const SearchData * const Data,
293                                            MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
294                                            const int x, const int y,
295                                            const MBParam * const pParam, const uint32_t MotionFlags,
296                                            const VECTOR * const backup);
297    
298    static int
299    CountMBBitsIntra(const SearchData * const Data);
300    
301    int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
302    int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
303    
304  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

Legend:
Removed from v.1.1.2.4  
changed lines
  Added in v.1.6

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