[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 136, Thu Apr 25 06:55:00 2002 UTC revision 140, Thu Apr 25 21:32:05 2002 UTC
# Line 56  Line 56 
56  /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */  /* sad16(0,0) bias; mpeg4 spec suggests nb/2+1 */
57  /* nb  = vop pixels * 2^(bpp-8) */  /* nb  = vop pixels * 2^(bpp-8) */
58  #define MV16_00_BIAS    (128+1)  #define MV16_00_BIAS    (128+1)
59    #define MV8_00_BIAS     (0)
60    
61  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
62  #define INTER_BIAS      512  #define INTER_BIAS      512
# Line 279  Line 280 
280          /* eventhough we have a seperate prevMBs,          /* eventhough we have a seperate prevMBs,
281             pmvfast/epsz does something "funny" with the previous frames data */             pmvfast/epsz does something "funny" with the previous frames data */
282    
283          for (i = 0; i < iHcount; i++)  /*      for (i = 0; i < iHcount; i++)
284                  for (j = 0; j < iWcount; j++)                  for (j = 0; j < iWcount; j++)
285                  {                  {
286                          pMBs[j + i * iWcount].mvs[0] = prevMBs[j + i * iWcount].mvs[0];                          pMBs[j + i * iWcount].mvs[0] = prevMBs[j + i * iWcount].mvs[0];
# Line 287  Line 288 
288                          pMBs[j + i * iWcount].mvs[2] = prevMBs[j + i * iWcount].mvs[2];                          pMBs[j + i * iWcount].mvs[2] = prevMBs[j + i * iWcount].mvs[2];
289                          pMBs[j + i * iWcount].mvs[3] = prevMBs[j + i * iWcount].mvs[3];                          pMBs[j + i * iWcount].mvs[3] = prevMBs[j + i * iWcount].mvs[3];
290                  }                  }
291    */
292          /*dprintf("*** BEFORE ***");          /*dprintf("*** BEFORE ***");
293          for (i = 0; i < iHcount; i++)          for (i = 0; i < iHcount; i++)
294                  for (j = 0; j < iWcount; j++)                  for (j = 0; j < iWcount; j++)
# Line 431  Line 432 
432    { \    { \
433      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); \
434      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; \  
435      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
436      {  iMinSAD=iSAD; currMV->x=0; currMV->y=0; }  }     \      {  iMinSAD=iSAD; currMV->x=0; currMV->y=0; }  }     \
437  }  }
# Line 1002  Line 1001 
1001     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.
1002     Also calculate (0,0) but do not subtract offset.     Also calculate (0,0) but do not subtract offset.
1003     Let MinSAD be the smallest SAD up to this point.     Let MinSAD be the smallest SAD up to this point.
1004     If MV is (0,0) subtract offset. ******** WHAT'S THIS 'OFFSET' ??? ***********     If MV is (0,0) subtract offset.
1005  */  */
1006    
1007  // (0,0) is always possible  // (0,0) is always possible
# Line 1042  Line 1041 
1041                  }                  }
1042          }          }
1043    
1044            if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) && (iSAD <= iQuant * 96) )
1045                    iMinSAD -= MV16_00_BIAS;
1046    
1047    
1048  /* Step 6: If MinSAD <= thresa goto Step 10.  /* Step 6: If MinSAD <= thresa goto Step 10.
1049     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.
1050  */  */
# Line 1274  Line 1277 
1277          get_range(&min_dx, &max_dx, &min_dy, &max_dy,          get_range(&min_dx, &max_dx, &min_dy, &max_dy,
1278                    x, y, 8, iWidth, iHeight, iFcode);                    x, y, 8, iWidth, iHeight, iFcode);
1279    
 /* we work with abs. MVs, not relative to prediction, so range is relative to 0,0 */  
   
1280          if (!(MotionFlags & PMV_HALFPELDIAMOND8 ))          if (!(MotionFlags & PMV_HALFPELDIAMOND8 ))
1281          { min_dx = EVEN(min_dx);          { min_dx = EVEN(min_dx);
1282          max_dx = EVEN(max_dx);          max_dx = EVEN(max_dx);
# Line 1308  Line 1309 
1309     If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2     If PredEq=1 and MVpredicted = Previous Frame MV, set Found=2
1310  */  */
1311    
1312          if ((bPredEq) && (MVequal(pmv[0],pMB->mvs[iSubBlock]) ) )          if ((bPredEq) && (MVequal(pmv[0],prevMB->mvs[iSubBlock]) ) )
1313                  iFound=2;                  iFound=2;
1314    
1315  /* Step 3: If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.  /* Step 3: If Distance>0 or thresb<1536 or PredEq=1 Select small Diamond Search.
# Line 1341  Line 1342 
1342                          iEdgedWidth);                          iEdgedWidth);
1343          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;
1344    
1345          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,pMB->mvs[iSubBlock])) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )          if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock])) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1346          {          {
1347                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1348                          goto PMVfast8_Terminate_without_Refine;                          goto PMVfast8_Terminate_without_Refine;
# Line 1354  Line 1355 
1355     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.
1356     Also calculate (0,0) but do not subtract offset.     Also calculate (0,0) but do not subtract offset.
1357     Let MinSAD be the smallest SAD up to this point.     Let MinSAD be the smallest SAD up to this point.
1358     If MV is (0,0) subtract offset. ******** WHAT'S THIS 'OFFSET' ??? ***********     If MV is (0,0) subtract offset.
1359  */  */
1360    
1361  // the prediction might be even better than mv16  // the prediction might be even better than mv16
# Line 1364  Line 1365 
1365          CHECK_MV8_ZERO;          CHECK_MV8_ZERO;
1366    
1367  // previous frame MV is always possible  // previous frame MV is always possible
1368          CHECK_MV8_CANDIDATE(pMB->mvs[iSubBlock].x,pMB->mvs[iSubBlock].y);          CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y);
1369    
1370  // left neighbour, if allowed  // left neighbour, if allowed
1371          if (psad[1] != MV_MAX_ERROR)          if (psad[1] != MV_MAX_ERROR)
# Line 1396  Line 1397 
1397                  }                  }
1398          }          }
1399    
1400            if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) && (iSAD <= iQuant * 96) )
1401                    iMinSAD -= MV8_00_BIAS;
1402    
1403    
1404  /* Step 6: If MinSAD <= thresa goto Step 10.  /* Step 6: If MinSAD <= thresa goto Step 10.
1405     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.
1406  */  */
1407    
1408          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,pMB->mvs[iSubBlock]) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )          if ( (iMinSAD <= threshA) || ( MVequal(*currMV,prevMB->mvs[iSubBlock]) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) )
1409          {          {
1410                  if (MotionFlags & PMV_QUICKSTOP16)                  if (MotionFlags & PMV_QUICKSTOP16)
1411                          goto PMVfast8_Terminate_without_Refine;                          goto PMVfast8_Terminate_without_Refine;
# Line 1531  Line 1536 
1536    
1537          if (oldMBs == NULL)          if (oldMBs == NULL)
1538          {       oldMBs = (MACROBLOCK*) calloc(1,iWcount*iHcount*sizeof(MACROBLOCK));          {       oldMBs = (MACROBLOCK*) calloc(1,iWcount*iHcount*sizeof(MACROBLOCK));
1539                  fprintf(stderr,"allocated %d bytes for oldMBs\n",iWcount*iHcount*sizeof(MACROBLOCK));  //              fprintf(stderr,"allocated %d bytes for oldMBs\n",iWcount*iHcount*sizeof(MACROBLOCK));
1540          }          }
1541          oldMB = oldMBs + x + y * iWcount;          oldMB = oldMBs + x + y * iWcount;
1542    
# Line 1539  Line 1544 
1544          get_range(&min_dx, &max_dx, &min_dy, &max_dy,          get_range(&min_dx, &max_dx, &min_dy, &max_dy,
1545                          x, y, 16, iWidth, iHeight, iFcode);                          x, y, 16, iWidth, iHeight, iFcode);
1546    
 /* we work with abs. MVs, not relative to prediction, so get_range is called relative to 0,0 */  
   
1547          if (!(MotionFlags & PMV_HALFPEL16 ))          if (!(MotionFlags & PMV_HALFPEL16 ))
1548          { min_dx = EVEN(min_dx);          { min_dx = EVEN(min_dx);
1549            max_dx = EVEN(max_dx);            max_dx = EVEN(max_dx);

Legend:
Removed from v.136  
changed lines
  Added in v.140

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