[svn] / trunk / xvidcore / src / motion / motion_est.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/motion/motion_est.c

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

revision 118, Sat Apr 13 16:30:02 2002 UTC revision 169, Thu May 9 00:42:35 2002 UTC
# Line 2  Line 2 
2   *   *
3   *  Modifications:   *  Modifications:
4   *   *
5     *      01.05.2002      updated MotionEstimationBVOP
6     *      25.04.2002 partial prevMB conversion
7     *  22.04.2002 remove some compile warning by chenm001 <chenm001@163.com>
8   *      14.04.2002 added MotionEstimationBVOP()   *      14.04.2002 added MotionEstimationBVOP()
9   *  02.04.2002 add EPZS(^2) as ME algorithm, use PMV_USESQUARES to choose between   *  02.04.2002 add EPZS(^2) as ME algorithm, use PMV_USESQUARES to choose between
10   *             EPZS and EPZS^2   *             EPZS and EPZS^2
# Line 54  Line 57 
57  /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */  /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */
58  /* nb  = vop pixels * 2^(bpp-8) */  /* nb  = vop pixels * 2^(bpp-8) */
59  #define MV16_00_BIAS    (128+1)  #define MV16_00_BIAS    (128+1)
60    #define MV8_00_BIAS     (0)
61    
62  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
63  #define INTER_BIAS      512  #define INTER_BIAS      512
# Line 78  Line 82 
82                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
83                                          const int x, const int y,                                          const int x, const int y,
84                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
85                                            const uint32_t iQuant,
86                                            const uint32_t iFcode,
87                                          const MBParam * const pParam,                                          const MBParam * const pParam,
88                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
89                                            const MACROBLOCK * const prevMBs,
90                                          VECTOR * const currMV,                                          VECTOR * const currMV,
91                                          VECTOR * const currPMV);                                          VECTOR * const currPMV);
92    
# Line 91  Line 98 
98                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
99                                          const int x, const int y,                                          const int x, const int y,
100                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
101                                            const uint32_t iQuant,
102                                            const uint32_t iFcode,
103                                          const MBParam * const pParam,                                          const MBParam * const pParam,
104                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
105                                            const MACROBLOCK * const prevMBs,
106                                          VECTOR * const currMV,                                          VECTOR * const currMV,
107                                          VECTOR * const currPMV);                                          VECTOR * const currPMV);
108    
# Line 104  Line 114 
114                                          const uint8_t * const pRefHV,                                          const uint8_t * const pRefHV,
115                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
116                                          const int x, const int y,                                          const int x, const int y,
117                                          const int start_x, int start_y,                                          const int start_x, const int start_y,
118                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
119                                            const uint32_t iQuant,
120                                            const uint32_t iFcode,
121                                          const MBParam * const pParam,                                          const MBParam * const pParam,
122                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
123                                            const MACROBLOCK * const prevMBs,
124                                          VECTOR * const currMV,                                          VECTOR * const currMV,
125                                          VECTOR * const currPMV);                                          VECTOR * const currPMV);
126    
# Line 118  Line 131 
131                                          const uint8_t * const pRefHV,                                          const uint8_t * const pRefHV,
132                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
133                                          const int x, const int y,                                          const int x, const int y,
134                                          const int start_x, int start_y,                                          const int start_x, const int start_y,
135                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
136                                            const uint32_t iQuant,
137                                            const uint32_t iFcode,
138                                          const MBParam * const pParam,                                          const MBParam * const pParam,
139                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
140                                            const MACROBLOCK * const prevMBs,
141                                          VECTOR * const currMV,                                          VECTOR * const currMV,
142                                          VECTOR * const currPMV);                                          VECTOR * const currPMV);
143    
# Line 169  Line 185 
185    
186  typedef MainSearch8Func* MainSearch8FuncPtr;  typedef MainSearch8Func* MainSearch8FuncPtr;
187    
188    static int32_t lambda_vec16[32] =  /* rounded values for lambda param for weight of motion bits as in modified H.26L */
189            {     0    ,(int)(1.00235+0.5), (int)(1.15582+0.5), (int)(1.31976+0.5), (int)(1.49591+0.5), (int)(1.68601+0.5),
190            (int)(1.89187+0.5), (int)(2.11542+0.5), (int)(2.35878+0.5), (int)(2.62429+0.5), (int)(2.91455+0.5),
191            (int)(3.23253+0.5), (int)(3.58158+0.5), (int)(3.96555+0.5), (int)(4.38887+0.5), (int)(4.85673+0.5),
192            (int)(5.37519+0.5), (int)(5.95144+0.5), (int)(6.59408+0.5), (int)(7.31349+0.5), (int)(8.12242+0.5),
193            (int)(9.03669+0.5), (int)(10.0763+0.5), (int)(11.2669+0.5), (int)(12.6426+0.5), (int)(14.2493+0.5),
194            (int)(16.1512+0.5), (int)(18.442+0.5),  (int)(21.2656+0.5), (int)(24.8580+0.5), (int)(29.6436+0.5),
195            (int)(36.4949+0.5)      };
196    
197    static int32_t *lambda_vec8 = lambda_vec16;     /* same table for INTER and INTER4V for now*/
198    
199    
200    
201  // mv.length table  // mv.length table
202  static const uint32_t mvtab[33] = {  static const uint32_t mvtab[33] = {
203      1,  2,  3,  4,  6,  7,  7,  7,      1,  2,  3,  4,  6,  7,  7,  7,
# Line 204  Line 233 
233  }  }
234    
235    
236  static __inline uint32_t calc_delta_16(const int32_t dx, const int32_t dy, const uint32_t iFcode)  static __inline uint32_t calc_delta_16(const int32_t dx, const int32_t dy, const uint32_t iFcode, const uint32_t iQuant)
237  {  {
238          return NEIGH_TEND_16X16 * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode));          return NEIGH_TEND_16X16 * lambda_vec16[iQuant] * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode));
239  }  }
240    
241  static __inline uint32_t calc_delta_8(const int32_t dx, const int32_t dy, const uint32_t iFcode)  static __inline uint32_t calc_delta_8(const int32_t dx, const int32_t dy, const uint32_t iFcode, const uint32_t iQuant)
242    
243  {  {
244      return NEIGH_TEND_8X8 * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode));      return NEIGH_TEND_8X8 * lambda_vec8[iQuant] * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode));
245  }  }
246    
247    
# Line 231  Line 260 
260  #endif  #endif
261    
262  bool MotionEstimation(  bool MotionEstimation(
         MACROBLOCK * const pMBs,  
263          MBParam * const pParam,          MBParam * const pParam,
264          const IMAGE * const pRef,          FRAMEINFO * const current,
265            FRAMEINFO * const reference,
266          const IMAGE * const pRefH,          const IMAGE * const pRefH,
267          const IMAGE * const pRefV,          const IMAGE * const pRefV,
268          const IMAGE * const pRefHV,          const IMAGE * const pRefHV,
         IMAGE * const pCurrent,  
269          const uint32_t iLimit)          const uint32_t iLimit)
270    
271  {  {
272          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
273          const uint32_t iHcount = pParam->mb_height;          const uint32_t iHcount = pParam->mb_height;
274            MACROBLOCK * pMBs = current->mbs;
275            IMAGE * pCurrent = &current->image;
276    
277            MACROBLOCK * prevMBs = reference->mbs;  // previous frame
278            IMAGE * pRef = &reference->image;
279    
280    
281          uint32_t i, j, iIntra = 0;          uint32_t i, j, iIntra = 0;
282    
# Line 261  Line 295 
295                  for (j = 0; j < iWcount; j++)                  for (j = 0; j < iWcount; j++)
296                  {                  {
297                          MACROBLOCK *pMB = &pMBs[j + i * iWcount];                          MACROBLOCK *pMB = &pMBs[j + i * iWcount];
298                            MACROBLOCK *prevMB = &prevMBs[j + i * iWcount];
299    
300                          sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                          sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
301                                           j, i, pParam->motion_flags,                                           j, i, current->motion_flags, current->quant, current->fcode,
302                                           pParam, pMBs, &mv16, &pmv16);                                           pParam, pMBs, prevMBs, &mv16, &pmv16);
303                          pMB->sad16=sad16;                          pMB->sad16=sad16;
304    
305    
# Line 280  Line 315 
315                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = 0;                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = 0;
316                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;
317    
318                                    pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = 0;
319    
320                                  iIntra++;                                  iIntra++;
321                                  if(iIntra >= iLimit)                                  if(iIntra >= iLimit)
322                                          return 1;                                          return 1;
# Line 287  Line 324 
324                                  continue;                                  continue;
325                          }                          }
326    
327                          if (pParam->global_flags & XVID_INTER4V)                          if (current->global_flags & XVID_INTER4V)
328                          {                          {
329                                  pMB->sad8[0] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  pMB->sad8[0] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
330                                                         2 * j, 2 * i, mv16.x, mv16.y, pParam->motion_flags,                                                         2 * j, 2 * i, mv16.x, mv16.y,
331                                                         pParam, pMBs, &pMB->mvs[0], &pMB->pmvs[0]);                                                             current->motion_flags, current->quant, current->fcode,
332                                                           pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);
333    
334                                  pMB->sad8[1] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  pMB->sad8[1] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
335                                                         2 * j + 1, 2 * i, mv16.x, mv16.y, pParam->motion_flags,                                                         2 * j + 1, 2 * i, mv16.x, mv16.y,
336                                                         pParam, pMBs, &pMB->mvs[1], &pMB->pmvs[1]);                                                             current->motion_flags, current->quant, current->fcode,
337                                                           pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);
338    
339                                  pMB->sad8[2] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  pMB->sad8[2] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
340                                                         2 * j, 2 * i + 1, mv16.x, mv16.y, pParam->motion_flags,                                                         2 * j, 2 * i + 1, mv16.x, mv16.y,
341                                                         pParam, pMBs, &pMB->mvs[2], &pMB->pmvs[2]);                                                             current->motion_flags, current->quant, current->fcode,
342                                                           pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);
343    
344                                  pMB->sad8[3] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  pMB->sad8[3] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
345                                                         2 * j + 1, 2 * i + 1, mv16.x, mv16.y, pParam->motion_flags,                                                         2 * j + 1, 2 * i + 1, mv16.x, mv16.y,
346                                                         pParam, pMBs, &pMB->mvs[3], &pMB->pmvs[3]);                                                             current->motion_flags, current->quant, current->fcode,
347                                                           pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);
348    
349                                  sad8 = pMB->sad8[0] + pMB->sad8[1] + pMB->sad8[2] + pMB->sad8[3];                                  sad8 = pMB->sad8[0] + pMB->sad8[1] + pMB->sad8[2] + pMB->sad8[3];
350                          }                          }
# Line 313  Line 354 
354                             mpeg4:   if (sad8 < sad16 - nb/2+1) use_inter4v                             mpeg4:   if (sad8 < sad16 - nb/2+1) use_inter4v
355                          */                          */
356    
357                          if (pMB->dquant == NO_CHANGE) {                          if (!(current->global_flags & XVID_LUMIMASKING) || pMB->dquant == NO_CHANGE)
358                                  if (((pParam->global_flags & XVID_INTER4V)==0) ||                          {
359                                      (sad16 < (sad8 + (int32_t)(IMV16X16 * pParam->quant)))) {                                  if (((current->global_flags & XVID_INTER4V)==0) ||
360                                        (sad16 < (sad8 + (int32_t)(IMV16X16 * current->quant))))
361                                    {
362    
363                                          sad8 = sad16;                                          sad8 = sad16;
364                                          pMB->mode = MODE_INTER;                                          pMB->mode = MODE_INTER;
365                                          pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;                                          pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;
366                                          pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;                                          pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;
367                                            pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;
368                                          pMB->pmvs[0].x = pmv16.x;                                          pMB->pmvs[0].x = pmv16.x;
369                                          pMB->pmvs[0].y = pmv16.y;                                          pMB->pmvs[0].y = pmv16.y;
370                                  }                                  }
371                                  else                                  else
372                                    {
373                                          pMB->mode = MODE_INTER4V;                                          pMB->mode = MODE_INTER4V;
374                                            pMB->sad8[0] *= 4;
375                                            pMB->sad8[1] *= 4;
376                                            pMB->sad8[2] *= 4;
377                                            pMB->sad8[3] *= 4;
378                                    }
379                          }                          }
380                          else                          else
381                          {                          {
# Line 333  Line 383 
383                                  pMB->mode = MODE_INTER;                                  pMB->mode = MODE_INTER;
384                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;
385                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;
386                                    pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;
387    
388                                  pMB->pmvs[0].x = pmv16.x;                                  pMB->pmvs[0].x = pmv16.x;
389                                  pMB->pmvs[0].y = pmv16.y;                                  pMB->pmvs[0].y = pmv16.y;
390                          }                          }
# Line 351  Line 403 
403      && (0 <= max_dy) && (0 >= min_dy) ) \      && (0 <= max_dy) && (0 >= min_dy) ) \
404    { \    { \
405      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, 0, 0 , iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); \      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, 0, 0 , iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); \
406      iSAD += calc_delta_16(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_16(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode, iQuant);\
     if (iSAD <= iQuant * 96)    \  
         iSAD -= MV16_00_BIAS; \  
407      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
408      {  iMinSAD=iSAD; currMV->x=0; currMV->y=0; }  }     \      {  iMinSAD=iSAD; currMV->x=0; currMV->y=0; }  }     \
409  }  }
410    
411  #define NOCHECK_MV16_CANDIDATE(X,Y) { \  #define NOCHECK_MV16_CANDIDATE(X,Y) { \
412      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \
413      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\
414      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
415      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \
416  }  }
# Line 370  Line 420 
420      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \
421    { \    { \
422      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \
423      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\
424      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
425      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \
426  }  }
# Line 380  Line 430 
430      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \
431    { \    { \
432      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \
433      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\
434      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
435      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \
436  }  }
# Line 390  Line 440 
440      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \
441    { \    { \
442      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \
443      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\
444      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
445      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \
446  }  }
# Line 398  Line 448 
448    
449  #define CHECK_MV8_ZERO {\  #define CHECK_MV8_ZERO {\
450    iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, 0, 0 , iEdgedWidth), iEdgedWidth); \    iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, 0, 0 , iEdgedWidth), iEdgedWidth); \
451    iSAD += calc_delta_8(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode) * iQuant;\    iSAD += calc_delta_8(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode, iQuant);\
452    if (iSAD < iMinSAD) \    if (iSAD < iMinSAD) \
453    { iMinSAD=iSAD; currMV->x=0; currMV->y=0; } \    { iMinSAD=iSAD; currMV->x=0; currMV->y=0; } \
454  }  }
# Line 406  Line 456 
456  #define NOCHECK_MV8_CANDIDATE(X,Y) \  #define NOCHECK_MV8_CANDIDATE(X,Y) \
457    { \    { \
458      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \
459      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\
460      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
461      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \
462  }  }
# Line 416  Line 466 
466      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \
467    { \    { \
468      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \
469      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\
470      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
471      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \
472  }  }
# Line 426  Line 476 
476      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \
477    { \    { \
478      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \
479      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\
480      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
481      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \
482  }  }
# Line 436  Line 486 
486      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \
487    { \    { \
488      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \      iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \
489      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\      iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\
490      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
491      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \
492  }  }
# Line 451  Line 501 
501                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
502                                          const int x, const int y,                                          const int x, const int y,
503                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
504                                            const uint32_t iQuant,
505                                            const uint32_t iFcode,
506                                          MBParam * const pParam,                                          MBParam * const pParam,
507                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
508                                            const MACROBLOCK * const prevMBs,
509                                          VECTOR * const currMV,                                          VECTOR * const currMV,
510                                          VECTOR * const currPMV)                                          VECTOR * const currPMV)
511  {  {
512          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
         const int32_t iQuant = pParam->quant;  
513          const uint8_t * cur = pCur->y + x*16 + y*16*iEdgedWidth;          const uint8_t * cur = pCur->y + x*16 + y*16*iEdgedWidth;
514          int32_t iSAD;          int32_t iSAD;
515          int32_t pred_x,pred_y;          int32_t pred_x,pred_y;
# Line 779  Line 831 
831                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
832                                          const int x, const int y,                                          const int x, const int y,
833                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
834                                            const uint32_t iQuant,
835                                            const uint32_t iFcode,
836                                          const MBParam * const pParam,                                          const MBParam * const pParam,
837                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
838                                            const MACROBLOCK * const prevMBs,
839                                          VECTOR * const currMV,                                          VECTOR * const currMV,
840                                          VECTOR * const currPMV)                                          VECTOR * const currPMV)
841  {  {
842          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
         const int32_t iFcode = pParam->fixed_code;  
         const int32_t iQuant = pParam->quant;  
843          const int32_t iWidth = pParam->width;          const int32_t iWidth = pParam->width;
844          const int32_t iHeight = pParam->height;          const int32_t iHeight = pParam->height;
845          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
# Line 808  Line 861 
861          VECTOR pmv[4];          VECTOR pmv[4];
862          int32_t psad[4];          int32_t psad[4];
863    
864          MACROBLOCK * const pMB = pMBs + x + y * iWcount;          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
865            const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
866    
867          static int32_t threshA,threshB;          static int32_t threshA,threshB;
868          int32_t bPredEq;          int32_t bPredEq;
# Line 847  Line 901 
901    
902          iFound=0;          iFound=0;
903    
 /* Step 2: Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion  
    vector of the median.  
    If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2  
 */  
   
         if ((bPredEq) && (MVequal(pmv[0],pMB->mvs[0]) ) )  
                 iFound=2;  
   
 /* Step 3: If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.  
    Otherwise select large Diamond Search.  
 */  
   
         if ( (pmv[0].x != 0) || (pmv[0].y != 0) || (threshB<1536) || (bPredEq) )  
                 iDiamondSize=1; // halfpel!  
         else  
                 iDiamondSize=2; // halfpel!  
   
         if (!(MotionFlags & PMV_HALFPELDIAMOND16) )  
                 iDiamondSize*=2;  
   
904  /* Step 4: Calculate SAD around the Median prediction.  /* Step 4: Calculate SAD around the Median prediction.
905     MinSAD=SAD     MinSAD=SAD
906     If Motion Vector equal to Previous frame motion vector     If Motion Vector equal to Previous frame motion vector
# Line 874  Line 908 
908     If SAD<=256 goto Step 10.     If SAD<=256 goto Step 10.
909  */  */
910    
   
 // Prepare for main loop  
   
911          *currMV=pmv[0];         /* current best := prediction */          *currMV=pmv[0];         /* current best := prediction */
912          if (!(MotionFlags & PMV_HALFPEL16 ))          if (!(MotionFlags & PMV_HALFPEL16 ))
913          {       /* This should NOT be necessary! */          {       /* This should NOT be necessary! */
# Line 904  Line 935 
935          iMinSAD = sad16( cur,          iMinSAD = sad16( cur,
936                           get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth),                           get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth),
937                           iEdgedWidth, MV_MAX_ERROR);                           iEdgedWidth, MV_MAX_ERROR);
938          iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode) * iQuant;          iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode, iQuant);
939    
940          if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,pMB->mvs[0])) && (iMinSAD < pMB->sad16) ) )          if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) )
941          {          {
942                    if (iMinSAD < 2*iQuant) // high chances for SKIP-mode
943                    {
944                            if (!MVzero(*currMV))
945                            {
946                                    iMinSAD += MV16_00_BIAS;
947                                    CHECK_MV16_ZERO;                // (0,0) saves space for letterboxed pictures
948                                    iMinSAD -= MV16_00_BIAS;
949                            }
950                    }
951    
952                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
953                          goto PMVfast16_Terminate_without_Refine;                          goto PMVfast16_Terminate_without_Refine;
# Line 915  Line 955 
955                          goto PMVfast16_Terminate_with_Refine;                          goto PMVfast16_Terminate_with_Refine;
956          }          }
957    
958    
959    /* Step 2 (lazy eval): Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion
960       vector of the median.
961       If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
962    */
963    
964            if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[0]) ) )
965                    iFound=2;
966    
967    /* Step 3 (lazy eval): If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
968       Otherwise select large Diamond Search.
969    */
970    
971            if ( (!MVzero(pmv[0])) || (threshB<1536) || (bPredEq) )
972                    iDiamondSize=1; // halfpel!
973            else
974                    iDiamondSize=2; // halfpel!
975    
976            if (!(MotionFlags & PMV_HALFPELDIAMOND16) )
977                    iDiamondSize*=2;
978    
979  /*  /*
980     Step 5: Calculate SAD for motion vectors taken from left block, top, top-right, and Previous frame block.     Step 5: Calculate SAD for motion vectors taken from left block, top, top-right, and Previous frame block.
981     Also calculate (0,0) but do not subtract offset.     Also calculate (0,0) but do not subtract offset.
982     Let MinSAD be the smallest SAD up to this point.     Let MinSAD be the smallest SAD up to this point.
983     If MV is (0,0) subtract offset. ******** WHAT'S THIS 'OFFSET' ??? ***********     If MV is (0,0) subtract offset.
984  */  */
985    
986  // (0,0) is always possible  // (0,0) is always possible
987    
988            if (!MVzero(pmv[0]))
989          CHECK_MV16_ZERO;          CHECK_MV16_ZERO;
990    
991  // previous frame MV is always possible  // previous frame MV is always possible
992          CHECK_MV16_CANDIDATE(pMB->mvs[0].x,pMB->mvs[0].y);  
993            if (!MVzero(prevMB->mvs[0]))
994            if (!MVequal(prevMB->mvs[0],pmv[0]))
995                    CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y);
996    
997  // left neighbour, if allowed  // left neighbour, if allowed
998          if (x != 0)  
999            if (!MVzero(pmv[1]))
1000            if (!MVequal(pmv[1],prevMB->mvs[0]))
1001            if (!MVequal(pmv[1],pmv[0]))
1002          {          {
1003                  if (!(MotionFlags & PMV_HALFPEL16 ))                  if (!(MotionFlags & PMV_HALFPEL16 ))
1004                  {       pmv[1].x = EVEN(pmv[1].x);                  {       pmv[1].x = EVEN(pmv[1].x);
1005                  pmv[1].y = EVEN(pmv[1].y);                  pmv[1].y = EVEN(pmv[1].y);
1006                  }                  }
1007    
1008                  CHECK_MV16_CANDIDATE(pmv[1].x,pmv[1].y);                  CHECK_MV16_CANDIDATE(pmv[1].x,pmv[1].y);
1009          }          }
1010    
1011  // top neighbour, if allowed  // top neighbour, if allowed
1012          if (y != 0)          if (!MVzero(pmv[2]))
1013            if (!MVequal(pmv[2],prevMB->mvs[0]))
1014            if (!MVequal(pmv[2],pmv[0]))
1015            if (!MVequal(pmv[2],pmv[1]))
1016          {          {
1017                  if (!(MotionFlags & PMV_HALFPEL16 ))                  if (!(MotionFlags & PMV_HALFPEL16 ))
1018                  {       pmv[2].x = EVEN(pmv[2].x);                  {       pmv[2].x = EVEN(pmv[2].x);
# Line 949  Line 1021 
1021                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);
1022    
1023  // top right neighbour, if allowed  // top right neighbour, if allowed
1024                  if (x != (iWcount-1))                  if (!MVzero(pmv[3]))
1025                    if (!MVequal(pmv[3],prevMB->mvs[0]))
1026                    if (!MVequal(pmv[3],pmv[0]))
1027                    if (!MVequal(pmv[3],pmv[1]))
1028                    if (!MVequal(pmv[3],pmv[2]))
1029                  {                  {
1030                          if (!(MotionFlags & PMV_HALFPEL16 ))                          if (!(MotionFlags & PMV_HALFPEL16 ))
1031                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 959  Line 1035 
1035                  }                  }
1036          }          }
1037    
1038            if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) /* && (iMinSAD <= iQuant * 96)*/ )
1039                    iMinSAD -= MV16_00_BIAS;
1040    
1041    
1042  /* Step 6: If MinSAD <= thresa goto Step 10.  /* Step 6: If MinSAD <= thresa goto Step 10.
1043     If Motion Vector equal to Previous frame motion vector and MinSAD<PrevFrmSAD goto Step 10.     If Motion Vector equal to Previous frame motion vector and MinSAD<PrevFrmSAD goto Step 10.
1044  */  */
1045    
1046          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,pMB->mvs[0]) && (iMinSAD < pMB->sad16) ) )          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,prevMB->mvs[0]) && ((uint32_t)iMinSAD < prevMB->sad16) ) )
1047          {          {
1048                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1049                          goto PMVfast16_Terminate_without_Refine;                          goto PMVfast16_Terminate_without_Refine;
# Line 1149  Line 1229 
1229                                          const uint8_t * const pRefHV,                                          const uint8_t * const pRefHV,
1230                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
1231                                          const int x, const int y,                                          const int x, const int y,
1232                                          const int start_x, int start_y,                                          const int start_x, const int start_y,
1233                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
1234                                            const uint32_t iQuant,
1235                                            const uint32_t iFcode,
1236                                          const MBParam * const pParam,                                          const MBParam * const pParam,
1237                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
1238                                            const MACROBLOCK * const prevMBs,
1239                                          VECTOR * const currMV,                                          VECTOR * const currMV,
1240                                          VECTOR * const currPMV)                                          VECTOR * const currPMV)
1241  {  {
1242          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
   
         const int32_t iFcode = pParam->fixed_code;  
         const int32_t iQuant = pParam->quant;  
1243          const int32_t iWidth = pParam->width;          const int32_t iWidth = pParam->width;
1244          const int32_t iHeight = pParam->height;          const int32_t iHeight = pParam->height;
1245          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
# Line 1177  Line 1257 
1257          int32_t psad[4];          int32_t psad[4];
1258          VECTOR newMV;          VECTOR newMV;
1259          VECTOR backupMV;          VECTOR backupMV;
1260            VECTOR startMV = { start_x, start_y };
1261    
1262          MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1263            const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1264    
1265          static int32_t threshA,threshB;          static int32_t threshA,threshB;
1266          int32_t iFound,bPredEq;          int32_t iFound,bPredEq;
1267          int32_t iMinSAD,iSAD;          int32_t iMinSAD,iSAD;
1268    
1269          int32_t iSubBlock = ((y&1)<<1) + (x&1);          int32_t iSubBlock = (y&1)+(y&1) + (x&1);
1270    
1271  /* Get maximum range */  /* Get maximum range */
1272          get_range(&min_dx, &max_dx, &min_dy, &max_dy,          get_range(&min_dx, &max_dx, &min_dy, &max_dy,
1273                    x, y, 8, iWidth, iHeight, iFcode);                    x, y, 8, iWidth, iHeight, iFcode);
1274    
 /* we work with abs. MVs, not relative to prediction, so range is relative to 0,0 */  
   
1275          if (!(MotionFlags & PMV_HALFPELDIAMOND8 ))          if (!(MotionFlags & PMV_HALFPELDIAMOND8 ))
1276          { min_dx = EVEN(min_dx);          { min_dx = EVEN(min_dx);
1277          max_dx = EVEN(max_dx);          max_dx = EVEN(max_dx);
# Line 1219  Line 1299 
1299    
1300          iFound=0;          iFound=0;
1301    
 /* Step 2: Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion  
    vector of the median.  
    If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2  
 */  
   
         if ((bPredEq) && (MVequal(pmv[0],pMB->mvs[iSubBlock]) ) )  
                 iFound=2;  
   
 /* Step 3: If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.  
    Otherwise select large Diamond Search.  
 */  
   
         if ( (pmv[0].x != 0) || (pmv[0].y != 0) || (threshB<1536/4) || (bPredEq) )  
                 iDiamondSize=1; // 1 halfpel!  
         else  
                 iDiamondSize=2; // 2 halfpel = 1 full pixel!  
   
         if (!(MotionFlags & PMV_HALFPELDIAMOND8) )  
                 iDiamondSize*=2;  
   
1302  /* Step 4: Calculate SAD around the Median prediction.  /* Step 4: Calculate SAD around the Median prediction.
1303     MinSAD=SAD     MinSAD=SAD
1304     If Motion Vector equal to Previous frame motion vector     If Motion Vector equal to Previous frame motion vector
# Line 1249  Line 1309 
1309    
1310  // Prepare for main loop  // Prepare for main loop
1311    
1312          currMV->x=start_x;              /* start with mv16 */          *currMV = startMV;
         currMV->y=start_y;  
1313    
1314          iMinSAD = sad8( cur,          iMinSAD = sad8( cur,
1315                          get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),                          get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),
1316                          iEdgedWidth);                          iEdgedWidth);
1317          iMinSAD += calc_delta_8(currMV->x - pmv[0].x, currMV->y - pmv[0].y, (uint8_t)iFcode) * iQuant;          iMinSAD += calc_delta_8(currMV->x - pmv[0].x, currMV->y - pmv[0].y, (uint8_t)iFcode, iQuant);
1318    
1319          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,pMB->mvs[iSubBlock])) && (iMinSAD < pMB->sad8[iSubBlock]) ) )          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock]))
1320                                    && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1321          {          {
1322                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1323                          goto PMVfast8_Terminate_without_Refine;                          goto PMVfast8_Terminate_without_Refine;
# Line 1265  Line 1325 
1325                          goto PMVfast8_Terminate_with_Refine;                          goto PMVfast8_Terminate_with_Refine;
1326          }          }
1327    
1328    /* Step 2 (lazy eval): Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion
1329       vector of the median.
1330       If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
1331    */
1332    
1333            if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[iSubBlock]) ) )
1334                    iFound=2;
1335    
1336    /* Step 3 (lazy eval): If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
1337       Otherwise select large Diamond Search.
1338    */
1339    
1340            if ( (!MVzero(pmv[0])) || (threshB<1536/4) || (bPredEq) )
1341                    iDiamondSize=1; // 1 halfpel!
1342            else
1343                    iDiamondSize=2; // 2 halfpel = 1 full pixel!
1344    
1345            if (!(MotionFlags & PMV_HALFPELDIAMOND8) )
1346                    iDiamondSize*=2;
1347    
1348    
1349  /*  /*
1350     Step 5: Calculate SAD for motion vectors taken from left block, top, top-right, and Previous frame block.     Step 5: Calculate SAD for motion vectors taken from left block, top, top-right, and Previous frame block.
1351     Also calculate (0,0) but do not subtract offset.     Also calculate (0,0) but do not subtract offset.
1352     Let MinSAD be the smallest SAD up to this point.     Let MinSAD be the smallest SAD up to this point.
1353     If MV is (0,0) subtract offset. ******** WHAT'S THIS 'OFFSET' ??? ***********     If MV is (0,0) subtract offset.
1354  */  */
1355    
1356  // the prediction might be even better than mv16  // the median prediction might be even better than mv16
1357    
1358            if (!MVequal(pmv[0],startMV))
1359          CHECK_MV8_CANDIDATE(pmv[0].x,pmv[0].y);          CHECK_MV8_CANDIDATE(pmv[0].x,pmv[0].y);
1360    
1361  // (0,0) is always possible  // (0,0) if needed
1362            if (!MVzero(pmv[0]))
1363            if (!MVzero(startMV))
1364          CHECK_MV8_ZERO;          CHECK_MV8_ZERO;
1365    
1366  // previous frame MV is always possible  // previous frame MV if needed
1367          CHECK_MV8_CANDIDATE(pMB->mvs[iSubBlock].x,pMB->mvs[iSubBlock].y);          if (!MVzero(prevMB->mvs[iSubBlock]))
1368            if (!MVequal(prevMB->mvs[iSubBlock],startMV))
1369            if (!MVequal(prevMB->mvs[iSubBlock],pmv[0]))
1370            CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);
1371    
1372  // left neighbour, if allowed          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,prevMB->mvs[iSubBlock]) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1373          if (psad[1] != MV_MAX_ERROR)          {
1374                    if (MotionFlags & PMV_QUICKSTOP16)
1375                            goto PMVfast8_Terminate_without_Refine;
1376                    if (MotionFlags & PMV_EARLYSTOP16)
1377                            goto PMVfast8_Terminate_with_Refine;
1378            }
1379    
1380    
1381    // left neighbour, if allowed and needed
1382            if (!MVzero(pmv[1]))
1383            if (!MVequal(pmv[1],startMV))
1384            if (!MVequal(pmv[1],prevMB->mvs[iSubBlock]))
1385            if (!MVequal(pmv[1],pmv[0]))
1386          {          {
1387                  if (!(MotionFlags & PMV_HALFPEL8 ))                  if (!(MotionFlags & PMV_HALFPEL8 ))
1388                  {       pmv[1].x = EVEN(pmv[1].x);                  {       pmv[1].x = EVEN(pmv[1].x);
# Line 1292  Line 1391 
1391                  CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);                  CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);
1392          }          }
1393    
1394  // top neighbour, if allowed  // top neighbour, if allowed and needed
1395          if (psad[2] != MV_MAX_ERROR)          if (!MVzero(pmv[2]))
1396            if (!MVequal(pmv[2],startMV))
1397            if (!MVequal(pmv[2],prevMB->mvs[iSubBlock]))
1398            if (!MVequal(pmv[2],pmv[0]))
1399            if (!MVequal(pmv[2],pmv[1]))
1400          {          {
1401                  if (!(MotionFlags & PMV_HALFPEL8 ))                  if (!(MotionFlags & PMV_HALFPEL8 ))
1402                  {       pmv[2].x = EVEN(pmv[2].x);                  {       pmv[2].x = EVEN(pmv[2].x);
# Line 1301  Line 1404 
1404                  }                  }
1405                  CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);
1406    
1407  // top right neighbour, if allowed  // top right neighbour, if allowed and needed
1408                  if (psad[3] != MV_MAX_ERROR)          if (!MVzero(pmv[3]))
1409            if (!MVequal(pmv[3],startMV))
1410            if (!MVequal(pmv[3],prevMB->mvs[iSubBlock]))
1411            if (!MVequal(pmv[3],pmv[0]))
1412            if (!MVequal(pmv[3],pmv[1]))
1413            if (!MVequal(pmv[3],pmv[2]))
1414                  {                  {
1415                          if (!(MotionFlags & PMV_HALFPEL8 ))                          if (!(MotionFlags & PMV_HALFPEL8 ))
1416                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 1312  Line 1420 
1420                  }                  }
1421          }          }
1422    
1423            if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) /* && (iMinSAD <= iQuant * 96) */ )
1424                    iMinSAD -= MV8_00_BIAS;
1425    
1426    
1427  /* Step 6: If MinSAD <= thresa goto Step 10.  /* Step 6: If MinSAD <= thresa goto Step 10.
1428     If Motion Vector equal to Previous frame motion vector and MinSAD<PrevFrmSAD goto Step 10.     If Motion Vector equal to Previous frame motion vector and MinSAD<PrevFrmSAD goto Step 10.
1429  */  */
1430    
1431          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,pMB->mvs[iSubBlock]) && (iMinSAD < pMB->sad8[iSubBlock]) ) )          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,prevMB->mvs[iSubBlock]) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1432          {          {
1433                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1434                          goto PMVfast8_Terminate_without_Refine;                          goto PMVfast8_Terminate_without_Refine;
# Line 1406  Line 1518 
1518                                          const IMAGE * const pCur,                                          const IMAGE * const pCur,
1519                                          const int x, const int y,                                          const int x, const int y,
1520                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
1521                                            const uint32_t iQuant,
1522                                            const uint32_t iFcode,
1523                                          const MBParam * const pParam,                                          const MBParam * const pParam,
1524                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
1525                                            const MACROBLOCK * const prevMBs,
1526                                          VECTOR * const currMV,                                          VECTOR * const currMV,
1527                                          VECTOR * const currPMV)                                          VECTOR * const currPMV)
1528  {  {
1529          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
1530          const uint32_t iHcount = pParam->mb_height;          const uint32_t iHcount = pParam->mb_height;
         const int32_t iFcode = pParam->fixed_code;  
         const int32_t iQuant = pParam->quant;  
1531    
1532          const int32_t iWidth = pParam->width;          const int32_t iWidth = pParam->width;
1533          const int32_t iHeight = pParam->height;          const int32_t iHeight = pParam->height;
# Line 1434  Line 1547 
1547          int32_t psad[8];          int32_t psad[8];
1548    
1549          static MACROBLOCK * oldMBs = NULL;          static MACROBLOCK * oldMBs = NULL;
1550          MACROBLOCK * const pMB = pMBs + x + y * iWcount;          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
1551            const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
1552          MACROBLOCK * oldMB = NULL;          MACROBLOCK * oldMB = NULL;
1553    
1554          static int32_t thresh2;          static int32_t thresh2;
# Line 1444  Line 1558 
1558          MainSearch16FuncPtr EPZSMainSearchPtr;          MainSearch16FuncPtr EPZSMainSearchPtr;
1559    
1560          if (oldMBs == NULL)          if (oldMBs == NULL)
1561          {       oldMBs = (MACROBLOCK*) calloc(1,iWcount*iHcount*sizeof(MACROBLOCK));          {       oldMBs = (MACROBLOCK*) calloc(iWcount*iHcount,sizeof(MACROBLOCK));
1562                  fprintf(stderr,"allocated %d bytes for oldMBs\n",iWcount*iHcount*sizeof(MACROBLOCK));  //              fprintf(stderr,"allocated %d bytes for oldMBs\n",iWcount*iHcount*sizeof(MACROBLOCK));
1563          }          }
1564          oldMB = oldMBs + x + y * iWcount;          oldMB = oldMBs + x + y * iWcount;
1565    
# Line 1453  Line 1567 
1567          get_range(&min_dx, &max_dx, &min_dy, &max_dy,          get_range(&min_dx, &max_dx, &min_dy, &max_dy,
1568                          x, y, 16, iWidth, iHeight, iFcode);                          x, y, 16, iWidth, iHeight, iFcode);
1569    
 /* we work with abs. MVs, not relative to prediction, so get_range is called relative to 0,0 */  
   
1570          if (!(MotionFlags & PMV_HALFPEL16 ))          if (!(MotionFlags & PMV_HALFPEL16 ))
1571          { min_dx = EVEN(min_dx);          { min_dx = EVEN(min_dx);
1572            max_dx = EVEN(max_dx);            max_dx = EVEN(max_dx);
# Line 1494  Line 1606 
1606          iMinSAD = sad16( cur,          iMinSAD = sad16( cur,
1607                  get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth),                  get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth),
1608                  iEdgedWidth, MV_MAX_ERROR);                  iEdgedWidth, MV_MAX_ERROR);
1609          iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode) * iQuant;          iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode, iQuant);
1610    
1611  // thresh1 is fixed to 256  // thresh1 is fixed to 256
1612          if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,pMB->mvs[0])) && (iMinSAD < pMB->sad16) ) )          if ( (iMinSAD < 256 ) || ( (MVequal(*currMV, prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) )
1613                  {                  {
1614                          if (MotionFlags & PMV_QUICKSTOP16)                          if (MotionFlags & PMV_QUICKSTOP16)
1615                                  goto EPZS16_Terminate_without_Refine;                                  goto EPZS16_Terminate_without_Refine;
# Line 1508  Line 1620 
1620  /************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/  /************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/
1621    
1622  // previous frame MV  // previous frame MV
1623          CHECK_MV16_CANDIDATE(pMB->mvs[0].x,pMB->mvs[0].y);          CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y);
1624    
1625  // set threshhold based on Min of Prediction and SAD of collocated block  // set threshhold based on Min of Prediction and SAD of collocated block
1626  // CHECK_MV16 always uses iSAD for the SAD of last vector to check, so now iSAD is what we want  // CHECK_MV16 always uses iSAD for the SAD of last vector to check, so now iSAD is what we want
# Line 1549  Line 1661 
1661                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);
1662    
1663  // top right neighbour, if allowed  // top right neighbour, if allowed
1664                  if (x != (iWcount-1))                  if ((uint32_t)x != (iWcount-1))
1665                  {                  {
1666                          if (!(MotionFlags & PMV_HALFPEL16 ))                          if (!(MotionFlags & PMV_HALFPEL16 ))
1667                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 1564  Line 1676 
1676  */  */
1677    
1678          if ( (iMinSAD <= thresh2)          if ( (iMinSAD <= thresh2)
1679                  || ( MVequal(*currMV,pMB->mvs[0]) && (iMinSAD <= pMB->sad16) ) )                  || ( MVequal(*currMV,prevMB->mvs[0]) && ((uint32_t)iMinSAD <= prevMB->sad16) ) )
1680                  {                  {
1681                          if (MotionFlags & PMV_QUICKSTOP16)                          if (MotionFlags & PMV_QUICKSTOP16)
1682                                  goto EPZS16_Terminate_without_Refine;                                  goto EPZS16_Terminate_without_Refine;
# Line 1574  Line 1686 
1686    
1687  /***** predictor SET C: acceleration MV (new!), neighbours in prev. frame(new!) ****/  /***** predictor SET C: acceleration MV (new!), neighbours in prev. frame(new!) ****/
1688    
1689          backupMV = pMB->mvs[0];                 // last MV          backupMV = prevMB->mvs[0];              // collocated MV
1690          backupMV.x += (pMB->mvs[0].x - oldMB->mvs[0].x );       // acceleration X          backupMV.x += (prevMB->mvs[0].x - oldMB->mvs[0].x );    // acceleration X
1691          backupMV.y += (pMB->mvs[0].y - oldMB->mvs[0].y );       // acceleration Y          backupMV.y += (prevMB->mvs[0].y - oldMB->mvs[0].y );    // acceleration Y
1692    
1693          CHECK_MV16_CANDIDATE(backupMV.x,backupMV.y);          CHECK_MV16_CANDIDATE(backupMV.x,backupMV.y);
1694    
1695  // left neighbour  // left neighbour
1696          if (x != 0)          if (x != 0)
1697                  CHECK_MV16_CANDIDATE((oldMB-1)->mvs[0].x,oldMB->mvs[0].y);                  CHECK_MV16_CANDIDATE((prevMB-1)->mvs[0].x,(prevMB-1)->mvs[0].y);
1698    
1699  // top neighbour  // top neighbour
1700          if (y != 0)          if (y != 0)
1701                  CHECK_MV16_CANDIDATE((oldMB-iWcount)->mvs[0].x,oldMB->mvs[0].y);                  CHECK_MV16_CANDIDATE((prevMB-iWcount)->mvs[0].x,(prevMB-iWcount)->mvs[0].y);
1702    
1703  // right neighbour, if allowed (this value is not written yet, so take it from   pMB->mvs  // right neighbour, if allowed (this value is not written yet, so take it from   pMB->mvs
1704    
1705          if (x != iWcount-1)          if ((uint32_t)x != iWcount-1)
1706                  CHECK_MV16_CANDIDATE((pMB+1)->mvs[0].x,oldMB->mvs[0].y);                  CHECK_MV16_CANDIDATE((prevMB+1)->mvs[0].x,(prevMB+1)->mvs[0].y);
1707    
1708  // bottom neighbour, dito  // bottom neighbour, dito
1709          if (y != iHcount-1)          if ((uint32_t)y != iHcount-1)
1710                  CHECK_MV16_CANDIDATE((pMB+iWcount)->mvs[0].x,oldMB->mvs[0].y);                  CHECK_MV16_CANDIDATE((prevMB+iWcount)->mvs[0].x,(prevMB+iWcount)->mvs[0].y);
1711    
1712  /* Terminate if MinSAD <= T_3 (here T_3 = T_2)  */  /* Terminate if MinSAD <= T_3 (here T_3 = T_2)  */
1713          if (iMinSAD <= thresh2)          if (iMinSAD <= thresh2)
# Line 1652  Line 1764 
1764                          iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur,                          iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur,
1765                                  x, y,                                  x, y,
1766                          0, 0, iMinSAD, &newMV,                          0, 0, iMinSAD, &newMV,
1767                          pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth, /*iDiamondSize*/ 2, iFcode, iQuant, 0);                          pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth, 2, iFcode, iQuant, 0);
1768    
1769                          if (iSAD < iMinSAD)                          if (iSAD < iMinSAD)
1770                          {                          {
# Line 1673  Line 1785 
1785    
1786  EPZS16_Terminate_without_Refine:  EPZS16_Terminate_without_Refine:
1787    
1788          *oldMB = *pMB;          *oldMB = *prevMB;
1789    
1790          currPMV->x = currMV->x - pmv[0].x;          currPMV->x = currMV->x - pmv[0].x;
1791          currPMV->y = currMV->y - pmv[0].y;          currPMV->y = currMV->y - pmv[0].y;
# Line 1690  Line 1802 
1802                                          const int x, const int y,                                          const int x, const int y,
1803                                          const int start_x, const int start_y,                                          const int start_x, const int start_y,
1804                                          const uint32_t MotionFlags,                                          const uint32_t MotionFlags,
1805                                            const uint32_t iQuant,
1806                                            const uint32_t iFcode,
1807                                          const MBParam * const pParam,                                          const MBParam * const pParam,
1808                                          MACROBLOCK * const pMBs,                                          const MACROBLOCK * const pMBs,
1809                                            const MACROBLOCK * const prevMBs,
1810                                          VECTOR * const currMV,                                          VECTOR * const currMV,
1811                                          VECTOR * const currPMV)                                          VECTOR * const currPMV)
1812  {  {
1813          const uint32_t iWcount = pParam->mb_width;  /* Please not that EPZS might not be a good choice for 8x8-block motion search ! */
         const int32_t iFcode = pParam->fixed_code;  
         const int32_t iQuant = pParam->quant;  
1814    
1815            const uint32_t iWcount = pParam->mb_width;
1816          const int32_t iWidth = pParam->width;          const int32_t iWidth = pParam->width;
1817          const int32_t iHeight = pParam->height;          const int32_t iHeight = pParam->height;
1818          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
# Line 1720  Line 1834 
1834    
1835          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);
1836    
1837          MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1838            const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1839    
1840          int32_t bPredEq;          int32_t bPredEq;
1841          int32_t iMinSAD,iSAD=9999;          int32_t iMinSAD,iSAD=9999;
# Line 1774  Line 1889 
1889          iMinSAD = sad8( cur,          iMinSAD = sad8( cur,
1890                  get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),                  get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),
1891                  iEdgedWidth);                  iEdgedWidth);
1892          iMinSAD += calc_delta_8(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode) * iQuant;          iMinSAD += calc_delta_8(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode, iQuant);
1893    
1894    
1895  // thresh1 is fixed to 256  // thresh1 is fixed to 256
# Line 1788  Line 1903 
1903    
1904  /************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/  /************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/
1905    
 // previous frame MV  
         CHECK_MV8_CANDIDATE(pMB->mvs[0].x,pMB->mvs[0].y);  
1906    
1907  // MV=(0,0) is often a good choice  // MV=(0,0) is often a good choice
   
1908          CHECK_MV8_ZERO;          CHECK_MV8_ZERO;
1909    
1910    // previous frame MV
1911            CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);
1912    
1913    // left neighbour, if allowed
1914            if (psad[1] != MV_MAX_ERROR)
1915            {
1916                    if (!(MotionFlags & PMV_HALFPEL8 ))
1917                    {       pmv[1].x = EVEN(pmv[1].x);
1918                            pmv[1].y = EVEN(pmv[1].y);
1919                    }
1920                    CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);
1921            }
1922    
1923    // top neighbour, if allowed
1924            if (psad[2] != MV_MAX_ERROR)
1925            {
1926                    if (!(MotionFlags & PMV_HALFPEL8 ))
1927                    {       pmv[2].x = EVEN(pmv[2].x);
1928                            pmv[2].y = EVEN(pmv[2].y);
1929                    }
1930                    CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);
1931    
1932    // top right neighbour, if allowed
1933                    if (psad[3] != MV_MAX_ERROR)
1934                    {
1935                            if (!(MotionFlags & PMV_HALFPEL8 ))
1936                            {       pmv[3].x = EVEN(pmv[3].x);
1937                                    pmv[3].y = EVEN(pmv[3].y);
1938                            }
1939                            CHECK_MV8_CANDIDATE(pmv[3].x,pmv[3].y);
1940                    }
1941            }
1942    
1943    /*  // this bias is zero anyway, at the moment!
1944    
1945            if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) ) // && (iMinSAD <= iQuant * 96)
1946                    iMinSAD -= MV8_00_BIAS;
1947    
1948    */
1949    
1950  /* Terminate if MinSAD <= T_2  /* Terminate if MinSAD <= T_2
1951     Terminate if MV[t] == MV[t-1] and MinSAD[t] <= MinSAD[t-1]     Terminate if MV[t] == MV[t-1] and MinSAD[t] <= MinSAD[t-1]
1952  */  */
# Line 1807  Line 1959 
1959                                  goto EPZS8_Terminate_with_Refine;                                  goto EPZS8_Terminate_with_Refine;
1960                  }                  }
1961    
1962  /************ (if Diamond Search)  **************/  /************ (Diamond Search)  **************/
1963    
1964          backupMV = *currMV; /* save best prediction, actually only for EXTSEARCH */          backupMV = *currMV; /* save best prediction, actually only for EXTSEARCH */
1965    
1966          if (!(MotionFlags & PMV_HALFPELDIAMOND8))          if (!(MotionFlags & PMV_HALFPELDIAMOND8))
1967                  iDiamondSize *= 2;                  iDiamondSize *= 2;
1968    
1969  /* default: use best prediction as starting point for one call of PMVfast_MainSearch */  /* default: use best prediction as starting point for one call of EPZS_MainSearch */
1970    
1971    /* // there is no EPZS^2 for inter4v at the moment
1972    
1973            if (MotionFlags & PMV_USESQUARES8)
1974                    EPZSMainSearchPtr = Square8_MainSearch;
1975            else
1976    */
1977    
 //      if (MotionFlags & PMV_USESQUARES8)  
 //              EPZSMainSearchPtr = Square8_MainSearch;  
 //      else  
1978                  EPZSMainSearchPtr = Diamond8_MainSearch;                  EPZSMainSearchPtr = Diamond8_MainSearch;
1979    
1980          iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur,          iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur,
1981                  x, y,                  x, y,
1982                  currMV->x, currMV->y, iMinSAD, &newMV,                  currMV->x, currMV->y, iMinSAD, &newMV,
1983                  pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth,                  pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth,
1984                  iDiamondSize, iFcode, iQuant, 00);                  iDiamondSize, iFcode, iQuant, 0);
1985    
1986    
1987          if (iSAD < iMinSAD)          if (iSAD < iMinSAD)
# Line 1892  Line 2048 
2048  // TODO: need to incorporate prediction here (eg. sad += calc_delta_16)  // TODO: need to incorporate prediction here (eg. sad += calc_delta_16)
2049  ***************************************************************/  ***************************************************************/
2050    
2051  /*  
2052  void MotionEstimationBVOP(  void MotionEstimationBVOP(
2053                          MBParam * const pParam,                          MBParam * const pParam,
2054                          FRAMEINFO * const frame,                          FRAMEINFO * const frame,
# Line 1914  Line 2070 
2070      const uint32_t mb_height = pParam->mb_height;      const uint32_t mb_height = pParam->mb_height;
2071          const int32_t edged_width = pParam->edged_width;          const int32_t edged_width = pParam->edged_width;
2072    
2073          int32_t i,j;          uint32_t i,j;
2074    
2075          int32_t f_sad16;          int32_t f_sad16;
2076          int32_t b_sad16;          int32_t b_sad16;
# Line 1938  Line 2094 
2094                                  && b_mb->mvs[0].x == 0                                  && b_mb->mvs[0].x == 0
2095                                  && b_mb->mvs[0].y == 0)                                  && b_mb->mvs[0].y == 0)
2096                          {                          {
2097                                  mb->mode = MB_IGNORE;                                  mb->mode = MODE_NOT_CODED;
2098                                  mb->mvs[0].x = 0;                                  mb->mvs[0].x = 0;
2099                                  mb->mvs[0].y = 0;                                  mb->mvs[0].y = 0;
2100                                  mb->b_mvs[0].x = 0;                                  mb->b_mvs[0].x = 0;
# Line 1953  Line 2109 
2109                                                  i, j,                                                  i, j,
2110                                                  frame->motion_flags,  frame->quant, frame->fcode,                                                  frame->motion_flags,  frame->quant, frame->fcode,
2111                                                  pParam,                                                  pParam,
2112                                                  f_mbs,                                                  f_mbs, f_mbs /* todo */,
2113                                                  &mb->mvs[0], &pmv_dontcare);    // ignore pmv                                                  &mb->mvs[0], &pmv_dontcare);    // ignore pmv
2114    
2115                          // backward search                          // backward search
# Line 1962  Line 2118 
2118                                                  i, j,                                                  i, j,
2119                                                  frame->motion_flags,  frame->quant, frame->bcode,                                                  frame->motion_flags,  frame->quant, frame->bcode,
2120                                                  pParam,                                                  pParam,
2121                                                  b_mbs,                                                  b_mbs, b_mbs, /* todo */
2122                                                  &mb->b_mvs[0], &pmv_dontcare);  // ignore pmv                                                  &mb->b_mvs[0], &pmv_dontcare);  // ignore pmv
2123    
2124                          // interpolate search (simple, but effective)                          // interpolate search (simple, but effective)
# Line 1982  Line 2138 
2138                          if (f_sad16 < b_sad16)                          if (f_sad16 < b_sad16)
2139                          {                          {
2140                                  best_sad = f_sad16;                                  best_sad = f_sad16;
2141                                  mb->mode = MB_FORWARD;                                  mb->mode = MODE_FORWARD;
2142                          }                          }
2143                          else                          else
2144                          {                          {
2145                                  best_sad = b_sad16;                                  best_sad = b_sad16;
2146                                  mb->mode = MB_BACKWARD;                                  mb->mode = MODE_BACKWARD;
2147                          }                          }
2148    
2149                          if (i_sad16 < best_sad)                          if (i_sad16 < best_sad)
2150                          {                          {
2151                                  best_sad = i_sad16;                                  best_sad = i_sad16;
2152                                  mb->mode = MB_INTERPOLATE;                                  mb->mode = MODE_INTERPOLATE;
2153                          }                          }
2154    
2155                          if (d_sad16 < best_sad)                          if (d_sad16 < best_sad)
2156                          {                          {
2157                                  best_sad = d_sad16;                                  best_sad = d_sad16;
2158                                  mb->mode = MB_DIRECT;                                  mb->mode = MODE_DIRECT;
2159                          }                          }
2160    
2161                  }                  }
2162          }          }
2163  }  }
   
 */  

Legend:
Removed from v.118  
changed lines
  Added in v.169

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