[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 871, Wed Feb 19 10:13:54 2003 UTC branches/dev-api-4/xvidcore/src/motion/motion_est.c revision 926, Sun Mar 16 12:05:09 2003 UTC
# Line 46  Line 46 
46  #include "../utils/emms.h"  #include "../utils/emms.h"
47  #include "../dct/fdct.h"  #include "../dct/fdct.h"
48    
49    /*****************************************************************************
50     * Modified rounding tables -- declared in motion.h
51     * Original tables see ISO spec tables 7-6 -> 7-9
52     ****************************************************************************/
53    
54    const uint32_t roundtab[16] =
55    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
56    
57    /* K = 4 */
58    const uint32_t roundtab_76[16] =
59    { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 };
60    
61    /* K = 2 */
62    const uint32_t roundtab_78[8] =
63    { 0, 0, 1, 1, 0, 0, 0, 1  };
64    
65    /* K = 1 */
66    const uint32_t roundtab_79[4] =
67    { 0, 1, 0, 0 };
68    
69  #define INITIAL_SKIP_THRESH     (10)  #define INITIAL_SKIP_THRESH     (10)
70  #define FINAL_SKIP_THRESH       (50)  #define FINAL_SKIP_THRESH       (50)
71  #define MAX_SAD00_FOR_SKIP      (20)  #define MAX_SAD00_FOR_SKIP      (20)
# Line 54  Line 74 
74  #define CHECK_CANDIDATE(X,Y,D) { \  #define CHECK_CANDIDATE(X,Y,D) { \
75  CheckCandidate((X),(Y), (D), &iDirection, data ); }  CheckCandidate((X),(Y), (D), &iDirection, data ); }
76    
77    /*****************************************************************************
78     * Code
79     ****************************************************************************/
80    
81  static __inline uint32_t  static __inline uint32_t
82  d_mv_bits(int x, int y, const VECTOR pred, const uint32_t iFcode, const int qpel, const int rrv)  d_mv_bits(int x, int y, const VECTOR pred, const uint32_t iFcode, const int qpel, const int rrv)
83  {  {
# Line 971  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 991  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_QUARTERPEL;
1019          Data.chroma = MotionFlags & PMV_CHROMA16;          Data.chroma = MotionFlags & PMV_CHROMA16;
1020          Data.rrv = current->global_flags & XVID_REDUCED;          Data.rrv = current->vop_flags & XVID_REDUCED;
1021    
1022          if ((current->global_flags & XVID_REDUCED)) {          if ((current->vop_flags & XVID_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 1028  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_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 1050  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_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_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_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 1073  Line 1086 
1086                  }                  }
1087          }          }
1088    
1089          if (current->global_flags & XVID_GMC )  /* GMC only for S(GMC)-VOPs */          if (current->vol_flags & XVID_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 1148  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_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 1196  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_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 1230  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 1265  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 1280  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_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 1306  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_MODEDECISION_BITS)) inter4v = 0;  }
1323          else {          else {
1324    
1325                  MainSearchFunc * MainSearchPtr;                  MainSearchFunc * MainSearchPtr;
# Line 1369  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_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0;
1386    
1387          if (inter4v && (!(GlobalFlags & XVID_MODEDECISION_BITS) ||          if (inter4v && (!(VopFlags & XVID_MODEDECISION_BITS) ||
1388                          (!(MotionFlags & QUARTERPELREFINE8_BITS)) || (!(MotionFlags & HALFPELREFINE8_BITS)) ||                          (!(MotionFlags & QUARTERPELREFINE8_BITS)) || (!(MotionFlags & HALFPELREFINE8_BITS)) ||
1389                          ((!(MotionFlags & EXTSEARCH_BITS)) && (!(MotionFlags&PMV_EXTSEARCH8)) ))) {                          ((!(MotionFlags & EXTSEARCH_BITS)) && (!(MotionFlags&PMV_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
# Line 1384  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_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 1400  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 2014  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_QUARTERPEL;
2031          Data.rounding = 0;          Data.rounding = 0;
2032          Data.chroma = frame->motion_flags & PMV_CHROMA8;          Data.chroma = frame->motion_flags & PMV_CHROMA8;
2033          Data.temp = temp;          Data.temp = temp;
# Line 2039  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 2139  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_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 2196  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_REDUCED;
2212          Data.temp = temp;          Data.temp = temp;
2213          CheckCandidate = CheckCandidate32I;          CheckCandidate = CheckCandidate32I;
2214    
# Line 2279  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 2296  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 2305  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 2318  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 2356  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 2385  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];

Legend:
Removed from v.871  
changed lines
  Added in v.926

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