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

Diff of /branches/dev-api-4/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 174, Sat May 11 23:54:30 2002 UTC
# Line 54  Line 54 
54  #define MV16_THRESHOLD  192  #define MV16_THRESHOLD  192
55  #define MV8_THRESHOLD   56  #define MV8_THRESHOLD   56
56    
57    #define NEIGH_MOVE_THRESH 8
58    // how much a block's MV must differ from his neighbour
59    // to be search for INTER4V. The more, the faster...
60    
61  /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */  /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */
62  /* nb  = vop pixels * 2^(bpp-8) */  /* nb  = vop pixels * 2^(bpp-8) */
63  #define MV16_00_BIAS    (128+1)  #define MV16_00_BIAS    (128+1)
64  #define MV8_00_BIAS     (0)  #define MV8_00_BIAS     (0)
65    
66  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
67  #define INTER_BIAS      512  #define MV16_INTER_BIAS 512
68    
69  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
70  #define IMV16X16                        5  #define IMV16X16                        5
# Line 69  Line 73 
73  #define NEIGH_TEND_16X16        2  #define NEIGH_TEND_16X16        2
74  #define NEIGH_TEND_8X8          2  #define NEIGH_TEND_8X8          2
75    
   
76  // fast ((A)/2)*2  // fast ((A)/2)*2
77  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)
78    
79    #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )
80    #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
81    
82  int32_t PMVfastSearch16(  int32_t PMVfastSearch16(
83                                          const uint8_t * const pRef,                                          const uint8_t * const pRef,
# Line 271  Line 276 
276  {  {
277          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
278          const uint32_t iHcount = pParam->mb_height;          const uint32_t iHcount = pParam->mb_height;
279          MACROBLOCK * pMBs = current->mbs;          MACROBLOCK * const pMBs = current->mbs;
280          IMAGE * pCurrent = &current->image;          MACROBLOCK * const prevMBs = reference->mbs;    // previous frame
   
         MACROBLOCK * prevMBs = reference->mbs;  // previous frame  
         IMAGE * pRef = &reference->image;  
281    
282            const IMAGE * const pCurrent = &current->image;
283            const IMAGE * const pRef = &reference->image;
284    
285          uint32_t i, j, iIntra = 0;          const VECTOR zeroMV = {0,0};
286    
287          VECTOR mv16;          int32_t x, y;
288          VECTOR pmv16;          int32_t iIntra = 0;
289            VECTOR pmv;
         int32_t sad8 = 0;  
         int32_t sad16;  
         int32_t deviation;  
290    
291          if (sadInit)          if (sadInit)
292                  (*sadInit)();                  (*sadInit)();
293    
294          // note: i==horizontal, j==vertical          for (y = 0; y < iHcount; y++)
295          for (i = 0; i < iHcount; i++)                  for (x = 0; x < iWcount; x++)
                 for (j = 0; j < iWcount; j++)  
296                  {                  {
297                          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;  
298    
299                            pMB->sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
300                                             x, y, current->motion_flags, current->quant, current->fcode,
301                                             pParam, pMBs, prevMBs, &pMB->mv16, &pMB->pmvs[0]);
302                    }
303    
304                          /* decide: MODE_INTER or MODE_INTRA          for (y = 0; y < iHcount; y++)
305                             if (dev_intra < sad_inter - 2 * nb) use_intra                  for (x = 0; x < iWcount; x++)
306                          */                  {
307                            MACROBLOCK* const pMB = &pMBs[x + y * iWcount];
308    
309                          deviation = dev16(pCurrent->y + j*16 + i*16*pParam->edged_width, pParam->edged_width);                          if (0 < (pMB->sad16 - MV16_INTER_BIAS))
310                            {
311                                    int32_t deviation;
312                                    deviation = dev16(pCurrent->y + x*16 + y*16*pParam->edged_width,
313                                                             pParam->edged_width);
314    
315                          if (deviation < (sad16 - INTER_BIAS))                                  if (deviation < (pMB->sad16 - MV16_INTER_BIAS))
316                          {                          {
317                                  pMB->mode = MODE_INTRA;                                  pMB->mode = MODE_INTRA;
318                                  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]
319                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;                                                                   = pMB->mvs[2] = pMB->mvs[3] = zeroMV;
320                                            pMB->sad16 = pMB->sad8[0] = pMB->sad8[1]
321                                  pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = 0;                                                               = pMB->sad8[2] = pMB->sad8[3] = 0;
322    
323                                  iIntra++;                                  iIntra++;
324                                  if(iIntra >= iLimit)                                  if(iIntra >= iLimit)
# Line 323  Line 326 
326    
327                                  continue;                                  continue;
328                          }                          }
329                            }
330    
331                          if (current->global_flags & XVID_INTER4V)                          if ( (current->global_flags & XVID_INTER4V)
332                                    && (!(current->global_flags & XVID_LUMIMASKING)
333                                            || pMB->dquant == NO_CHANGE) )
334                          {                          {
335                                  pMB->sad8[0] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  int32_t neigh=0;
336                                                         2 * j, 2 * i, mv16.x, mv16.y,  
337                                    if (x>0)
338                                    {       neigh += abs((pMB->mv16.x)-((pMB-1)->mv16.x));
339                                            neigh += abs((pMB->mv16.y)-((pMB-1)->mv16.y));
340                                    }
341                                    if (y>0)
342                                    {       neigh += abs((pMB->mv16.x)-((pMB-iWcount)->mv16.x));
343                                            neigh += abs((pMB->mv16.y)-((pMB-iWcount)->mv16.y));
344                                    }
345                                    if (x<(iWcount-1))
346                                    {       neigh += abs((pMB->mv16.x)-((pMB+1)->mv16.x));
347                                            neigh += abs((pMB->mv16.y)-((pMB+1)->mv16.y));
348                                    }
349                                    if (y<(iHcount-1))
350                                    {       neigh += abs((pMB->mv16.x)-((pMB+iHcount)->mv16.x));
351                                            neigh += abs((pMB->mv16.y)-((pMB+iHcount)->mv16.y));
352                                    }
353    
354                                    if (neigh > NEIGH_MOVE_THRESH)
355                                    {
356                                            int32_t sad8 = 129; //IMV16X16 * current->quant;
357    
358                                    if (sad8 < pMB->sad16)
359                                    sad8 += pMB->sad8[0]
360                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
361                                                           2*x, 2*y, pMB->mv16.x, pMB->mv16.y,
362                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
363                                                         pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);
364    
365                                  pMB->sad8[1] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
366                                                         2 * j + 1, 2 * i, mv16.x, mv16.y,                                  sad8 += pMB->sad8[1]
367                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
368                                   2*x+1, 2*y, pMB->mv16.x, pMB->mv16.y,
369                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
370                                                         pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);
371    
372                                  pMB->sad8[2] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
373                                                         2 * j, 2 * i + 1, mv16.x, mv16.y,                                  sad8 += pMB->sad8[2]
374                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
375                                                    2*x, 2*y+1, pMB->mv16.x, pMB->mv16.y,
376                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
377                                                         pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);
378    
379                                  pMB->sad8[3] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
380                                                         2 * j + 1, 2 * i + 1, mv16.x, mv16.y,                                  sad8 += pMB->sad8[3]
381                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
382                                                    2*x+1, 2*y+1, pMB->mv16.x, pMB->mv16.y,
383                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
384                                                         pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);
385    
                                 sad8 = pMB->sad8[0] + pMB->sad8[1] + pMB->sad8[2] + pMB->sad8[3];  
                         }  
   
   
386                          /* decide: MODE_INTER or MODE_INTER4V                          /* decide: MODE_INTER or MODE_INTER4V
387                             mpeg4:   if (sad8 < sad16 - nb/2+1) use_inter4v                             mpeg4:   if (sad8 < pMB->sad16 - nb/2+1) use_inter4v
388                          */                          */
389    
390                          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  
391                                  {                                  {
392                                          pMB->mode = MODE_INTER4V;                                          pMB->mode = MODE_INTER4V;
393                                          pMB->sad8[0] *= 4;                                          pMB->sad8[0] *= 4;
394                                          pMB->sad8[1] *= 4;                                          pMB->sad8[1] *= 4;
395                                          pMB->sad8[2] *= 4;                                          pMB->sad8[2] *= 4;
396                                          pMB->sad8[3] *= 4;                                          pMB->sad8[3] *= 4;
397                                            continue;
398                                  }                                  }
399                          }                          }
400                          else                          }
401                          {  
                                 sad8 = sad16;  
402                                  pMB->mode = MODE_INTER;                                  pMB->mode = MODE_INTER;
403                                  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;
404                                  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;
                                 pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;  
405    
406                                  pMB->pmvs[0].x = pmv16.x;                          pmv = get_pmv(pMBs, x, y, pParam->mb_width, 0);
407                                  pMB->pmvs[0].y = pmv16.y;                          // get_pmv has to be called again.
408                          }                          // intra-decision and inter4v change predictors
409    
410                                    pMB->pmvs[0].x = pMB->mv16.x - pmv.x;
411                                    pMB->pmvs[0].y = pMB->mv16.y - pmv.y;
412                  }                  }
413    
414          return 0;          return 0;
415  }  }
416    
 #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )  
   
 #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  
   
   
417  #define CHECK_MV16_ZERO {\  #define CHECK_MV16_ZERO {\
418    if ( (0 <= max_dx) && (0 >= min_dx) \    if ( (0 <= max_dx) && (0 >= min_dx) \
419      && (0 <= max_dy) && (0 >= min_dy) ) \      && (0 <= max_dy) && (0 >= min_dy) ) \
# Line 861  Line 877 
877          VECTOR pmv[4];          VECTOR pmv[4];
878          int32_t psad[4];          int32_t psad[4];
879    
880          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;  //      const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
881          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
882    
883          static int32_t threshA,threshB;          static int32_t threshA,threshB;
# Line 901  Line 917 
917    
918          iFound=0;          iFound=0;
919    
 /* 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;  
   
920  /* Step 4: Calculate SAD around the Median prediction.  /* Step 4: Calculate SAD around the Median prediction.
921     MinSAD=SAD     MinSAD=SAD
922     If Motion Vector equal to Previous frame motion vector     If Motion Vector equal to Previous frame motion vector
# Line 928  Line 924 
924     If SAD<=256 goto Step 10.     If SAD<=256 goto Step 10.
925  */  */
926    
   
 // Prepare for main loop  
   
927          *currMV=pmv[0];         /* current best := prediction */          *currMV=pmv[0];         /* current best := prediction */
928          if (!(MotionFlags & PMV_HALFPEL16 ))          if (!(MotionFlags & PMV_HALFPEL16 ))
929          {       /* This should NOT be necessary! */          {       /* This should NOT be necessary! */
# Line 962  Line 955 
955    
956          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) ) )
957          {          {
958                    if (iMinSAD < 2*iQuant) // high chances for SKIP-mode
959                    {
960                            if (!MVzero(*currMV))
961                            {
962                                    iMinSAD += MV16_00_BIAS;
963                                    CHECK_MV16_ZERO;                // (0,0) saves space for letterboxed pictures
964                                    iMinSAD -= MV16_00_BIAS;
965                            }
966                    }
967    
968                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
969                          goto PMVfast16_Terminate_without_Refine;                          goto PMVfast16_Terminate_without_Refine;
# Line 969  Line 971 
971                          goto PMVfast16_Terminate_with_Refine;                          goto PMVfast16_Terminate_with_Refine;
972          }          }
973    
974    
975    /* Step 2 (lazy eval): Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion
976       vector of the median.
977       If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
978    */
979    
980            if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[0]) ) )
981                    iFound=2;
982    
983    /* Step 3 (lazy eval): If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
984       Otherwise select large Diamond Search.
985    */
986    
987            if ( (!MVzero(pmv[0])) || (threshB<1536) || (bPredEq) )
988                    iDiamondSize=1; // halfpel!
989            else
990                    iDiamondSize=2; // halfpel!
991    
992            if (!(MotionFlags & PMV_HALFPELDIAMOND16) )
993                    iDiamondSize*=2;
994    
995  /*  /*
996     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.
997     Also calculate (0,0) but do not subtract offset.     Also calculate (0,0) but do not subtract offset.
# Line 978  Line 1001 
1001    
1002  // (0,0) is always possible  // (0,0) is always possible
1003    
1004            if (!MVzero(pmv[0]))
1005          CHECK_MV16_ZERO;          CHECK_MV16_ZERO;
1006    
1007  // previous frame MV is always possible  // previous frame MV is always possible
1008    
1009            if (!MVzero(prevMB->mvs[0]))
1010            if (!MVequal(prevMB->mvs[0],pmv[0]))
1011          CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y);          CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y);
1012    
1013  // left neighbour, if allowed  // left neighbour, if allowed
1014          if (x != 0)  
1015            if (!MVzero(pmv[1]))
1016            if (!MVequal(pmv[1],prevMB->mvs[0]))
1017            if (!MVequal(pmv[1],pmv[0]))
1018          {          {
1019                  if (!(MotionFlags & PMV_HALFPEL16 ))                  if (!(MotionFlags & PMV_HALFPEL16 ))
1020                  {       pmv[1].x = EVEN(pmv[1].x);                  {       pmv[1].x = EVEN(pmv[1].x);
1021                  pmv[1].y = EVEN(pmv[1].y);                  pmv[1].y = EVEN(pmv[1].y);
1022                  }                  }
1023    
1024                  CHECK_MV16_CANDIDATE(pmv[1].x,pmv[1].y);                  CHECK_MV16_CANDIDATE(pmv[1].x,pmv[1].y);
1025          }          }
1026    
1027  // top neighbour, if allowed  // top neighbour, if allowed
1028          if (y != 0)          if (!MVzero(pmv[2]))
1029            if (!MVequal(pmv[2],prevMB->mvs[0]))
1030            if (!MVequal(pmv[2],pmv[0]))
1031            if (!MVequal(pmv[2],pmv[1]))
1032          {          {
1033                  if (!(MotionFlags & PMV_HALFPEL16 ))                  if (!(MotionFlags & PMV_HALFPEL16 ))
1034                  {       pmv[2].x = EVEN(pmv[2].x);                  {       pmv[2].x = EVEN(pmv[2].x);
# Line 1003  Line 1037 
1037                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV16_CANDIDATE(pmv[2].x,pmv[2].y);
1038    
1039  // top right neighbour, if allowed  // top right neighbour, if allowed
1040                  if ((uint32_t)x != (iWcount-1))                  if (!MVzero(pmv[3]))
1041                    if (!MVequal(pmv[3],prevMB->mvs[0]))
1042                    if (!MVequal(pmv[3],pmv[0]))
1043                    if (!MVequal(pmv[3],pmv[1]))
1044                    if (!MVequal(pmv[3],pmv[2]))
1045                  {                  {
1046                          if (!(MotionFlags & PMV_HALFPEL16 ))                          if (!(MotionFlags & PMV_HALFPEL16 ))
1047                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 1235  Line 1273 
1273          int32_t psad[4];          int32_t psad[4];
1274          VECTOR newMV;          VECTOR newMV;
1275          VECTOR backupMV;          VECTOR backupMV;
1276            VECTOR startMV;
1277    
1278          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;  //      const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1279          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1280    
1281          static int32_t threshA,threshB;          static int32_t threshA,threshB;
1282          int32_t iFound,bPredEq;          int32_t iFound,bPredEq;
1283          int32_t iMinSAD,iSAD;          int32_t iMinSAD,iSAD;
1284    
1285          int32_t iSubBlock = ((y&1)<<1) + (x&1);          int32_t iSubBlock = (y&1)+(y&1) + (x&1);
1286    
1287            /* Init variables */
1288            startMV.x = start_x;
1289            startMV.y = start_y;
1290    
1291  /* Get maximum range */  /* Get maximum range */
1292          get_range(&min_dx, &max_dx, &min_dy, &max_dy,          get_range(&min_dx, &max_dx, &min_dy, &max_dy,
# Line 1276  Line 1319 
1319    
1320          iFound=0;          iFound=0;
1321    
 /* 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;  
   
1322  /* Step 4: Calculate SAD around the Median prediction.  /* Step 4: Calculate SAD around the Median prediction.
1323     MinSAD=SAD     MinSAD=SAD
1324     If Motion Vector equal to Previous frame motion vector     If Motion Vector equal to Previous frame motion vector
# Line 1306  Line 1329 
1329    
1330  // Prepare for main loop  // Prepare for main loop
1331    
1332          currMV->x=start_x;              /* start with mv16 */          *currMV = startMV;
         currMV->y=start_y;  
1333    
1334          iMinSAD = sad8( cur,          iMinSAD = sad8( cur,
1335                          get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),                          get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth),
1336                          iEdgedWidth);                          iEdgedWidth);
1337          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);
1338    
1339          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock])) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock]))
1340                                    && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1341          {          {
1342                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1343                          goto PMVfast8_Terminate_without_Refine;                          goto PMVfast8_Terminate_without_Refine;
# Line 1322  Line 1345 
1345                          goto PMVfast8_Terminate_with_Refine;                          goto PMVfast8_Terminate_with_Refine;
1346          }          }
1347    
1348    /* Step 2 (lazy eval): Calculate Distance= |MedianMVX| + |MedianMVY| where MedianMV is the motion
1349       vector of the median.
1350       If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
1351    */
1352    
1353            if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[iSubBlock]) ) )
1354                    iFound=2;
1355    
1356    /* Step 3 (lazy eval): If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
1357       Otherwise select large Diamond Search.
1358    */
1359    
1360            if ( (!MVzero(pmv[0])) || (threshB<1536/4) || (bPredEq) )
1361                    iDiamondSize=1; // 1 halfpel!
1362            else
1363                    iDiamondSize=2; // 2 halfpel = 1 full pixel!
1364    
1365            if (!(MotionFlags & PMV_HALFPELDIAMOND8) )
1366                    iDiamondSize*=2;
1367    
1368    
1369  /*  /*
1370     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 1373 
1373     If MV is (0,0) subtract offset.     If MV is (0,0) subtract offset.
1374  */  */
1375    
1376  // the prediction might be even better than mv16  // the median prediction might be even better than mv16
1377    
1378            if (!MVequal(pmv[0],startMV))
1379          CHECK_MV8_CANDIDATE(pmv[0].x,pmv[0].y);          CHECK_MV8_CANDIDATE(pmv[0].x,pmv[0].y);
1380    
1381  // (0,0) is always possible  // (0,0) if needed
1382            if (!MVzero(pmv[0]))
1383            if (!MVzero(startMV))
1384          CHECK_MV8_ZERO;          CHECK_MV8_ZERO;
1385    
1386  // previous frame MV is always possible  // previous frame MV if needed
1387            if (!MVzero(prevMB->mvs[iSubBlock]))
1388            if (!MVequal(prevMB->mvs[iSubBlock],startMV))
1389            if (!MVequal(prevMB->mvs[iSubBlock],pmv[0]))
1390          CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);          CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);
1391    
1392  // left neighbour, if allowed          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,prevMB->mvs[iSubBlock]) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1393          if (psad[1] != MV_MAX_ERROR)          {
1394                    if (MotionFlags & PMV_QUICKSTOP16)
1395                            goto PMVfast8_Terminate_without_Refine;
1396                    if (MotionFlags & PMV_EARLYSTOP16)
1397                            goto PMVfast8_Terminate_with_Refine;
1398            }
1399    
1400    
1401    // left neighbour, if allowed and needed
1402            if (!MVzero(pmv[1]))
1403            if (!MVequal(pmv[1],startMV))
1404            if (!MVequal(pmv[1],prevMB->mvs[iSubBlock]))
1405            if (!MVequal(pmv[1],pmv[0]))
1406          {          {
1407                  if (!(MotionFlags & PMV_HALFPEL8 ))                  if (!(MotionFlags & PMV_HALFPEL8 ))
1408                  {       pmv[1].x = EVEN(pmv[1].x);                  {       pmv[1].x = EVEN(pmv[1].x);
# Line 1349  Line 1411 
1411                  CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);                  CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y);
1412          }          }
1413    
1414  // top neighbour, if allowed  // top neighbour, if allowed and needed
1415          if (psad[2] != MV_MAX_ERROR)          if (!MVzero(pmv[2]))
1416            if (!MVequal(pmv[2],startMV))
1417            if (!MVequal(pmv[2],prevMB->mvs[iSubBlock]))
1418            if (!MVequal(pmv[2],pmv[0]))
1419            if (!MVequal(pmv[2],pmv[1]))
1420          {          {
1421                  if (!(MotionFlags & PMV_HALFPEL8 ))                  if (!(MotionFlags & PMV_HALFPEL8 ))
1422                  {       pmv[2].x = EVEN(pmv[2].x);                  {       pmv[2].x = EVEN(pmv[2].x);
# Line 1358  Line 1424 
1424                  }                  }
1425                  CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);                  CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y);
1426    
1427  // top right neighbour, if allowed  // top right neighbour, if allowed and needed
1428                  if (psad[3] != MV_MAX_ERROR)          if (!MVzero(pmv[3]))
1429            if (!MVequal(pmv[3],startMV))
1430            if (!MVequal(pmv[3],prevMB->mvs[iSubBlock]))
1431            if (!MVequal(pmv[3],pmv[0]))
1432            if (!MVequal(pmv[3],pmv[1]))
1433            if (!MVequal(pmv[3],pmv[2]))
1434                  {                  {
1435                          if (!(MotionFlags & PMV_HALFPEL8 ))                          if (!(MotionFlags & PMV_HALFPEL8 ))
1436                          {       pmv[3].x = EVEN(pmv[3].x);                          {       pmv[3].x = EVEN(pmv[3].x);
# Line 1496  Line 1567 
1567          int32_t psad[8];          int32_t psad[8];
1568    
1569          static MACROBLOCK * oldMBs = NULL;          static MACROBLOCK * oldMBs = NULL;
1570          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;  //      const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
1571          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
1572          MACROBLOCK * oldMB = NULL;          MACROBLOCK * oldMB = NULL;
1573    
# Line 1783  Line 1854 
1854    
1855          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);
1856    
1857          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;  //      const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1858          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1859    
1860          int32_t bPredEq;          int32_t bPredEq;

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

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