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

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

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

revision 978, Tue Apr 8 15:35:52 2003 UTC revision 1010, Tue May 6 23:41:29 2003 UTC
# Line 200  Line 200 
200  GetReferenceB(const int x, const int y, const uint32_t dir, const SearchData * const data)  GetReferenceB(const int x, const int y, const uint32_t dir, const SearchData * const data)
201  {  {
202  //      dir : 0 = forward, 1 = backward  //      dir : 0 = forward, 1 = backward
203          const uint8_t* const *direction = ( dir == 0 ? data->RefP : data->b_RefP );          const uint8_t *const *const direction = ( dir == 0 ? data->RefP : data->b_RefP );
204          const int picture = ((x&1)<<1) | (y&1);          const int picture = ((x&1)<<1) | (y&1);
205          const int offset = (x>>1) + (y>>1)*data->iEdgedWidth;          const int offset = (x>>1) + (y>>1)*data->iEdgedWidth;
206          return direction[picture] + offset;          return direction[picture] + offset;
# Line 351  Line 351 
351                  data->iMinSAD[3] = data->temp[3]; current[3].x = x; current[3].y = y; }                  data->iMinSAD[3] = data->temp[3]; current[3].x = x; current[3].y = y; }
352          if (data->temp[4] < data->iMinSAD[4]) {          if (data->temp[4] < data->iMinSAD[4]) {
353                  data->iMinSAD[4] = data->temp[4]; current[4].x = x; current[4].y = y; }                  data->iMinSAD[4] = data->temp[4]; current[4].x = x; current[4].y = y; }
   
354  }  }
355    
356  static void  static void
# Line 384  Line 383 
383          }          }
384  }  }
385    
   
386  static void  static void
387  CheckCandidate32(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidate32(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
388  {  {
# Line 465  Line 463 
463          if ( (x > data->max_dx) || (x < data->min_dx)          if ( (x > data->max_dx) || (x < data->min_dx)
464                  || (y > data->max_dy) || (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
465    
466          sad = sad32v_c(data->Cur, data->RefP[0] + x/2 + (y/2)*(data->iEdgedWidth),          sad = sad32v_c(data->Cur, data->RefP[0] + (x>>1) + (y>>1)*(data->iEdgedWidth),
467                                                          data->iEdgedWidth, data->temp+1);                                                          data->iEdgedWidth, data->temp+1);
468    
469          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
# Line 1052  Line 1050 
1050                                  if (quant > 31) quant = 31;                                  if (quant > 31) quant = 31;
1051                                  else if (quant < 1) quant = 1;                                  else if (quant < 1) quant = 1;
1052                          }                          }
   
1053                          pMB->quant = current->quant;                          pMB->quant = current->quant;
1054    
1055  //initial skip decision  //initial skip decision
# Line 1084  Line 1081 
1081          }          }
1082    
1083          if (current->vol_flags & XVID_VOL_GMC ) /* GMC only for S(GMC)-VOPs */          if (current->vol_flags & XVID_VOL_GMC ) /* GMC only for S(GMC)-VOPs */
1084            {
1085                  current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV);                  current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV);
1086            }
1087          return 0;          return 0;
1088  }  }
1089    
# Line 1220  Line 1218 
1218                          if (bits_inter4v < bits) { Data->iMinSAD[0] = bits = bits_inter4v; mode = MODE_INTER4V; }                          if (bits_inter4v < bits) { Data->iMinSAD[0] = bits = bits_inter4v; mode = MODE_INTER4V; }
1219                  }                  }
1220    
   
1221                  intra = CountMBBitsIntra(Data);                  intra = CountMBBitsIntra(Data);
1222    
1223                  if (intra < bits) { *Data->iMinSAD = bits = intra; return MODE_INTRA; }                  if (intra < bits) { *Data->iMinSAD = bits = intra; return MODE_INTRA; }
# Line 1359  Line 1356 
1356          }          }
1357    
1358          if (MotionFlags & XVID_ME_HALFPELREFINE16)          if (MotionFlags & XVID_ME_HALFPELREFINE16)
                 if ((!(MotionFlags & XVID_ME_HALFPELREFINE16_BITS)) || Data->iMinSAD[0] < 200*(int)iQuant)  
1359                          SubpelRefine(Data);                          SubpelRefine(Data);
1360    
1361          for(i = 0; i < 5; i++) {          for(i = 0; i < 5; i++) {
# Line 1371  Line 1367 
1367    
1368                  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,
1369                                  pParam->width, pParam->height, Data->iFcode, 1, 0);                                  pParam->width, pParam->height, Data->iFcode, 1, 0);
   
                 if ((!(MotionFlags & XVID_ME_QUARTERPELREFINE16_BITS)) || (Data->iMinSAD[0] < 200*(int)iQuant)) {  
1370                          Data->qpel_precision = 1;                          Data->qpel_precision = 1;
1371                          SubpelRefine(Data);                          SubpelRefine(Data);
1372                  }                  }
         }  
1373    
1374          if ((!(VopFlags & XVID_VOP_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;
1375    
1376          if (inter4v && (!(VopFlags & XVID_VOP_MODEDECISION_BITS) ||          if (inter4v) {
                         (!(MotionFlags & XVID_ME_QUARTERPELREFINE8_BITS)) || (!(MotionFlags & XVID_ME_HALFPELREFINE8_BITS)) ||  
                         ((!(MotionFlags & XVID_ME_EXTSEARCH_BITS)) && (!(MotionFlags&XVID_ME_EXTSEARCH8)) ))) {  
                 // if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop  
   
1377                  SearchData Data8;                  SearchData Data8;
1378                  memcpy(&Data8, Data, sizeof(SearchData)); //quick copy of common data                  memcpy(&Data8, Data, sizeof(SearchData)); //quick copy of common data
1379    
# Line 1396  Line 1385 
1385                  if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_BITS))) {                  if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_BITS))) {
1386                          // 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
1387                          int sumx = 0, sumy = 0;                          int sumx = 0, sumy = 0;
1388                          const int div = 1 + Data->qpel;                          const int div = Data->qpel ? 2 : 1;
1389                          const VECTOR * const mv = Data->qpel ? pMB->qmvs : pMB->mvs;                          const VECTOR * const mv = Data->qpel ? pMB->qmvs : pMB->mvs;
1390    
1391                          for (i = 0; i < 4; i++) {                          for (i = 0; i < 4; i++) {
# Line 2189  Line 2178 
2178          }          }
2179  }  }
2180    
2181  #define INTRA_THRESH    2400  #define INTRA_THRESH    1800
2182  #define INTER_THRESH    1300  #define INTER_THRESH    1200
2183    
2184  int  int
2185  MEanalysis(     const IMAGE * const pRef,  MEanalysis(     const IMAGE * const pRef,
# Line 2219  Line 2208 
2208          CheckCandidate = CheckCandidate32I;          CheckCandidate = CheckCandidate32I;
2209    
2210          if (intraCount != 0 && intraCount < 10) // we're right after an I frame          if (intraCount != 0 && intraCount < 10) // we're right after an I frame
2211                  IntraThresh += 8 * (intraCount - 10) * (intraCount - 10);                  IntraThresh += 15 * (intraCount - 10) * (intraCount - 10);
2212          else          else
2213                  if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec                  if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec
2214                          IntraThresh -= (IntraThresh * (maxIntra - 5*(maxIntra - intraCount)))/maxIntra;                          IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra;
2215    
2216          InterThresh -= (350 - 8*b_thresh) * bCount;          InterThresh -= (350 - 8*b_thresh) * bCount;
2217          if (InterThresh < 300 + 5*b_thresh) InterThresh = 300 + 5*b_thresh;          if (InterThresh < 300 + 5*b_thresh) InterThresh = 300 + 5*b_thresh;
# Line 2265  Line 2254 
2254          sSAD /= blocks;          sSAD /= blocks;
2255          s = (10*s) / blocks;          s = (10*s) / blocks;
2256    
2257          if (s > 4) sSAD += (s - 3) * (300 - 2*b_thresh); //static block - looks bad when in bframe...          if (s > 4) sSAD += (s - 2) * (60 - 2*b_thresh); //static block - looks bad when in bframe...
2258    
2259          if (sSAD > InterThresh ) return P_VOP;          if (sSAD > InterThresh ) return P_VOP;
2260          emms();          emms();
# Line 2319  Line 2308 
2308                  if (pMB->mode == MODE_INTRA || pMB->mode == MODE_NOT_CODED)                  if (pMB->mode == MODE_INTRA || pMB->mode == MODE_NOT_CODED)
2309                          continue;                          continue;
2310    
2311                  if ( ( (ABS(mv.x -   (pMB-1)->mvs[0].x) < deltax) && (ABS(mv.y -   (pMB-1)->mvs[0].y) < deltay) )                  if ( ( (abs(mv.x -   (pMB-1)->mvs[0].x) < deltax) && (abs(mv.y -   (pMB-1)->mvs[0].y) < deltay) )
2312                  &&   ( (ABS(mv.x -   (pMB+1)->mvs[0].x) < deltax) && (ABS(mv.y -   (pMB+1)->mvs[0].y) < deltay) )                  &&   ( (abs(mv.x -   (pMB+1)->mvs[0].x) < deltax) && (abs(mv.y -   (pMB+1)->mvs[0].y) < deltay) )
2313                  &&   ( (ABS(mv.x - (pMB-MBw)->mvs[0].x) < deltax) && (ABS(mv.y - (pMB-MBw)->mvs[0].y) < deltay) )                  &&   ( (abs(mv.x - (pMB-MBw)->mvs[0].x) < deltax) && (abs(mv.y - (pMB-MBw)->mvs[0].y) < deltay) )
2314                  &&   ( (ABS(mv.x - (pMB+MBw)->mvs[0].x) < deltax) && (ABS(mv.y - (pMB+MBw)->mvs[0].y) < deltay) ) )                  &&   ( (abs(mv.x - (pMB+MBw)->mvs[0].x) < deltax) && (abs(mv.y - (pMB+MBw)->mvs[0].y) < deltay) ) )
2315                          MBmask[mbnum]=1;                          MBmask[mbnum]=1;
2316          }          }
2317    
# Line 2397  Line 2386 
2386                                  continue;                                  continue;
2387    
2388                          oldnum++;                          oldnum++;
2389                          meanx += ABS(( sol[0] + (16*mx+8)*sol[1] + (16*my+8)*sol[2] ) - mv.x );                          meanx += fabs(( sol[0] + (16*mx+8)*sol[1] + (16*my+8)*sol[2] ) - mv.x );
2390                          meany += ABS(( sol[3] - (16*mx+8)*sol[2] + (16*my+8)*sol[1] ) - mv.y );                          meany += fabs(( sol[3] - (16*mx+8)*sol[2] + (16*my+8)*sol[1] ) - mv.y );
2391                  }                  }
2392    
2393          if (4*meanx > oldnum)   /* better fit than 0.25 is useless */          if (4*meanx > oldnum)   /* better fit than 0.25 is useless */
# Line 2425  Line 2414 
2414                          if (!MBmask[mbnum])                          if (!MBmask[mbnum])
2415                                  continue;                                  continue;
2416    
2417                          if  ( ( ABS(( sol[0] + (16*mx+8)*sol[1] + (16*my+8)*sol[2] ) - mv.x ) > meanx )                          if  ( ( fabs(( sol[0] + (16*mx+8)*sol[1] + (16*my+8)*sol[2] ) - mv.x ) > meanx )
2418                             || ( ABS(( sol[3] - (16*mx+8)*sol[2] + (16*my+8)*sol[1] ) - mv.y ) > meany ) )                                  || ( fabs(( sol[3] - (16*mx+8)*sol[2] + (16*my+8)*sol[1] ) - mv.y ) > meany ) )
2419                                  MBmask[mbnum]=0;                                  MBmask[mbnum]=0;
2420                          else                          else
2421                                  num++;                                  num++;
# Line 2569  Line 2558 
2558    
2559                  Data8->qpel_precision = Data8->qpel;                  Data8->qpel_precision = Data8->qpel;
2560                  // checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far)                  // checking the vector which has been found by SAD-based 8x8 search (if it's different than the one found so far)
2561                  if (Data8->qpel) {                  {
2562                          if (!(Data8->currentQMV->x == backup[i+1].x && Data8->currentQMV->y == backup[i+1].y))                          VECTOR *v = Data8->qpel ? Data8->currentQMV : Data8->currentMV;
2563                                  CheckCandidateBits8(backup[i+1].x, backup[i+1].y, 255, &iDirection, Data8);                          if (!( (v->x == backup[i+1].x) && (v->y == backup[i+1].y) ))
                 } else {  
                         if (!(Data8->currentMV->x == backup[i+1].x && Data8->currentMV->y == backup[i+1].y))  
2564                                  CheckCandidateBits8(backup[i+1].x, backup[i+1].y, 255, &iDirection, Data8);                                  CheckCandidateBits8(backup[i+1].x, backup[i+1].y, 255, &iDirection, Data8);
2565                  }                  }
2566    

Legend:
Removed from v.978  
changed lines
  Added in v.1010

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