[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.3, Wed Oct 2 10:16:36 2002 UTC revision 1.3.2.1, Sat Feb 22 08:49:45 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 44  Line 45 
45  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
46  #define MV16_INTER_BIAS 512  #define MV16_INTER_BIAS 512
47    
48    /* vector map (vlc delta size) smoother parameters ! float !*/
49    #define NEIGH_TEND_16X16        10.5
50    #define NEIGH_TEND_8X8          40.0
51    #define NEIGH_8X8_BIAS          30
52    
53  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
54  #define IMV16X16                        2  #define IMV16X16                        2
55    
 /* vector map (vlc delta size) smoother parameters ! float !*/  
 #define NEIGH_TEND_16X16        4.0  
 #define NEIGH_TEND_8X8          7.0  
   
56  static const int lambda_vec16[32] =  static const int lambda_vec16[32] =
57          {     0    ,(int)(1.00235 * NEIGH_TEND_16X16 + 0.5),          {     0    ,(int)(1.00235 * NEIGH_TEND_16X16 + 0.5),
58          (int)(1.15582*NEIGH_TEND_16X16 + 0.5), (int)(1.31976*NEIGH_TEND_16X16 + 0.5),          (int)(1.15582*NEIGH_TEND_16X16 + 0.5), (int)(1.31976*NEIGH_TEND_16X16 + 0.5),
# Line 99  Line 101 
101          -1, -2, 1, 2          -1, -2, 1, 2
102  };  };
103    
104    #define RRV_MV_SCALEDOWN(a)     ( (a)>=0 ? (a+1)/2 : (a-1)/2 )
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;
111                  VECTOR predMV;                  VECTOR predMV;
112                  VECTOR *currentMV;                  VECTOR *currentMV;
113            VECTOR * currentQMV;
114                  int32_t *iMinSAD;                  int32_t *iMinSAD;
115                  const uint8_t * Ref;                  const uint8_t * Ref;
116                  const uint8_t * RefH;                  const uint8_t * RefH;
117                  const uint8_t * RefV;                  const uint8_t * RefV;
118                  const uint8_t * RefHV;                  const uint8_t * RefHV;
119            const uint8_t * RefCU;
120            const uint8_t * RefCV;
121            const uint8_t * CurU;
122            const uint8_t * CurV;
123            uint8_t * RefQ;
124                  const uint8_t * Cur;                  const uint8_t * Cur;
125                  uint32_t iQuant;          uint32_t lambda16;
126            uint32_t lambda8;
127                  uint32_t iEdgedWidth;                  uint32_t iEdgedWidth;
128                  uint32_t iFcode;                  uint32_t iFcode;
129                  int * temp;                  int * temp;
130  //fields for interpolate and direct mode          int qpel, qpel_precision;
131            int chroma;
132            int rrv;
133    //fields for interpolate and direct modes
134                  const uint8_t *bRef;                  const uint8_t *bRef;
135                  const uint8_t *bRefH;                  const uint8_t *bRefH;
136                  const uint8_t *bRefV;                  const uint8_t *bRefV;
137                  const uint8_t *bRefHV;                  const uint8_t *bRefHV;
138            const uint8_t * b_RefCU;
139            const uint8_t * b_RefCV;
140    
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          }  
148          SearchData;  } SearchData;
149    
150    
151  typedef void(CheckFunc)(const int x, const int y,  typedef void(CheckFunc)(const int x, const int y,
152                                                  const int Direction, int * const dir,                                                  const int Direction, int * const dir,
153                                                  const SearchData * const Data);                                                  const SearchData * const Data);
   
 static CheckFunc CheckCandidate16, CheckCandidate16no4v, CheckCandidateInt,  
                         CheckCandidateDirect, CheckCandidateDirectno4v,  
                         CheckCandidate8;  
154  CheckFunc *CheckCandidate;  CheckFunc *CheckCandidate;
155    
156  /*  /*
157   * Calculate the min/max range (in halfpixels)   * Calculate the min/max range
158   * relative to the _MACROBLOCK_ position   * relative to the _MACROBLOCK_ position
159   */   */
160  static void __inline  static void __inline
# Line 151  Line 164 
164                    int32_t * const max_dy,                    int32_t * const max_dy,
165                    const uint32_t x,                    const uint32_t x,
166                    const uint32_t y,                    const uint32_t y,
167                    const uint32_t block_sz,      /* block dimension, 8 or 16 */                    uint32_t block_sz, /* block dimension, 8 or 16 */
168                    const uint32_t width,                    const uint32_t width,
169                    const uint32_t height,                    const uint32_t height,
170                    const uint32_t fcode)                    const uint32_t fcode,
171                      const int qpel, /* 1 if the resulting range should be in qpel precision; otherwise 0 */
172                      const int rrv)
173  {  {
174            int k, m = qpel ? 4 : 2;
175            const int search_range = 32 << (fcode - 1);
176            int high = search_range - 1;
177            int low = -search_range;
178    
179            if (rrv) {
180                    high = RRV_MV_SCALEUP(high);
181                    low = RRV_MV_SCALEUP(low);
182                    block_sz *= 2;
183            }
184    
185          int k;          k = m * (int)(width - x * block_sz);
         int high = (32 << (fcode - 1)) - 1;  
   
         k = 2 * (int)(width - x*block_sz);  
186          *max_dx = MIN(high, k);          *max_dx = MIN(high, k);
187          k = 2 * (int)(height -  y*block_sz);          k = m * (int)(height -  y * block_sz);
188          *max_dy = MIN(high, k);          *max_dy = MIN(high, k);
189    
190          high = -(32 << (fcode - 1));          k = -m * (int)((x+1) * block_sz);
191          k = -2 * (int)((x+1) * block_sz);          *min_dx = MAX(low, k);
192          *min_dx = MAX(high, k);          k = -m * (int)((y+1) * block_sz);
193          k = -2 * (int)((y+1) * block_sz);          *min_dy = MAX(low, k);
         *min_dy = MAX(high, k);  
   
194  }  }
195    
   
196  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);
197    
198  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;  static MainSearchFunc DiamondSearch, AdvDiamondSearch, SquareSearch;
# Line 197  Line 216 
216                                   const uint32_t iLimit);                                   const uint32_t iLimit);
217    
218  static void  static void
219  SearchP(const uint8_t * const pRef,  SearchP(const IMAGE * const pRef,
220                  const uint8_t * const pRefH,                  const uint8_t * const pRefH,
221                  const uint8_t * const pRefV,                  const uint8_t * const pRefV,
222                  const uint8_t * const pRefHV,                  const uint8_t * const pRefHV,
# Line 205  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,
228                  const uint32_t iQuant,                  const uint32_t iQuant,
229                  SearchData * const Data,                  SearchData * const Data,
230                  const MBParam * const pParam,                  const MBParam * const pParam,
# Line 214  Line 234 
234                  MACROBLOCK * const pMB);                  MACROBLOCK * const pMB);
235    
236    
237  #ifdef _SMP  static WARPPOINTS
238  bool  GlobalMotionEst(const MACROBLOCK * const pMBs,
239  SMP_MotionEstimation(MBParam * const pParam,                                  const MBParam * const pParam,
240                                   FRAMEINFO * const current,                                  const FRAMEINFO * const current,
241                                   FRAMEINFO * const reference,                                  const FRAMEINFO * const reference,
242                                   const IMAGE * const pRefH,                                   const IMAGE * const pRefH,
243                                   const IMAGE * const pRefV,                                   const IMAGE * const pRefV,
244                                   const IMAGE * const pRefHV,                                  const IMAGE * const pRefHV      );
245                                   const uint32_t iLimit);  
246  #endif  #define iDiamondSize 2
247    
248    static __inline uint32_t
249    MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t VopFlags, const uint32_t VolFlags)
250    {
251            uint32_t Flags = MotionFlags;
252    
253            if (!(VopFlags & XVID_MODEDECISION_BITS))
254                    Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS);
255    
256            if (Flags & EXTSEARCH_BITS)
257                    Flags |= HALFPELREFINE16_BITS;
258    
259            if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8)
260                    Flags |= HALFPELREFINE8_BITS;
261    
262            if (Flags & HALFPELREFINE16_BITS)
263                    Flags |= QUARTERPELREFINE16_BITS;
264    
265            if (Flags & HALFPELREFINE8_BITS) {
266                    Flags |= QUARTERPELREFINE8_BITS;
267                    Flags &= ~PMV_HALFPELREFINE8;
268            }
269    
270            if (Flags & QUARTERPELREFINE8_BITS)
271                    Flags &= ~PMV_QUARTERPELREFINE8;
272    
273            if (!(VolFlags & XVID_QUARTERPEL))
274                    Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS);
275    
276            if (!(VopFlags & XVID_HALFPEL))
277                    Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS);
278    
279            if ((VopFlags & XVID_GREYSCALE) || (VopFlags & XVID_REDUCED))
280                    Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8);
281    
282            return Flags;
283    }
284    
285    /* BITS mode decision and search */
286    
287    #include "../bitstream/zigzag.h"
288    #include "../quant/quant_mpeg4.h"
289    #include "../quant/quant_h263.h"
290    #include "../bitstream/vlc_codes.h"
291    
292    static int
293    CountMBBitsInter(SearchData * const Data,
294                                    const MACROBLOCK * const pMBs, const int x, const int y,
295                                    const MBParam * const pParam,
296                                    const uint32_t MotionFlags);
297    
298    static int
299    CountMBBitsInter4v(const SearchData * const Data,
300                                            MACROBLOCK * const pMB, const MACROBLOCK * const pMBs,
301                                            const int x, const int y,
302                                            const MBParam * const pParam, const uint32_t MotionFlags,
303                                            const VECTOR * const backup);
304    
305    static int
306    CountMBBitsIntra(const SearchData * const Data);
307    
308    int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
309    int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag);
310    
311  #endif                                                  /* _MOTION_EST_H_ */  #endif                                                  /* _MOTION_EST_H_ */

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.3.2.1

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