[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 771, Sat Jan 11 18:26:58 2003 UTC revision 819, Sat Feb 8 03:49:47 2003 UTC
# Line 50  Line 50 
50  #define MAX_SAD00_FOR_SKIP      (20)  #define MAX_SAD00_FOR_SKIP      (20)
51  #define MAX_CHROMA_SAD_FOR_SKIP (22)  #define MAX_CHROMA_SAD_FOR_SKIP (22)
52    
53  #define CHECK_CANDIDATE(X,Y,D) { \  #define CHECK_CANDIDATE(X,Y,D) { CheckCandidate((X),(Y), (D), &iDirection, data ); }
 (*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); }  
54    
55  static __inline uint32_t  static __inline uint32_t
56  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)
57  {  {
58          int xb, yb;          int xb, yb;
59          x += x * qpel; y += y * qpel;          x = qpel ? x<<1 : x;
60            y = qpel ? y<<1 : y;
61          if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); }          if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); }
62    
63          x -= pred.x;          x -= pred.x;
64          y -= pred.y;          y -= pred.y;
65    
# Line 80  Line 81 
81          return xb + yb;          return xb + yb;
82  }  }
83    
84    static int32_t ChromaSAD2(int fx, int fy, int bx, int by, const SearchData * const data)
85    {
86            int sad;
87            const uint32_t stride = data->iEdgedWidth/2;
88            uint8_t * f_refu = data->RefQ,
89                    * f_refv = data->RefQ + 8,
90                    * b_refu = data->RefQ + 16,
91                    * b_refv = data->RefQ + 24;
92    
93            switch (((fx & 1) << 1) | (fy & 1))     {
94                    case 0:
95                            fx = fx / 2; fy = fy / 2;
96                            f_refu = (uint8_t*)data->RefCU + fy * stride + fx, stride;
97                            f_refv = (uint8_t*)data->RefCV + fy * stride + fx, stride;
98                            break;
99                    case 1:
100                            fx = fx / 2; fy = (fy - 1) / 2;
101                            interpolate8x8_halfpel_v(f_refu, data->RefCU + fy * stride + fx, stride, data->rounding);
102                            interpolate8x8_halfpel_v(f_refv, data->RefCV + fy * stride + fx, stride, data->rounding);
103                            break;
104                    case 2:
105                            fx = (fx - 1) / 2; fy = fy / 2;
106                            interpolate8x8_halfpel_h(f_refu, data->RefCU + fy * stride + fx, stride, data->rounding);
107                            interpolate8x8_halfpel_h(f_refv, data->RefCV + fy * stride + fx, stride, data->rounding);
108                            break;
109                    default:
110                            fx = (fx - 1) / 2; fy = (fy - 1) / 2;
111                            interpolate8x8_halfpel_hv(f_refu, data->RefCU + fy * stride + fx, stride, data->rounding);
112                            interpolate8x8_halfpel_hv(f_refv, data->RefCV + fy * stride + fx, stride, data->rounding);
113                            break;
114            }
115    
116            switch (((bx & 1) << 1) | (by & 1))     {
117                    case 0:
118                            bx = bx / 2; by = by / 2;
119                            b_refu = (uint8_t*)data->b_RefCU + by * stride + bx, stride;
120                            b_refv = (uint8_t*)data->b_RefCV + by * stride + bx, stride;
121                            break;
122                    case 1:
123                            bx = bx / 2; by = (by - 1) / 2;
124                            interpolate8x8_halfpel_v(b_refu, data->b_RefCU + by * stride + bx, stride, data->rounding);
125                            interpolate8x8_halfpel_v(b_refv, data->b_RefCV + by * stride + bx, stride, data->rounding);
126                            break;
127                    case 2:
128                            bx = (bx - 1) / 2; by = by / 2;
129                            interpolate8x8_halfpel_h(b_refu, data->b_RefCU + by * stride + bx, stride, data->rounding);
130                            interpolate8x8_halfpel_h(b_refv, data->b_RefCV + by * stride + bx, stride, data->rounding);
131                            break;
132                    default:
133                            bx = (bx - 1) / 2; by = (by - 1) / 2;
134                            interpolate8x8_halfpel_hv(b_refu, data->b_RefCU + by * stride + bx, stride, data->rounding);
135                            interpolate8x8_halfpel_hv(b_refv, data->b_RefCV + by * stride + bx, stride, data->rounding);
136                            break;
137            }
138    
139            sad = sad8bi(data->CurU, b_refu, f_refu, stride);
140            sad += sad8bi(data->CurV, b_refv, f_refv, stride);
141    
142            return sad;
143    }
144    
145    
146  static int32_t  static int32_t
147  ChromaSAD(int dx, int dy, const SearchData * const data)  ChromaSAD(int dx, int dy, const SearchData * const data)
148  {  {
# Line 140  Line 203 
203  {  {
204          switch ( ((x&1)<<1) | (y&1) ) {          switch ( ((x&1)<<1) | (y&1) ) {
205                  case 0 : return data->Ref + x/2 + (y/2)*(data->iEdgedWidth);                  case 0 : return data->Ref + x/2 + (y/2)*(data->iEdgedWidth);
206                    case 3 : return data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth);
207                  case 1 : return data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth);                  case 1 : return data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth);
208                  case 2 : return data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth);                  default : return data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth);      //case 2
                 default : return data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth);  
209          }          }
210  }  }
211    
# Line 203  Line 266 
266    
267          ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data);          ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data);
268          switch( ((x&1)<<1) + (y&1) ) {          switch( ((x&1)<<1) + (y&1) ) {
269          case 0: // pure halfpel position          case 3: // x and y in qpel resolution - the "corners" (top left/right and
270                  return (uint8_t *) ref1;                           // bottom left/right) during qpel refinement
271                    ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data);
272                    ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data);
273                    ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data);
274                    interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);
275                    interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding);
276                    interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding);
277                    interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding);
278                    break;
279    
280          case 1: // x halfpel, y qpel - top or bottom during qpel refinement          case 1: // x halfpel, y qpel - top or bottom during qpel refinement
281                  ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data);                  ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data);
282                  interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8);                  interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8);
# Line 221  Line 293 
293                  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);
294                  break;                  break;
295    
296          default: // x and y in qpel resolution - the "corners" (top left/right and          case 0: // pure halfpel position
297                           // bottom left/right) during qpel refinement                  return (uint8_t *) ref1;
                 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);  
                 interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);  
                 interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding);  
                 interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding);  
                 interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding);  
                 break;  
298          }          }
299          return Reference;          return Reference;
300  }  }
# Line 240  Line 304 
304  static void  static void
305  CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
306  {  {
307          int t, xc, yc;          int xc, yc;
308          const uint8_t * Reference;          const uint8_t * Reference;
309          VECTOR * current;          VECTOR * current;
310            int32_t sad; uint32_t t;
311    
312          if ( (x > data->max_dx) | (x < data->min_dx)          if ( (x > data->max_dx) || (x < data->min_dx)
313                  | (y > data->max_dy) | (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
314    
315          if (data->qpel_precision) { // x and y are in 1/4 precision          if (!data->qpel_precision) {
                 Reference = Interpolate16x16qpel(x, y, 0, data);  
                 xc = x/2; yc = y/2; //for chroma sad  
                 current = data->currentQMV;  
         } else {  
316                  Reference = GetReference(x, y, data);                  Reference = GetReference(x, y, data);
317                  current = data->currentMV;                  current = data->currentMV;
318                  xc = x; yc = y;                  xc = x; yc = y;
319            } else { // x and y are in 1/4 precision
320                    Reference = Interpolate16x16qpel(x, y, 0, data);
321                    xc = x/2; yc = y/2; //for chroma sad
322                    current = data->currentQMV;
323          }          }
         t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);  
324    
325          data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1);          sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1);
326            t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
327    
328          data->temp[0] += (data->lambda16 * t * data->temp[0])>>10;          sad += (data->lambda16 * t * sad)>>10;
329          data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))>>10;          data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))>>10;
330    
331          if (data->chroma) data->temp[0] += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3],          if (data->chroma) sad += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3],
332                                                                                                          (yc >> 1) + roundtab_79[yc & 0x3], data);                                                                                                          (yc >> 1) + roundtab_79[yc & 0x3], data);
333    
334          if (data->temp[0] < data->iMinSAD[0]) {          if (sad < data->iMinSAD[0]) {
335                  data->iMinSAD[0] = data->temp[0];                  data->iMinSAD[0] = sad;
336                  current[0].x = x; current[0].y = y;                  current[0].x = x; current[0].y = y;
337                  *dir = Direction; }                  *dir = Direction;
338            }
339    
340          if (data->temp[1] < data->iMinSAD[1]) {          if (data->temp[1] < data->iMinSAD[1]) {
341                  data->iMinSAD[1] = data->temp[1]; current[1].x = x; current[1].y= y; }                  data->iMinSAD[1] = data->temp[1]; current[1].x = x; current[1].y= y; }
# Line 283  Line 349 
349  }  }
350    
351  static void  static void
352    CheckCandidate8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
353    {
354            int32_t sad; uint32_t t;
355            const uint8_t * Reference;
356    
357            if ( (x > data->max_dx) || (x < data->min_dx)
358                    || (y > data->max_dy) || (y < data->min_dy) ) return;
359    
360            if (!data->qpel_precision) Reference = GetReference(x, y, data);
361            else Reference = Interpolate8x8qpel(x, y, 0, 0, data);
362    
363            sad = sad8(data->Cur, Reference, data->iEdgedWidth);
364            t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
365    
366            sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))>>10;
367    
368            if (sad < *(data->iMinSAD)) {
369                    *(data->iMinSAD) = sad;
370                    data->currentMV->x = x; data->currentMV->y = y;
371                    *dir = Direction;
372            }
373    }
374    
375    
376    static void
377  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)
378  {  {
379          uint32_t t;          uint32_t t;
380          const uint8_t * Reference;          const uint8_t * Reference;
381    
382          if ( (!(x&1) && x !=0) | (!(y&1) && y !=0) || //non-zero integer value          if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero integer value
383                  (x > data->max_dx) | (x < data->min_dx)                  (x > data->max_dx) || (x < data->min_dx)
384                  | (y > data->max_dy) | (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
385    
386          Reference = GetReference(x, y, data);          Reference = GetReference(x, y, data);
387          t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1);          t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1);
# Line 318  Line 409 
409  static void  static void
410  CheckCandidate16no4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidate16no4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
411  {  {
412          int32_t sad;          int32_t sad, xc, yc;
413          const uint8_t * Reference;          const uint8_t * Reference;
414          uint32_t t;          uint32_t t;
415          VECTOR * current;          VECTOR * current;
# Line 331  Line 422 
422          if (data->qpel_precision) { // x and y are in 1/4 precision          if (data->qpel_precision) { // x and y are in 1/4 precision
423                  Reference = Interpolate16x16qpel(x, y, 0, data);                  Reference = Interpolate16x16qpel(x, y, 0, data);
424                  current = data->currentQMV;                  current = data->currentQMV;
425                    xc = x/2; yc = y/2;
426          } else {          } else {
427                  Reference = GetReference(x, y, data);                  Reference = GetReference(x, y, data);
428                  current = data->currentMV;                  current = data->currentMV;
429                    xc = x; yc = y;
430          }          }
431          t = d_mv_bits(x, y, data->predMV, data->iFcode,          t = d_mv_bits(x, y, data->predMV, data->iFcode,
432                                          data->qpel^data->qpel_precision, data->rrv);                                          data->qpel^data->qpel_precision, data->rrv);
# Line 341  Line 434 
434          sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096);          sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096);
435          sad += (data->lambda16 * t * sad)>>10;          sad += (data->lambda16 * t * sad)>>10;
436    
437            if (data->chroma) sad += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3],
438                                                                                    (yc >> 1) + roundtab_79[yc & 0x3], data);
439    
440    
441          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
442                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
443                  current->x = x; current->y = y;                  current->x = x; current->y = y;
444                  *dir = Direction; }                  *dir = Direction;
445            }
446  }  }
447    
448  static void  static void
449  CheckCandidate32I(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidate32I(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
450  {  {
451  // maximum speed - for P/B/I decision  // maximum speed - for P/B/I decision
452            int32_t sad;
453    
454          if ( (x > data->max_dx) | (x < data->min_dx)          if ( (x > data->max_dx) || (x < data->min_dx)
455                  | (y > data->max_dy) | (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
456    
457          data->temp[0] = sad32v_c(data->Cur, data->Ref + x/2 + (y/2)*(data->iEdgedWidth),          sad = sad32v_c(data->Cur, data->Ref + x/2 + (y/2)*(data->iEdgedWidth),
458                                                          data->iEdgedWidth, data->temp+1);                                                          data->iEdgedWidth, data->temp+1);
459    
460          if (data->temp[0] < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
461                  *(data->iMinSAD) = data->temp[0];                  *(data->iMinSAD) = sad;
462                  data->currentMV[0].x = x; data->currentMV[0].y = y;                  data->currentMV[0].x = x; data->currentMV[0].y = y;
463                  *dir = Direction; }                  *dir = Direction;
464            }
465          if (data->temp[1] < data->iMinSAD[1]) {          if (data->temp[1] < data->iMinSAD[1]) {
466                  data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; }                  data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; }
467          if (data->temp[2] < data->iMinSAD[2]) {          if (data->temp[2] < data->iMinSAD[2]) {
# Line 376  Line 476 
476  static void  static void
477  CheckCandidateInt(const int xf, const int yf, const int Direction, int * const dir, const SearchData * const data)  CheckCandidateInt(const int xf, const int yf, const int Direction, int * const dir, const SearchData * const data)
478  {  {
479          int32_t sad, xb, yb;          int32_t sad, xb, yb, xcf, ycf, xcb, ycb;
480          uint32_t t;          uint32_t t;
481          const uint8_t *ReferenceF, *ReferenceB;          const uint8_t *ReferenceF, *ReferenceB;
482          VECTOR *current;          VECTOR *current;
# Line 389  Line 489 
489                  xb = data->currentMV[1].x; yb = data->currentMV[1].y;                  xb = data->currentMV[1].x; yb = data->currentMV[1].y;
490                  ReferenceB = GetReferenceB(xb, yb, 1, data);                  ReferenceB = GetReferenceB(xb, yb, 1, data);
491                  current = data->currentMV;                  current = data->currentMV;
492                    xcf = xf; ycf = yf;
493                    xcb = xb; ycb = yb;
494          } else {          } else {
495                  ReferenceF = Interpolate16x16qpel(xf, yf, 0, data);                  ReferenceF = Interpolate16x16qpel(xf, yf, 0, data);
496                  xb = data->currentQMV[1].x; yb = data->currentQMV[1].y;                  xb = data->currentQMV[1].x; yb = data->currentQMV[1].y;
497                  current = data->currentQMV;                  current = data->currentQMV;
498                  ReferenceB = Interpolate16x16qpel(xb, yb, 1, data);                  ReferenceB = Interpolate16x16qpel(xb, yb, 1, data);
499                    xcf = xf/2; ycf = yf/2;
500                    xcb = xb/2; ycb = yb/2;
501          }          }
502    
503          t = d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0)          t = d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0)
# Line 402  Line 506 
506          sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth);          sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth);
507          sad += (data->lambda16 * t * sad)>>10;          sad += (data->lambda16 * t * sad)>>10;
508    
509            if (data->chroma) sad += ChromaSAD2((xcf >> 1) + roundtab_79[xcf & 0x3],
510                                                                                    (ycf >> 1) + roundtab_79[ycf & 0x3],
511                                                                                    (xcb >> 1) + roundtab_79[xcb & 0x3],
512                                                                                    (ycb >> 1) + roundtab_79[ycb & 0x3], data);
513    
514          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
515                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
516                  current->x = xf; current->y = yf;                  current->x = xf; current->y = yf;
517                  *dir = Direction; }                  *dir = Direction;
518            }
519  }  }
520    
521  static void  static void
522  CheckCandidateDirect(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidateDirect(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
523  {  {
524          int32_t sad = 0;          int32_t sad = 0, xcf = 0, ycf = 0, xcb = 0, ycb = 0;
525          uint32_t k;          uint32_t k;
526          const uint8_t *ReferenceF;          const uint8_t *ReferenceF;
527          const uint8_t *ReferenceB;          const uint8_t *ReferenceB;
# Line 430  Line 540 
540                          data->directmvB[k].y                          data->directmvB[k].y
541                          : mvs.y - data->referencemv[k].y);                          : mvs.y - data->referencemv[k].y);
542    
543                  if (( mvs.x > data->max_dx ) || ( mvs.x < data->min_dx )                  if ( (mvs.x > data->max_dx) | (mvs.x < data->min_dx)
544                          || ( mvs.y > data->max_dy ) || ( mvs.y < data->min_dy )                          | (mvs.y > data->max_dy) | (mvs.y < data->min_dy)
545                          || ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx )                          | (b_mvs.x > data->max_dx) | (b_mvs.x < data->min_dx)
546                          || ( 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;
547    
548                    if (data->qpel) {
549                  mvs.x *= 2 - data->qpel; mvs.y *= 2 - data->qpel;                          xcf += mvs.x/2; ycf += mvs.y/2;
550                  b_mvs.x *= 2 - data->qpel; b_mvs.y *= 2 - data->qpel; //we move to qpel precision anyway                          xcb += b_mvs.x/2; ycb += b_mvs.y/2;
551                    } else {
552                            xcf += mvs.x; ycf += mvs.y;
553                            xcb += b_mvs.x; ycb += b_mvs.y;
554                            mvs.x *= 2; mvs.y *= 2; //we move to qpel precision anyway
555                            b_mvs.x *= 2; b_mvs.y *= 2;
556                    }
557    
558                  ReferenceF = Interpolate8x8qpel(mvs.x, mvs.y, k, 0, data);                  ReferenceF = Interpolate8x8qpel(mvs.x, mvs.y, k, 0, data);
559                  ReferenceB = Interpolate8x8qpel(b_mvs.x, b_mvs.y, k, 1, data);                  ReferenceB = Interpolate8x8qpel(b_mvs.x, b_mvs.y, k, 1, data);
# Line 449  Line 565 
565    
566          sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)>>10;          sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)>>10;
567    
568            if (data->chroma) sad += ChromaSAD2((xcf >> 3) + roundtab_76[xcf & 0xf],
569                                                                                    (ycf >> 3) + roundtab_76[ycf & 0xf],
570                                                                                    (xcb >> 3) + roundtab_76[xcb & 0xf],
571                                                                                    (ycb >> 3) + roundtab_76[ycb & 0xf], data);
572    
573          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
574                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
575                  data->currentMV->x = x; data->currentMV->y = y;                  data->currentMV->x = x; data->currentMV->y = y;
576                  *dir = Direction; }                  *dir = Direction;
577            }
578  }  }
579    
580  static void  static void
581  CheckCandidateDirectno4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidateDirectno4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
582  {  {
583          int32_t sad;          int32_t sad, xcf, ycf, xcb, ycb;
584          const uint8_t *ReferenceF;          const uint8_t *ReferenceF;
585          const uint8_t *ReferenceB;          const uint8_t *ReferenceB;
586          VECTOR mvs, b_mvs;          VECTOR mvs, b_mvs;
# Line 475  Line 597 
597                  data->directmvB[0].y                  data->directmvB[0].y
598                  : mvs.y - data->referencemv[0].y);                  : mvs.y - data->referencemv[0].y);
599    
600          if (( mvs.x > data->max_dx ) || ( mvs.x < data->min_dx )          if ( (mvs.x > data->max_dx) | (mvs.x < data->min_dx)
601                  || ( mvs.y > data->max_dy ) || ( mvs.y < data->min_dy )                  | (mvs.y > data->max_dy) | (mvs.y < data->min_dy)
602                  || ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx )                  | (b_mvs.x > data->max_dx) | (b_mvs.x < data->min_dx)
603                  || ( 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;
604    
605          mvs.x *= 2 - data->qpel; mvs.y *= 2 - data->qpel;          if (data->qpel) {
606          b_mvs.x *= 2 - data->qpel; b_mvs.y *= 2 - data->qpel; //we move to qpel precision anyway                  xcf = 4*(mvs.x/2); ycf = 4*(mvs.y/2);
607                    xcb = 4*(b_mvs.x/2); ycb = 4*(b_mvs.y/2);
608          ReferenceF = Interpolate16x16qpel(mvs.x, mvs.y, 0, data);          ReferenceF = Interpolate16x16qpel(mvs.x, mvs.y, 0, data);
609          ReferenceB = Interpolate16x16qpel(b_mvs.x, b_mvs.y, 1, data);          ReferenceB = Interpolate16x16qpel(b_mvs.x, b_mvs.y, 1, data);
610            } else {
611                    xcf = 4*mvs.x; ycf = 4*mvs.y;
612                    xcb = 4*b_mvs.x; ycb = 4*b_mvs.y;
613                    ReferenceF = GetReference(mvs.x, mvs.y, data);
614                    ReferenceB = GetReferenceB(b_mvs.x, b_mvs.y, 1, data);
615            }
616    
617          sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth);          sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth);
618          sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)>>10;          sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)>>10;
619    
620          if (sad < *(data->iMinSAD)) {          if (data->chroma) sad += ChromaSAD2((xcf >> 3) + roundtab_76[xcf & 0xf],
621                  *(data->iMinSAD) = sad;                                                                                  (ycf >> 3) + roundtab_76[ycf & 0xf],
622                  data->currentMV->x = x; data->currentMV->y = y;                                                                                  (xcb >> 3) + roundtab_76[xcb & 0xf],
623                  *dir = Direction; }                                                                                  (ycb >> 3) + roundtab_76[ycb & 0xf], data);
 }  
   
 static void  
 CheckCandidate8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  
 {  
         int32_t sad; uint32_t t;  
         const uint8_t * Reference;  
   
         if ( (x > data->max_dx) | (x < data->min_dx)  
                 | (y > data->max_dy) | (y < data->min_dy) ) return;  
   
         if (data->qpel) Reference = Interpolate16x16qpel(x, y, 0, data);  
         else Reference = GetReference(x, y, data);  
   
         sad = sad8(data->Cur, Reference, data->iEdgedWidth);  
         t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel && !data->qpel_precision, 0);  
   
         sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))>>10;  
624    
625          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
626                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
627                  data->currentMV->x = x; data->currentMV->y = y;                  data->currentMV->x = x; data->currentMV->y = y;
628                  *dir = Direction; }                  *dir = Direction;
629            }
630  }  }
631    
632  /* CHECK_CANDIATE FUNCTIONS END */  /* CHECK_CANDIATE FUNCTIONS END */
# Line 753  Line 864 
864          Data.iFcode = current->fcode;          Data.iFcode = current->fcode;
865          Data.rounding = pParam->m_rounding_type;          Data.rounding = pParam->m_rounding_type;
866          Data.qpel = pParam->m_quarterpel;          Data.qpel = pParam->m_quarterpel;
867          Data.chroma = current->motion_flags & ( PMV_CHROMA16 | PMV_CHROMA8 );          Data.chroma = current->motion_flags & PMV_CHROMA16;
868          Data.rrv = current->global_flags & XVID_REDUCED;          Data.rrv = current->global_flags & XVID_REDUCED;
869    
870          if ((current->global_flags & XVID_REDUCED)) {          if ((current->global_flags & XVID_REDUCED)) {
# Line 1000  Line 1111 
1111    
1112          for (i = 1; i < 7; i++) {          for (i = 1; i < 7; i++) {
1113                  if (!(mask = make_mask(pmv, i)) ) continue;                  if (!(mask = make_mask(pmv, i)) ) continue;
1114                  (*CheckCandidate)(pmv[i].x, pmv[i].y, mask, &iDirection, Data);                  CheckCandidate(pmv[i].x, pmv[i].y, mask, &iDirection, Data);
1115                  if (Data->iMinSAD[0] <= threshA) break;                  if (Data->iMinSAD[0] <= threshA) break;
1116          }          }
1117    
# Line 1033  Line 1144 
1144                          if (!(MVequal(startMV, backupMV))) {                          if (!(MVequal(startMV, backupMV))) {
1145                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
1146    
1147                                  (*CheckCandidate)(startMV.x, startMV.y, 255, &iDirection, Data);                                  CheckCandidate(startMV.x, startMV.y, 255, &iDirection, Data);
1148                                  (*MainSearchPtr)(startMV.x, startMV.y, Data, 255);                                  (*MainSearchPtr)(startMV.x, startMV.y, Data, 255);
1149                                  if (bSAD < Data->iMinSAD[0]) {                                  if (bSAD < Data->iMinSAD[0]) {
1150                                          Data->currentMV[0] = backupMV;                                          Data->currentMV[0] = backupMV;
# Line 1046  Line 1157 
1157                          if (!(MVequal(startMV, backupMV))) {                          if (!(MVequal(startMV, backupMV))) {
1158                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
1159    
1160                                  (*CheckCandidate)(startMV.x, startMV.y, 255, &iDirection, Data);                                  CheckCandidate(startMV.x, startMV.y, 255, &iDirection, Data);
1161                                  (*MainSearchPtr)(startMV.x, startMV.y, Data, 255);                                  (*MainSearchPtr)(startMV.x, startMV.y, Data, 255);
1162                                  if (bSAD < Data->iMinSAD[0]) {                                  if (bSAD < Data->iMinSAD[0]) {
1163                                          Data->currentMV[0] = backupMV;                                          Data->currentMV[0] = backupMV;
# Line 1270  Line 1381 
1381    
1382  /* search backward or forward */  /* search backward or forward */
1383  static void  static void
1384  SearchBF(       const uint8_t * const pRef,  SearchBF(       const IMAGE * const pRef,
1385                          const uint8_t * const pRefH,                          const uint8_t * const pRefH,
1386                          const uint8_t * const pRefV,                          const uint8_t * const pRefV,
1387                          const uint8_t * const pRefHV,                          const uint8_t * const pRefHV,
# Line 1292  Line 1403 
1403          *Data->iMinSAD = MV_MAX_ERROR;          *Data->iMinSAD = MV_MAX_ERROR;
1404          Data->iFcode = iFcode;          Data->iFcode = iFcode;
1405          Data->qpel_precision = 0;          Data->qpel_precision = 0;
1406            Data->temp[5] = Data->temp[6] = Data->temp[7] = 256*4096; // reset chroma-sad cache
1407    
1408          Data->Ref = pRef + (x + y * Data->iEdgedWidth) * 16;          Data->Ref = pRef->y + (x + y * Data->iEdgedWidth) * 16;
1409          Data->RefH = pRefH + (x + y * Data->iEdgedWidth) * 16;          Data->RefH = pRefH + (x + y * Data->iEdgedWidth) * 16;
1410          Data->RefV = pRefV + (x + y * Data->iEdgedWidth) * 16;          Data->RefV = pRefV + (x + y * Data->iEdgedWidth) * 16;
1411          Data->RefHV = pRefHV + (x + y * Data->iEdgedWidth) * 16;          Data->RefHV = pRefHV + (x + y * Data->iEdgedWidth) * 16;
1412            Data->RefCU = pRef->u + (x + y * Data->iEdgedWidth/2) * 8;
1413            Data->RefCV = pRef->v + (x + y * Data->iEdgedWidth/2) * 8;
1414    
1415          Data->predMV = *predMV;          Data->predMV = *predMV;
1416    
# Line 1436  Line 1550 
1550          Data->bRefH = b_RefH + k;          Data->bRefH = b_RefH + k;
1551          Data->bRefV = b_RefV + k;          Data->bRefV = b_RefV + k;
1552          Data->bRefHV = b_RefHV + k;          Data->bRefHV = b_RefHV + k;
1553            Data->RefCU = f_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8;
1554            Data->RefCV = f_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8;
1555            Data->b_RefCU = b_Ref->u + (x + (Data->iEdgedWidth/2) * y) * 8;
1556            Data->b_RefCV = b_Ref->v + (x + (Data->iEdgedWidth/2) * y) * 8;
1557    
1558          k = Data->qpel ? 4 : 2;          k = Data->qpel ? 4 : 2;
1559          Data->max_dx = k * (pParam->width - x * 16);          Data->max_dx = k * (pParam->width - x * 16);
# Line 1471  Line 1589 
1589    
1590          CheckCandidate = b_mb->mode == MODE_INTER4V ? CheckCandidateDirect : CheckCandidateDirectno4v;          CheckCandidate = b_mb->mode == MODE_INTER4V ? CheckCandidateDirect : CheckCandidateDirectno4v;
1591    
1592          (*CheckCandidate)(0, 0, 255, &k, Data);          CheckCandidate(0, 0, 255, &k, Data);
1593    
1594  // initial (fast) skip decision  // initial (fast) skip decision
1595          if (*Data->iMinSAD < pMB->quant * INITIAL_SKIP_THRESH * 2) {          if (*Data->iMinSAD < pMB->quant * INITIAL_SKIP_THRESH * (2 + Data->chroma?1:0)) {
1596                  //possible skip - checking chroma                  //possible skip
1597                    if (Data->chroma) {
1598                            pMB->mode = MODE_DIRECT_NONE_MV;
1599                            return *Data->iMinSAD; // skip.
1600                    } else {
1601                  SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data);                  SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data);
1602                  if (pMB->mode == MODE_DIRECT_NONE_MV) return *Data->iMinSAD; // skip.                  if (pMB->mode == MODE_DIRECT_NONE_MV) return *Data->iMinSAD; // skip.
1603          }          }
1604            }
1605    
1606          skip_sad = *Data->iMinSAD;          skip_sad = *Data->iMinSAD;
1607    
# Line 1528  Line 1651 
1651  }  }
1652    
1653  static void  static void
1654  SearchInterpolate(const uint8_t * const f_Ref,  SearchInterpolate(const IMAGE * const f_Ref,
1655                                  const uint8_t * const f_RefH,                                  const uint8_t * const f_RefH,
1656                                  const uint8_t * const f_RefV,                                  const uint8_t * const f_RefV,
1657                                  const uint8_t * const f_RefHV,                                  const uint8_t * const f_RefHV,
1658                                  const uint8_t * const b_Ref,                                  const IMAGE * const b_Ref,
1659                                  const uint8_t * const b_RefH,                                  const uint8_t * const b_RefH,
1660                                  const uint8_t * const b_RefV,                                  const uint8_t * const b_RefV,
1661                                  const uint8_t * const b_RefHV,                                  const uint8_t * const b_RefHV,
# Line 1560  Line 1683 
1683          fData->iFcode = bData.bFcode = fcode; fData->bFcode = bData.iFcode = bcode;          fData->iFcode = bData.bFcode = fcode; fData->bFcode = bData.iFcode = bcode;
1684    
1685          i = (x + y * fData->iEdgedWidth) * 16;          i = (x + y * fData->iEdgedWidth) * 16;
1686          bData.bRef = fData->Ref = f_Ref + i;          bData.bRef = fData->Ref = f_Ref->y + i;
1687          bData.bRefH = fData->RefH = f_RefH + i;          bData.bRefH = fData->RefH = f_RefH + i;
1688          bData.bRefV = fData->RefV = f_RefV + i;          bData.bRefV = fData->RefV = f_RefV + i;
1689          bData.bRefHV = fData->RefHV = f_RefHV + i;          bData.bRefHV = fData->RefHV = f_RefHV + i;
1690          bData.Ref = fData->bRef = b_Ref + i;          bData.Ref = fData->bRef = b_Ref->y + i;
1691          bData.RefH = fData->bRefH = b_RefH + i;          bData.RefH = fData->bRefH = b_RefH + i;
1692          bData.RefV = fData->bRefV = b_RefV + i;          bData.RefV = fData->bRefV = b_RefV + i;
1693          bData.RefHV = fData->bRefHV = b_RefHV + i;          bData.RefHV = fData->bRefHV = b_RefHV + i;
1694            bData.b_RefCU = fData->RefCU = f_Ref->u + (x + (fData->iEdgedWidth/2) * y) * 8;
1695            bData.b_RefCV = fData->RefCV = f_Ref->v + (x + (fData->iEdgedWidth/2) * y) * 8;
1696            bData.RefCU = fData->b_RefCU = b_Ref->u + (x + (fData->iEdgedWidth/2) * y) * 8;
1697            bData.RefCV = fData->b_RefCV = b_Ref->v + (x + (fData->iEdgedWidth/2) * y) * 8;
1698    
1699    
1700          bData.bpredMV = fData->predMV = *f_predMV;          bData.bpredMV = fData->predMV = *f_predMV;
1701          fData->bpredMV = bData.predMV = *b_predMV;          fData->bpredMV = bData.predMV = *b_predMV;
# Line 1684  Line 1812 
1812          int32_t iMinSAD;          int32_t iMinSAD;
1813          VECTOR currentMV[3];          VECTOR currentMV[3];
1814          VECTOR currentQMV[3];          VECTOR currentQMV[3];
1815            int32_t temp[8];
1816          memset(&Data, 0, sizeof(SearchData));          memset(&Data, 0, sizeof(SearchData));
1817          Data.iEdgedWidth = pParam->edged_width;          Data.iEdgedWidth = pParam->edged_width;
1818          Data.currentMV = currentMV; Data.currentQMV = currentQMV;          Data.currentMV = currentMV; Data.currentQMV = currentQMV;
1819          Data.iMinSAD = &iMinSAD;          Data.iMinSAD = &iMinSAD;
1820          Data.lambda16 = lambda_vec16[frame->quant];          Data.lambda16 = lambda_vec16[frame->quant];
         Data.chroma = frame->quant;  
1821          Data.qpel = pParam->m_quarterpel;          Data.qpel = pParam->m_quarterpel;
1822          Data.rounding = 0;          Data.rounding = 0;
1823            Data.chroma = frame->motion_flags & PMV_CHROMA8;
1824            Data.temp = temp;
1825    
1826          Data.RefQ = f_refV->u; // a good place, also used in MC (for similar purpose)          Data.RefQ = f_refV->u; // a good place, also used in MC (for similar purpose)
1827          // note: i==horizontal, j==vertical          // note: i==horizontal, j==vertical
# Line 1711  Line 1841 
1841                                  }                                  }
1842    
1843                          Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16;                          Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16;
1844                            Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8;
1845                            Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8;
1846                          pMB->quant = frame->quant;                          pMB->quant = frame->quant;
1847    
1848  /* direct search comes first, because it (1) checks for SKIP-mode  /* direct search comes first, because it (1) checks for SKIP-mode
# Line 1729  Line 1861 
1861                          if (pMB->mode == MODE_DIRECT_NONE_MV) { n_count++; continue; }                          if (pMB->mode == MODE_DIRECT_NONE_MV) { n_count++; continue; }
1862    
1863                          // forward search                          // forward search
1864                          SearchBF(f_ref->y, f_refH->y, f_refV->y, f_refHV->y,                          SearchBF(f_ref, f_refH->y, f_refV->y, f_refHV->y,
1865                                                  &frame->image, i, j,                                                  &frame->image, i, j,
1866                                                  frame->motion_flags,                                                  frame->motion_flags,
1867                                                  frame->fcode, pParam,                                                  frame->fcode, pParam,
# Line 1737  Line 1869 
1869                                                  MODE_FORWARD, &Data);                                                  MODE_FORWARD, &Data);
1870    
1871                          // backward search                          // backward search
1872                          SearchBF(b_ref->y, b_refH->y, b_refV->y, b_refHV->y,                          SearchBF(b_ref, b_refH->y, b_refV->y, b_refHV->y,
1873                                                  &frame->image, i, j,                                                  &frame->image, i, j,
1874                                                  frame->motion_flags,                                                  frame->motion_flags,
1875                                                  frame->bcode, pParam,                                                  frame->bcode, pParam,
# Line 1745  Line 1877 
1877                                                  MODE_BACKWARD, &Data);                                                  MODE_BACKWARD, &Data);
1878    
1879                          // 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
1880                          SearchInterpolate(f_ref->y, f_refH->y, f_refV->y, f_refHV->y,                          SearchInterpolate(f_ref, f_refH->y, f_refV->y, f_refHV->y,
1881                                                  b_ref->y, b_refH->y, b_refV->y, b_refHV->y,                                                  b_ref, b_refH->y, b_refV->y, b_refHV->y,
1882                                                  &frame->image,                                                  &frame->image,
1883                                                  i, j,                                                  i, j,
1884                                                  frame->fcode, frame->bcode,                                                  frame->fcode, frame->bcode,
# Line 1907  Line 2039 
2039                  }                  }
2040          }          }
2041          sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2);          sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2);
2042          if (sSAD > IntraThresh + INTRA_BIAS) return I_VOP;  //      if (sSAD > IntraThresh + INTRA_BIAS) return I_VOP;
2043          if (sSAD > InterThresh ) return P_VOP;          if (sSAD > InterThresh ) return P_VOP;
2044          emms();          emms();
2045          return B_VOP;          return B_VOP;

Legend:
Removed from v.771  
changed lines
  Added in v.819

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