[svn] / trunk / xvidcore / src / motion / motion_est.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/motion/motion_est.c

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

revision 171, Sat May 11 12:28:19 2002 UTC revision 172, Sat May 11 15:32:59 2002 UTC
# Line 60  Line 60 
60  #define MV8_00_BIAS     (0)  #define MV8_00_BIAS     (0)
61    
62  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */  /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */
63  #define INTER_BIAS      512  #define MV16_INTER_BIAS 512
64    
65  /* Parameters which control inter/inter4v decision */  /* Parameters which control inter/inter4v decision */
66  #define IMV16X16                        5  #define IMV16X16                        5
# Line 69  Line 69 
69  #define NEIGH_TEND_16X16        2  #define NEIGH_TEND_16X16        2
70  #define NEIGH_TEND_8X8          2  #define NEIGH_TEND_8X8          2
71    
   
72  // fast ((A)/2)*2  // fast ((A)/2)*2
73  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)  #define EVEN(A)         (((A)<0?(A)+1:(A)) & ~1)
74    
75    #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )
76    #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
77    
78  int32_t PMVfastSearch16(  int32_t PMVfastSearch16(
79                                          const uint8_t * const pRef,                                          const uint8_t * const pRef,
# Line 271  Line 272 
272  {  {
273          const uint32_t iWcount = pParam->mb_width;          const uint32_t iWcount = pParam->mb_width;
274          const uint32_t iHcount = pParam->mb_height;          const uint32_t iHcount = pParam->mb_height;
275          MACROBLOCK * pMBs = current->mbs;          MACROBLOCK * const pMBs = current->mbs;
276          IMAGE * pCurrent = &current->image;          MACROBLOCK * const prevMBs = reference->mbs;    // previous frame
   
         MACROBLOCK * prevMBs = reference->mbs;  // previous frame  
         IMAGE * pRef = &reference->image;  
   
277    
278          uint32_t i, j, iIntra = 0;          const IMAGE * const pCurrent = &current->image;
279            const IMAGE * const pRef = &reference->image;
280    
281          VECTOR mv16;          const VECTOR zeroMV = {0,0};
         VECTOR pmv16;  
282    
283          int32_t sad8 = 0;          int32_t x, y;
284          int32_t sad16;          int32_t iIntra = 0;
285          int32_t deviation;          VECTOR pmv;
286    
287          if (sadInit)          if (sadInit)
288                  (*sadInit)();                  (*sadInit)();
289    
290          // note: i==horizontal, j==vertical          for (y = 0; y < iHcount; y++)
291          for (i = 0; i < iHcount; i++)                  for (x = 0; x < iWcount; x++)
                 for (j = 0; j < iWcount; j++)  
292                  {                  {
293                          MACROBLOCK *pMB = &pMBs[j + i * iWcount];                          MACROBLOCK* const pMB = &pMBs[x + y * iWcount];
                         MACROBLOCK *prevMB = &prevMBs[j + i * iWcount];  
   
                         sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,  
                                          j, i, current->motion_flags, current->quant, current->fcode,  
                                          pParam, pMBs, prevMBs, &mv16, &pmv16);  
                         pMB->sad16=sad16;  
294    
295                            pMB->sad16 = SEARCH16(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
296                                             x, y, current->motion_flags, current->quant, current->fcode,
297                                             pParam, pMBs, prevMBs, &pMB->mv16, &pMB->pmvs[0]);
298                    }
299    
300                          /* decide: MODE_INTER or MODE_INTRA          for (y = 0; y < iHcount; y++)
301                             if (dev_intra < sad_inter - 2 * nb) use_intra                  for (x = 0; x < iWcount; x++)
302                          */                  {
303                            MACROBLOCK* const pMB = &pMBs[x + y * iWcount];
304    
305                          deviation = dev16(pCurrent->y + j*16 + i*16*pParam->edged_width, pParam->edged_width);                          if (0 < (pMB->sad16 - MV16_INTER_BIAS))
306                            {
307                                    int32_t deviation;
308                                    deviation = dev16(pCurrent->y + x*16 + y*16*pParam->edged_width,
309                                                             pParam->edged_width);
310    
311                          if (deviation < (sad16 - INTER_BIAS))                                  if (deviation < (pMB->sad16 - MV16_INTER_BIAS))
312                          {                          {
313                                  pMB->mode = MODE_INTRA;                                  pMB->mode = MODE_INTRA;
314                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = 0;                                          pMB->mv16 = pMB->mvs[0] = pMB->mvs[1]
315                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;                                                                   = pMB->mvs[2] = pMB->mvs[3] = zeroMV;
316                                            pMB->sad16 = pMB->sad8[0] = pMB->sad8[1]
317                                  pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = 0;                                                               = pMB->sad8[2] = pMB->sad8[3] = 0;
318    
319                                  iIntra++;                                  iIntra++;
320                                  if(iIntra >= iLimit)                                  if(iIntra >= iLimit)
# Line 323  Line 322 
322    
323                                  continue;                                  continue;
324                          }                          }
325                            }
326    
327                          if (current->global_flags & XVID_INTER4V)                          if ( (current->global_flags & XVID_INTER4V)
328                          {                                  && (!(current->global_flags & XVID_LUMIMASKING)
329                                  pMB->sad8[0] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                          || pMB->dquant == NO_CHANGE) )
330                                                         2 * j, 2 * i, mv16.x, mv16.y,                          {
331                                    int32_t sad8 = 129; //IMV16X16 * current->quant;
332    
333                                    if (sad8 < pMB->sad16)
334                                    sad8 += pMB->sad8[0]
335                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
336                                                           2*x, 2*y, pMB->mv16.x, pMB->mv16.y,
337                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
338                                                         pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[0], &pMB->pmvs[0]);
339    
340                                  pMB->sad8[1] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
341                                                         2 * j + 1, 2 * i, mv16.x, mv16.y,                                  sad8 += pMB->sad8[1]
342                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
343                                   2*x+1, 2*y, pMB->mv16.x, pMB->mv16.y,
344                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
345                                                         pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[1], &pMB->pmvs[1]);
346    
347                                  pMB->sad8[2] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
348                                                         2 * j, 2 * i + 1, mv16.x, mv16.y,                                  sad8 += pMB->sad8[2]
349                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
350                                                    2*x, 2*y+1, pMB->mv16.x, pMB->mv16.y,
351                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
352                                                         pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[2], &pMB->pmvs[2]);
353    
354                                  pMB->sad8[3] = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,                                  if (sad8 < pMB->sad16)
355                                                         2 * j + 1, 2 * i + 1, mv16.x, mv16.y,                                  sad8 += pMB->sad8[3]
356                                            = SEARCH8(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent,
357                                                    2*x+1, 2*y+1, pMB->mv16.x, pMB->mv16.y,
358                                                             current->motion_flags, current->quant, current->fcode,                                                             current->motion_flags, current->quant, current->fcode,
359                                                         pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);                                                         pParam, pMBs, prevMBs, &pMB->mvs[3], &pMB->pmvs[3]);
360    
                                 sad8 = pMB->sad8[0] + pMB->sad8[1] + pMB->sad8[2] + pMB->sad8[3];  
                         }  
   
   
361                          /* decide: MODE_INTER or MODE_INTER4V                          /* decide: MODE_INTER or MODE_INTER4V
362                             mpeg4:   if (sad8 < sad16 - nb/2+1) use_inter4v                             mpeg4:   if (sad8 < pMB->sad16 - nb/2+1) use_inter4v
363                          */                          */
364    
365                          if (!(current->global_flags & XVID_LUMIMASKING) || pMB->dquant == NO_CHANGE)                                  if (sad8 < pMB->sad16)
                         {  
                                 if (((current->global_flags & XVID_INTER4V)==0) ||  
                                     (sad16 < (sad8 + (int32_t)(IMV16X16 * current->quant))))  
                                 {  
   
                                         sad8 = sad16;  
                                         pMB->mode = MODE_INTER;  
                                         pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;  
                                         pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;  
                                         pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;  
                                         pMB->pmvs[0].x = pmv16.x;  
                                         pMB->pmvs[0].y = pmv16.y;  
                                 }  
                                 else  
366                                  {                                  {
367                                          pMB->mode = MODE_INTER4V;                                          pMB->mode = MODE_INTER4V;
368                                          pMB->sad8[0] *= 4;                                          pMB->sad8[0] *= 4;
369                                          pMB->sad8[1] *= 4;                                          pMB->sad8[1] *= 4;
370                                          pMB->sad8[2] *= 4;                                          pMB->sad8[2] *= 4;
371                                          pMB->sad8[3] *= 4;                                          pMB->sad8[3] *= 4;
372                                            continue;
373                                  }                                  }
374                          }                          }
375                          else  
                         {  
                                 sad8 = sad16;  
376                                  pMB->mode = MODE_INTER;                                  pMB->mode = MODE_INTER;
377                                  pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x;                          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->mv16;
378                                  pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y;           pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = pMB->sad16;
379                                  pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16;  
380                            if (current->global_flags & XVID_INTER4V)
381                            {       pmv = get_pmv(pMBs, x, y, pParam->mb_width, 0);
382                                    // get_pmv has to be called again. inter4v changes predictors
383    
384                                  pMB->pmvs[0].x = pmv16.x;                                  pMB->pmvs[0].x = pMB->mv16.x - pmv.x;
385                                  pMB->pmvs[0].y = pmv16.y;                                  pMB->pmvs[0].y = pMB->mv16.y - pmv.y;
386                          }                          }
387                  }                  }
   
388          return 0;          return 0;
389  }  }
390    
 #define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) )  
   
 #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  
   
   
391  #define CHECK_MV16_ZERO {\  #define CHECK_MV16_ZERO {\
392    if ( (0 <= max_dx) && (0 >= min_dx) \    if ( (0 <= max_dx) && (0 >= min_dx) \
393      && (0 <= max_dy) && (0 >= min_dy) ) \      && (0 <= max_dy) && (0 >= min_dy) ) \
# Line 861  Line 851 
851          VECTOR pmv[4];          VECTOR pmv[4];
852          int32_t psad[4];          int32_t psad[4];
853    
854          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;  //      const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
855          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
856    
857          static int32_t threshA,threshB;          static int32_t threshA,threshB;
# Line 1259  Line 1249 
1249          VECTOR backupMV;          VECTOR backupMV;
1250          VECTOR startMV;          VECTOR startMV;
1251    
1252          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;  //      const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1253          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1254    
1255          static int32_t threshA,threshB;          static int32_t threshA,threshB;
# Line 1551  Line 1541 
1541          int32_t psad[8];          int32_t psad[8];
1542    
1543          static MACROBLOCK * oldMBs = NULL;          static MACROBLOCK * oldMBs = NULL;
1544          const MACROBLOCK * const pMB = pMBs + x + y * iWcount;  //      const MACROBLOCK * const pMB = pMBs + x + y * iWcount;
1545          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;          const MACROBLOCK * const prevMB = prevMBs + x + y * iWcount;
1546          MACROBLOCK * oldMB = NULL;          MACROBLOCK * oldMB = NULL;
1547    
# Line 1838  Line 1828 
1828    
1829          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);          const   int32_t iSubBlock = ((y&1)<<1) + (x&1);
1830    
1831          const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;  //      const MACROBLOCK * const pMB = pMBs + (x>>1) + (y>>1) * iWcount;
1832          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;          const MACROBLOCK * const prevMB = prevMBs + (x>>1) + (y>>1) * iWcount;
1833    
1834          int32_t bPredEq;          int32_t bPredEq;

Legend:
Removed from v.171  
changed lines
  Added in v.172

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