[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.12, Sat Jun 28 15:51:54 2003 UTC revision 1.4, Sat Mar 29 10:21:23 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 45  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 86  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 uint32_t mvtab[33] = {
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,          10, 11, 11, 11, 11, 11, 11, 12, 12
98                  12, 12, 12, 12, 12, 12, 12, 12,  };
                 12, 12, 12, 12, 12, 12, 12, 12,  
                 12, 12, 12, 12, 12, 12, 12, 12, 12 };  
99    
100  static const int DQtab[4] = {  static const int DQtab[4] = {
101          -1, -2, 1, 2          -1, -2, 1, 2
# Line 104  Line 105 
105    
106  typedef struct  typedef struct
107  {  {
108          /* general fields */  // general fields
109          int max_dx, min_dx, max_dy, min_dy;          int max_dx, min_dx, max_dy, min_dy;
110          uint32_t rounding;          uint32_t rounding;
111          VECTOR predMV;          VECTOR predMV;
112          VECTOR * currentMV;          VECTOR * currentMV;
113          VECTOR * currentQMV;          VECTOR * currentQMV;
114          int32_t * iMinSAD;          int32_t * iMinSAD;
115          const uint8_t * RefP[6]; /* N, V, H, HV, cU, cV */          const uint8_t * Ref;
116            const uint8_t * RefH;
117            const uint8_t * RefV;
118            const uint8_t * RefHV;
119            const uint8_t * RefCU;
120            const uint8_t * RefCV;
121          const uint8_t * CurU;          const uint8_t * CurU;
122          const uint8_t * CurV;          const uint8_t * CurV;
123          uint8_t * RefQ;          uint8_t * RefQ;
# Line 124  Line 130 
130          int qpel, qpel_precision;          int qpel, qpel_precision;
131          int chroma;          int chroma;
132          int rrv;          int rrv;
133    //fields for interpolate and direct modes
134            const uint8_t * bRef;
135            const uint8_t * bRefH;
136            const uint8_t * bRefV;
137            const uint8_t * bRefHV;
138            const uint8_t * b_RefCU;
139            const uint8_t * b_RefCV;
140    
         /* fields for interpolate and direct modes */  
         const uint8_t * b_RefP[6]; /* N, V, H, HV, cU, cV */  
141          VECTOR bpredMV;          VECTOR bpredMV;
142          uint32_t bFcode;          uint32_t bFcode;
143    // fields for direct mode
         /* fields for direct mode */  
144          VECTOR directmvF[4];          VECTOR directmvF[4];
145          VECTOR directmvB[4];          VECTOR directmvB[4];
146          const VECTOR * referencemv;          const VECTOR * referencemv;
147    // _BITS stuff
         /* BITS/R-D stuff */  
148          int16_t * dctSpace;          int16_t * dctSpace;
         uint32_t iQuant;  
         uint32_t quant_type;  
149    
150  } SearchData;  } SearchData;
151    
# Line 208  Line 215 
215                                  const IMAGE * const pRefH,                                  const IMAGE * const pRefH,
216                                  const IMAGE * const pRefV,                                  const IMAGE * const pRefV,
217                                  const IMAGE * const pRefHV,                                  const IMAGE * const pRefHV,
                                 const IMAGE * const pGMC,  
218                                  const uint32_t iLimit);                                  const uint32_t iLimit);
219    
220  static void  static void
# Line 220  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 VopFlags,                  const uint32_t GlobalFlags,
230                  const uint32_t VolFlags,                  const uint32_t iQuant,
231                  SearchData * const Data,                  SearchData * const Data,
232                  const MBParam * const pParam,                  const MBParam * const pParam,
233                  const MACROBLOCK * const pMBs,                  const MACROBLOCK * const pMBs,
234                  const MACROBLOCK * const prevMBs,                  const MACROBLOCK * const prevMBs,
235                    int inter4v,
236                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
237    
 static __inline void  
 GMEanalyzeMB (const uint8_t * const pCur,  
               const uint8_t * const pRef,  
               const uint8_t * const pRefH,  
               const uint8_t * const pRefV,  
               const uint8_t * const pRefHV,  
               const int x,  
               const int y,  
               const MBParam * const pParam,  
               MACROBLOCK * const pMBs,  
               SearchData * const Data);  
   
 void  
 GMEanalysis(const MBParam * const pParam,  
             const FRAMEINFO * const current,  
             const FRAMEINFO * const reference,  
             const IMAGE * const pRefH,  
             const IMAGE * const pRefV,  
             const IMAGE * const pRefHV);  
   
   
   
 WARPPOINTS  
 GlobalMotionEst(MACROBLOCK * const pMBs,  
                                 const MBParam * const pParam,  
                                 const FRAMEINFO * const current,  
                                 const FRAMEINFO * const reference,  
                                 const IMAGE * const pRefH,  
                                 const IMAGE * const pRefV,  
                                 const IMAGE * const pRefHV      );  
   
238    
239  int  static WARPPOINTS
240  GlobalMotionEstRefine(WARPPOINTS *const startwp,  GlobalMotionEst(const MACROBLOCK * const pMBs,
                       MACROBLOCK * const pMBs,  
241                        const MBParam * const pParam,                        const MBParam * const pParam,
242                        const FRAMEINFO * const current,                        const FRAMEINFO * const current,
243                        const FRAMEINFO * const reference,                        const FRAMEINFO * const reference,
                       const IMAGE * const pCurr,  
                       const IMAGE * const pRef,  
244                        const IMAGE * const pRefH,                        const IMAGE * const pRefH,
245                        const IMAGE * const pRefV,                        const IMAGE * const pRefV,
246                        const IMAGE * const pRefHV);                        const IMAGE * const pRefHV);
247    
   
   
   
 int  
 globalSAD(const WARPPOINTS *const wp,  
                 const MBParam * const pParam,  
                 const MACROBLOCK * const pMBs,  
                 const FRAMEINFO * const current,  
                 const IMAGE * const pRef,  
                 const IMAGE * const pCurr,  
                 uint8_t *const GMCblock);  
   
248  #define iDiamondSize 2  #define iDiamondSize 2
249    
250  static __inline uint32_t  static __inline uint32_t
251  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t VopFlags, const uint32_t VolFlags)  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags)
252  {  {
253          uint32_t Flags = MotionFlags;          uint32_t Flags = MotionFlags;
254    
255          if (!(VopFlags & XVID_VOP_MODEDECISION_BITS))          if (!(GlobalFlags & XVID_MODEDECISION_BITS))
256                  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);
257    
258          if (Flags & XVID_ME_EXTSEARCH_BITS)          if (Flags & EXTSEARCH_BITS)
259                  Flags |= XVID_ME_HALFPELREFINE16_BITS;                  Flags |= HALFPELREFINE16_BITS;
260    
261          if (Flags & XVID_ME_EXTSEARCH_BITS && MotionFlags & XVID_ME_EXTSEARCH8)          if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)
262                  Flags |= XVID_ME_HALFPELREFINE8_BITS;                  Flags |= HALFPELREFINE8_BITS;
263    
264          if (Flags & XVID_ME_HALFPELREFINE16_BITS)          if (Flags & HALFPELREFINE16_BITS)
265                  Flags |= XVID_ME_QUARTERPELREFINE16_BITS;                  Flags |= QUARTERPELREFINE16_BITS;
266    
267          if (Flags & XVID_ME_HALFPELREFINE8_BITS) {          if (Flags & HALFPELREFINE8_BITS) {
268                  Flags |= XVID_ME_QUARTERPELREFINE8_BITS;                  Flags |= QUARTERPELREFINE8_BITS;
269                  Flags &= ~XVID_ME_HALFPELREFINE8;                  Flags &= ~PMV_HALFPELREFINE8;
270          }          }
271    
272          if (Flags & XVID_ME_QUARTERPELREFINE8_BITS)          if (Flags & QUARTERPELREFINE8_BITS)
273                  Flags &= ~XVID_ME_QUARTERPELREFINE8;                  Flags &= ~PMV_QUARTERPELREFINE8;
274    
275          if (!(VolFlags & XVID_VOL_QUARTERPEL))          if (!(GlobalFlags & XVID_QUARTERPEL))
276                  Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS);                  Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);
277    
278          if (!(VopFlags & XVID_VOP_HALFPEL))          if (!(GlobalFlags & XVID_HALFPEL))
279                  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);
280    
281          if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED))          if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED))
282                  Flags &= ~(XVID_ME_CHROMA16 + XVID_ME_CHROMA8);                  Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);
283    
284          return Flags;          return Flags;
285  }  }
# Line 329  Line 290 
290  #include "../quant/quant_mpeg4.h"  #include "../quant/quant_mpeg4.h"
291  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
292  #include "../bitstream/vlc_codes.h"  #include "../bitstream/vlc_codes.h"
 #include "../dct/fdct.h"  
293    
294  static int  static int
295  CountMBBitsInter(SearchData * const Data,  CountMBBitsInter(SearchData * const Data,
# Line 350  Line 310 
310  int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);  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);  int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
312    
 /* one over lambda for R-D mode decision and motion search */  
 #define LAMBDA          ( (int)(BITS_MULT/1.0) )  
   
 static __inline unsigned int  
 Block_CalcBits( int16_t * const coeff,  
                                 int16_t * const data,  
                                 int16_t * const dqcoeff,  
                                 const uint32_t quant, const int quant_type,  
                                 uint32_t * cbp,  
                                 const int block)  
 {  
         int sum;  
         int bits;  
         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(dqcoeff, coeff, quant);  
         else dequant4_inter(dqcoeff, coeff, quant);  
   
         for (i = 0; i < 64; i++) {  
                 distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]);  
         }  
   
         bits += (LAMBDA*distortion)/(quant*quant);  
   
         return bits;  
 }  
   
 static __inline unsigned int  
 Block_CalcBitsIntra(int16_t * const coeff,  
                                         int16_t * const data,  
                                         int16_t * const dqcoeff,  
                                         const uint32_t quant, const int quant_type,  
                                         uint32_t * cbp,  
                                         const int block,  
                                         int * dcpred)  
 {  
         int bits, i;  
         int distortion = 0;  
         uint32_t iDcScaler = get_dc_scaler(quant, block < 4);  
         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;  
         }  
   
         bits = BITS_MULT*CodeCoeffIntra_CalcBits(coeff, scan_tables[0]);  
         if (bits != 0) *cbp |= 1 << (5 - block);  
   
         if (block < 4) bits += BITS_MULT*dcy_tab[coeff[0] + 255].len;  
         else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len;  
   
         coeff[0] = b_dc;  
         if (quant_type == 0) dequant_intra(dqcoeff, coeff, quant, iDcScaler);  
         else dequant4_intra(dqcoeff, coeff, quant, iDcScaler);  
   
         for (i = 0; i < 64; i++) {  
                 distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]);  
         }  
   
         bits += (LAMBDA*distortion)/(quant*quant);  
   
         return bits;  
 }  
   
313  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

Legend:
Removed from v.1.3.2.12  
changed lines
  Added in v.1.4

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