[svn] / branches / dev-api-4 / xvidcore / src / motion / motion_est.h Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/motion/motion_est.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 886, Fri Feb 21 14:49:29 2003 UTC revision 1053, Mon Jun 9 01:25:19 2003 UTC
# Line 26  Line 26 
26   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
27   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
28   *   *
29   *  $Id: motion_est.h,v 1.3 2003-02-21 14:40:11 syskin Exp $   *  $Id: motion_est.h,v 1.3.2.8 2003-06-09 01:22:18 edgomez Exp $
30   *   *
31   ***************************************************************************/   ***************************************************************************/
32    
# 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    
53    #define BITS_MULT                       16
54    
55  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
56  #define IMV16X16                        2  #define IMV16X16                        2
57    
# Line 89  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 uint32_t mvtab[33] = {  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,
98          10, 10, 10, 10, 10, 10, 10, 10,          10, 10, 10, 10, 10, 10, 10, 10,
99          10, 11, 11, 11, 11, 11, 11, 12, 12                  10, 11, 11, 11, 11, 11, 11, 12,
100  };                  12, 12, 12, 12, 12, 12, 12, 12,
101                    12, 12, 12, 12, 12, 12, 12, 12,
102                    12, 12, 12, 12, 12, 12, 12, 12, 12 };
103    
104  static const int DQtab[4] = {  static const int DQtab[4] = {
105          -1, -2, 1, 2          -1, -2, 1, 2
# Line 105  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 * 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;  
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 130  Line 129 
129          int qpel, qpel_precision;          int qpel, qpel_precision;
130          int chroma;          int chroma;
131          int rrv;          int rrv;
 //fields for interpolate and direct modes  
         const uint8_t * bRef;  
         const uint8_t * bRefH;  
         const uint8_t * bRefV;  
         const uint8_t * bRefHV;  
         const uint8_t * b_RefCU;  
         const uint8_t * b_RefCV;  
132    
133            /* fields for interpolate and direct modes */
134            const uint8_t * b_RefP[6]; /* N, V, H, HV, cU, cV */
135          VECTOR bpredMV;          VECTOR bpredMV;
136          uint32_t bFcode;          uint32_t bFcode;
137  // fields for direct mode  
138            /* fields for direct mode */
139          VECTOR directmvF[4];          VECTOR directmvF[4];
140          VECTOR directmvB[4];          VECTOR directmvB[4];
141          const VECTOR * referencemv;          const VECTOR * referencemv;
142    
143            /* BITS/R-D stuff */
144            int16_t * dctSpace;
145            uint32_t iQuant;
146            uint32_t quant_type;
147    
148  } SearchData;  } SearchData;
149    
150    
# Line 224  Line 224 
224                  const int x,                  const int x,
225                  const int y,                  const int y,
226                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
227                  const uint32_t GlobalFlags,                  const uint32_t VopFlags,
228                  const uint32_t iQuant,                  const uint32_t VolFlags,
229                  SearchData * const Data,                  SearchData * const Data,
230                  const MBParam * const pParam,                  const MBParam * const pParam,
231                  const MACROBLOCK * const pMBs,                  const MACROBLOCK * const pMBs,
232                  const MACROBLOCK * const prevMBs,                  const MACROBLOCK * const prevMBs,
                 int inter4v,  
233                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
234    
   
235  static WARPPOINTS  static WARPPOINTS
236  GlobalMotionEst(const MACROBLOCK * const pMBs,  GlobalMotionEst(const MACROBLOCK * const pMBs,
237                                  const MBParam * const pParam,                                  const MBParam * const pParam,
# Line 246  Line 244 
244  #define iDiamondSize 2  #define iDiamondSize 2
245    
246  static __inline uint32_t  static __inline uint32_t
247  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags)  MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t VopFlags, const uint32_t VolFlags)
248  {  {
249          uint32_t Flags = MotionFlags;          uint32_t Flags = MotionFlags;
250    
251          if (!(GlobalFlags & XVID_MODEDECISION_BITS))          if (!(VopFlags & XVID_VOP_MODEDECISION_BITS))
252                  Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS);                  Flags &= ~(XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS+XVID_ME_EXTSEARCH_BITS);
253    
254          if (Flags & EXTSEARCH_BITS)          if (Flags & XVID_ME_EXTSEARCH_BITS)
255                  Flags |= HALFPELREFINE16_BITS;                  Flags |= XVID_ME_HALFPELREFINE16_BITS;
256    
257          if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)          if (Flags & XVID_ME_EXTSEARCH_BITS && MotionFlags & XVID_ME_EXTSEARCH8)
258                  Flags |= HALFPELREFINE8_BITS;                  Flags |= XVID_ME_HALFPELREFINE8_BITS;
259    
260          if (Flags & HALFPELREFINE16_BITS)          if (Flags & XVID_ME_HALFPELREFINE16_BITS)
261                  Flags |= QUARTERPELREFINE16_BITS;                  Flags |= XVID_ME_QUARTERPELREFINE16_BITS;
262    
263          if (Flags & HALFPELREFINE8_BITS) {          if (Flags & XVID_ME_HALFPELREFINE8_BITS) {
264                  Flags |= QUARTERPELREFINE8_BITS;                  Flags |= XVID_ME_QUARTERPELREFINE8_BITS;
265                  Flags &= ~PMV_HALFPELREFINE8;                  Flags &= ~XVID_ME_HALFPELREFINE8;
266          }          }
267    
268          if (Flags & QUARTERPELREFINE8_BITS)          if (Flags & XVID_ME_QUARTERPELREFINE8_BITS)
269                  Flags &= ~PMV_QUARTERPELREFINE8;                  Flags &= ~XVID_ME_QUARTERPELREFINE8;
270    
271          if (!(GlobalFlags & XVID_QUARTERPEL))          if (!(VolFlags & XVID_VOL_QUARTERPEL))
272                  Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);                  Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS);
273    
274          if (!(GlobalFlags & XVID_HALFPEL))          if (!(VopFlags & XVID_VOP_HALFPEL))
275                  Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS);                  Flags &= ~(XVID_ME_EXTSEARCH16+XVID_ME_HALFPELREFINE16+XVID_ME_HALFPELREFINE8+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS);
276    
277          if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED))          if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED))
278                  Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);                  Flags &= ~(XVID_ME_CHROMA16 + XVID_ME_CHROMA8);
279    
280          return Flags;          return Flags;
281  }  }
# Line 288  Line 286 
286  #include "../quant/quant_mpeg4.h"  #include "../quant/quant_mpeg4.h"
287  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
288  #include "../bitstream/vlc_codes.h"  #include "../bitstream/vlc_codes.h"
289    #include "../dct/fdct.h"
290    
291  static int  static int
292  CountMBBitsInter(SearchData * const Data,  CountMBBitsInter(SearchData * const Data,
# Line 308  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    #define LAMBDA          ( (int)(1.0*BITS_MULT) )
311    
312    static __inline unsigned int
313    Block_CalcBits( int16_t * const coeff,
314                                    int16_t * const data,
315                                    const uint32_t quant, const int quant_type,
316                                    uint32_t * cbp,
317                                    const int block)
318    {
319            int sum;
320            int bits;
321            const int lambda = LAMBDA*quant*quant;
322            int distortion = 0;
323            int i;
324    
325            fdct(data);
326    
327            if (quant_type == 0) sum = quant_inter(coeff, data, quant);
328            else sum = quant4_inter(coeff, data, quant);
329    
330            if (sum > 0) {
331                    *cbp |= 1 << (5 - block);
332                    bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]);
333            } else bits = 0;
334    
335            if (quant_type == 0) dequant_inter(coeff, coeff, quant);
336            else dequant4_inter(coeff, coeff, quant);
337    
338            for (i = 0; i < 64; i++) {
339                    distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);
340            }
341            bits += (BITS_MULT*BITS_MULT*distortion)/lambda;
342    
343    
344            return bits;
345    }
346    
347    static __inline unsigned int
348    Block_CalcBitsIntra(int16_t * const coeff,
349                                            int16_t * const data,
350                                            const uint32_t quant, const int quant_type,
351                                            uint32_t * cbp,
352                                            const int block,
353                                            int * dcpred)
354    {
355            int bits, i;
356            const int lambda = LAMBDA*quant*quant;
357            int distortion = 0;
358            uint32_t iDcScaler = get_dc_scaler(quant, block > 3);
359            int b_dc;
360    
361            fdct(data);
362            data[0] -= 1024;
363    
364            if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler);
365            else quant4_intra(coeff, data, quant, iDcScaler);
366    
367            b_dc = coeff[0];
368            if (block < 4) {
369                    coeff[0] -= *dcpred;
370                    *dcpred = b_dc;
371            }
372    
373            *cbp |= 1 << (5 - block);
374            bits = BITS_MULT*CodeCoeffIntra_CalcBits(coeff, scan_tables[0]);
375            bits += BITS_MULT*dcy_tab[coeff[0] + 255].len;
376            if (bits != 0) *cbp |= 1 << (5 - block);
377    
378            coeff[0] = b_dc;
379            if (quant_type == 0) dequant_intra(coeff, coeff, quant, iDcScaler);
380            else dequant4_intra(coeff, coeff, quant, iDcScaler);
381    
382            for (i = 0; i < 64; i++) {
383                    distortion += (data[i] - coeff[i])*(data[i] - coeff[i]);
384            }
385    
386            bits += (BITS_MULT*BITS_MULT*distortion)/lambda;
387    
388            return bits;
389    }
390    
391  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

Legend:
Removed from v.886  
changed lines
  Added in v.1053

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