[cvs] / xvidcore / src / motion / estimation_common.c Repository:
ViewVC logotype

Diff of /xvidcore/src/motion/estimation_common.c

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

revision 1.1.2.1, Wed Sep 10 22:18:59 2003 UTC revision 1.1.2.3, Thu Dec 18 02:02:08 2003 UTC
# Line 78  Line 78 
78   ****************************************************************************/   ****************************************************************************/
79    
80  int32_t  int32_t
81  xvid_me_ChromaSAD(const int dx, const int dy, const SearchData * const data)  xvid_me_ChromaSAD(const int dx, const int dy, SearchData * const data)
82  {  {
83          int sad;          int sad;
84          const uint32_t stride = data->iEdgedWidth/2;          const uint32_t stride = data->iEdgedWidth/2;
85          int offset = (dx>>1) + (dy>>1)*stride;          int offset = (dx>>1) + (dy>>1)*stride;
86          int next = 1;          int next = 1;
87    
88          if (dx == data->temp[5] && dy == data->temp[6]) return data->temp[7]; /* it has been checked recently */          if (dx == data->chromaX && dy == data->chromaY)
89          data->temp[5] = dx; data->temp[6] = dy; /* backup */                  return data->chromaSAD; /* it has been checked recently */
90            data->chromaX = dx; data->chromaY = dy; /* backup */
91    
92          switch (((dx & 1) << 1) | (dy & 1))     {          switch (((dx & 1) << 1) | (dy & 1))     {
93                  case 0:                  case 0:
# Line 107  Line 108 
108                          sad += sad8(data->CurV, data->RefQ, stride);                          sad += sad8(data->CurV, data->RefQ, stride);
109                          break;                          break;
110          }          }
111          data->temp[7] = sad; /* backup, part 2 */          data->chromaSAD = sad; /* backup, part 2 */
112          return sad;          return sad;
113  }  }
114    
# Line 206  Line 207 
207  }  }
208    
209  void  void
210  xvid_me_AdvDiamondSearch(int x, int y, const SearchData * const data,  xvid_me_AdvDiamondSearch(int x, int y, SearchData * const data,
211                                                   int bDirection, CheckFunc * const CheckCandidate)                                                   int bDirection, CheckFunc * const CheckCandidate)
212  {  {
213    
214  /* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */  /* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */
215    
216          unsigned int * const iDirection = data->dir;          unsigned int * const iDirection = &data->dir;
217    
218          for(;;) { /* forever */          for(;;) { /* forever */
219                  *iDirection = 0;                  *iDirection = 0;
# Line 292  Line 293 
293  }  }
294    
295  void  void
296  xvid_me_SquareSearch(int x, int y, const SearchData * const data,  xvid_me_SquareSearch(int x, int y, SearchData * const data,
297                                           int bDirection, CheckFunc * const CheckCandidate)                                           int bDirection, CheckFunc * const CheckCandidate)
298  {  {
299          unsigned int * const iDirection = data->dir;          unsigned int * const iDirection = &data->dir;
300    
301          do {          do {
302                  *iDirection = 0;                  *iDirection = 0;
# Line 314  Line 315 
315  }  }
316    
317  void  void
318  xvid_me_DiamondSearch(int x, int y, const SearchData * const data,  xvid_me_DiamondSearch(int x, int y, SearchData * const data,
319                                            int bDirection, CheckFunc * const CheckCandidate)                                            int bDirection, CheckFunc * const CheckCandidate)
320  {  {
321    
322  /* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */  /* directions: 1 - left (x-1); 2 - right (x+1), 4 - up (y-1); 8 - down (y+1) */
323    
324          unsigned int * const iDirection = data->dir;          unsigned int * const iDirection = &data->dir;
325    
326          do {          do {
327                  *iDirection = 0;                  *iDirection = 0;
# Line 350  Line 351 
351  }  }
352    
353  void  void
354  xvid_me_SubpelRefine(const SearchData * const data, CheckFunc * const CheckCandidate)  xvid_me_SubpelRefine(SearchData * const data, CheckFunc * const CheckCandidate)
355  {  {
356  /* Do a half-pel or q-pel refinement */  /* Do a half-pel or q-pel refinement */
357          const VECTOR centerMV = data->qpel_precision ? *data->currentQMV : *data->currentMV;          const VECTOR centerMV = data->qpel_precision ? *data->currentQMV : *data->currentMV;
# Line 365  Line 366 
366          CHECK_CANDIDATE(centerMV.x - 1, centerMV.y - 1, 0);          CHECK_CANDIDATE(centerMV.x - 1, centerMV.y - 1, 0);
367  }  }
368    
369    void
370    SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate)
371    {
372    /* Do a fast q-pel refinement */
373            VECTOR centerMV;
374            VECTOR second_best;
375            int best_sad = *data->iMinSAD;
376            int xo, yo, xo2, yo2;
377            int size = 2;
378            data->iMinSAD2 = 0;
379    
380            /* check all halfpixel positions near our best halfpel position */
381            centerMV = *data->currentQMV;
382            *data->iMinSAD = 256 * 4096;
383    
384            CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0);
385            CHECK_CANDIDATE(centerMV.x + size, centerMV.y - size, 0);
386            CHECK_CANDIDATE(centerMV.x + size, centerMV.y, 0);
387            CHECK_CANDIDATE(centerMV.x + size, centerMV.y + size, 0);
388    
389            CHECK_CANDIDATE(centerMV.x, centerMV.y + size, 0);
390            CHECK_CANDIDATE(centerMV.x - size, centerMV.y + size, 0);
391            CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0);
392            CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0);
393    
394            second_best = *data->currentQMV;
395    
396            /* after second_best has been found, go back to the vector we began with */
397    
398            data->currentQMV[0] = centerMV;
399            *data->iMinSAD = best_sad;
400    
401            xo = centerMV.x;
402            yo = centerMV.y;
403            xo2 = second_best.x;
404            yo2 = second_best.y;
405    
406            data->iMinSAD2 = 256 * 4096;
407    
408            if (yo == yo2) {
409                    CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);
410                    CHECK_CANDIDATE(xo, yo-1, 0);
411                    CHECK_CANDIDATE(xo, yo+1, 0);
412    
413                    if(best_sad <= data->iMinSAD2) return;
414    
415                    if(data->currentQMV[0].x == data->currentQMV2.x) {
416                            CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0);
417                            CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0);
418                    } else {
419                            CHECK_CANDIDATE((xo+xo2)>>1,
420                                    (data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2.y, 0);
421                    }
422                    return;
423            }
424    
425            if (xo == xo2) {
426                    CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0);
427                    CHECK_CANDIDATE(xo-1, yo, 0);
428                    CHECK_CANDIDATE(xo+1, yo, 0);
429    
430                    if(best_sad < data->iMinSAD2) return;
431    
432                    if(data->currentQMV[0].y == data->currentQMV2.y) {
433                            CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0);
434                            CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0);
435                    } else {
436                            CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2.x, (yo+yo2)>>1, 0);
437                    }
438                    return;
439            }
440    
441            CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0);
442            CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);
443    
444            if(best_sad <= data->iMinSAD2) return;
445    
446            CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0);
447    }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.3

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