[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.3.2.11, Thu Jun 26 11:50:27 2003 UTC revision 1.9, Thu Jun 19 10:06:40 2003 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /**************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Motion Estimation related header -   *  -  Motion estimation header  -
5   *   *
6   *  Copyright(C) 2002 Christoph Lampert <gruel@web.de>   *  This program is an implementation of a part of one or more MPEG-4
7   *               2002 Michael Militzer <michael@xvid.org>   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
8   *               2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net>   *  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
# Line 23  Line 28 
28   *   *
29   * $Id$   * $Id$
30   *   *
31   ****************************************************************************/   ***************************************************************************/
32    
33  #ifndef _MOTION_EST_H_  #ifndef _MOTION_EST_H_
34  #define _MOTION_EST_H_  #define _MOTION_EST_H_
# Line 34  Line 39 
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    
42  /* very large value */  // very large value
43  #define MV_MAX_ERROR    (4096 * 256)  #define MV_MAX_ERROR    (4096 * 256)
44    
45  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
# Line 86  Line 91 
91          (int)(21.2656*NEIGH_TEND_8X8 + 0.5), (int)(24.8580*NEIGH_TEND_8X8 + 0.5),          (int)(21.2656*NEIGH_TEND_8X8 + 0.5), (int)(24.8580*NEIGH_TEND_8X8 + 0.5),
92          (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)        };
93    
94  /* mv.length table */  // mv.length table
95  static const int mvtab[64] = {  static const int mvtab[64] = {
96                  1, 2, 3, 4, 6, 7, 7, 7,                  1, 2, 3, 4, 6, 7, 7, 7,
97                  9, 9, 9, 10, 10, 10, 10, 10,                  9, 9, 9, 10, 10, 10, 10, 10,
# Line 104  Line 109 
109    
110  typedef struct  typedef struct
111  {  {
112          /* general fields */  // general fields
113          int max_dx, min_dx, max_dy, min_dy;          int max_dx, min_dx, max_dy, min_dy;
114          uint32_t rounding;          uint32_t rounding;
115          VECTOR predMV;          VECTOR predMV;
116          VECTOR * currentMV;          VECTOR * currentMV;
117          VECTOR * currentQMV;          VECTOR * currentQMV;
118          int32_t * iMinSAD;          int32_t * iMinSAD;
119          const uint8_t * RefP[6]; /* N, V, H, HV, cU, cV */          const uint8_t * RefP[6]; // N, V, H, HV, cU, cV
120          const uint8_t * CurU;          const uint8_t * CurU;
121          const uint8_t * CurV;          const uint8_t * CurV;
122          uint8_t * RefQ;          uint8_t * RefQ;
# Line 124  Line 129 
129          int qpel, qpel_precision;          int qpel, qpel_precision;
130          int chroma;          int chroma;
131          int rrv;          int rrv;
132    //fields for interpolate and direct modes
133          /* fields for interpolate and direct modes */          const uint8_t * b_RefP[6]; // N, V, H, HV, cU, cV
         const uint8_t * b_RefP[6]; /* N, V, H, HV, cU, cV */  
134          VECTOR bpredMV;          VECTOR bpredMV;
135          uint32_t bFcode;          uint32_t bFcode;
136    // fields for direct mode
         /* fields for direct mode */  
137          VECTOR directmvF[4];          VECTOR directmvF[4];
138          VECTOR directmvB[4];          VECTOR directmvB[4];
139          const VECTOR * referencemv;          const VECTOR * referencemv;
140    // BITS/R-D stuff
         /* BITS/R-D stuff */  
141          int16_t * dctSpace;          int16_t * dctSpace;
142          uint32_t iQuant;          uint32_t iQuant;
143          uint32_t quant_type;          uint32_t quant_type;
# Line 219  Line 221 
221                  const int x,                  const int x,
222                  const int y,                  const int y,
223                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
224                  const uint32_t VopFlags,                  const uint32_t GlobalFlags,
                 const uint32_t VolFlags,  
225                  SearchData * const Data,                  SearchData * const Data,
226                  const MBParam * const pParam,                  const MBParam * const pParam,
227                  const MACROBLOCK * const pMBs,                  const MACROBLOCK * const pMBs,
228                  const MACROBLOCK * const prevMBs,                  const MACROBLOCK * const prevMBs,
229                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
230    
231    
232  static WARPPOINTS  static WARPPOINTS
233  GlobalMotionEst(const MACROBLOCK * const pMBs,  GlobalMotionEst(const MACROBLOCK * const pMBs,
234                                  const MBParam * const pParam,                                  const MBParam * const pParam,
# Line 239  Line 241 
241  #define iDiamondSize 2  #define iDiamondSize 2
242    
243  static __inline uint32_t  static __inline uint32_t
244  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t VopFlags, const uint32_t VolFlags)  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags)
245  {  {
246          uint32_t Flags = MotionFlags;          uint32_t Flags = MotionFlags;
247    
248          if (!(VopFlags & XVID_VOP_MODEDECISION_BITS))          if (!(GlobalFlags & XVID_MODEDECISION_BITS))
249                  Flags &= ~(XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS+XVID_ME_EXTSEARCH_BITS);                  Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS);
250    
251          if (Flags & XVID_ME_EXTSEARCH_BITS)          if (Flags & EXTSEARCH_BITS)
252                  Flags |= XVID_ME_HALFPELREFINE16_BITS;                  Flags |= HALFPELREFINE16_BITS;
253    
254          if (Flags & XVID_ME_EXTSEARCH_BITS && MotionFlags & XVID_ME_EXTSEARCH8)          if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)
255                  Flags |= XVID_ME_HALFPELREFINE8_BITS;                  Flags |= HALFPELREFINE8_BITS;
256    
257          if (Flags & XVID_ME_HALFPELREFINE16_BITS)          if (Flags & HALFPELREFINE16_BITS)
258                  Flags |= XVID_ME_QUARTERPELREFINE16_BITS;                  Flags |= QUARTERPELREFINE16_BITS;
259    
260          if (Flags & XVID_ME_HALFPELREFINE8_BITS) {          if (Flags & HALFPELREFINE8_BITS) {
261                  Flags |= XVID_ME_QUARTERPELREFINE8_BITS;                  Flags |= QUARTERPELREFINE8_BITS;
262                  Flags &= ~XVID_ME_HALFPELREFINE8;                  Flags &= ~PMV_HALFPELREFINE8;
263          }          }
264    
265          if (Flags & XVID_ME_QUARTERPELREFINE8_BITS)          if (Flags & QUARTERPELREFINE8_BITS)
266                  Flags &= ~XVID_ME_QUARTERPELREFINE8;                  Flags &= ~PMV_QUARTERPELREFINE8;
267    
268            if (Flags & QUARTERPELREFINE16_BITS)
269                    Flags &= ~PMV_QUARTERPELREFINE16;
270    
271          if (!(VolFlags & XVID_VOL_QUARTERPEL))          if (!(GlobalFlags & XVID_QUARTERPEL))
272                  Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS);                  Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);
273    
274          if (!(VopFlags & XVID_VOP_HALFPEL))          if (!(GlobalFlags & XVID_HALFPEL))
275                  Flags &= ~(XVID_ME_EXTSEARCH16+XVID_ME_HALFPELREFINE16+XVID_ME_HALFPELREFINE8+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS);                  Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS);
276    
277          if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED))          if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED))
278                  Flags &= ~(XVID_ME_CHROMA16 + XVID_ME_CHROMA8);                  Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);
279    
280          return Flags;          return Flags;
281  }  }
# Line 302  Line 307 
307  int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);  int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
308  int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);  int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
309    
310  /* one over lambda for R-D mode decision and motion search */  #define LAMBDA          ( (int)(1.0*BITS_MULT) )
 #define LAMBDA          ( (int)(BITS_MULT/1.0) )  
311    
312  static __inline unsigned int  static __inline unsigned int
313  Block_CalcBits( int16_t * const coeff,  Block_CalcBits( int16_t * const coeff,
314                                  int16_t * const data,                                  int16_t * const data,
                                 int16_t * const dqcoeff,  
315                                  const uint32_t quant, const int quant_type,                                  const uint32_t quant, const int quant_type,
316                                  uint32_t * cbp,                                  uint32_t * cbp,
317                                  const int block)                                  const int block)
318  {  {
319          int sum;          int sum;
320          int bits;          int bits;
321            const int lambda = LAMBDA*quant*quant;
322          int distortion = 0;          int distortion = 0;
323          int i;          int i;
324    
# Line 328  Line 332 
332                  bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]);                  bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]);
333          } else bits = 0;          } else bits = 0;
334    
335          if (quant_type == 0) dequant_inter(dqcoeff, coeff, quant);          if (quant_type == 0) dequant_inter(coeff, coeff, quant);
336          else dequant4_inter(dqcoeff, coeff, quant);          else dequant4_inter(coeff, coeff, quant);
337    
338          for (i = 0; i < 64; i++) {          for (i = 0; i < 64; i++) {
339                  distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]);                  distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);
340          }          }
341            bits += (BITS_MULT*BITS_MULT*distortion)/lambda;
         bits += (LAMBDA*distortion)/(quant*quant);  
342    
343          return bits;          return bits;
344  }  }
# Line 343  Line 346 
346  static __inline unsigned int  static __inline unsigned int
347  Block_CalcBitsIntra(int16_t * const coeff,  Block_CalcBitsIntra(int16_t * const coeff,
348                                          int16_t * const data,                                          int16_t * const data,
                                         int16_t * const dqcoeff,  
349                                          const uint32_t quant, const int quant_type,                                          const uint32_t quant, const int quant_type,
350                                          uint32_t * cbp,                                          uint32_t * cbp,
351                                          const int block,                                          const int block,
352                                          int * dcpred)                                          int * dcpred)
353  {  {
354          int bits, i;          int bits, i;
355            const int lambda = LAMBDA*quant*quant;
356          int distortion = 0;          int distortion = 0;
357          uint32_t iDcScaler = get_dc_scaler(quant, block < 4);          uint32_t iDcScaler = get_dc_scaler(quant, block < 4);
358          int b_dc;          int b_dc;
# Line 357  Line 360 
360          fdct(data);          fdct(data);
361          data[0] -= 1024;          data[0] -= 1024;
362    
363          if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler);          if (quant_type == 0) quant_intra_c(coeff, data, quant, iDcScaler); // MUST BE _C
364          else quant4_intra(coeff, data, quant, iDcScaler);          else quant4_intra_c(coeff, data, quant, iDcScaler); // MUST BE _C
365    
366          b_dc = coeff[0];          b_dc = coeff[0];
367          if (block < 4) {          if (block < 4) {
# Line 373  Line 376 
376          else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len;          else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len;
377    
378          coeff[0] = b_dc;          coeff[0] = b_dc;
379          if (quant_type == 0) dequant_intra(dqcoeff, coeff, quant, iDcScaler);          if (quant_type == 0) dequant_intra(coeff, coeff, quant, iDcScaler);
380          else dequant4_intra(dqcoeff, coeff, quant, iDcScaler);          else dequant4_intra(coeff, coeff, quant, iDcScaler);
381    
382          for (i = 0; i < 64; i++) {          for (i = 0; i < 64; i++) {
383                  distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]);                  distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);
384          }          }
385    
386          bits += (LAMBDA*distortion)/(quant*quant);          bits += (BITS_MULT*BITS_MULT*distortion)/lambda;
387    
388          return bits;          return bits;
389  }  }

Legend:
Removed from v.1.3.2.11  
changed lines
  Added in v.1.9

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