[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.8, Mon Jun 9 01:22:18 2003 UTC revision 1.6, Tue Apr 8 11:12:07 2003 UTC
# Line 39  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 50  Line 50 
50  #define NEIGH_TEND_8X8          40.0  #define NEIGH_TEND_8X8          40.0
51  #define NEIGH_8X8_BIAS          30  #define NEIGH_8X8_BIAS          30
52    
 #define BITS_MULT                       16  
   
53  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
54  #define IMV16X16                        2  #define IMV16X16                        2
55    
# Line 91  Line 89 
89          (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),
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 int mvtab[64] = {  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,
# Line 109  Line 107 
107    
108  typedef struct  typedef struct
109  {  {
110          /* general fields */  // general fields
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;
114          VECTOR * currentMV;          VECTOR * currentMV;
115          VECTOR * currentQMV;          VECTOR * currentQMV;
116          int32_t * iMinSAD;          int32_t * iMinSAD;
117          const uint8_t * RefP[6]; /* N, V, H, HV, cU, cV */          const uint8_t * RefP[6]; // N, V, H, HV, cU, cV
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 129  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 modes
131          /* 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 */  
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
         /* BITS/R-D stuff */  
139          int16_t * dctSpace;          int16_t * dctSpace;
         uint32_t iQuant;  
         uint32_t quant_type;  
140    
141  } SearchData;  } SearchData;
142    
# Line 224  Line 217 
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 VopFlags,                  const uint32_t GlobalFlags,
221                  const uint32_t VolFlags,                  const uint32_t iQuant,
222                  SearchData * const Data,                  SearchData * const Data,
223                  const MBParam * const pParam,                  const MBParam * const pParam,
224                  const MACROBLOCK * const pMBs,                  const MACROBLOCK * const pMBs,
225                  const MACROBLOCK * const prevMBs,                  const MACROBLOCK * const prevMBs,
226                    int inter4v,
227                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
228    
229    
230  static WARPPOINTS  static WARPPOINTS
231  GlobalMotionEst(const MACROBLOCK * const pMBs,  GlobalMotionEst(const MACROBLOCK * const pMBs,
232                                  const MBParam * const pParam,                                  const MBParam * const pParam,
# Line 244  Line 239 
239  #define iDiamondSize 2  #define iDiamondSize 2
240    
241  static __inline uint32_t  static __inline uint32_t
242  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t VopFlags, const uint32_t VolFlags)  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags)
243  {  {
244          uint32_t Flags = MotionFlags;          uint32_t Flags = MotionFlags;
245    
246          if (!(VopFlags & XVID_VOP_MODEDECISION_BITS))          if (!(GlobalFlags & XVID_MODEDECISION_BITS))
247                  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);
248    
249          if (Flags & XVID_ME_EXTSEARCH_BITS)          if (Flags & EXTSEARCH_BITS)
250                  Flags |= XVID_ME_HALFPELREFINE16_BITS;                  Flags |= HALFPELREFINE16_BITS;
251    
252          if (Flags & XVID_ME_EXTSEARCH_BITS && MotionFlags & XVID_ME_EXTSEARCH8)          if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)
253                  Flags |= XVID_ME_HALFPELREFINE8_BITS;                  Flags |= HALFPELREFINE8_BITS;
254    
255          if (Flags & XVID_ME_HALFPELREFINE16_BITS)          if (Flags & HALFPELREFINE16_BITS)
256                  Flags |= XVID_ME_QUARTERPELREFINE16_BITS;                  Flags |= QUARTERPELREFINE16_BITS;
257    
258          if (Flags & XVID_ME_HALFPELREFINE8_BITS) {          if (Flags & HALFPELREFINE8_BITS) {
259                  Flags |= XVID_ME_QUARTERPELREFINE8_BITS;                  Flags |= QUARTERPELREFINE8_BITS;
260                  Flags &= ~XVID_ME_HALFPELREFINE8;                  Flags &= ~PMV_HALFPELREFINE8;
261          }          }
262    
263          if (Flags & XVID_ME_QUARTERPELREFINE8_BITS)          if (Flags & QUARTERPELREFINE8_BITS)
264                  Flags &= ~XVID_ME_QUARTERPELREFINE8;                  Flags &= ~PMV_QUARTERPELREFINE8;
265    
266          if (!(VolFlags & XVID_VOL_QUARTERPEL))          if (!(GlobalFlags & XVID_QUARTERPEL))
267                  Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS);                  Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);
268    
269          if (!(VopFlags & XVID_VOP_HALFPEL))          if (!(GlobalFlags & XVID_HALFPEL))
270                  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);
271    
272          if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED))          if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED))
273                  Flags &= ~(XVID_ME_CHROMA16 + XVID_ME_CHROMA8);                  Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);
274    
275          return Flags;          return Flags;
276  }  }
# Line 286  Line 281 
281  #include "../quant/quant_mpeg4.h"  #include "../quant/quant_mpeg4.h"
282  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
283  #include "../bitstream/vlc_codes.h"  #include "../bitstream/vlc_codes.h"
 #include "../dct/fdct.h"  
284    
285  static int  static int
286  CountMBBitsInter(SearchData * const Data,  CountMBBitsInter(SearchData * const Data,
# Line 307  Line 301 
301  int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);  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);  int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
303    
 #define LAMBDA          ( (int)(1.0*BITS_MULT) )  
   
 static __inline unsigned int  
 Block_CalcBits( int16_t * const coeff,  
                                 int16_t * const data,  
                                 const uint32_t quant, const int quant_type,  
                                 uint32_t * cbp,  
                                 const int block)  
 {  
         int sum;  
         int bits;  
         const int lambda = LAMBDA*quant*quant;  
         int distortion = 0;  
         int i;  
   
         fdct(data);  
   
         if (quant_type == 0) sum = quant_inter(coeff, data, quant);  
         else sum = quant4_inter(coeff, data, quant);  
   
         if (sum > 0) {  
                 *cbp |= 1 << (5 - block);  
                 bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]);  
         } else bits = 0;  
   
         if (quant_type == 0) dequant_inter(coeff, coeff, quant);  
         else dequant4_inter(coeff, coeff, quant);  
   
         for (i = 0; i < 64; i++) {  
                 distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);  
         }  
         bits += (BITS_MULT*BITS_MULT*distortion)/lambda;  
   
   
         return bits;  
 }  
   
 static __inline unsigned int  
 Block_CalcBitsIntra(int16_t * const coeff,  
                                         int16_t * const data,  
                                         const uint32_t quant, const int quant_type,  
                                         uint32_t * cbp,  
                                         const int block,  
                                         int * dcpred)  
 {  
         int bits, i;  
         const int lambda = LAMBDA*quant*quant;  
         int distortion = 0;  
         uint32_t iDcScaler = get_dc_scaler(quant, block > 3);  
         int b_dc;  
   
         fdct(data);  
         data[0] -= 1024;  
   
         if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler);  
         else quant4_intra(coeff, data, quant, iDcScaler);  
   
         b_dc = coeff[0];  
         if (block < 4) {  
                 coeff[0] -= *dcpred;  
                 *dcpred = b_dc;  
         }  
   
         *cbp |= 1 << (5 - block);  
         bits = BITS_MULT*CodeCoeffIntra_CalcBits(coeff, scan_tables[0]);  
         bits += BITS_MULT*dcy_tab[coeff[0] + 255].len;  
         if (bits != 0) *cbp |= 1 << (5 - block);  
   
         coeff[0] = b_dc;  
         if (quant_type == 0) dequant_intra(coeff, coeff, quant, iDcScaler);  
         else dequant4_intra(coeff, coeff, quant, iDcScaler);  
   
         for (i = 0; i < 64; i++) {  
                 distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);  
         }  
   
         bits += (BITS_MULT*BITS_MULT*distortion)/lambda;  
   
         return bits;  
 }  
   
304  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

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

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