[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.7, Tue May 13 12:48:20 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 89  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 )  #define RRV_MV_SCALEDOWN(a)     ( (a)>=0 ? (a+1)/2 : (a-1)/2 )
 #define RRV_MV_SCALEUP(a)       ( (a)>0 ? 2*(a)-1 : (a)<0 ? 2*(a)+1 : (a) )  
107    
108  typedef struct  typedef struct
109          {          {
# Line 112  Line 114 
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
                 const uint8_t * RefH;  
                 const uint8_t * RefV;  
                 const uint8_t * RefHV;  
                 const uint8_t * RefCU;  
                 const uint8_t * RefCV;  
118                  const uint8_t * CurU;                  const uint8_t * CurU;
119                  const uint8_t * CurV;                  const uint8_t * CurV;
120                  uint8_t * RefQ;                  uint8_t * RefQ;
# Line 130  Line 127 
127                  int qpel, qpel_precision;                  int qpel, qpel_precision;
128                  int chroma;                  int chroma;
129                  int rrv;                  int rrv;
130  //fields for interpolate and direct mode  //fields for interpolate and direct modes
131                  const uint8_t *bRef;          const uint8_t * b_RefP[6]; // N, V, H, HV, cU, cV
                 const uint8_t *bRefH;  
                 const uint8_t *bRefV;  
                 const uint8_t *bRefHV;  
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            uint32_t iQuant;
141            uint32_t quant_type;
142    
143    } SearchData;
144    
145    
146  typedef void(CheckFunc)(const int x, const int y,  typedef void(CheckFunc)(const int x, const int y,
147                                                  const int Direction, int * const dir,                                                  const int Direction, int * const dir,
148                                                  const SearchData * const Data);                                                  const SearchData * const Data);
   
 static CheckFunc CheckCandidate16, CheckCandidate16no4v, CheckCandidateInt,  
                         CheckCandidateDirect, CheckCandidateDirectno4v,  
                         CheckCandidate8;  
149  CheckFunc *CheckCandidate;  CheckFunc *CheckCandidate;
150    
151  /*  /*
152   * Calculate the min/max range (in halfpixels)   * Calculate the min/max range
153   * relative to the _MACROBLOCK_ position   * relative to the _MACROBLOCK_ position
154   */   */
155  static void __inline  static void __inline
# Line 165  Line 159 
159                    int32_t * const max_dy,                    int32_t * const max_dy,
160                    const uint32_t x,                    const uint32_t x,
161                    const uint32_t y,                    const uint32_t y,
162                    const uint32_t block_sz,      /* block dimension, 8 or 16 */                    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 = 2 * (int)(width - x*block_sz);  
         *max_dx = MIN(high, k);  
         k = 2 * (int)(height -  y*block_sz);  
         *max_dy = MIN(high, k);  
   
         k = -2 * (int)((x+1) * block_sz);  
         *min_dx = MAX(low, k);  
         k = -2 * (int)((y+1) * block_sz);  
         *min_dy = MAX(low, k);  
 }  
   
 static void __inline  
 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 */  
163                    const uint32_t width,                    const uint32_t width,
164                    const uint32_t height,                    const uint32_t height,
165                    const uint32_t fcode)                    const uint32_t fcode,
166                      const int qpel, /* 1 if the resulting range should be in qpel precision; otherwise 0 */
167                      const int rrv)
168  {  {
169          int k;          int k, m = qpel ? 4 : 2;
170          const int search_range = 32 << (fcode - 1);          const int search_range = 32 << (fcode - 1);
171          const int high = RRV_MV_SCALEUP(search_range - 1); //halfzero -> halfpel, because we do our search in halfpel          int high = search_range - 1;
172          const int low = RRV_MV_SCALEUP(-search_range);          int low = -search_range;
   
         k = 2 * (int)(width - x*block_sz);  
         *max_dx = MIN(high, k);  
         k = 2 * (int)(height -  y*block_sz);  
         *max_dy = MIN(high, k);  
173    
174          k = -2 * (int)((x+1) * block_sz);          if (rrv) {
175          *min_dx = MAX(low, k);                  high = RRV_MV_SCALEUP(high);
176          k = -2 * (int)((y+1) * block_sz);                  low = RRV_MV_SCALEUP(low);
177          *min_dy = MAX(low, k);                  block_sz *= 2;
178  }  }
179    
180  static void __inline          k = m * (int)(width - x * block_sz);
 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);  
181          *max_dx = MIN(high, k);          *max_dx = MIN(high, k);
182          k = 4 * (int)(height -  y*block_sz);          k = m * (int)(height -  y * block_sz);
183          *max_dy = MIN(high, k);          *max_dy = MIN(high, k);
184    
185          k = -4 * (int)((x+1) * block_sz);          k = -m * (int)((x+1) * block_sz);
186          *min_dx = MAX(low, k);          *min_dx = MAX(low, k);
187          k = -4 * (int)((y+1) * block_sz);          k = -m * (int)((y+1) * block_sz);
188          *min_dy = MAX(low, k);          *min_dy = MAX(low, k);
189  }  }
190    
   
191  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);
192    
193  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;
# Line 274  Line 219 
219                  const int x,                  const int x,
220                  const int y,                  const int y,
221                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
222                  const uint32_t iQuant,                  const uint32_t GlobalFlags,
223                  SearchData * const Data,                  SearchData * const Data,
224                  const MBParam * const pParam,                  const MBParam * const pParam,
225                  const MACROBLOCK * const pMBs,                  const MACROBLOCK * const pMBs,
226                  const MACROBLOCK * const prevMBs,                  const MACROBLOCK * const prevMBs,
                 int inter4v,  
227                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
228    
229    
230    static WARPPOINTS
231    GlobalMotionEst(const MACROBLOCK * const pMBs,
232                                    const MBParam * const pParam,
233                                    const FRAMEINFO * const current,
234                                    const FRAMEINFO * const reference,
235                                    const IMAGE * const pRefH,
236                                    const IMAGE * const pRefV,
237                                    const IMAGE * const pRefHV      );
238    
239    #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    #include "../dct/fdct.h"
285    
286    static int
287    CountMBBitsInter(SearchData * const Data,
288                                    const MACROBLOCK * const pMBs, const int x, const int y,
289                                    const MBParam * const pParam,
290                                    const uint32_t MotionFlags);
291    
292    static int
293    CountMBBitsInter4v(const SearchData * const Data,
294                                            MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
295                                            const int x, const int y,
296                                            const MBParam * const pParam, const uint32_t MotionFlags,
297                                            const VECTOR * const backup);
298    
299    static int
300    CountMBBitsIntra(const SearchData * const Data);
301    
302    int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
303    int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
304    /*
305    static int
306    CountDistortionSkip(const SearchData * const Data);
307    */
308    static __inline unsigned int
309    Block_CalcBits(uint16_t * const coeff,
310                                            uint16_t * const data,
311                                            const uint32_t quant, const int quant_type,
312                                            uint32_t * cbp,
313                                            const int block,
314                                            const int RD)
315    {
316            int sum;
317    
318            fdct(data);
319    
320            if (quant_type == 0) sum = quant_inter(coeff, data, quant);
321            else sum = quant4_inter(coeff, data, quant);
322    
323            if (sum > 0) {
324                    *cbp |= 1 << (5 - block);
325                    return CodeCoeffInter_CalcBits(coeff, scan_tables[0]);
326            } else return 0;
327    }
328    
329    /* RD experiment. ignore.
330    static __inline unsigned int
331    Block_CalcBits( int16_t * const coeff,
332                                    int16_t * const data,
333                                    const uint32_t quant, const int quant_type,
334                                    uint32_t * cbp,
335                                    const int block,
336                                    const int RD)
337    {
338            int sum;
339            int bits;
340            const int lambda = quant*quant/2;
341            int distortion = 0;
342    
343            fdct(data);
344    
345            if (quant_type == 0) sum = quant_inter(coeff, data, quant);
346            else sum = quant4_inter(coeff, data, quant);
347    
348            if (sum > 0) {
349                    *cbp |= 1 << (5 - block);
350                    bits = CodeCoeffInter_CalcBits(coeff, scan_tables[0]);
351            } else bits = 0;
352    
353            if (RD) {
354                    int i;
355                    if (quant_type == 0) dequant_inter_c(coeff, coeff, quant);
356                    else dequant4_inter_c(coeff, coeff, quant);
357    
358                    for (i = 0; i < 64; i++) {
359                            distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);
360                    }
361            }
362    
363            bits += distortion/lambda;
364    
365            return bits;
366    }
367    */
368    
369  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

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

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