[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 904, Tue Mar 4 11:00:53 2003 UTC revision 973, Sat Apr 5 15:54:59 2003 UTC
# Line 81  Line 81 
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  {  {
84          int xb, yb;          int bits;
85          x = qpel ? x<<1 : x;          const int q = (1 << (iFcode - 1)) - 1;
86          y = qpel ? y<<1 : y;  
87            x <<= qpel;
88            y <<= qpel;
89          if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); }          if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); }
90    
91          x -= pred.x;          x -= pred.x;
92          y -= pred.y;          bits = (x != 0 ? iFcode:0);
93            x = abs(x);
94          if (x) {          x += q;
                 x = ABS(x);  
                 x += (1 << (iFcode - 1)) - 1;  
95                  x >>= (iFcode - 1);                  x >>= (iFcode - 1);
96                  if (x > 32) x = 32;          bits += mvtab[x];
97                  xb = mvtab[x] + iFcode;  
98          } else xb = 1;          y -= pred.y;
99            bits += (y != 0 ? iFcode:0);
100          if (y) {          y = abs(y);
101                  y = ABS(y);          y += q;
                 y += (1 << (iFcode - 1)) - 1;  
102                  y >>= (iFcode - 1);                  y >>= (iFcode - 1);
103                  if (y > 32) y = 32;          bits += mvtab[y];
104                  yb = mvtab[y] + iFcode;  
105          } else yb = 1;          return bits;
         return xb + yb;  
106  }  }
107    
108  static int32_t ChromaSAD2(int fx, int fy, int bx, int by, const SearchData * const data)  static int32_t ChromaSAD2(int fx, int fy, int bx, int by, const SearchData * const data)
# Line 249  Line 247 
247          ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data);          ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data);
248          ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;          ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;
249          switch( ((x&1)<<1) + (y&1) ) {          switch( ((x&1)<<1) + (y&1) ) {
250          case 0: // pure halfpel position          case 3: // x and y in qpel resolution - the "corners" (top left/right and
251                  return (uint8_t *) ref1;                          // bottom left/right) during qpel refinement
252                    ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data);
253                    ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data);
254                    ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data);
255                    ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;
256                    ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;
257                    ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;
258                    interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);
259                  break;                  break;
260    
261          case 1: // x halfpel, y qpel - top or bottom during qpel refinement          case 1: // x halfpel, y qpel - top or bottom during qpel refinement
# Line 265  Line 270 
270                  interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8);                  interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8);
271                  break;                  break;
272    
273          default: // x and y in qpel resolution - the "corners" (top left/right and          default: // pure halfpel position
274                           // bottom left/right) during qpel refinement                  return (uint8_t *) ref1;
275                  ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data);  
                 ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data);  
                 ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data);  
                 ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;  
                 ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;  
                 ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth;  
                 interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);  
                 break;  
276          }          }
277          return Reference;          return Reference;
278  }  }
# Line 319  Line 317 
317                  interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding, 8);                  interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding, 8);
318                  break;                  break;
319    
320          case 0: // pure halfpel position          default: // pure halfpel position
321                  return (uint8_t *) ref1;                  return (uint8_t *) ref1;
322          }          }
323          return Reference;          return Reference;
# Line 379  Line 377 
377  {  {
378          int32_t sad; uint32_t t;          int32_t sad; uint32_t t;
379          const uint8_t * Reference;          const uint8_t * Reference;
380            VECTOR * current;
381    
382          if ( (x > data->max_dx) || (x < data->min_dx)          if ( (x > data->max_dx) || (x < data->min_dx)
383                  || (y > data->max_dy) || (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
384    
385          if (!data->qpel_precision) Reference = GetReference(x, y, data);          if (!data->qpel_precision) {
386          else Reference = Interpolate8x8qpel(x, y, 0, 0, data);                  Reference = GetReference(x, y, data);
387                    current = data->currentMV;
388            } else { // x and y are in 1/4 precision
389                    Reference = Interpolate8x8qpel(x, y, 0, 0, data);
390                    current = data->currentQMV;
391            }
392    
393          sad = sad8(data->Cur, Reference, data->iEdgedWidth);          sad = sad8(data->Cur, Reference, data->iEdgedWidth);
394          t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);          t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
# Line 393  Line 397 
397    
398          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
399                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
400                  data->currentMV->x = x; data->currentMV->y = y;                  current->x = x; current->y = y;
401                  *dir = Direction;                  *dir = Direction;
402          }          }
403  }  }
# Line 405  Line 409 
409          uint32_t t;          uint32_t t;
410          const uint8_t * Reference;          const uint8_t * Reference;
411    
412          if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero integer value          if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero even value
413                  (x > data->max_dx) || (x < data->min_dx)                  (x > data->max_dx) || (x < data->min_dx)
414                  || (y > data->max_dy) || (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
415    
# Line 440  Line 444 
444          uint32_t t;          uint32_t t;
445          VECTOR * current;          VECTOR * current;
446    
447          if ( (x > data->max_dx) | ( x < data->min_dx)          if ( (x > data->max_dx) || ( x < data->min_dx)
448                  | (y > data->max_dy) | (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
449    
450          if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; //non-zero even value          if (data->rrv && (!(x&1) && x !=0) | (!(y&1) && y !=0) ) return; //non-zero even value
451    
# Line 506  Line 510 
510          const uint8_t *ReferenceF, *ReferenceB;          const uint8_t *ReferenceF, *ReferenceB;
511          VECTOR *current;          VECTOR *current;
512    
513          if ( (xf > data->max_dx) || (xf < data->min_dx)          if ((xf > data->max_dx) || (xf < data->min_dx) ||
514                  || (yf > data->max_dy) || (yf < data->min_dy) ) return;                  (yf > data->max_dy) || (yf < data->min_dy))
515                    return;
516    
517          if (!data->qpel_precision) {          if (!data->qpel_precision) {
518                  ReferenceF = GetReference(xf, yf, data);                  ReferenceF = GetReference(xf, yf, data);
# Line 565  Line 570 
570                          data->directmvB[k].y                          data->directmvB[k].y
571                          : mvs.y - data->referencemv[k].y);                          : mvs.y - data->referencemv[k].y);
572    
573                  if ( (mvs.x > data->max_dx) || (mvs.x < data->min_dx)                  if ((mvs.x > data->max_dx)   || (mvs.x < data->min_dx)   ||
574                          || (mvs.y > data->max_dy) || (mvs.y < data->min_dy)                          (mvs.y > data->max_dy)   || (mvs.y < data->min_dy)   ||
575                          || (b_mvs.x > data->max_dx) || (b_mvs.x < data->min_dx)                          (b_mvs.x > data->max_dx) || (b_mvs.x < data->min_dx) ||
576                          || (b_mvs.y > data->max_dy) || (b_mvs.y < data->min_dy) ) return;                          (b_mvs.y > data->max_dy) || (b_mvs.y < data->min_dy) )
577                            return;
578    
579                  if (data->qpel) {                  if (data->qpel) {
580                          xcf += mvs.x/2; ycf += mvs.y/2;                          xcf += mvs.x/2; ycf += mvs.y/2;
# Line 610  Line 616 
616          const uint8_t *ReferenceB;          const uint8_t *ReferenceB;
617          VECTOR mvs, b_mvs;          VECTOR mvs, b_mvs;
618    
619          if (( x > 31) | ( x < -32) | ( y > 31) | (y < -32)) return;          if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return;
620    
621          mvs.x = data->directmvF[0].x + x;          mvs.x = data->directmvF[0].x + x;
622          b_mvs.x = ((x == 0) ?          b_mvs.x = ((x == 0) ?
# Line 622  Line 628 
628                  data->directmvB[0].y                  data->directmvB[0].y
629                  : mvs.y - data->referencemv[0].y);                  : mvs.y - data->referencemv[0].y);
630    
631          if ( (mvs.x > data->max_dx) | (mvs.x < data->min_dx)          if ( (mvs.x > data->max_dx) || (mvs.x < data->min_dx)
632                  | (mvs.y > data->max_dy) | (mvs.y < data->min_dy)                  || (mvs.y > data->max_dy) || (mvs.y < data->min_dy)
633                  | (b_mvs.x > data->max_dx) | (b_mvs.x < data->min_dx)                  || (b_mvs.x > data->max_dx) || (b_mvs.x < data->min_dx)
634                  | (b_mvs.y > data->max_dy) | (b_mvs.y < data->min_dy) ) return;                  || (b_mvs.y > data->max_dy) || (b_mvs.y < data->min_dy) ) return;
635    
636          if (data->qpel) {          if (data->qpel) {
637                  xcf = 4*(mvs.x/2); ycf = 4*(mvs.y/2);                  xcf = 4*(mvs.x/2); ycf = 4*(mvs.y/2);
# Line 659  Line 665 
665  CheckCandidateBits16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidateBits16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
666  {  {
667    
668          static int16_t in[64], coeff[64];          int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64;
669          int32_t bits = 0, sum;          int32_t bits = 0, sum;
670          VECTOR * current;          VECTOR * current;
671          const uint8_t * ptr;          const uint8_t * ptr;
# Line 744  Line 750 
750  CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
751  {  {
752    
753          static int16_t in[64], coeff[64];          int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64;
754          int32_t sum, bits;          int32_t sum, bits;
755          VECTOR * current;          VECTOR * current;
756          const uint8_t * ptr;          const uint8_t * ptr;
# Line 950  Line 956 
956                                                          const uint32_t stride, const uint32_t iQuant, int rrv)                                                          const uint32_t stride, const uint32_t iQuant, int rrv)
957    
958  {  {
959            int offset = (x + y*stride)*8;
960          if(!rrv) {          if(!rrv) {
961                  uint32_t sadC = sad8(current->u + x*8 + y*stride*8,                  uint32_t sadC = sad8(current->u + offset,
962                                                  reference->u + x*8 + y*stride*8, stride);                                                  reference->u + offset, stride);
963                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;
964                  sadC += sad8(current->v + (x + y*stride)*8,                  sadC += sad8(current->v + offset,
965                                                  reference->v + (x + y*stride)*8, stride);                                                  reference->v + offset, stride);
966                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;
967                  return 1;                  return 1;
968    
969          } else {          } else {
970                  uint32_t sadC = sad16(current->u + x*16 + y*stride*16,                  uint32_t sadC = sad16(current->u + 2*offset,
971                                                  reference->u + x*16 + y*stride*16, stride, 256*4096);                                                  reference->u + 2*offset, stride, 256*4096);
972                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0;                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0;
973                  sadC += sad16(current->v + (x + y*stride)*16,                  sadC += sad16(current->v + 2*offset,
974                                                  reference->v + (x + y*stride)*16, stride, 256*4096);                                                  reference->v + 2*offset, stride, 256*4096);
975                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0;                  if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0;
976                  return 1;                  return 1;
977          }          }
# Line 1009  Line 1016 
1016          VECTOR currentMV[5];          VECTOR currentMV[5];
1017          VECTOR currentQMV[5];          VECTOR currentQMV[5];
1018          int32_t iMinSAD[5];          int32_t iMinSAD[5];
1019            DECLARE_ALIGNED_MATRIX(dct_space, 2, 64, int16_t, CACHE_LINE);
1020          SearchData Data;          SearchData Data;
1021          memset(&Data, 0, sizeof(SearchData));          memset(&Data, 0, sizeof(SearchData));
1022          Data.iEdgedWidth = iEdgedWidth;          Data.iEdgedWidth = iEdgedWidth;
# Line 1021  Line 1029 
1029          Data.qpel = pParam->m_quarterpel;          Data.qpel = pParam->m_quarterpel;
1030          Data.chroma = MotionFlags & PMV_CHROMA16;          Data.chroma = MotionFlags & PMV_CHROMA16;
1031          Data.rrv = current->global_flags & XVID_REDUCED;          Data.rrv = current->global_flags & XVID_REDUCED;
1032            Data.dctSpace = dct_space;
1033    
1034          if ((current->global_flags & XVID_REDUCED)) {          if ((current->global_flags & XVID_REDUCED)) {
1035                  mb_width = (pParam->width + 31) / 32;                  mb_width = (pParam->width + 31) / 32;
# Line 1175  Line 1184 
1184          int mode = MODE_INTER;          int mode = MODE_INTER;
1185    
1186          if (!(GlobalFlags & XVID_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision          if (!(GlobalFlags & XVID_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision
 //              int intra = 0;  
1187                  int sad;                  int sad;
1188                  int InterBias = MV16_INTER_BIAS;                  int InterBias = MV16_INTER_BIAS;
1189                  if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] +                  if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] +
1190                          Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) {                          Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) {
1191                                  mode = 0; //inter                          mode = MODE_INTER;
1192                                  sad = Data->iMinSAD[0];                                  sad = Data->iMinSAD[0];
1193                  } else {                  } else {
1194                          mode = MODE_INTER4V;                          mode = MODE_INTER4V;
# Line 1208  Line 1216 
1216                                  dev16(Data->Cur + 8*Data->iEdgedWidth, Data->iEdgedWidth) +                                  dev16(Data->Cur + 8*Data->iEdgedWidth, Data->iEdgedWidth) +
1217                                  dev16(Data->Cur+8+8*Data->iEdgedWidth, Data->iEdgedWidth);                                  dev16(Data->Cur+8+8*Data->iEdgedWidth, Data->iEdgedWidth);
1218    
1219                          if (deviation < (sad - InterBias))  return MODE_INTRA;// intra                          if (deviation < (sad - InterBias)) return MODE_INTRA;
1220                  }                  }
1221                  return mode;                  return mode;
1222    
# Line 1229  Line 1237 
1237                  if (bits == 0) return MODE_INTER; // quick stop                  if (bits == 0) return MODE_INTER; // quick stop
1238    
1239                  if (inter4v) {                  if (inter4v) {
1240                          int inter4v = CountMBBitsInter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);                          int bits_inter4v = CountMBBitsInter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup);
1241                          if (inter4v < bits) { Data->iMinSAD[0] = bits = inter4v; mode = MODE_INTER4V; }                          if (bits_inter4v < bits) { Data->iMinSAD[0] = bits = bits_inter4v; mode = MODE_INTER4V; }
1242                  }                  }
1243    
1244    
# Line 1288  Line 1296 
1296    
1297          if (pMB->dquant != NO_CHANGE) inter4v = 0;          if (pMB->dquant != NO_CHANGE) inter4v = 0;
1298    
1299          for(i = 0; i < 5; i++)          memset(Data->currentMV, 0, 5*sizeof(VECTOR));
                 Data->currentMV[i].x = Data->currentMV[i].y = 0;  
1300    
1301          if (Data->qpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0);          if (Data->qpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0);
1302          else Data->predMV = pmv[0];          else Data->predMV = pmv[0];
# Line 1711  Line 1718 
1718    
1719          for (k = 0; k < 4; k++) {          for (k = 0; k < 4; k++) {
1720                  dy += Data->directmvF[k].y / div;                  dy += Data->directmvF[k].y / div;
1721                  dx += Data->directmvF[0].x / div;                  dx += Data->directmvF[k].x / div;
1722                  b_dy += Data->directmvB[0].y / div;                  b_dy += Data->directmvB[k].y / div;
1723                  b_dx += Data->directmvB[0].x / div;                  b_dx += Data->directmvB[k].x / div;
1724          }          }
1725    
1726          dy = (dy >> 3) + roundtab_76[dy & 0xf];          dy = (dy >> 3) + roundtab_76[dy & 0xf];
# Line 1733  Line 1740 
1740                                          b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2,                                          b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2,
1741                                          stride);                                          stride);
1742    
1743          if (sum < 2 * MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) pMB->mode = MODE_DIRECT_NONE_MV; //skipped          if (sum < 2 * MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) {
1744                    pMB->mode = MODE_DIRECT_NONE_MV; //skipped
1745                    for (k = 0; k < 4; k++) {
1746                            pMB->qmvs[k] = pMB->mvs[k];
1747                            pMB->b_qmvs[k] = pMB->b_mvs[k];
1748                    }
1749            }
1750  }  }
1751    
1752  static __inline uint32_t  static __inline uint32_t
# Line 2547  Line 2560 
2560          int cbp = 0, bits = 0, t = 0, i, iDirection;          int cbp = 0, bits = 0, t = 0, i, iDirection;
2561          SearchData Data2, *Data8 = &Data2;          SearchData Data2, *Data8 = &Data2;
2562          int sumx = 0, sumy = 0;          int sumx = 0, sumy = 0;
2563          int16_t in[64], coeff[64];          int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64;
2564    
2565          memcpy(Data8, Data, sizeof(SearchData));          memcpy(Data8, Data, sizeof(SearchData));
2566          CheckCandidate = CheckCandidateBits8;          CheckCandidate = CheckCandidateBits8;
# Line 2689  Line 2702 
2702          int bits = 1; //this one is ac/dc prediction flag. always 1.          int bits = 1; //this one is ac/dc prediction flag. always 1.
2703          int cbp = 0, i, t, dc = 0, b_dc = 1024;          int cbp = 0, i, t, dc = 0, b_dc = 1024;
2704          const uint32_t iQuant = Data->lambda16;          const uint32_t iQuant = Data->lambda16;
2705          int16_t in[64], coeff[64];          int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64;
2706    
2707          for(i = 0; i < 4; i++) {          for(i = 0; i < 4; i++) {
2708                  uint32_t iDcScaler = get_dc_scaler(iQuant, 1);                  uint32_t iDcScaler = get_dc_scaler(iQuant, 1);

Legend:
Removed from v.904  
changed lines
  Added in v.973

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