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

Legend:
Removed from v.770  
changed lines
  Added in v.817

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