[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 167, Tue May 7 20:03:18 2002 UTC revision 172, Sat May 11 15:32:59 2002 UTC
# Line 60  Line 60 
60  #define MV8_00_BIAS     (0)  #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 MV16_INTER_BIAS 512
64    
65  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
66  #define IMV16X16                        5  #define IMV16X16                        5
# Line 69  Line 69 
69  #define NEIGH_TEND_16X16        2  #define NEIGH_TEND_16X16        2
70  #define NEIGH_TEND_8X8          2  #define NEIGH_TEND_8X8          2
71    
   
72  // fast ((A)/2)*2  // fast ((A)/2)*2
73  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)
74    
75    #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )
76    #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
77    
78  int32_t PMVfastSearch16(  int32_t PMVfastSearch16(
79                                          const uint8_t * const pRef,                                          const uint8_t * const pRef,
# Line 271  Line 272 
272  {  {
273          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
274          const uint32_t iHcount = pParam->mb_height;          const uint32_t iHcount = pParam->mb_height;
275          MACROBLOCK * pMBs = current->mbs;          MACROBLOCK * const pMBs = current->mbs;
276          IMAGE * pCurrent = &current->image;          MACROBLOCK * const prevMBs = reference->mbs;    // previous frame
277    
278          MACROBLOCK * prevMBs = reference->mbs;  // previous frame          const IMAGE * const pCurrent = &current->image;
279          IMAGE * pRef = &reference->image;          const IMAGE * const pRef = &reference->image;
280    
281            const VECTOR zeroMV = {0,0};
282    
283          uint32_t i, j, iIntra = 0;          int32_t x, y;
284            int32_t iIntra = 0;
285          VECTOR mv16;          VECTOR pmv;
         VECTOR pmv16;  
   
         int32_t sad8 = 0;  
         int32_t sad16;  
         int32_t deviation;  
286    
287          if (sadInit)          if (sadInit)
288                  (*sadInit)();                  (*sadInit)();
289    
290          // note: i==horizontal, j==vertical          for (y = 0; y < iHcount; y++)
291          for (i = 0; i < iHcount; i++)                  for (x = 0; x < iWcount; x++)
                 for (j = 0; j < iWcount; j++)  
292                  {                  {
293                          MACROBLOCK *pMB = &pMBs[j + i * iWcount];                          MACROBLOCK* const pMB = &pMBs[x + y * iWcount];
                         MACROBLOCK *prevMB = &prevMBs[j + i * iWcount];  
   
                         sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,  
                                          j, i, current->motion_flags, current->quant, current->fcode,  
                                          pParam, pMBs, prevMBs, &mv16, &pmv16);  
                         pMB->sad16=sad16;  
294    
295                            pMB->sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
296                                             x, y, current->motion_flags, current->quant, current->fcode,
297                                             pParam, pMBs, prevMBs, &pMB->mv16, &pMB->pmvs[0]);
298                    }
299    
300                          /* decide: MODE_INTER or MODE_INTRA          for (y = 0; y < iHcount; y++)
301                             if (dev_intra < sad_inter - 2 * nb) use_intra                  for (x = 0; x < iWcount; x++)
302                          */                  {
303                            MACROBLOCK* const pMB = &pMBs[x + y * iWcount];
304    
305                          deviation = dev16(pCurrent->y + j*16 + i*16*pParam->edged_width, pParam->edged_width);                          if (0 < (pMB->sad16 - MV16_INTER_BIAS))
306                            {
307                                    int32_t deviation;
308                                    deviation = dev16(pCurrent->y + x*16 + y*16*pParam->edged_width,
309                                                             pParam->edged_width);
310    
311                          if (deviation < (sad16 - INTER_BIAS))                                  if (deviation < (pMB->sad16 - MV16_INTER_BIAS))
312                          {                          {
313                                  pMB->mode = MODE_INTRA;                                  pMB->mode = MODE_INTRA;
314                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = 0;                                          pMB->mv16 = pMB->mvs[0] = pMB->mvs[1]
315                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;                                                                   = pMB->mvs[2] = pMB->mvs[3] = zeroMV;
316                                            pMB->sad16 = pMB->sad8[0] = pMB->sad8[1]
317                                  pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = 0;                                                               = pMB->sad8[2] = pMB->sad8[3] = 0;
318    
319                                  iIntra++;                                  iIntra++;
320                                  if(iIntra >= iLimit)                                  if(iIntra >= iLimit)
# Line 323  Line 322 
322    
323                                  continue;                                  continue;
324                          }                          }
325                            }
326    
327                          if (current->global_flags & XVID_INTER4V)                          if ( (current->global_flags & XVID_INTER4V)
328                          {                                  && (!(current->global_flags & XVID_LUMIMASKING)
329                                  pMB->sad8[0] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                          || pMB->dquant == NO_CHANGE) )
330                                                         2 * j, 2 * i, mv16.x, mv16.y,                          {
331                                    int32_t sad8 = 129; //IMV16X16 * current->quant;
332    
333                                    if (sad8 < pMB->sad16)
334                                    sad8 += pMB->sad8[0]
335                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
336                                                           2*x, 2*y, pMB->mv16.x, pMB->mv16.y,
337                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
338                                                         pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);
339    
340                                  pMB->sad8[1] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
341                                                         2 * j + 1, 2 * i, mv16.x, mv16.y,                                  sad8 += pMB->sad8[1]
342                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
343                                   2*x+1, 2*y, pMB->mv16.x, pMB->mv16.y,
344                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
345                                                         pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);
346    
347                                  pMB->sad8[2] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
348                                                         2 * j, 2 * i + 1, mv16.x, mv16.y,                                  sad8 += pMB->sad8[2]
349                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
350                                                    2*x, 2*y+1, pMB->mv16.x, pMB->mv16.y,
351                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
352                                                         pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);
353    
354                                  pMB->sad8[3] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
355                                                         2 * j + 1, 2 * i + 1, mv16.x, mv16.y,                                  sad8 += pMB->sad8[3]
356                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
357                                                    2*x+1, 2*y+1, pMB->mv16.x, pMB->mv16.y,
358                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
359                                                         pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);
360    
                                 sad8 = pMB->sad8[0] + pMB->sad8[1] + pMB->sad8[2] + pMB->sad8[3];  
                         }  
   
   
361                          /* decide: MODE_INTER or MODE_INTER4V                          /* decide: MODE_INTER or MODE_INTER4V
362                             mpeg4:   if (sad8 < sad16 - nb/2+1) use_inter4v                             mpeg4:   if (sad8 < pMB->sad16 - nb/2+1) use_inter4v
363                          */                          */
364    
365                          if (!(current->global_flags & XVID_LUMIMASKING) || pMB->dquant == NO_CHANGE)                                  if (sad8 < pMB->sad16)
                         {  
                                 if (((current->global_flags & XVID_INTER4V)==0) ||  
                                     (sad16 < (sad8 + (int32_t)(IMV16X16 * current->quant))))  
                                 {  
   
                                         sad8 = sad16;  
                                         pMB->mode = MODE_INTER;  
                                         pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;  
                                         pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;  
                                         pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;  
                                         pMB->pmvs[0].x = pmv16.x;  
                                         pMB->pmvs[0].y = pmv16.y;  
                                 }  
                                 else  
366                                  {                                  {
367                                          pMB->mode = MODE_INTER4V;                                          pMB->mode = MODE_INTER4V;
368                                          pMB->sad8[0] *= 4;                                          pMB->sad8[0] *= 4;
369                                          pMB->sad8[1] *= 4;                                          pMB->sad8[1] *= 4;
370                                          pMB->sad8[2] *= 4;                                          pMB->sad8[2] *= 4;
371                                          pMB->sad8[3] *= 4;                                          pMB->sad8[3] *= 4;
372                                            continue;
373                                  }                                  }
374                          }                          }
375                          else  
                         {  
                                 sad8 = sad16;  
376                                  pMB->mode = MODE_INTER;                                  pMB->mode = MODE_INTER;
377                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;                          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mv16;
378                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;           pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = pMB->sad16;
379                                  pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;  
380                            if (current->global_flags & XVID_INTER4V)
381                            {       pmv = get_pmv(pMBs, x, y, pParam->mb_width, 0);
382                                    // get_pmv has to be called again. inter4v changes predictors
383    
384                                  pMB->pmvs[0].x = pmv16.x;                                  pMB->pmvs[0].x = pMB->mv16.x - pmv.x;
385                                  pMB->pmvs[0].y = pmv16.y;                                  pMB->pmvs[0].y = pMB->mv16.y - pmv.y;
386                          }                          }
387                  }                  }
   
388          return 0;          return 0;
389  }  }
390    
 #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )  
   
 #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  
   
   
391  #define CHECK_MV16_ZERO {\  #define CHECK_MV16_ZERO {\
392    if ( (0 <= max_dx) && (0 >= min_dx) \    if ( (0 <= max_dx) && (0 >= min_dx) \
393      && (0 <= max_dy) && (0 >= min_dy) ) \      && (0 <= max_dy) && (0 >= min_dy) ) \
# Line 861  Line 851 
851          VECTOR pmv[4];          VECTOR pmv[4];
852          int32_t psad[4];          int32_t psad[4];
853    
854          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;  //      const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
855          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
856    
857          static int32_t threshA,threshB;          static int32_t threshA,threshB;
# Line 901  Line 891 
891    
892          iFound=0;          iFound=0;
893    
 /* 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],prevMB->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;  
   
894  /* Step 4: Calculate SAD around the Median prediction.  /* Step 4: Calculate SAD around the Median prediction.
895     MinSAD=SAD     MinSAD=SAD
896     If Motion Vector equal to Previous frame motion vector     If Motion Vector equal to Previous frame motion vector
# Line 928  Line 898 
898     If SAD<=256 goto Step 10.     If SAD<=256 goto Step 10.
899  */  */
900    
   
 // Prepare for main loop  
   
901          *currMV=pmv[0];         /* current best := prediction */          *currMV=pmv[0];         /* current best := prediction */
902          if (!(MotionFlags & PMV_HALFPEL16 ))          if (!(MotionFlags & PMV_HALFPEL16 ))
903          {       /* This should NOT be necessary! */          {       /* This should NOT be necessary! */
# Line 962  Line 929 
929    
930          if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) )          if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) )
931          {          {
932                    if (iMinSAD < 2*iQuant) // high chances for SKIP-mode
933                    {
934                            if (!MVzero(*currMV))
935                            {
936                                    iMinSAD += MV16_00_BIAS;
937                                    CHECK_MV16_ZERO;                // (0,0) saves space for letterboxed pictures
938                                    iMinSAD -= MV16_00_BIAS;
939                            }
940                    }
941    
942                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
943                          goto PMVfast16_Terminate_without_Refine;                          goto PMVfast16_Terminate_without_Refine;
# Line 969  Line 945 
945                          goto PMVfast16_Terminate_with_Refine;                          goto PMVfast16_Terminate_with_Refine;
946          }          }
947    
948    
949    /* Step 2 (lazy eval): Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion
950       vector of the median.
951       If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
952    */
953    
954            if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[0]) ) )
955                    iFound=2;
956    
957    /* Step 3 (lazy eval): If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
958       Otherwise select large Diamond Search.
959    */
960    
961            if ( (!MVzero(pmv[0])) || (threshB<1536) || (bPredEq) )
962                    iDiamondSize=1; // halfpel!
963            else
964                    iDiamondSize=2; // halfpel!
965    
966            if (!(MotionFlags & PMV_HALFPELDIAMOND16) )
967                    iDiamondSize*=2;
968    
969  /*  /*
970     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.
971     Also calculate (0,0) but do not subtract offset.     Also calculate (0,0) but do not subtract offset.
# Line 978  Line 975 
975    
976  // (0,0) is always possible  // (0,0) is always possible
977    
978            if (!MVzero(pmv[0]))
979          CHECK_MV16_ZERO;          CHECK_MV16_ZERO;
980    
981  // previous frame MV is always possible  // previous frame MV is always possible
982    
983            if (!MVzero(prevMB->mvs[0]))
984            if (!MVequal(prevMB->mvs[0],pmv[0]))
985          CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y);          CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y);
986    
987  // left neighbour, if allowed  // left neighbour, if allowed
988          if (x != 0)  
989            if (!MVzero(pmv[1]))
990            if (!MVequal(pmv[1],prevMB->mvs[0]))
991            if (!MVequal(pmv[1],pmv[0]))
992          {          {
993                  if (!(MotionFlags & PMV_HALFPEL16 ))                  if (!(MotionFlags & PMV_HALFPEL16 ))
994                  {       pmv[1].x = EVEN(pmv[1].x);                  {       pmv[1].x = EVEN(pmv[1].x);
995                  pmv[1].y = EVEN(pmv[1].y);                  pmv[1].y = EVEN(pmv[1].y);
996                  }                  }
997    
998                  CHECK_MV16_CANDIDATE(pmv[1].x,pmv[1].y);                  CHECK_MV16_CANDIDATE(pmv[1].x,pmv[1].y);
999          }          }
1000    
1001  // top neighbour, if allowed  // top neighbour, if allowed
1002          if (y != 0)          if (!MVzero(pmv[2]))
1003            if (!MVequal(pmv[2],prevMB->mvs[0]))
1004            if (!MVequal(pmv[2],pmv[0]))
1005            if (!MVequal(pmv[2],pmv[1]))
1006          {          {
1007                  if (!(MotionFlags & PMV_HALFPEL16 ))                  if (!(MotionFlags & PMV_HALFPEL16 ))
1008                  {       pmv[2].x = EVEN(pmv[2].x);                  {       pmv[2].x = EVEN(pmv[2].x);
# Line 1003  Line 1011 
1011                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);
1012    
1013  // top right neighbour, if allowed  // top right neighbour, if allowed
1014                  if ((uint32_t)x != (iWcount-1))                  if (!MVzero(pmv[3]))
1015                    if (!MVequal(pmv[3],prevMB->mvs[0]))
1016                    if (!MVequal(pmv[3],pmv[0]))
1017                    if (!MVequal(pmv[3],pmv[1]))
1018                    if (!MVequal(pmv[3],pmv[2]))
1019                  {                  {
1020                          if (!(MotionFlags & PMV_HALFPEL16 ))                          if (!(MotionFlags & PMV_HALFPEL16 ))
1021                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 1235  Line 1247 
1247          int32_t psad[4];          int32_t psad[4];
1248          VECTOR newMV;          VECTOR newMV;
1249          VECTOR backupMV;          VECTOR backupMV;
1250            VECTOR startMV;
1251    
1252          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;  //      const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1253          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1254    
1255          static int32_t threshA,threshB;          static int32_t threshA,threshB;
1256          int32_t iFound,bPredEq;          int32_t iFound,bPredEq;
1257          int32_t iMinSAD,iSAD;          int32_t iMinSAD,iSAD;
1258    
1259          int32_t iSubBlock = ((y&1)<<1) + (x&1);          int32_t iSubBlock = (y&1)+(y&1) + (x&1);
1260    
1261            /* Init variables */
1262            startMV.x = start_x;
1263            startMV.y = start_y;
1264    
1265  /* Get maximum range */  /* Get maximum range */
1266          get_range(&min_dx, &max_dx, &min_dy, &max_dy,          get_range(&min_dx, &max_dx, &min_dy, &max_dy,
# Line 1276  Line 1293 
1293    
1294          iFound=0;          iFound=0;
1295    
 /* 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],prevMB->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;  
   
1296  /* Step 4: Calculate SAD around the Median prediction.  /* Step 4: Calculate SAD around the Median prediction.
1297     MinSAD=SAD     MinSAD=SAD
1298     If Motion Vector equal to Previous frame motion vector     If Motion Vector equal to Previous frame motion vector
# Line 1306  Line 1303 
1303    
1304  // Prepare for main loop  // Prepare for main loop
1305    
1306          currMV->x=start_x;              /* start with mv16 */          *currMV = startMV;
         currMV->y=start_y;  
1307    
1308          iMinSAD = sad8( cur,          iMinSAD = sad8( cur,
1309                          get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),                          get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),
1310                          iEdgedWidth);                          iEdgedWidth);
1311          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);
1312    
1313          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock])) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock]))
1314                                    && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1315          {          {
1316                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1317                          goto PMVfast8_Terminate_without_Refine;                          goto PMVfast8_Terminate_without_Refine;
# Line 1322  Line 1319 
1319                          goto PMVfast8_Terminate_with_Refine;                          goto PMVfast8_Terminate_with_Refine;
1320          }          }
1321    
1322    /* Step 2 (lazy eval): Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion
1323       vector of the median.
1324       If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
1325    */
1326    
1327            if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[iSubBlock]) ) )
1328                    iFound=2;
1329    
1330    /* Step 3 (lazy eval): If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
1331       Otherwise select large Diamond Search.
1332    */
1333    
1334            if ( (!MVzero(pmv[0])) || (threshB<1536/4) || (bPredEq) )
1335                    iDiamondSize=1; // 1 halfpel!
1336            else
1337                    iDiamondSize=2; // 2 halfpel = 1 full pixel!
1338    
1339            if (!(MotionFlags & PMV_HALFPELDIAMOND8) )
1340                    iDiamondSize*=2;
1341    
1342    
1343  /*  /*
1344     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.
# Line 1330  Line 1347 
1347     If MV is (0,0) subtract offset.     If MV is (0,0) subtract offset.
1348  */  */
1349    
1350  // the prediction might be even better than mv16  // the median prediction might be even better than mv16
1351    
1352            if (!MVequal(pmv[0],startMV))
1353          CHECK_MV8_CANDIDATE(pmv[0].x,pmv[0].y);          CHECK_MV8_CANDIDATE(pmv[0].x,pmv[0].y);
1354    
1355  // (0,0) is always possible  // (0,0) if needed
1356            if (!MVzero(pmv[0]))
1357            if (!MVzero(startMV))
1358          CHECK_MV8_ZERO;          CHECK_MV8_ZERO;
1359    
1360  // previous frame MV is always possible  // previous frame MV if needed
1361            if (!MVzero(prevMB->mvs[iSubBlock]))
1362            if (!MVequal(prevMB->mvs[iSubBlock],startMV))
1363            if (!MVequal(prevMB->mvs[iSubBlock],pmv[0]))
1364          CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);          CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);
1365    
1366  // left neighbour, if allowed          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,prevMB->mvs[iSubBlock]) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1367          if (psad[1] != MV_MAX_ERROR)          {
1368                    if (MotionFlags & PMV_QUICKSTOP16)
1369                            goto PMVfast8_Terminate_without_Refine;
1370                    if (MotionFlags & PMV_EARLYSTOP16)
1371                            goto PMVfast8_Terminate_with_Refine;
1372            }
1373    
1374    
1375    // left neighbour, if allowed and needed
1376            if (!MVzero(pmv[1]))
1377            if (!MVequal(pmv[1],startMV))
1378            if (!MVequal(pmv[1],prevMB->mvs[iSubBlock]))
1379            if (!MVequal(pmv[1],pmv[0]))
1380          {          {
1381                  if (!(MotionFlags & PMV_HALFPEL8 ))                  if (!(MotionFlags & PMV_HALFPEL8 ))
1382                  {       pmv[1].x = EVEN(pmv[1].x);                  {       pmv[1].x = EVEN(pmv[1].x);
# Line 1349  Line 1385 
1385                  CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);                  CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);
1386          }          }
1387    
1388  // top neighbour, if allowed  // top neighbour, if allowed and needed
1389          if (psad[2] != MV_MAX_ERROR)          if (!MVzero(pmv[2]))
1390            if (!MVequal(pmv[2],startMV))
1391            if (!MVequal(pmv[2],prevMB->mvs[iSubBlock]))
1392            if (!MVequal(pmv[2],pmv[0]))
1393            if (!MVequal(pmv[2],pmv[1]))
1394          {          {
1395                  if (!(MotionFlags & PMV_HALFPEL8 ))                  if (!(MotionFlags & PMV_HALFPEL8 ))
1396                  {       pmv[2].x = EVEN(pmv[2].x);                  {       pmv[2].x = EVEN(pmv[2].x);
# Line 1358  Line 1398 
1398                  }                  }
1399                  CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);
1400    
1401  // top right neighbour, if allowed  // top right neighbour, if allowed and needed
1402                  if (psad[3] != MV_MAX_ERROR)          if (!MVzero(pmv[3]))
1403            if (!MVequal(pmv[3],startMV))
1404            if (!MVequal(pmv[3],prevMB->mvs[iSubBlock]))
1405            if (!MVequal(pmv[3],pmv[0]))
1406            if (!MVequal(pmv[3],pmv[1]))
1407            if (!MVequal(pmv[3],pmv[2]))
1408                  {                  {
1409                          if (!(MotionFlags & PMV_HALFPEL8 ))                          if (!(MotionFlags & PMV_HALFPEL8 ))
1410                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 1496  Line 1541 
1541          int32_t psad[8];          int32_t psad[8];
1542    
1543          static MACROBLOCK * oldMBs = NULL;          static MACROBLOCK * oldMBs = NULL;
1544          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;  //      const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
1545          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
1546          MACROBLOCK * oldMB = NULL;          MACROBLOCK * oldMB = NULL;
1547    
# Line 1783  Line 1828 
1828    
1829          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);
1830    
1831          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;  //      const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1832          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1833    
1834          int32_t bPredEq;          int32_t bPredEq;

Legend:
Removed from v.167  
changed lines
  Added in v.172

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