[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

trunk/xvidcore/src/motion/motion_est.c revision 872, Wed Feb 19 20:12:43 2003 UTC branches/dev-api-4/xvidcore/src/motion/motion_est.c revision 949, Wed Mar 26 14:56:49 2003 UTC
# Line 995  Line 995 
995          uint32_t mb_width = pParam->mb_width;          uint32_t mb_width = pParam->mb_width;
996          uint32_t mb_height = pParam->mb_height;          uint32_t mb_height = pParam->mb_height;
997          const uint32_t iEdgedWidth = pParam->edged_width;          const uint32_t iEdgedWidth = pParam->edged_width;
998          const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->global_flags);          const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags);
999    
1000          uint32_t x, y;          uint32_t x, y;
1001          uint32_t iIntra = 0;          uint32_t iIntra = 0;
1002          int32_t quant = current->quant, sad00;      int32_t sad00;
1003    
1004          // some pre-initialized thingies for SearchP          // some pre-initialized thingies for SearchP
1005          int32_t temp[8];          int32_t temp[8];
# Line 1015  Line 1015 
1015          Data.temp = temp;          Data.temp = temp;
1016          Data.iFcode = current->fcode;          Data.iFcode = current->fcode;
1017          Data.rounding = pParam->m_rounding_type;          Data.rounding = pParam->m_rounding_type;
1018          Data.qpel = pParam->m_quarterpel;          Data.qpel = current->vol_flags & XVID_VOL_QUARTERPEL;
1019          Data.chroma = MotionFlags & PMV_CHROMA16;          Data.chroma = MotionFlags & XVID_ME_CHROMA16;
1020          Data.rrv = current->global_flags & XVID_REDUCED;          Data.rrv = current->vop_flags & XVID_VOP_REDUCED;
1021    
1022          if ((current->global_flags & XVID_REDUCED)) {          if ((current->vop_flags & XVID_VOP_REDUCED)) {
1023                  mb_width = (pParam->width + 31) / 32;                  mb_width = (pParam->width + 31) / 32;
1024                  mb_height = (pParam->height + 31) / 32;                  mb_height = (pParam->height + 31) / 32;
1025                  Data.qpel = 0;                  Data.qpel = 0;
# Line 1052  Line 1052 
1052    
1053                          sad00 = pMB->sad16;                          sad00 = pMB->sad16;
1054    
                         if (!(current->global_flags & XVID_LUMIMASKING)) {  
                                 pMB->dquant = NO_CHANGE;  
                         } else {  
                                 if (pMB->dquant != NO_CHANGE) {  
                                         quant += DQtab[pMB->dquant];  
                                         if (quant > 31) quant = 31;  
                                         else if (quant < 1) quant = 1;  
                                 }  
                         }  
                         pMB->quant = current->quant;  
   
1055  //initial skip decision  //initial skip decision
1056  /* no early skip for GMC (global vector = skip vector is unknown!)  */  /* no early skip for GMC (global vector = skip vector is unknown!)  */
1057                          if (!(current->global_flags & XVID_GMC))        { /* no fast SKIP for S(GMC)-VOPs */                          if (!(current->vol_flags & XVID_VOL_GMC))       { /* no fast SKIP for S(GMC)-VOPs */
1058                                  if (pMB->dquant == NO_CHANGE && sad00 < pMB->quant * INITIAL_SKIP_THRESH * (Data.rrv ? 4:1) )                                  if (pMB->dquant == 0 && sad00 < pMB->quant * INITIAL_SKIP_THRESH * (Data.rrv ? 4:1) )
1059                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) {                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) {
1060                                                  SkipMacroblockP(pMB, sad00);                                                  SkipMacroblockP(pMB, sad00);
1061                                                  continue;                                                  continue;
# Line 1074  Line 1063 
1063                          }                          }
1064    
1065                          SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,                          SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,
1066                                                  y, MotionFlags, current->global_flags, pMB->quant,                                                  y, MotionFlags, current->vol_flags, pMB->quant,
1067                                                  &Data, pParam, pMBs, reference->mbs,                                                  &Data, pParam, pMBs, reference->mbs,
1068                                                  current->global_flags & XVID_INTER4V, pMB);                                                  current->vop_flags & XVID_VOP_INTER4V, pMB);
1069    
1070  /* final skip decision, a.k.a. "the vector you found, really that good?" */  /* final skip decision, a.k.a. "the vector you found, really that good?" */
1071                          if (!(current->global_flags & XVID_GMC))        {                          if (!(current->vol_flags & XVID_VOL_GMC))       {
1072                                  if ( pMB->dquant == NO_CHANGE && sad00 < pMB->quant * MAX_SAD00_FOR_SKIP) {                                  if ( pMB->dquant == 0 && sad00 < pMB->quant * MAX_SAD00_FOR_SKIP) {
1073                                          if (!(current->global_flags & XVID_MODEDECISION_BITS)) {                                          if (!(current->vop_flags & XVID_VOP_MODEDECISION_BITS)) {
1074                                                  if ( (100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1) )                                                  if ( (100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1) )
1075                                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv))                                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv))
1076                                                                  SkipMacroblockP(pMB, sad00);                                                                  SkipMacroblockP(pMB, sad00);
# Line 1097  Line 1086 
1086                  }                  }
1087          }          }
1088    
1089          if (current->global_flags & XVID_GMC )  /* GMC only for S(GMC)-VOPs */          if (current->vol_flags & XVID_VOL_GMC ) /* GMC only for S(GMC)-VOPs */
1090          {          {
1091                  current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV);                  current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV);
1092          }          }
# Line 1172  Line 1161 
1161                  const int x, const int y,                  const int x, const int y,
1162                  const MBParam * const pParam,                  const MBParam * const pParam,
1163                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
1164                  const uint32_t GlobalFlags)                  const uint32_t VopFlags)
1165  {  {
1166    
1167          int mode = MODE_INTER;          int mode = MODE_INTER;
1168    
1169          if (!(GlobalFlags & XVID_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision          if (!(VopFlags & XVID_VOP_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision
1170  //              int intra = 0;  //              int intra = 0;
1171                  int sad;                  int sad;
1172                  int InterBias = MV16_INTER_BIAS;                  int InterBias = MV16_INTER_BIAS;
# Line 1220  Line 1209 
1209                  int bits, intra, i;                  int bits, intra, i;
1210                  VECTOR backup[5], *v;                  VECTOR backup[5], *v;
1211                  Data->lambda16 = iQuant;                  Data->lambda16 = iQuant;
1212                  Data->lambda8 = pParam->m_quant_type;          Data->lambda8 = (pParam->vol_flags & XVID_VOL_MPEGQUANT)?1:0;
1213    
1214                  v = Data->qpel ? Data->currentQMV : Data->currentMV;                  v = Data->qpel ? Data->currentQMV : Data->currentMV;
1215                  for (i = 0; i < 5; i++) {                  for (i = 0; i < 5; i++) {
# Line 1254  Line 1243 
1243                  const int x,                  const int x,
1244                  const int y,                  const int y,
1245                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
1246                  const uint32_t GlobalFlags,                  const uint32_t VopFlags,
1247                  const uint32_t iQuant,                  const uint32_t iQuant,
1248                  SearchData * const Data,                  SearchData * const Data,
1249                  const MBParam * const pParam,                  const MBParam * const pParam,
# Line 1289  Line 1278 
1278          Data->lambda8 = lambda_vec8[iQuant];          Data->lambda8 = lambda_vec8[iQuant];
1279          Data->qpel_precision = 0;          Data->qpel_precision = 0;
1280    
1281          if (pMB->dquant != NO_CHANGE) inter4v = 0;          if (pMB->dquant != 0) inter4v = 0;
1282    
1283          for(i = 0; i < 5; i++)          for(i = 0; i < 5; i++)
1284                  Data->currentMV[i].x = Data->currentMV[i].y = 0;                  Data->currentMV[i].x = Data->currentMV[i].y = 0;
# Line 1304  Line 1293 
1293          Data->iMinSAD[3] = pMB->sad8[2];          Data->iMinSAD[3] = pMB->sad8[2];
1294          Data->iMinSAD[4] = pMB->sad8[3];          Data->iMinSAD[4] = pMB->sad8[3];
1295    
1296          if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) || (x | y)) {          if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) || (x | y)) {
1297                  threshA = Data->temp[0]; // that's where we keep this SAD atm                  threshA = Data->temp[0]; // that's where we keep this SAD atm
1298                  if (threshA < 512) threshA = 512;                  if (threshA < 512) threshA = 512;
1299                  else if (threshA > 1024) threshA = 1024;                  else if (threshA > 1024) threshA = 1024;
# Line 1330  Line 1319 
1319          if ((Data->iMinSAD[0] <= threshA) ||          if ((Data->iMinSAD[0] <= threshA) ||
1320                          (MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) &&                          (MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) &&
1321                          (Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16))) {                          (Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16))) {
1322                  if (!(GlobalFlags & XVID_MODEDECISION_BITS)) inter4v = 0;       }                  if (!(VopFlags & XVID_VOP_MODEDECISION_BITS)) inter4v = 0;      }
1323          else {          else {
1324    
1325                  MainSearchFunc * MainSearchPtr;                  MainSearchFunc * MainSearchPtr;
1326                  if (MotionFlags & PMV_USESQUARES16) MainSearchPtr = SquareSearch;                  if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = SquareSearch;
1327                  else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;
1328                          else MainSearchPtr = DiamondSearch;                          else MainSearchPtr = DiamondSearch;
1329    
1330                  MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection);                  MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection);
# Line 1344  Line 1333 
1333          note that this search is/might be done in halfpel positions,          note that this search is/might be done in halfpel positions,
1334          which makes it more different than the diamond above */          which makes it more different than the diamond above */
1335    
1336                  if (MotionFlags & PMV_EXTSEARCH16) {                  if (MotionFlags & XVID_ME_EXTSEARCH16) {
1337                          int32_t bSAD;                          int32_t bSAD;
1338                          VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0];                          VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0];
1339                          if (Data->rrv) {                          if (Data->rrv) {
# Line 1375  Line 1364 
1364                  }                  }
1365          }          }
1366    
1367          if (MotionFlags & PMV_HALFPELREFINE16)          if (MotionFlags & XVID_ME_HALFPELREFINE16)
1368                  if ((!(MotionFlags & HALFPELREFINE16_BITS)) || Data->iMinSAD[0] < 200*(int)iQuant)                  if ((!(MotionFlags & XVID_ME_HALFPELREFINE16_BITS)) || Data->iMinSAD[0] < 200*(int)iQuant)
1369                          SubpelRefine(Data);                          SubpelRefine(Data);
1370    
1371          for(i = 0; i < 5; i++) {          for(i = 0; i < 5; i++) {
# Line 1384  Line 1373 
1373                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
1374          }          }
1375    
1376          if (MotionFlags & PMV_QUARTERPELREFINE16)          if (MotionFlags & XVID_ME_QUARTERPELREFINE16)
1377                  if ((!(MotionFlags & QUARTERPELREFINE16_BITS)) || (Data->iMinSAD[0] < 200*(int)iQuant)) {                  if ((!(MotionFlags & XVID_ME_QUARTERPELREFINE16_BITS)) || (Data->iMinSAD[0] < 200*(int)iQuant)) {
1378                          Data->qpel_precision = 1;                          Data->qpel_precision = 1;
1379                          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,                          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
1380                                          pParam->width, pParam->height, Data->iFcode, 1, 0);                                          pParam->width, pParam->height, Data->iFcode, 1, 0);
# Line 1393  Line 1382 
1382                          SubpelRefine(Data);                          SubpelRefine(Data);
1383                  }                  }
1384    
1385          if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0;          if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0;
1386    
1387          if (inter4v && (!(GlobalFlags & XVID_MODEDECISION_BITS) ||          if (inter4v && (!(VopFlags & XVID_VOP_MODEDECISION_BITS) ||
1388                          (!(MotionFlags & QUARTERPELREFINE8_BITS)) || (!(MotionFlags & HALFPELREFINE8_BITS)) ||                          (!(MotionFlags & XVID_ME_QUARTERPELREFINE8_BITS)) || (!(MotionFlags & XVID_ME_HALFPELREFINE8_BITS)) ||
1389                          ((!(MotionFlags & EXTSEARCH_BITS)) && (!(MotionFlags&PMV_EXTSEARCH8)) ))) {                          ((!(MotionFlags & XVID_ME_EXTSEARCH_BITS)) && (!(MotionFlags&XVID_ME_EXTSEARCH8)) ))) {
1390                  // if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop                  // if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop
1391    
1392                  SearchData Data8;                  SearchData Data8;
# Line 1408  Line 1397 
1397                  Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8);                  Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8);
1398                  Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8);                  Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8);
1399    
1400                  if ((Data->chroma) && (!(GlobalFlags & XVID_MODEDECISION_BITS))) {                  if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_BITS))) {
1401                          // chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, there is no reason to compute it                          // chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, there is no reason to compute it
1402                          int sumx = 0, sumy = 0;                          int sumx = 0, sumy = 0;
1403                          const int div = 1 + Data->qpel;                          const int div = 1 + Data->qpel;
# Line 1424  Line 1413 
1413                  }                  }
1414          }          }
1415    
1416          inter4v = ModeDecision(iQuant, Data, inter4v, pMB, pMBs, x, y, pParam, MotionFlags, GlobalFlags);          inter4v = ModeDecision(iQuant, Data, inter4v, pMB, pMBs, x, y, pParam, MotionFlags, VopFlags);
1417    
1418          if (Data->rrv) {          if (Data->rrv) {
1419                          Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);                          Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
# Line 1483  Line 1472 
1472    
1473          *(Data->iMinSAD) += (Data->lambda8 * i * (*Data->iMinSAD + NEIGH_8X8_BIAS))>>10;          *(Data->iMinSAD) += (Data->lambda8 * i * (*Data->iMinSAD + NEIGH_8X8_BIAS))>>10;
1474    
1475          if (MotionFlags & (PMV_EXTSEARCH8|PMV_HALFPELREFINE8|PMV_QUARTERPELREFINE8)) {          if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) {
1476                  if (Data->rrv) i = 2; else i = 1;                  if (Data->rrv) i = 2; else i = 1;
1477    
1478                  Data->Ref = OldData->Ref + i * 8 * ((block&1) + Data->iEdgedWidth*(block>>1));                  Data->Ref = OldData->Ref + i * 8 * ((block&1) + Data->iEdgedWidth*(block>>1));
# Line 1500  Line 1489 
1489                  if (!Data->rrv) CheckCandidate = CheckCandidate8;                  if (!Data->rrv) CheckCandidate = CheckCandidate8;
1490                  else CheckCandidate = CheckCandidate16no4v;                  else CheckCandidate = CheckCandidate16no4v;
1491    
1492                  if (MotionFlags & PMV_EXTSEARCH8 && (!(MotionFlags & EXTSEARCH_BITS))) {                  if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_BITS))) {
1493                          int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD                          int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD
1494    
1495                          MainSearchFunc *MainSearchPtr;                          MainSearchFunc *MainSearchPtr;
1496                          if (MotionFlags & PMV_USESQUARES8) MainSearchPtr = SquareSearch;                          if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = SquareSearch;
1497                                  else if (MotionFlags & PMV_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch;                                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch;
1498                                          else MainSearchPtr = DiamondSearch;                                          else MainSearchPtr = DiamondSearch;
1499    
1500                          MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255);                          MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255);
# Line 1516  Line 1505 
1505                          }                          }
1506                  }                  }
1507    
1508                  if (MotionFlags & PMV_HALFPELREFINE8) {                  if (MotionFlags & XVID_ME_HALFPELREFINE8) {
1509                          int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD                          int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD
1510    
1511                          SubpelRefine(Data); // perform halfpel refine of current best vector                          SubpelRefine(Data); // perform halfpel refine of current best vector
# Line 1527  Line 1516 
1516                          }                          }
1517                  }                  }
1518    
1519                  if (Data->qpel && MotionFlags & PMV_QUARTERPELREFINE8) {                  if (Data->qpel && MotionFlags & XVID_ME_QUARTERPELREFINE8) {
1520                                  Data->qpel_precision = 1;                                  Data->qpel_precision = 1;
1521                                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,                                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,
1522                                          pParam->width, pParam->height, Data->iFcode, 1, 0);                                          pParam->width, pParam->height, Data->iFcode, 1, 0);
# Line 1651  Line 1640 
1640                  CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data);                  CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data);
1641          }          }
1642    
1643          if (MotionFlags & PMV_USESQUARES16) MainSearchPtr = SquareSearch;          if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = SquareSearch;
1644          else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;          else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;
1645                  else MainSearchPtr = DiamondSearch;                  else MainSearchPtr = DiamondSearch;
1646    
1647          MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection);          MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, iDirection);
# Line 1828  Line 1817 
1817  //      DIRECT MODE DELTA VECTOR SEARCH.  //      DIRECT MODE DELTA VECTOR SEARCH.
1818  //      This has to be made more effective, but at the moment I'm happy it's running at all  //      This has to be made more effective, but at the moment I'm happy it's running at all
1819    
1820          if (MotionFlags & PMV_USESQUARES16) MainSearchPtr = SquareSearch;          if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = SquareSearch;
1821                  else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;
1822                          else MainSearchPtr = DiamondSearch;                          else MainSearchPtr = DiamondSearch;
1823    
1824          MainSearchPtr(0, 0, Data, 255);          MainSearchPtr(0, 0, Data, 255);
# Line 2038  Line 2027 
2027          Data.currentMV = currentMV; Data.currentQMV = currentQMV;          Data.currentMV = currentMV; Data.currentQMV = currentQMV;
2028          Data.iMinSAD = &iMinSAD;          Data.iMinSAD = &iMinSAD;
2029          Data.lambda16 = lambda_vec16[frame->quant];          Data.lambda16 = lambda_vec16[frame->quant];
2030          Data.qpel = pParam->m_quarterpel;          Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL;
2031          Data.rounding = 0;          Data.rounding = 0;
2032          Data.chroma = frame->motion_flags & PMV_CHROMA8;          Data.chroma = frame->motion_flags & XVID_ME_CHROMA8;
2033          Data.temp = temp;          Data.temp = temp;
2034    
2035          Data.RefQ = f_refV->u; // a good place, also used in MC (for similar purpose)          Data.RefQ = f_refV->u; // a good place, also used in MC (for similar purpose)
# Line 2063  Line 2052 
2052                          Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16;                          Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16;
2053                          Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8;                          Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8;
2054                          Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8;                          Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8;
                         pMB->quant = frame->quant;  
2055    
2056  /* direct search comes first, because it (1) checks for SKIP-mode  /* direct search comes first, because it (1) checks for SKIP-mode
2057          and (2) sets very good predictions for forward and backward search */          and (2) sets very good predictions for forward and backward search */
# Line 2163  Line 2151 
2151                          else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median                          else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median
2152    
2153          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
2154                                  pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, Data->rrv);          pParam->width, pParam->height, Data->iFcode - (pParam->vol_flags&XVID_VOL_QUARTERPEL?1:0), 0, Data->rrv);
2155    
2156          Data->Cur = pCur + (x + y * pParam->edged_width) * 16;          Data->Cur = pCur + (x + y * pParam->edged_width) * 16;
2157          Data->Ref = pRef + (x + y * pParam->edged_width) * 16;          Data->Ref = pRef + (x + y * pParam->edged_width) * 16;
# Line 2220  Line 2208 
2208          Data.currentMV = currentMV;          Data.currentMV = currentMV;
2209          Data.iMinSAD = iMinSAD;          Data.iMinSAD = iMinSAD;
2210          Data.iFcode = Current->fcode;          Data.iFcode = Current->fcode;
2211          Data.rrv = Current->global_flags & XVID_REDUCED;          Data.rrv = Current->vop_flags & XVID_VOP_REDUCED;
2212          Data.temp = temp;          Data.temp = temp;
2213          CheckCandidate = CheckCandidate32I;          CheckCandidate = CheckCandidate32I;
2214    
# Line 2303  Line 2291 
2291    
2292  // filter mask of all blocks  // filter mask of all blocks
2293    
2294          for (my = 1; my < MBh-1; my++)          for (my = 1; my < (uint32_t)MBh-1; my++)
2295          for (mx = 1; mx < MBw-1; mx++)          for (mx = 1; mx < (uint32_t)MBw-1; mx++)
2296          {          {
2297                  const int mbnum = mx + my * MBw;                  const int mbnum = mx + my * MBw;
2298                  const MACROBLOCK *pMB = &pMBs[mbnum];                  const MACROBLOCK *pMB = &pMBs[mbnum];
# Line 2320  Line 2308 
2308                          MBmask[mbnum]=1;                          MBmask[mbnum]=1;
2309          }          }
2310    
2311          for (my = 1; my < MBh-1; my++)          for (my = 1; my < (uint32_t)MBh-1; my++)
2312          for (mx = 1; mx < MBw-1; mx++)          for (mx = 1; mx < (uint32_t)MBw-1; mx++)
2313          {          {
2314                  const uint8_t *const pCur = current->image.y + 16*my*pParam->edged_width + 16*mx;                  const uint8_t *const pCur = current->image.y + 16*my*pParam->edged_width + 16*mx;
2315    
# Line 2329  Line 2317 
2317                  if (!MBmask[mbnum])                  if (!MBmask[mbnum])
2318                          continue;                          continue;
2319    
2320                  if (sad16 ( pCur, pCur+1 , pParam->edged_width, 65536) <= grad )                  if (sad16 ( pCur, pCur+1 , pParam->edged_width, 65536) <= (uint32_t)grad )
2321                          MBmask[mbnum] = 0;                          MBmask[mbnum] = 0;
2322                  if (sad16 ( pCur, pCur+pParam->edged_width, pParam->edged_width, 65536) <= grad )                  if (sad16 ( pCur, pCur+pParam->edged_width, pParam->edged_width, 65536) <= (uint32_t)grad )
2323                          MBmask[mbnum] = 0;                          MBmask[mbnum] = 0;
2324    
2325          }          }
# Line 2342  Line 2330 
2330    
2331          a = b = c = n = 0;          a = b = c = n = 0;
2332          DtimesF[0] = DtimesF[1] = DtimesF[2] = DtimesF[3] = 0.;          DtimesF[0] = DtimesF[1] = DtimesF[2] = DtimesF[3] = 0.;
2333          for (my = 0; my < MBh; my++)          for (my = 0; my < (uint32_t)MBh; my++)
2334                  for (mx = 0; mx < MBw; mx++)                  for (mx = 0; mx < (uint32_t)MBw; mx++)
2335                  {                  {
2336                          const int mbnum = mx + my * MBw;                          const int mbnum = mx + my * MBw;
2337                          const MACROBLOCK *pMB = &pMBs[mbnum];                          const MACROBLOCK *pMB = &pMBs[mbnum];
# Line 2380  Line 2368 
2368    
2369          meanx = meany = 0.;          meanx = meany = 0.;
2370          oldnum = 0;          oldnum = 0;
2371          for (my = 0; my < MBh; my++)          for (my = 0; my < (uint32_t)MBh; my++)
2372                  for (mx = 0; mx < MBw; mx++)                  for (mx = 0; mx < (uint32_t)MBw; mx++)
2373                  {                  {
2374                          const int mbnum = mx + my * MBw;                          const int mbnum = mx + my * MBw;
2375                          const MACROBLOCK *pMB = &pMBs[mbnum];                          const MACROBLOCK *pMB = &pMBs[mbnum];
# Line 2409  Line 2397 
2397          fprintf(stderr,"meanx = %8.5f  meany = %8.5f   %d\n",meanx,meany, oldnum);          fprintf(stderr,"meanx = %8.5f  meany = %8.5f   %d\n",meanx,meany, oldnum);
2398  */  */
2399          num = 0;          num = 0;
2400          for (my = 0; my < MBh; my++)          for (my = 0; my < (uint32_t)MBh; my++)
2401                  for (mx = 0; mx < MBw; mx++)                  for (mx = 0; mx < (uint32_t)MBw; mx++)
2402                  {                  {
2403                          const int mbnum = mx + my * MBw;                          const int mbnum = mx + my * MBw;
2404                          const MACROBLOCK *pMB = &pMBs[mbnum];                          const MACROBLOCK *pMB = &pMBs[mbnum];
# Line 2474  Line 2462 
2462                  if (Data->temp[0] == 0 && Data->temp[1] == 0 && Data->temp[2] == 0 && Data->temp[3] == 0)                  if (Data->temp[0] == 0 && Data->temp[1] == 0 && Data->temp[2] == 0 && Data->temp[3] == 0)
2463                          return 0; //quick stop                          return 0; //quick stop
2464    
2465                  if (MotionFlags & (HALFPELREFINE16_BITS | EXTSEARCH_BITS)) { //we have to prepare for halfpixel-precision search                  if (MotionFlags & (XVID_ME_HALFPELREFINE16_BITS | XVID_ME_EXTSEARCH_BITS)) { //we have to prepare for halfpixel-precision search
2466                          for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i];                          for(i = 0; i < 5; i++) bsad[i] = Data->iMinSAD[i];
2467                          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,                          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
2468                                                  pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv);                                                  pParam->width, pParam->height, Data->iFcode - Data->qpel, 0, Data->rrv);
# Line 2492  Line 2480 
2480                  }                  }
2481          }          }
2482    
2483          if (MotionFlags&EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection);          if (MotionFlags&XVID_ME_EXTSEARCH_BITS) SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, iDirection);
2484    
2485          if (MotionFlags&HALFPELREFINE16_BITS) SubpelRefine(Data);          if (MotionFlags&XVID_ME_HALFPELREFINE16_BITS) SubpelRefine(Data);
2486    
2487          if (Data->qpel) {          if (Data->qpel) {
2488                  if (MotionFlags&(EXTSEARCH_BITS | HALFPELREFINE16_BITS)) { // there was halfpel-precision search                  if (MotionFlags&(XVID_ME_EXTSEARCH_BITS | XVID_ME_HALFPELREFINE16_BITS)) { // there was halfpel-precision search
2489                          for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) {                          for(i = 0; i < 5; i++) if (bsad[i] > Data->iMinSAD[i]) {
2490                                  Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // we have found a better match                                  Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // we have found a better match
2491                                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;                                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
# Line 2508  Line 2496 
2496                          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,                          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
2497                                          pParam->width, pParam->height, Data->iFcode, 1, 0);                                          pParam->width, pParam->height, Data->iFcode, 1, 0);
2498                  }                  }
2499                  if (MotionFlags&QUARTERPELREFINE16_BITS) SubpelRefine(Data);                  if (MotionFlags&XVID_ME_QUARTERPELREFINE16_BITS) SubpelRefine(Data);
2500          }          }
2501    
2502          if (MotionFlags&CHECKPREDICTION_BITS) { //let's check vector equal to prediction          if (MotionFlags&XVID_ME_CHECKPREDICTION_BITS) { //let's check vector equal to prediction
2503                  VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV;                  VECTOR * v = Data->qpel ? Data->currentQMV : Data->currentMV;
2504                  if (!(Data->predMV.x == v->x && Data->predMV.y == v->y))                  if (!(Data->predMV.x == v->x && Data->predMV.y == v->y))
2505                          CheckCandidateBits16(Data->predMV.x, Data->predMV.y, 255, &iDirection, Data);                          CheckCandidateBits16(Data->predMV.x, Data->predMV.y, 255, &iDirection, Data);
# Line 2572  Line 2560 
2560                  }                  }
2561    
2562                  if (Data8->qpel) {                  if (Data8->qpel) {
2563                          if (MotionFlags&HALFPELREFINE8_BITS || (MotionFlags&PMV_EXTSEARCH8 && MotionFlags&EXTSEARCH_BITS)) { // halfpixel motion search follows                          if (MotionFlags&XVID_ME_HALFPELREFINE8_BITS || (MotionFlags&XVID_ME_EXTSEARCH8 && MotionFlags&XVID_ME_EXTSEARCH_BITS)) { // halfpixel motion search follows
2564                                  int32_t s = *Data8->iMinSAD;                                  int32_t s = *Data8->iMinSAD;
2565                                  Data8->currentMV->x = Data8->currentQMV->x/2;                                  Data8->currentMV->x = Data8->currentQMV->x/2;
2566                                  Data8->currentMV->y = Data8->currentQMV->y/2;                                  Data8->currentMV->y = Data8->currentQMV->y/2;
# Line 2583  Line 2571 
2571                                  if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1)                                  if (Data8->currentQMV->x & 1 || Data8->currentQMV->y & 1)
2572                                          CheckCandidateBits8(Data8->currentMV->x, Data8->currentMV->y, 255, &iDirection, Data8);                                          CheckCandidateBits8(Data8->currentMV->x, Data8->currentMV->y, 255, &iDirection, Data8);
2573    
2574                                  if (MotionFlags & PMV_EXTSEARCH8 && MotionFlags & EXTSEARCH_BITS)                                  if (MotionFlags & XVID_ME_EXTSEARCH8 && MotionFlags & XVID_ME_EXTSEARCH_BITS)
2575                                          SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255);                                          SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255);
2576    
2577                                  if (MotionFlags & HALFPELREFINE8_BITS) SubpelRefine(Data8);                                  if (MotionFlags & XVID_ME_HALFPELREFINE8_BITS) SubpelRefine(Data8);
2578    
2579                                  if(s > *Data8->iMinSAD) { //we have found a better match                                  if(s > *Data8->iMinSAD) { //we have found a better match
2580                                          Data8->currentQMV->x = 2*Data8->currentMV->x;                                          Data8->currentQMV->x = 2*Data8->currentMV->x;
# Line 2598  Line 2586 
2586                                                          pParam->width, pParam->height, Data8->iFcode, 1, 0);                                                          pParam->width, pParam->height, Data8->iFcode, 1, 0);
2587    
2588                          }                          }
2589                          if (MotionFlags & QUARTERPELREFINE8_BITS) SubpelRefine(Data8);                          if (MotionFlags & XVID_ME_QUARTERPELREFINE8_BITS) SubpelRefine(Data8);
2590    
2591                  } else // not qpel                  } else // not qpel
2592                          if (MotionFlags & HALFPELREFINE8_BITS) SubpelRefine(Data8); //halfpel mode, halfpel refinement                          if (MotionFlags & XVID_ME_HALFPELREFINE8_BITS) SubpelRefine(Data8); //halfpel mode, halfpel refinement
2593    
2594                  //checking vector equal to predicion                  //checking vector equal to predicion
2595                  if (i != 0 && MotionFlags & CHECKPREDICTION_BITS) {                  if (i != 0 && MotionFlags & XVID_ME_CHECKPREDICTION_BITS) {
2596                          const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV;                          const VECTOR * v = Data->qpel ? Data8->currentQMV : Data8->currentMV;
2597                          if (!(Data8->predMV.x == v->x && Data8->predMV.y == v->y))                          if (!(Data8->predMV.x == v->x && Data8->predMV.y == v->y))
2598                                  CheckCandidateBits8(Data8->predMV.x, Data8->predMV.y, 255, &iDirection, Data8);                                  CheckCandidateBits8(Data8->predMV.x, Data8->predMV.y, 255, &iDirection, Data8);

Legend:
Removed from v.872  
changed lines
  Added in v.949

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