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

Diff of /branches/dev-api-3/xvidcore/src/motion/motion_est.c

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

revision 544, Thu Sep 26 04:52:16 2002 UTC revision 545, Fri Sep 27 17:25:17 2002 UTC
# Line 517  Line 517 
517          uint32_t sadC = sad8(current->u + x*8 + y*(iEdgedWidth/2)*8,          uint32_t sadC = sad8(current->u + x*8 + y*(iEdgedWidth/2)*8,
518                                          reference->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2);                                          reference->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2);
519          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;
520          sadC += sad8(current->v + x*8 + y*(iEdgedWidth/2)*8,          sadC += sad8(current->v + (x + y*(iEdgedWidth/2))*8,
521                                          reference->v + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2);                                          reference->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);
522          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;
523    
524          return 1;          return 1;
# Line 947  Line 947 
947                          const IMAGE * const pCur,                          const IMAGE * const pCur,
948                          const int x, const int y,                          const int x, const int y,
949                          const uint32_t MotionFlags,                          const uint32_t MotionFlags,
                         const uint32_t iQuant,  
950                          const uint32_t iFcode,                          const uint32_t iFcode,
951                          const MBParam * const pParam,                          const MBParam * const pParam,
952                          MACROBLOCK * const pMB,                          MACROBLOCK * const pMB,
953                          const VECTOR * const predMV,                          const VECTOR * const predMV,
954                          int32_t * const best_sad,                          int32_t * const best_sad,
955                          const int32_t mode_current)                          const int32_t mode_current,
956                            SearchData * const Data)
957  {  {
958    
959          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
960    
961          int i, iDirection, mask;          int i, iDirection, mask;
962          VECTOR currentMV, pmv[7];          VECTOR pmv[7];
963          MainSearchFunc *MainSearchPtr;          MainSearchFunc *MainSearchPtr;
964          int32_t iMinSAD = MV_MAX_ERROR;          *Data->iMinSAD = MV_MAX_ERROR;
965          SearchData Data;          Data->iFcode = iFcode;
966    
967          Data.iMinSAD = &iMinSAD;          Data->Ref = pRef + (x + y * iEdgedWidth) * 16;
968          Data.Cur = pCur->y + (x + y * iEdgedWidth) * 16;          Data->RefH = pRefH + (x + y * iEdgedWidth) * 16;
969          Data.iEdgedWidth = iEdgedWidth;          Data->RefV = pRefV + (x + y * iEdgedWidth) * 16;
970          Data.currentMV = &currentMV;          Data->RefHV = pRefHV + (x + y * iEdgedWidth) * 16;
         Data.iMinSAD = &iMinSAD;  
         Data.Ref = pRef + (x + y * iEdgedWidth) * 16;  
         Data.RefH = pRefH + (x + y * iEdgedWidth) * 16;  
         Data.RefV = pRefV + (x + y * iEdgedWidth) * 16;  
         Data.RefHV = pRefHV + (x + y * iEdgedWidth) * 16;  
971    
972          Data.iQuant = iQuant;          Data->predMV = *predMV;
         Data.iFcode = iFcode;  
         Data.predMV = *predMV;  
973    
974          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,
975                                  pParam->width, pParam->height, iFcode);                                  pParam->width, pParam->height, iFcode);
976    
977          if (!(MotionFlags & PMV_HALFPEL16)) {          pmv[0] = Data->predMV;
978                  Data.min_dx = EVEN(Data.min_dx);          PreparePredictionsBF(pmv, x, y, pParam->mb_width, pMB, mode_current);
                 Data.max_dx = EVEN(Data.max_dx);  
                 Data.min_dy = EVEN(Data.min_dy);  
                 Data.max_dy = EVEN(Data.max_dy); } // no-halpel and b-frames. do we need it?  
   
   
         pmv[0] = Data.predMV;  
         PreparePredictionsBF(pmv, x, y, pParam->mb_width,  
                                         pMB, mode_current);  
979    
980          currentMV.x = currentMV.y = 0;          Data->currentMV->x = Data->currentMV->y = 0;
981    
982          CheckCandidate = CheckCandidate16no4v;          CheckCandidate = CheckCandidate16no4v;
983    
984  // main loop. checking all predictions  // main loop. checking all predictions
985          for (i = 0; i < 8; i++) {          for (i = 0; i < 8; i++) {
986                  if (!(mask = make_mask(pmv, i)) ) continue;                  if (!(mask = make_mask(pmv, i)) ) continue;
987                  CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, &Data);                  CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data);
988          }          }
989    
990          if (MotionFlags & PMV_USESQUARES16)          if (MotionFlags & PMV_USESQUARES16)
# Line 1008  Line 993 
993                  MainSearchPtr = AdvDiamondSearch;                  MainSearchPtr = AdvDiamondSearch;
994                  else MainSearchPtr = DiamondSearch;                  else MainSearchPtr = DiamondSearch;
995    
996          (*MainSearchPtr)(currentMV.x, currentMV.y, &Data, 255);          (*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255);
997    
998          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(&Data);          HalfpelRefine(Data);
999    
1000  // three bits are needed to code backward mode. four for forward  // three bits are needed to code backward mode. four for forward
1001  // we treat the bits just like they were vector's  // we treat the bits just like they were vector's
1002          if (mode_current == MODE_FORWARD) iMinSAD +=  4 * lambda_vec16[iQuant];          if (mode_current == MODE_FORWARD) *Data->iMinSAD +=  4 * lambda_vec16[Data->iQuant];
1003          else iMinSAD +=  3 * lambda_vec16[iQuant];          else *Data->iMinSAD +=  3 * lambda_vec16[Data->iQuant];
1004    
1005    
1006          if (iMinSAD < *best_sad) {          if (*Data->iMinSAD < *best_sad) {
1007                  *best_sad = iMinSAD;                  *best_sad = *Data->iMinSAD;
1008                  pMB->mode = mode_current;                  pMB->mode = mode_current;
1009                  pMB->pmvs[0].x = currentMV.x - predMV->x;                  pMB->pmvs[0].x = Data->currentMV->x - predMV->x;
1010                  pMB->pmvs[0].y = currentMV.y - predMV->y;                  pMB->pmvs[0].y = Data->currentMV->y - predMV->y;
1011                  if (mode_current == MODE_FORWARD) pMB->mvs[0] = currentMV;                  if (mode_current == MODE_FORWARD) pMB->mvs[0] = *Data->currentMV;
1012                  else pMB->b_mvs[0] = currentMV;                  else pMB->b_mvs[0] = *Data->currentMV;
1013          }          }
1014    
1015  }  }
# Line 1041  Line 1026 
1026                                  const IMAGE * const pCur,                                  const IMAGE * const pCur,
1027                                  const int x, const int y,                                  const int x, const int y,
1028                                  const uint32_t MotionFlags,                                  const uint32_t MotionFlags,
                                 const uint32_t iQuant,  
1029                                  const int32_t TRB, const int32_t TRD,                                  const int32_t TRB, const int32_t TRD,
1030                                  const MBParam * const pParam,                                  const MBParam * const pParam,
1031                                  MACROBLOCK * const pMB,                                  MACROBLOCK * const pMB,
1032                                  const MACROBLOCK * const b_mb,                                  const MACROBLOCK * const b_mb,
1033                                  int32_t * const best_sad)                                  int32_t * const best_sad,
1034                                    SearchData * const Data)
1035    
1036  {  {
1037          const uint32_t iEdgedWidth = pParam->edged_width;          int32_t skip_sad;
         int32_t iMinSAD = 266*4096, skip_sad;  
1038          int k;          int k;
1039          VECTOR currentMV;  
1040          MainSearchFunc *MainSearchPtr;          MainSearchFunc *MainSearchPtr;
         SearchData Data;  
1041    
1042          Data.iMinSAD = &iMinSAD;          *Data->iMinSAD = 256*4096;
1043          Data.Cur = pCur->y + x * 16 + y * 16 * iEdgedWidth;          Data->referencemv = b_mb->mvs;
         Data.iEdgedWidth = iEdgedWidth;  
         Data.currentMV = &currentMV;  
         Data.iQuant = iQuant;  
         Data.referencemv = b_mb->mvs;  
1044    
1045          Data.Ref= f_Ref->y + (x + iEdgedWidth*y) * 16;          Data->Ref = f_Ref->y + (x + Data->iEdgedWidth*y) * 16;
1046          Data.RefH = f_RefH + (x + iEdgedWidth*y) * 16;          Data->RefH = f_RefH + (x + Data->iEdgedWidth*y) * 16;
1047          Data.RefV = f_RefV + (x + iEdgedWidth*y) * 16;          Data->RefV = f_RefV + (x + Data->iEdgedWidth*y) * 16;
1048          Data.RefHV = f_RefHV + (x + iEdgedWidth*y) * 16;          Data->RefHV = f_RefHV + (x + Data->iEdgedWidth*y) * 16;
1049          Data.bRef = b_Ref->y + (x + iEdgedWidth*y) * 16;          Data->bRef = b_Ref->y + (x + Data->iEdgedWidth*y) * 16;
1050          Data.bRefH = b_RefH + (x + iEdgedWidth*y) * 16;          Data->bRefH = b_RefH + (x + Data->iEdgedWidth*y) * 16;
1051          Data.bRefV = b_RefV + (x + iEdgedWidth*y) * 16;          Data->bRefV = b_RefV + (x + Data->iEdgedWidth*y) * 16;
1052          Data.bRefHV = b_RefHV + (x + iEdgedWidth*y) * 16;          Data->bRefHV = b_RefHV + (x + Data->iEdgedWidth*y) * 16;
1053  /*  
1054  //What we do here is a complicated version of CheckCandidateDirect(0,0);          Data->max_dx = 2 * pParam->width - 2 * (x) * 16;
1055  get_range(&Data.min_dx, &Data.max_dx, &Data.min_dy, &Data.max_dy, x, y, 16, pParam->width, pParam->height, 19);          Data->max_dy = 2 * pParam->height - 2 * (y) * 16;
1056            Data->min_dx = -(2 * 16 + 2 * (x) * 16);
1057  */          Data->min_dy = -(2 * 16 + 2 * (y) * 16);
         Data.max_dx = 2 * pParam->width - 2 * (x) * 16;  
         Data.max_dy = 2 * pParam->height - 2 * (y) * 16;  
         Data.min_dx = -(2 * 16 + 2 * (x) * 16);  
         Data.min_dy = -(2 * 16 + 2 * (y) * 16);  
1058    
1059          for (k = 0; k < 4; k++) {          for (k = 0; k < 4; k++) {
1060                  pMB->mvs[k].x = Data.directmvF[k].x = ((TRB * Data.referencemv[k].x) / TRD);                  pMB->mvs[k].x = Data->directmvF[k].x = ((TRB * Data->referencemv[k].x) / TRD);
1061                  pMB->b_mvs[k].x = Data.directmvB[k].x = ((TRB - TRD) * Data.referencemv[k].x) / TRD;                  pMB->b_mvs[k].x = Data->directmvB[k].x = ((TRB - TRD) * Data->referencemv[k].x) / TRD;
1062                  pMB->mvs[k].y = Data.directmvF[k].y = ((TRB * Data.referencemv[k].y) / TRD);                  pMB->mvs[k].y = Data->directmvF[k].y = ((TRB * Data->referencemv[k].y) / TRD);
1063                  pMB->b_mvs[k].y = Data.directmvB[k].y = ((TRB - TRD) * Data.referencemv[k].y) / TRD;                  pMB->b_mvs[k].y = Data->directmvB[k].y = ((TRB - TRD) * Data->referencemv[k].y) / TRD;
1064    
1065                  if (( pMB->mvs[k].x > Data.max_dx ) || ( pMB->mvs[k].x < Data.min_dx )                  if ( ( pMB->b_mvs[k].x > Data->max_dx ) || ( pMB->b_mvs[k].x < Data->min_dx )
1066                          || ( pMB->mvs[k].y > Data.max_dy ) || ( pMB->mvs[k].y < Data.min_dy )                          || ( pMB->b_mvs[k].y > Data->max_dy ) || ( pMB->b_mvs[k].y < Data->min_dy )) {
                         || ( pMB->b_mvs[k].x > Data.max_dx ) || ( pMB->b_mvs[k].x < Data.min_dx )  
                         || ( pMB->b_mvs[k].y > Data.max_dy ) || ( pMB->b_mvs[k].y < Data.min_dy )) {  
1067    
1068                          *best_sad = 256*4096; // in that case, we won't use direct mode                          *best_sad = 256*4096; // in that case, we won't use direct mode
1069                          pMB->mode = MODE_DIRECT; // just to make sure it doesn't say "MODE_DIRECT_NONE_MV"                          pMB->mode = MODE_DIRECT; // just to make sure it doesn't say "MODE_DIRECT_NONE_MV"
# Line 1100  Line 1073 
1073                  if (b_mb->mode != MODE_INTER4V) {                  if (b_mb->mode != MODE_INTER4V) {
1074                          pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mvs[0];                          pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mvs[0];
1075                          pMB->b_mvs[1] = pMB->b_mvs[2] = pMB->b_mvs[3] = pMB->b_mvs[0];                          pMB->b_mvs[1] = pMB->b_mvs[2] = pMB->b_mvs[3] = pMB->b_mvs[0];
1076                          Data.directmvF[1] = Data.directmvF[2] = Data.directmvF[3] = Data.directmvF[0];                          Data->directmvF[1] = Data->directmvF[2] = Data->directmvF[3] = Data->directmvF[0];
1077                          Data.directmvB[1] = Data.directmvB[2] = Data.directmvB[3] = Data.directmvB[0];                          Data->directmvB[1] = Data->directmvB[2] = Data->directmvB[3] = Data->directmvB[0];
1078                          break;                          break;
1079                  }                  }
1080          }          }
# Line 1110  Line 1083 
1083                  CheckCandidate = CheckCandidateDirect;                  CheckCandidate = CheckCandidateDirect;
1084          else CheckCandidate = CheckCandidateDirectno4v;          else CheckCandidate = CheckCandidateDirectno4v;
1085    
1086          (*CheckCandidate)(0, 0, 255, &k, &Data);          (*CheckCandidate)(0, 0, 255, &k, Data);
1087    
1088  // skip decision  // skip decision
1089          if (iMinSAD - 2 * lambda_vec16[iQuant] < (int32_t)iQuant * SKIP_THRESH_B) {          if (*Data->iMinSAD - 2 * lambda_vec16[Data->iQuant] < (int32_t)Data->iQuant * SKIP_THRESH_B) {
1090                  //checking chroma. everything copied from MC                  //checking chroma. everything copied from MC
1091                  //this is not full chroma compensation, only it's fullpel approximation. should work though                  //this is not full chroma compensation, only it's fullpel approximation. should work though
1092                  int sum, dx, dy, b_dx, b_dy;                  int sum, dx, dy, b_dx, b_dy;
# Line 1130  Line 1103 
1103                  sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;                  sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
1104                  b_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));                  b_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
1105    
1106                  sum = sad8bi(pCur->u + 8*x + 8*y*(iEdgedWidth/2),                  sum = sad8bi(pCur->u + 8*x + 8*y*(Data->iEdgedWidth/2),
1107                                          f_Ref->u + (y*8 + dy/2) * (iEdgedWidth/2) + x*8 + dx/2,                                          f_Ref->u + (y*8 + dy/2) * (Data->iEdgedWidth/2) + x*8 + dx/2,
1108                                          b_Ref->u + (y*8 + b_dy/2) * (iEdgedWidth/2) + x*8 + b_dx/2,                                          b_Ref->u + (y*8 + b_dy/2) * (Data->iEdgedWidth/2) + x*8 + b_dx/2,
1109                                          iEdgedWidth/2);                                          Data->iEdgedWidth/2);
1110                  sum += sad8bi(pCur->v + 8*x + 8*y*(iEdgedWidth/2),                  sum += sad8bi(pCur->v + 8*x + 8*y*(Data->iEdgedWidth/2),
1111                                          f_Ref->v + (y*8 + dy/2) * (iEdgedWidth/2) + x*8 + dx/2,                                          f_Ref->v + (y*8 + dy/2) * (Data->iEdgedWidth/2) + x*8 + dx/2,
1112                                          b_Ref->v + (y*8 + b_dy/2) * (iEdgedWidth/2) + x*8 + b_dx/2,                                          b_Ref->v + (y*8 + b_dy/2) * (Data->iEdgedWidth/2) + x*8 + b_dx/2,
1113                                          iEdgedWidth/2);                                          Data->iEdgedWidth/2);
1114    
1115                  if ((uint32_t) sum < MAX_CHROMA_SAD_FOR_SKIP * Data.iQuant) {                  if ((uint32_t) sum < MAX_CHROMA_SAD_FOR_SKIP * Data->iQuant) {
1116                          pMB->mode = MODE_DIRECT_NONE_MV;                          pMB->mode = MODE_DIRECT_NONE_MV;
1117                          return iMinSAD;                          return *Data->iMinSAD;
1118                  }                  }
1119          }          }
1120    
1121          skip_sad = iMinSAD;          skip_sad = *Data->iMinSAD;
1122    
1123  //  DIRECT MODE DELTA VECTOR SEARCH.  //  DIRECT MODE DELTA VECTOR SEARCH.
1124  //      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
# Line 1154  Line 1127 
1127                  else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;                  else if (MotionFlags & PMV_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch;
1128                          else MainSearchPtr = DiamondSearch;                          else MainSearchPtr = DiamondSearch;
1129    
1130          (*MainSearchPtr)(0, 0, &Data, 255);          (*MainSearchPtr)(0, 0, Data, 255);
1131    
1132          HalfpelRefine(&Data);          HalfpelRefine(Data);
1133    
1134          iMinSAD +=  1 * lambda_vec16[iQuant]; // one bit is needed to code direct mode. we treat this bit just like it was vector's          *Data->iMinSAD +=  1 * lambda_vec16[Data->iQuant]; // one bit is needed to code direct mode. we treat this bit just like it was vector's
1135          *best_sad = iMinSAD;          *best_sad = *Data->iMinSAD;
1136    
1137          if (b_mb->mode == MODE_INTER4V)          if (b_mb->mode == MODE_INTER4V)
1138                  pMB->mode = MODE_DIRECT;                  pMB->mode = MODE_DIRECT;
1139          else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation          else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation
1140    
1141          pMB->pmvs[3] = currentMV;          pMB->pmvs[3] = *Data->currentMV;
1142    
1143          for (k = 0; k < 4; k++) {          for (k = 0; k < 4; k++) {
1144                  pMB->mvs[k].x = Data.directmvF[k].x + currentMV.x;                  pMB->mvs[k].x = Data->directmvF[k].x + Data->currentMV->x;
1145                  pMB->b_mvs[k].x = ((currentMV.x == 0)                  pMB->b_mvs[k].x = ((Data->currentMV->x == 0)
1146                                                          ? Data.directmvB[k].x                                                          ? Data->directmvB[k].x
1147                                                          : pMB->mvs[k].x - Data.referencemv[k].x);                                                          : pMB->mvs[k].x - Data->referencemv[k].x);
1148                  pMB->mvs[k].y = (Data.directmvF[k].y + currentMV.y);                  pMB->mvs[k].y = (Data->directmvF[k].y + Data->currentMV->y);
1149                  pMB->b_mvs[k].y = ((currentMV.y == 0)                  pMB->b_mvs[k].y = ((Data->currentMV->y == 0)
1150                                                          ? Data.directmvB[k].y                                                          ? Data->directmvB[k].y
1151                                                          : pMB->mvs[k].y - Data.referencemv[k].y);                                                          : pMB->mvs[k].y - Data->referencemv[k].y);
1152                  if (b_mb->mode != MODE_INTER4V) {                  if (b_mb->mode != MODE_INTER4V) {
1153                          pMB->mvs[3] = pMB->mvs[2] = pMB->mvs[1] = pMB->mvs[0];                          pMB->mvs[3] = pMB->mvs[2] = pMB->mvs[1] = pMB->mvs[0];
1154                          pMB->b_mvs[3] = pMB->b_mvs[2] = pMB->b_mvs[1] = pMB->b_mvs[0];                          pMB->b_mvs[3] = pMB->b_mvs[2] = pMB->b_mvs[1] = pMB->b_mvs[0];
1155                          break;                          break;
1156                  }                  }
1157          }          }
1158          return 0;//skip_sad;          return skip_sad;
1159  }  }
1160    
1161    
1162  static __inline void  static __inline void
1163  SearchInterpolate(const uint8_t * const f_Ref,  SearchInterpolate(const uint8_t * const f_Ref,
1164                                  const uint8_t * const f_RefH,                                  const uint8_t * const f_RefH,
# Line 1199  Line 1173 
1173                                  const uint32_t fcode,                                  const uint32_t fcode,
1174                                  const uint32_t bcode,                                  const uint32_t bcode,
1175                                  const uint32_t MotionFlags,                                  const uint32_t MotionFlags,
                                 const uint32_t iQuant,  
1176                                  const MBParam * const pParam,                                  const MBParam * const pParam,
1177                                  const VECTOR * const f_predMV,                                  const VECTOR * const f_predMV,
1178                                  const VECTOR * const b_predMV,                                  const VECTOR * const b_predMV,
1179                                  MACROBLOCK * const pMB,                                  MACROBLOCK * const pMB,
1180                                  int32_t * const best_sad)                                  int32_t * const best_sad,
1181                                    SearchData * const fData)
1182    
1183  {  {
 /* Interpolated MC motion vector search, this is tedious and more complicated because there are  
    two values for everything, always one for backward and one for forward ME. Still, we don't gain  
    much from this search, maybe it should simply be skipped and simply current i_sad16 value used  
    as "optimal". */  
1184    
1185          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
1186    
1187          int iDirection, i, j;          int iDirection, i, j;
1188          int32_t iMinSAD = 256*4096;          SearchData bData;
         VECTOR currentMV[3];  
         SearchData fData, bData;  
   
         fData.iMinSAD = bData.iMinSAD = &iMinSAD;  
1189    
1190          fData.Cur = bData.Cur = pCur->y + (x + y * iEdgedWidth) * 16;          bData.iMinSAD = fData->iMinSAD;
1191          fData.iEdgedWidth = bData.iEdgedWidth = iEdgedWidth;          *bData.iMinSAD = 4096*256;
1192          fData.currentMV = currentMV; bData.currentMV = currentMV + 1;          bData.Cur = fData->Cur;
1193          fData.iQuant = bData.iQuant = iQuant;          fData->iEdgedWidth = bData.iEdgedWidth = iEdgedWidth;
1194          fData.iFcode = bData.bFcode = fcode; fData.bFcode = bData.iFcode = bcode;          bData.currentMV = fData->currentMV + 1;
1195            bData.iQuant = fData->iQuant;
1196          bData.bRef = fData.Ref = f_Ref + (x + y * iEdgedWidth) * 16;          fData->iFcode = bData.bFcode = fcode; fData->bFcode = bData.iFcode = bcode;
1197          bData.bRefH = fData.RefH = f_RefH + (x + y * iEdgedWidth) * 16;  
1198          bData.bRefV = fData.RefV = f_RefV + (x + y * iEdgedWidth) * 16;          bData.bRef = fData->Ref = f_Ref + (x + y * iEdgedWidth) * 16;
1199          bData.bRefHV = fData.RefHV = f_RefHV + (x + y * iEdgedWidth) * 16;          bData.bRefH = fData->RefH = f_RefH + (x + y * iEdgedWidth) * 16;
1200          bData.Ref = fData.bRef = b_Ref + (x + y * iEdgedWidth) * 16;          bData.bRefV = fData->RefV = f_RefV + (x + y * iEdgedWidth) * 16;
1201          bData.RefH = fData.bRefH = b_RefH + (x + y * iEdgedWidth) * 16;          bData.bRefHV = fData->RefHV = f_RefHV + (x + y * iEdgedWidth) * 16;
1202          bData.RefV = fData.bRefV = b_RefV + (x + y * iEdgedWidth) * 16;          bData.Ref = fData->bRef = b_Ref + (x + y * iEdgedWidth) * 16;
1203          bData.RefHV = fData.bRefHV = b_RefHV + (x + y * iEdgedWidth) * 16;          bData.RefH = fData->bRefH = b_RefH + (x + y * iEdgedWidth) * 16;
1204            bData.RefV = fData->bRefV = b_RefV + (x + y * iEdgedWidth) * 16;
1205          bData.bpredMV = fData.predMV = *f_predMV;          bData.RefHV = fData->bRefHV = b_RefHV + (x + y * iEdgedWidth) * 16;
1206          fData.bpredMV = bData.predMV = *b_predMV;  
1207            bData.bpredMV = fData->predMV = *f_predMV;
1208          currentMV[0] = pMB->mvs[0];          fData->bpredMV = bData.predMV = *b_predMV;
1209          currentMV[1] = pMB->b_mvs[0];  
1210          get_range(&fData.min_dx, &fData.max_dx, &fData.min_dy, &fData.max_dy, x, y, 16, pParam->width, pParam->height, fcode);          fData->currentMV[0] = pMB->mvs[0];
1211            fData->currentMV[1] = pMB->b_mvs[0];
1212            get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode);
1213          get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode);          get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode);
1214    
1215          if (currentMV[0].x > fData.max_dx) currentMV[0].x = fData.max_dx;          if (fData->currentMV[0].x > fData->max_dx) fData->currentMV[0].x = fData->max_dx;
1216          if (currentMV[0].x < fData.min_dx) currentMV[0].x = fData.min_dy;          if (fData->currentMV[0].x < fData->min_dx) fData->currentMV[0].x = fData->min_dy;
1217          if (currentMV[0].y > fData.max_dy) currentMV[0].y = fData.max_dx;          if (fData->currentMV[0].y > fData->max_dy) fData->currentMV[0].y = fData->max_dx;
1218          if (currentMV[0].y > fData.min_dy) currentMV[0].y = fData.min_dy;          if (fData->currentMV[0].y > fData->min_dy) fData->currentMV[0].y = fData->min_dy;
1219    
1220          if (currentMV[1].x > bData.max_dx) currentMV[1].x = bData.max_dx;          if (fData->currentMV[1].x > bData.max_dx) fData->currentMV[1].x = bData.max_dx;
1221          if (currentMV[1].x < bData.min_dx) currentMV[1].x = bData.min_dy;          if (fData->currentMV[1].x < bData.min_dx) fData->currentMV[1].x = bData.min_dy;
1222          if (currentMV[1].y > bData.max_dy) currentMV[1].y = bData.max_dx;          if (fData->currentMV[1].y > bData.max_dy) fData->currentMV[1].y = bData.max_dx;
1223          if (currentMV[1].y > bData.min_dy) currentMV[1].y = bData.min_dy;          if (fData->currentMV[1].y > bData.min_dy) fData->currentMV[1].y = bData.min_dy;
1224    
1225          CheckCandidateInt(currentMV[0].x, currentMV[0].y, 255, &iDirection, &fData);          CheckCandidateInt(fData->currentMV[0].x, fData->currentMV[0].y, 255, &iDirection, fData);
1226    
1227  //diamond. I wish we could use normal mainsearch functions (square, advdiamond)  //diamond. I wish we could use normal mainsearch functions (square, advdiamond)
1228    
1229          do {          do {
1230                  iDirection = 255;                  iDirection = 255;
1231                  // forward MV moves                  // forward MV moves
1232                  i = currentMV[0].x; j = currentMV[0].y;                  i = fData->currentMV[0].x; j = fData->currentMV[0].y;
1233    
1234                  CheckCandidateInt(i + 1, j, 0, &iDirection, &fData);                  CheckCandidateInt(i + 1, j, 0, &iDirection, fData);
1235                  CheckCandidateInt(i, j + 1, 0, &iDirection, &fData);                  CheckCandidateInt(i, j + 1, 0, &iDirection, fData);
1236                  CheckCandidateInt(i - 1, j, 0, &iDirection, &fData);                  CheckCandidateInt(i - 1, j, 0, &iDirection, fData);
1237                  CheckCandidateInt(i, j - 1, 0, &iDirection, &fData);                  CheckCandidateInt(i, j - 1, 0, &iDirection, fData);
1238    
1239                  // backward MV moves                  // backward MV moves
1240                  i = currentMV[1].x; j = currentMV[1].y;                  i = fData->currentMV[1].x; j = fData->currentMV[1].y;
1241                  currentMV[2] = currentMV[0];                  fData->currentMV[2] = fData->currentMV[0];
1242    
1243                  CheckCandidateInt(i + 1, j, 0, &iDirection, &bData);                  CheckCandidateInt(i + 1, j, 0, &iDirection, &bData);
1244                  CheckCandidateInt(i, j + 1, 0, &iDirection, &bData);                  CheckCandidateInt(i, j + 1, 0, &iDirection, &bData);
# Line 1280  Line 1248 
1248          } while (!(iDirection));          } while (!(iDirection));
1249    
1250  // two bits are needed to code interpolate mode. we treat the bits just like they were vector's  // two bits are needed to code interpolate mode. we treat the bits just like they were vector's
1251          iMinSAD +=  2 * lambda_vec16[iQuant];          *fData->iMinSAD +=  2 * lambda_vec16[fData->iQuant];
1252          if (iMinSAD < *best_sad) {          if (*fData->iMinSAD < *best_sad) {
1253                  *best_sad = iMinSAD;                  *best_sad = *fData->iMinSAD;
1254                  pMB->mvs[0] = currentMV[0];                  pMB->mvs[0] = fData->currentMV[0];
1255                  pMB->b_mvs[0] = currentMV[1];                  pMB->b_mvs[0] = fData->currentMV[1];
1256                  pMB->mode = MODE_INTERPOLATE;                  pMB->mode = MODE_INTERPOLATE;
1257    
1258                  pMB->pmvs[1].x = pMB->mvs[0].x - f_predMV->x;                  pMB->pmvs[1].x = pMB->mvs[0].x - f_predMV->x;
# Line 1294  Line 1262 
1262          }          }
1263  }  }
1264    
1265    
1266  void  void
1267  MotionEstimationBVOP(MBParam * const pParam,  MotionEstimationBVOP(MBParam * const pParam,
1268                                           FRAMEINFO * const frame,                                           FRAMEINFO * const frame,
# Line 1322  Line 1291 
1291          const int32_t TRB = time_pp - time_bp;          const int32_t TRB = time_pp - time_bp;
1292          const int32_t TRD = time_pp;          const int32_t TRD = time_pp;
1293    
1294    // some pre-inintialized data for the rest of the search
1295    
1296            SearchData Data;
1297            int32_t iMinSAD;
1298            VECTOR currentMV[3];
1299            Data.iEdgedWidth = pParam->edged_width;
1300            Data.currentMV = currentMV;
1301            Data.iMinSAD = &iMinSAD;
1302            Data.iQuant = frame->quant;
1303    
1304          // note: i==horizontal, j==vertical          // note: i==horizontal, j==vertical
1305    
1306          for (j = 0; j < pParam->mb_height; j++) {          for (j = 0; j < pParam->mb_height; j++) {
# Line 1338  Line 1317 
1317                                  continue;                                  continue;
1318                          }                          }
1319    
1320                            Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16;
1321  /* direct search comes first, because it (1) checks for SKIP-mode  /* direct search comes first, because it (1) checks for SKIP-mode
1322          and (2) sets very good predictions for forward and backward search */          and (2) sets very good predictions for forward and backward search */
1323    
# Line 1346  Line 1326 
1326                                                                          &frame->image,                                                                          &frame->image,
1327                                                                          i, j,                                                                          i, j,
1328                                                                          frame->motion_flags,                                                                          frame->motion_flags,
                                                                         frame->quant,  
1329                                                                          TRB, TRD,                                                                          TRB, TRD,
1330                                                                          pParam,                                                                          pParam,
1331                                                                          pMB, b_mb,                                                                          pMB, b_mb,
1332                                                                          &best_sad);                                                                          &best_sad,
1333                                                                            &Data);
1334    
1335                          if (pMB->mode == MODE_DIRECT_NONE_MV) { n_count++; continue; }                          if (pMB->mode == MODE_DIRECT_NONE_MV) { n_count++; continue; }
1336    
# Line 1361  Line 1341 
1341                          SearchBF(f_ref->y, f_refH->y, f_refV->y, f_refHV->y,                          SearchBF(f_ref->y, f_refH->y, f_refV->y, f_refHV->y,
1342                                                  &frame->image, i, j,                                                  &frame->image, i, j,
1343                                                  frame->motion_flags,                                                  frame->motion_flags,
1344                                                  frame->quant, frame->fcode, pParam,                                                  frame->fcode, pParam,
1345                                                  pMB, &f_predMV, &best_sad,                                                  pMB, &f_predMV, &best_sad,
1346                                                  MODE_FORWARD);                                                  MODE_FORWARD, &Data);
1347    
1348                          // backward search                          // backward search
1349                          SearchBF(b_ref->y, b_refH->y, b_refV->y, b_refHV->y,                          SearchBF(b_ref->y, b_refH->y, b_refV->y, b_refHV->y,
1350                                                  &frame->image, i, j,                                                  &frame->image, i, j,
1351                                                  frame->motion_flags,                                                  frame->motion_flags,
1352                                                  frame->quant, frame->bcode, pParam,                                                  frame->bcode, pParam,
1353                                                  pMB, &b_predMV, &best_sad,                                                  pMB, &b_predMV, &best_sad,
1354                                                  MODE_BACKWARD);                                                  MODE_BACKWARD, &Data);
1355    
1356                          // interpolate search comes last, because it uses data from forward and backward as prediction                          // interpolate search comes last, because it uses data from forward and backward as prediction
1357    
# Line 1381  Line 1361 
1361                                                  i, j,                                                  i, j,
1362                                                  frame->fcode, frame->bcode,                                                  frame->fcode, frame->bcode,
1363                                                  frame->motion_flags,                                                  frame->motion_flags,
1364                                                  frame->quant, pParam,                                                  pParam,
1365                                                  &f_predMV, &b_predMV,                                                  &f_predMV, &b_predMV,
1366                                                  pMB, &best_sad);                                                  pMB, &best_sad,
1367                                                    &Data);
1368    
1369                          switch (pMB->mode) {                          switch (pMB->mode) {
1370                                  case MODE_FORWARD:                                  case MODE_FORWARD:
# Line 1482  Line 1463 
1463                                  const int y,                                  const int y,
1464                                  const uint32_t MotionFlags,                                  const uint32_t MotionFlags,
1465                                  const uint32_t iQuant,                                  const uint32_t iQuant,
                                 const uint32_t iFcode,  
1466                                  const MBParam * const pParam,                                  const MBParam * const pParam,
1467                                  const MACROBLOCK * const pMBs,                                  const MACROBLOCK * const pMBs,
1468                                  int inter4v,                                  int inter4v,
1469                                  MACROBLOCK * const pMB)                                  MACROBLOCK * const pMB,
1470                                    SearchData * Data)
1471  {  {
1472    
1473          const int32_t iEdgedWidth = pParam->edged_width;          const int32_t iEdgedWidth = pParam->edged_width;
1474    
1475          int i;          int i;
         VECTOR currentMV[5];  
         int32_t iMinSAD[5];  
         int32_t temp[5];  
1476          MainSearchFunc * MainSearchPtr;          MainSearchFunc * MainSearchPtr;
         SearchData Data;  
1477    
1478          Data.predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);
1479          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,
1480                                  pParam->width, pParam->height, iFcode);                                  pParam->width, pParam->height, Data->iFcode);
1481    
1482          Data.Cur = pCur->y + (x + y * iEdgedWidth) * 16;          Data->Cur = pCur->y + (x + y * iEdgedWidth) * 16;
1483          Data.iEdgedWidth = iEdgedWidth;          Data->Ref = pRef + (x + iEdgedWidth*y)*16;
1484          Data.currentMV = currentMV;          Data->RefH = pRefH + (x + iEdgedWidth*y) * 16;
1485          Data.iMinSAD = iMinSAD;          Data->RefV = pRefV + (x + iEdgedWidth*y) * 16;
1486          Data.Ref = pRef + (x + iEdgedWidth*y)*16;          Data->RefHV = pRefHV + (x + iEdgedWidth*y) * 16;
1487          Data.RefH = pRefH + (x + iEdgedWidth*y) * 16;          Data->iQuant = iQuant;
         Data.RefV = pRefV + (x + iEdgedWidth*y) * 16;  
         Data.RefHV = pRefHV + (x + iEdgedWidth*y) * 16;  
         Data.temp = temp;  
         Data.iQuant = iQuant;  
         Data.iFcode = iFcode;  
1488    
1489          if (!(MotionFlags & PMV_HALFPEL16)) {          if (!(MotionFlags & PMV_HALFPEL16)) {
1490                  Data.min_dx = EVEN(Data.min_dx);                  Data->min_dx = EVEN(Data->min_dx);
1491                  Data.max_dx = EVEN(Data.max_dx);                  Data->max_dx = EVEN(Data->max_dx);
1492                  Data.min_dy = EVEN(Data.min_dy);                  Data->min_dy = EVEN(Data->min_dy);
1493                  Data.max_dy = EVEN(Data.max_dy);                  Data->max_dy = EVEN(Data->max_dy);
1494          }          }
1495    
1496          for(i = 0; i < 5; i++) iMinSAD[i] = MV_MAX_ERROR;          for(i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR;
1497    
1498          if (pMB->dquant != NO_CHANGE) inter4v = 0;          if (pMB->dquant != NO_CHANGE) inter4v = 0;
1499    
# Line 1532  Line 1504 
1504    
1505          pMB->mvs[0].x = EVEN(pMB->mvs[0].x);          pMB->mvs[0].x = EVEN(pMB->mvs[0].x);
1506          pMB->mvs[0].y = EVEN(pMB->mvs[0].y);          pMB->mvs[0].y = EVEN(pMB->mvs[0].y);
1507          if (pMB->mvs[0].x > Data.max_dx) pMB->mvs[0].x = Data.max_dx; // this is in case iFcode changed          if (pMB->mvs[0].x > Data->max_dx) pMB->mvs[0].x = Data->max_dx; // this is in case iFcode changed
1508          if (pMB->mvs[0].x < Data.min_dx) pMB->mvs[0].x = Data.min_dx;          if (pMB->mvs[0].x < Data->min_dx) pMB->mvs[0].x = Data->min_dx;
1509          if (pMB->mvs[0].y > Data.max_dy) pMB->mvs[0].y = Data.max_dy;          if (pMB->mvs[0].y > Data->max_dy) pMB->mvs[0].y = Data->max_dy;
1510          if (pMB->mvs[0].y < Data.min_dy) pMB->mvs[0].y = Data.min_dy;          if (pMB->mvs[0].y < Data->min_dy) pMB->mvs[0].y = Data->min_dy;
1511    
1512          CheckCandidate16(pMB->mvs[0].x, pMB->mvs[0].y, 0, &i, &Data);          (*CheckCandidate)(pMB->mvs[0].x, pMB->mvs[0].y, 0, &i, Data);
1513    
1514          if (pMB->mode == MODE_INTER4V)          if (pMB->mode == MODE_INTER4V)
1515                  for (i = 1; i < 4; i++) { // all four vectors will be used as four predictions for 16x16 search                  for (i = 1; i < 4; i++) { // all four vectors will be used as four predictions for 16x16 search
1516                          pMB->mvs[i].x = EVEN(pMB->mvs[i].x);                          pMB->mvs[i].x = EVEN(pMB->mvs[i].x);
1517                          pMB->mvs[i].y = EVEN(pMB->mvs[i].y);                          pMB->mvs[i].y = EVEN(pMB->mvs[i].y);
1518                          if (!(make_mask(pMB->mvs, i)))                          if (!(make_mask(pMB->mvs, i)))
1519                                  CheckCandidate16(pMB->mvs[i].x, pMB->mvs[i].y, 0, &i, &Data);                                  (*CheckCandidate)(pMB->mvs[i].x, pMB->mvs[i].y, 0, &i, Data);
1520                  }                  }
1521    
1522          if (MotionFlags & PMV_USESQUARES16)          if (MotionFlags & PMV_USESQUARES16)
# Line 1553  Line 1525 
1525                  MainSearchPtr = AdvDiamondSearch;                  MainSearchPtr = AdvDiamondSearch;
1526                  else MainSearchPtr = DiamondSearch;                  else MainSearchPtr = DiamondSearch;
1527    
1528          (*MainSearchPtr)(currentMV->x, currentMV->y, &Data, 255);          (*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255);
1529    
1530          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(&Data);          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data);
1531    
1532          if (inter4v)          if (inter4v)
1533                  for(i = 0; i < 4; i++)                  for(i = 0; i < 4; i++)
1534                          Search8hinted(&Data, 2*x+(i&1), 2*y+(i>>1), MotionFlags, pParam, pMB, pMBs, i);                          Search8hinted(Data, 2*x+(i&1), 2*y+(i>>1), MotionFlags, pParam, pMB, pMBs, i);
1535    
1536          if (!(inter4v) ||          if (!(inter4v) ||
1537                  (iMinSAD[0] < iMinSAD[1] + iMinSAD[2] + iMinSAD[3] + iMinSAD[4] + IMV16X16 * (int32_t)iQuant )) {                  (Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + Data->iMinSAD[3] +
1538                                                            Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant )) {
1539  // INTER MODE  // INTER MODE
1540    
1541                  pMB->mode = MODE_INTER;                  pMB->mode = MODE_INTER;
1542                  pMB->mvs[0] = pMB->mvs[1]                  pMB->mvs[0] = pMB->mvs[1]
1543                          = pMB->mvs[2] = pMB->mvs[3] = currentMV[0];                          = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
1544    
1545                  pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] =                  pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] =
1546                          pMB->sad8[2] = pMB->sad8[3] =  iMinSAD[0];                          pMB->sad8[2] = pMB->sad8[3] =  Data->iMinSAD[0];
1547    
1548                  pMB->pmvs[0].x = currentMV[0].x - Data.predMV.x;                  pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
1549                  pMB->pmvs[0].y = currentMV[0].y - Data.predMV.y;                  pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
1550          } else {          } else {
1551  // INTER4V MODE; all other things are already set in Search8hinted  // INTER4V MODE; all other things are already set in Search8hinted
1552                  pMB->mode = MODE_INTER4V;                  pMB->mode = MODE_INTER4V;
1553                  pMB->sad16 = iMinSAD[1] + iMinSAD[2] + iMinSAD[3] + iMinSAD[4] + IMV16X16 * iQuant;                  pMB->sad16 = Data->iMinSAD[1] + Data->iMinSAD[2] + Data->iMinSAD[3]
1554                                                    + Data->iMinSAD[4] + IMV16X16 * iQuant;
1555          }          }
1556    
1557  }  }
# Line 1595  Line 1569 
1569          const IMAGE *const pRef = &reference->image;          const IMAGE *const pRef = &reference->image;
1570    
1571          uint32_t x, y;          uint32_t x, y;
1572            int32_t temp[5];
1573            int32_t iMinSAD[5];
1574            VECTOR currentMV[5];
1575            SearchData Data;
1576            Data.iEdgedWidth = pParam->edged_width;
1577            Data.currentMV = currentMV;
1578            Data.iMinSAD = iMinSAD;
1579            Data.temp = temp;
1580            Data.iFcode = current->fcode;
1581    
1582          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
1583    
# Line 1612  Line 1595 
1595    
1596                          SearchPhinted(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,                          SearchPhinted(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,
1597                                                          y, current->motion_flags, pMB->quant,                                                          y, current->motion_flags, pMB->quant,
1598                                                          current->fcode, pParam, pMBs,                                                          pParam, pMBs, current->global_flags & XVID_INTER4V, pMB,
1599                                                          current->global_flags & XVID_INTER4V, pMB);                                                          &Data);
1600    
1601                  }                  }
1602          }          }
# Line 1624  Line 1607 
1607                                  const uint8_t * const pCur,                                  const uint8_t * const pCur,
1608                                  const int x,                                  const int x,
1609                                  const int y,                                  const int y,
                                 const uint32_t iFcode,  
1610                                  const MBParam * const pParam,                                  const MBParam * const pParam,
1611                                  const MACROBLOCK * const pMBs,                                  const MACROBLOCK * const pMBs,
1612                                  MACROBLOCK * const pMB)                                  MACROBLOCK * const pMB,
1613                                    SearchData * const Data)
1614  {  {
1615    
         const int32_t iEdgedWidth = pParam->edged_width;  
1616          int i, mask;          int i, mask;
1617          VECTOR currentMV, pmv[3];          VECTOR pmv[3];
         int32_t iMinSAD = MV_MAX_ERROR;  
         SearchData Data;  
1618    
1619          Data.predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);          *(Data->iMinSAD) = MV_MAX_ERROR;
1620          get_range(&Data.min_dx, &Data.max_dx, &Data.min_dy, &Data.max_dy, x, y, 16,          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);
1621                                  pParam->width, pParam->height, iFcode);          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
1622                                    pParam->width, pParam->height, Data->iFcode);
1623    
1624          Data.Cur = pCur + (x + y * iEdgedWidth) * 16;          Data->Cur = pCur + (x + y * pParam->edged_width) * 16;
1625          Data.iEdgedWidth = iEdgedWidth;          Data->Ref = pRef + (x + y * pParam->edged_width) * 16;
         Data.currentMV = &currentMV;  
         Data.iMinSAD = &iMinSAD;  
         Data.Ref = pRef + (x + iEdgedWidth*y)*16;  
         Data.iQuant = 2;  
         Data.iFcode = iFcode;  
1626    
1627          CheckCandidate = CheckCandidate16no4vI;          CheckCandidate = CheckCandidate16no4vI;
1628    
1629          pmv[1].x = EVEN(pMB->mvs[0].x);          pmv[1].x = EVEN(pMB->mvs[0].x);
1630          pmv[1].y = EVEN(pMB->mvs[0].y);          pmv[1].y = EVEN(pMB->mvs[0].y);
1631          pmv[0].x = EVEN(Data.predMV.x);          pmv[0].x = EVEN(Data->predMV.x);
1632          pmv[0].y = EVEN(Data.predMV.y);          pmv[0].y = EVEN(Data->predMV.y);
1633          pmv[2].x = pmv[2].y = 0;          pmv[2].x = pmv[2].y = 0;
1634    
1635          CheckCandidate16no4vI(pmv[0].x, pmv[0].y, 255, &i, &Data);          CheckCandidate16no4vI(pmv[0].x, pmv[0].y, 255, &i, Data);
1636          if (!(mask = make_mask(pmv, 1)))          if (!(mask = make_mask(pmv, 1)))
1637                  CheckCandidate16no4vI(pmv[1].x, pmv[1].y, mask, &i, &Data);                  CheckCandidate16no4vI(pmv[1].x, pmv[1].y, mask, &i, Data);
1638          if (!(mask = make_mask(pmv, 2)))          if (!(mask = make_mask(pmv, 2)))
1639                  CheckCandidate16no4vI(0, 0, mask, &i, &Data);                  CheckCandidate16no4vI(0, 0, mask, &i, Data);
1640    
1641          DiamondSearch(currentMV.x, currentMV.y, &Data, i);          DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, i);
1642    
1643          pMB->mvs[0] = pMB->mvs[1]          pMB->mvs[0] = pMB->mvs[1]
1644                          = pMB->mvs[2] = pMB->mvs[3] = currentMV; // all, for future get_pmv()                          = pMB->mvs[2] = pMB->mvs[3] = *Data->currentMV; // all, for future get_pmv()
1645    
1646          return iMinSAD;          return *(Data->iMinSAD);
1647  }  }
1648    
1649  #define INTRA_THRESH    1350  #define INTRA_THRESH    1350
# Line 1683  Line 1659 
1659          uint32_t x, y, intra = 0;          uint32_t x, y, intra = 0;
1660          int sSAD = 0;          int sSAD = 0;
1661    
1662            VECTOR currentMV;
1663            int32_t iMinSAD;
1664            SearchData Data;
1665            Data.iEdgedWidth = pParam->edged_width;
1666            Data.currentMV = &currentMV;
1667            Data.iMinSAD = &iMinSAD;
1668            Data.iFcode = iFcode;
1669            Data.iQuant = 2;
1670    
1671          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
1672    
1673          for (y = 0; y < pParam->mb_height-1; y++) {          for (y = 0; y < pParam->mb_height-1; y++) {
1674                  for (x = 0; x < pParam->mb_width; x++) {                  for (x = 0; x < pParam->mb_width; x++) {
1675                          int sad, dev;                          int sad, dev;
   
1676                          MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width];                          MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width];
1677    
1678                          sad = MEanalyzeMB(pRef->y, pCurrent->y, x, y,                          sad = MEanalyzeMB(pRef->y, pCurrent->y, x, y,
1679                                                                  iFcode, pParam, pMBs, pMB);                                                                  pParam, pMBs, pMB, &Data);
1680    
1681                          if ( x != 0 && y != 0 && x != pParam->mb_width-1 ) { //no edge macroblocks, they just don't work                          if ( x != 0 && y != 0 && x != pParam->mb_width-1 ) { //no edge macroblocks, they just don't work
1682                                  if (sad > INTRA_THRESH) {                                  if (sad > INTRA_THRESH) {

Legend:
Removed from v.544  
changed lines
  Added in v.545

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