[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.10, Wed Dec 11 10:32:29 2002 UTC revision 1.1.2.15, Wed Feb 12 12:57:27 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 46  Line 47 
47    
48  /* vector map (vlc delta size) smoother parameters ! float !*/  /* vector map (vlc delta size) smoother parameters ! float !*/
49  #define NEIGH_TEND_16X16        10.5  #define NEIGH_TEND_16X16        10.5
50  #define NEIGH_TEND_8X8          4.0  #define NEIGH_TEND_8X8          40.0
51  #define NEIGH_8X8_BIAS          30  #define NEIGH_8X8_BIAS          30
52    
53  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
# Line 101  Line 102 
102  };  };
103    
104  #define RRV_MV_SCALEDOWN(a)     ( (a)>=0 ? (a+1)/2 : (a-1)/2 )  #define RRV_MV_SCALEDOWN(a)     ( (a)>=0 ? (a+1)/2 : (a-1)/2 )
105  #define RRV_MV_SCALEUP(a)       ( (a)>0 ? 2*(a)-1 : (a)<0 ? 2*(a)+1 : (a) )  
106    static const VECTOR zeroMV = {0,0};
107    
108  typedef struct  typedef struct
109          {          {
# Line 130  Line 132 
132                  int qpel, qpel_precision;                  int qpel, qpel_precision;
133                  int chroma;                  int chroma;
134                  int rrv;                  int rrv;
135  //fields for interpolate and direct mode  //fields for interpolate and direct modes
136                  const uint8_t *bRef;                  const uint8_t *bRef;
137                  const uint8_t *bRefH;                  const uint8_t *bRefH;
138                  const uint8_t *bRefV;                  const uint8_t *bRefV;
139                  const uint8_t *bRefHV;                  const uint8_t *bRefHV;
140            const uint8_t * b_RefCU;
141            const uint8_t * b_RefCV;
142    
143                  VECTOR bpredMV;                  VECTOR bpredMV;
144                  uint32_t bFcode;                  uint32_t bFcode;
145  // fields for direct mode  // fields for direct mode
146                  VECTOR directmvF[4];                  VECTOR directmvF[4];
147                  VECTOR directmvB[4];                  VECTOR directmvB[4];
148                  const VECTOR * referencemv;                  const VECTOR * referencemv;
149          }  
150          SearchData;  } SearchData;
151    
152    
153  typedef void(CheckFunc)(const int x, const int y,  typedef void(CheckFunc)(const int x, const int y,
154                                                  const int Direction, int * const dir,                                                  const int Direction, int * const dir,
155                                                  const SearchData * const Data);                                                  const SearchData * const Data);
   
 static CheckFunc CheckCandidate16, CheckCandidate16no4v, CheckCandidateInt,  
                         CheckCandidateDirect, CheckCandidateDirectno4v,  
                         CheckCandidate8;  
156  CheckFunc *CheckCandidate;  CheckFunc *CheckCandidate;
157    
158  /*  /*
159   * Calculate the min/max range (in halfpixels)   * Calculate the min/max range
160   * relative to the _MACROBLOCK_ position   * relative to the _MACROBLOCK_ position
161   */   */
162  static void __inline  static void __inline
# Line 165  Line 166 
166                    int32_t * const max_dy,                    int32_t * const max_dy,
167                    const uint32_t x,                    const uint32_t x,
168                    const uint32_t y,                    const uint32_t y,
169                    const uint32_t block_sz,      /* block dimension, 8 or 16 */                    uint32_t block_sz, /* block dimension, 8 or 16 */
170                    const uint32_t width,                    const uint32_t width,
171                    const uint32_t height,                    const uint32_t height,
172                    const uint32_t fcode)                    const uint32_t fcode,
173                      const int qpel, /* 1 if the resulting range should be in qpel precision; otherwise 0 */
174                      const int rrv)
175  {  {
176          int k;          int k, m = qpel ? 4 : 2;
177          const int search_range = 32 << (fcode - 1);          const int search_range = 32 << (fcode - 1);
178          const int high = search_range - 1;          int high = search_range - 1;
179          const int low = -search_range;          int low = -search_range;
180    
181          k = 2 * (int)(width - x*block_sz);          if (rrv) {
182          *max_dx = MIN(high, k);                  high = RRV_MV_SCALEUP(high);
183          k = 2 * (int)(height -  y*block_sz);                  low = RRV_MV_SCALEUP(low);
184          *max_dy = MIN(high, k);                  block_sz *= 2;
   
         k = -2 * (int)((x+1) * block_sz);  
         *min_dx = MAX(low, k);  
         k = -2 * (int)((y+1) * block_sz);  
         *min_dy = MAX(low, k);  
185  }  }
186    
187  static void __inline          k = m * (int)(width - x * block_sz);
 get_range_rrv(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)  
 {  
         int k;  
         const int search_range = 32 << (fcode - 1);  
         const int high = RRV_MV_SCALEUP(search_range - 1); //halfzero -> halfpel, because we do our search in halfpel  
         const int low = RRV_MV_SCALEUP(-search_range);  
   
         k = 2 * (int)(width - x*block_sz);  
188          *max_dx = MIN(high, k);          *max_dx = MIN(high, k);
189          k = 2 * (int)(height -  y*block_sz);          k = m * (int)(height -  y * block_sz);
190          *max_dy = MIN(high, k);          *max_dy = MIN(high, k);
191    
192          k = -2 * (int)((x+1) * block_sz);          k = -m * (int)((x+1) * block_sz);
193          *min_dx = MAX(low, k);          *min_dx = MAX(low, k);
194          k = -2 * (int)((y+1) * block_sz);          k = -m * (int)((y+1) * block_sz);
195          *min_dy = MAX(low, k);          *min_dy = MAX(low, k);
196  }  }
197    
 static void __inline  
 get_range_qpel(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)  
 {  
         int k;  
         const int search_range = 32 << (fcode - 1);  
         const int high = search_range - 1;  
         const int low = -search_range;  
   
         k = 4 * (int)(width - x*block_sz);  
         *max_dx = MIN(high, k);  
         k = 4 * (int)(height -  y*block_sz);  
         *max_dy = MIN(high, k);  
   
         k = -4 * (int)((x+1) * block_sz);  
         *min_dx = MAX(low, k);  
         k = -4 * (int)((y+1) * block_sz);  
         *min_dy = MAX(low, k);  
 }  
   
   
198  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);
199    
200  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;
# Line 274  Line 226 
226                  const int x,                  const int x,
227                  const int y,                  const int y,
228                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
229                    const uint32_t GlobalFlags,
230                  const uint32_t iQuant,                  const uint32_t iQuant,
231                  SearchData * const Data,                  SearchData * const Data,
232                  const MBParam * const pParam,                  const MBParam * const pParam,
# Line 282  Line 235 
235                  int inter4v,                  int inter4v,
236                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
237    
238    
239    static WARPPOINTS
240    GlobalMotionEst(const MACROBLOCK * const pMBs,
241                                    const MBParam * const pParam,
242                                    const FRAMEINFO * const current,
243                                    const FRAMEINFO * const reference,
244                                    const IMAGE * const pRefH,
245                                    const IMAGE * const pRefV,
246                                    const IMAGE * const pRefHV      );
247    
248    #define iDiamondSize 2
249    
250    static __inline uint32_t
251    MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags)
252    {
253            uint32_t Flags = MotionFlags;
254    
255            if (!(GlobalFlags & XVID_MODEDECISION_BITS))
256                    Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS);
257    
258            if (Flags & EXTSEARCH_BITS)
259                    Flags |= HALFPELREFINE16_BITS;
260    
261            if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)
262                    Flags |= HALFPELREFINE8_BITS;
263    
264            if (Flags & HALFPELREFINE16_BITS)
265                    Flags |= QUARTERPELREFINE16_BITS;
266    
267            if (Flags & HALFPELREFINE8_BITS) {
268                    Flags |= QUARTERPELREFINE8_BITS;
269                    Flags &= ~PMV_HALFPELREFINE8;
270            }
271    
272            if (Flags & QUARTERPELREFINE8_BITS)
273                    Flags &= ~PMV_QUARTERPELREFINE8;
274    
275            if (!(GlobalFlags & XVID_QUARTERPEL))
276                    Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);
277    
278            if (!(GlobalFlags & XVID_HALFPEL))
279                    Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS);
280    
281            if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED))
282                    Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);
283    
284            return Flags;
285    }
286    
287    /* BITS mode decision and search */
288    
289    #include "../bitstream/zigzag.h"
290    #include "../quant/quant_mpeg4.h"
291    #include "../quant/quant_h263.h"
292    #include "../bitstream/vlc_codes.h"
293    
294    static int
295    CountMBBitsInter(SearchData * const Data,
296                                    const MACROBLOCK * const pMBs, const int x, const int y,
297                                    const MBParam * const pParam,
298                                    const uint32_t MotionFlags);
299    
300    static int
301    CountMBBitsInter4v(const SearchData * const Data,
302                                            MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
303                                            const int x, const int y,
304                                            const MBParam * const pParam, const uint32_t MotionFlags,
305                                            const VECTOR * const backup);
306    
307    static int
308    CountMBBitsIntra(const SearchData * const Data);
309    
310    int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
311    int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
312    
313  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

Legend:
Removed from v.1.1.2.10  
changed lines
  Added in v.1.1.2.15

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