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

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

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

revision 1.3, Mon Apr 12 14:05:08 2004 UTC revision 1.4, Tue Apr 20 06:10:40 2004 UTC
# Line 63  Line 63 
63  CheckCandidate16(const int x, const int y, SearchData * const data, const unsigned int Direction)  CheckCandidate16(const int x, const int y, SearchData * const data, const unsigned int Direction)
64  {  {
65          const uint8_t * Reference;          const uint8_t * Reference;
66          int32_t sad; uint32_t t;          int32_t sad, xc, yc; uint32_t t;
67            VECTOR * current;
68    
69          if ( (x > data->max_dx) || (x < data->min_dx)          if ( (x > data->max_dx) || (x < data->min_dx)
70                  || (y > data->max_dy) || (y < data->min_dy) ) return;                  || (y > data->max_dy) || (y < data->min_dy) ) return;
71    
72            if (data->qpel_precision) { /* x and y are in 1/4 precision */
73                    Reference = xvid_me_interpolate16x16qpel(x, y, 0, data);
74                    current = data->currentQMV;
75                    xc = x/2; yc = y/2;
76            } else {
77          Reference = GetReference(x, y, data);          Reference = GetReference(x, y, data);
78                    current = data->currentMV;
79                    xc = x; yc = y;
80            }
81    
82          sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp);          sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp);
83          t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel, 0);          t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
84    
85          sad += (data->lambda16 * t * sad)>>10;          sad += (data->lambda16 * t * sad)>>10;
86          data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10;          data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10;
87    
88          if (data->chroma) {          if (data->chroma) {
89                  if (sad >= data->iMinSAD[0]) goto no16;                  if (sad >= data->iMinSAD[0]) goto no16;
90                  sad += xvid_me_ChromaSAD((x >> 1) + roundtab_79[x & 0x3],                  sad += xvid_me_ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3],
91                                                                  (y >> 1) + roundtab_79[y & 0x3], data);                                                                  (yc >> 1) + roundtab_79[yc & 0x3], data);
92          }          }
93    
94          if (sad < data->iMinSAD[0]) {          if (sad < data->iMinSAD[0]) {
95                  data->iMinSAD[0] = sad;                  data->iMinSAD[0] = sad;
96                  data->currentMV[0].x = x; data->currentMV[0].y = y;                  current[0].x = x; current[0].y = y;
97                  data->dir = Direction;                  data->dir = Direction;
98          }          }
99    
100  no16:  no16:
101          if (data->temp[0] < data->iMinSAD[1]) {          if (data->temp[0] < data->iMinSAD[1]) {
102                  data->iMinSAD[1] = data->temp[0]; data->currentMV[1].x = x; data->currentMV[1].y = y; }                  data->iMinSAD[1] = data->temp[0]; current[1].x = x; current[1].y = y; }
         if (data->temp[1] < data->iMinSAD[2]) {  
                 data->iMinSAD[2] = data->temp[1]; data->currentMV[2].x = x; data->currentMV[2].y = y; }  
         if (data->temp[2] < data->iMinSAD[3]) {  
                 data->iMinSAD[3] = data->temp[2]; data->currentMV[3].x = x; data->currentMV[3].y = y; }  
         if (data->temp[3] < data->iMinSAD[4]) {  
                 data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; }  
 }  
   
 static void  
 CheckCandidate16_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction)  
 {  
         const uint8_t *Reference;  
         int32_t sad; uint32_t t;  
   
         if ( (x > data->max_dx) || (x < data->min_dx)  
                 || (y > data->max_dy) || (y < data->min_dy) ) return;  
   
         Reference = xvid_me_interpolate16x16qpel(x, y, 0, data);  
   
         sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp);  
         t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 0);  
   
         sad += (data->lambda16 * t * sad)>>10;  
         data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10;  
   
         if (data->chroma && (sad < data->iMinSAD[0] || sad < data->iMinSAD2) )  
                 sad += xvid_me_ChromaSAD(((x/2) >> 1) + roundtab_79[(x/2) & 0x3],  
                                                                 ((y/2) >> 1) + roundtab_79[(y/2) & 0x3], data);  
   
         if (data->temp[0] < data->iMinSAD[1]) {  
                 data->iMinSAD[1] = data->temp[0]; data->currentQMV[1].x = x; data->currentQMV[1].y = y; }  
103          if (data->temp[1] < data->iMinSAD[2]) {          if (data->temp[1] < data->iMinSAD[2]) {
104                  data->iMinSAD[2] = data->temp[1]; data->currentQMV[2].x = x; data->currentQMV[2].y = y; }                  data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; }
105          if (data->temp[2] < data->iMinSAD[3]) {          if (data->temp[2] < data->iMinSAD[3]) {
106                  data->iMinSAD[3] = data->temp[2]; data->currentQMV[3].x = x; data->currentQMV[3].y = y; }                  data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; }
107          if (data->temp[3] < data->iMinSAD[4]) {          if (data->temp[3] < data->iMinSAD[4]) {
108                  data->iMinSAD[4] = data->temp[3]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; }                  data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; }
   
         if (sad < data->iMinSAD[0]) {  
                 data->iMinSAD2 = *(data->iMinSAD);  
                 data->currentQMV2.x = data->currentQMV->x;  
                 data->currentQMV2.y = data->currentQMV->y;  
   
                 data->iMinSAD[0] = sad;  
                 data->currentQMV[0].x = x; data->currentQMV[0].y = y;  
         } else if (sad < data->iMinSAD2) {  
                 data->iMinSAD2 = sad;  
                 data->currentQMV2.x = x; data->currentQMV2.y = y;  
         }  
109  }  }
110    
111  static void  static void
# Line 173  Line 139 
139  }  }
140    
141  static void  static void
 CheckCandidate8_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction)  
 {  
         int32_t sad; uint32_t t;  
         const uint8_t * Reference;  
         VECTOR * current;  
   
         if ( (x > data->max_dx) || (x < data->min_dx)  
                 || (y > data->max_dy) || (y < data->min_dy) ) return;  
   
         /* x and y are in 1/4 precision */  
         Reference = xvid_me_interpolate8x8qpel(x, y, 0, 0, data);  
         current = data->currentQMV;  
   
         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;  
   
         if (sad < *(data->iMinSAD)) {  
                 data->iMinSAD2 = *(data->iMinSAD);  
                 data->currentQMV2.x = data->currentQMV->x;  
                 data->currentQMV2.y = data->currentQMV->y;  
   
                 *(data->iMinSAD) = sad;  
                 data->currentQMV->x = x; data->currentQMV->y = y;  
                 data->dir = Direction;  
         } else if (sad < data->iMinSAD2) {  
                 data->iMinSAD2 = sad;  
                 data->currentQMV2.x = x; data->currentQMV2.y = y;  
         }  
 }  
   
 static void  
142  CheckCandidate32(const int x, const int y, SearchData * const data, const unsigned int Direction)  CheckCandidate32(const int x, const int y, SearchData * const data, const unsigned int Direction)
143  {  {
144          uint32_t t;          uint32_t t;
# Line 544  Line 477 
477                  SearchData * const Data)                  SearchData * const Data)
478  {  {
479          int i = 0;          int i = 0;
480            VECTOR vbest_q; int32_t sbest_q;
481          CheckFunc * CheckCandidate;          CheckFunc * CheckCandidate;
482          *Data->iMinSAD = *(OldData->iMinSAD + 1 + block);          *Data->iMinSAD = *(OldData->iMinSAD + 1 + block);
483          *Data->currentMV = *(OldData->currentMV + 1 + block);          *Data->currentMV = *(OldData->currentMV + 1 + block);
# Line 563  Line 497 
497    
498          if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) {          if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) {
499    
500                    vbest_q = Data->currentQMV[0];
501                    sbest_q = Data->iMinSAD[0];
502    
503                  if (Data->rrv) i = 16; else i = 8;                  if (Data->rrv) i = 16; else i = 8;
504    
505                  Data->RefP[0] = OldData->RefP[0] + i * ((block&1) + Data->iEdgedWidth*(block>>1));                  Data->RefP[0] = OldData->RefP[0] + i * ((block&1) + Data->iEdgedWidth*(block>>1));
# Line 580  Line 517 
517                  else CheckCandidate = CheckCandidate16no4v;                  else CheckCandidate = CheckCandidate16no4v;
518    
519                  if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_RD))) {                  if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_RD))) {
                         int32_t temp_sad = *(Data->iMinSAD); /* store current MinSAD */  
520    
521                          MainSearchFunc *MainSearchPtr;                          MainSearchFunc *MainSearchPtr;
522                          if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = xvid_me_SquareSearch;                          if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = xvid_me_SquareSearch;
# Line 588  Line 524 
524                                          else MainSearchPtr = xvid_me_DiamondSearch;                                          else MainSearchPtr = xvid_me_DiamondSearch;
525    
526                          MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidate);                          MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidate);
527                    }
528    
529                          if(*(Data->iMinSAD) < temp_sad) {                  if(!Data->qpel) {
530                                          Data->currentQMV->x = 2 * Data->currentMV->x; /* update our qpel vector */                          /* halfpel mode */
531                            if (MotionFlags & XVID_ME_HALFPELREFINE8)
532                                    xvid_me_SubpelRefine(Data, CheckCandidate, 0); /* perform halfpel refine of current best vector */
533                    } else {
534                            /* qpel mode */
535                            Data->currentQMV->x = 2*Data->currentMV->x;
536                                          Data->currentQMV->y = 2 * Data->currentMV->y;                                          Data->currentQMV->y = 2 * Data->currentMV->y;
                         }  
                 }  
537    
538                            if(MotionFlags & XVID_ME_FASTREFINE8) {
539                                    /* fast */
540                                    get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3,
541                                            pParam->width, pParam->height, Data->iFcode, 2, 0);
542                                    FullRefine_Fast(Data, CheckCandidate8, 0);
543                            } else if(MotionFlags & XVID_ME_QUARTERPELREFINE8) {
544                                    /* full */
545                  if (MotionFlags & XVID_ME_HALFPELREFINE8) {                  if (MotionFlags & XVID_ME_HALFPELREFINE8) {
546                          int32_t temp_sad = *(Data->iMinSAD); /* store current MinSAD */                                          xvid_me_SubpelRefine(Data, CheckCandidate8, 0); /* hpel part */
547                                            Data->currentQMV->x = 2*Data->currentMV->x;
                         xvid_me_SubpelRefine(Data, CheckCandidate); /* perform halfpel refine of current best vector */  
   
                         if(*(Data->iMinSAD) < temp_sad) { /* we have found a better match */  
                                 Data->currentQMV->x = 2 * Data->currentMV->x; /* update our qpel vector */  
548                                  Data->currentQMV->y = 2 * Data->currentMV->y;                                  Data->currentQMV->y = 2 * Data->currentMV->y;
549                          }                          }
                 }  
550    
                 if (Data->qpel && (MotionFlags & XVID_ME_QUARTERPELREFINE8)) {  
                                 Data->qpel_precision = 1;  
551                                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3,                                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3,
552                                          pParam->width, pParam->height, Data->iFcode, 2, 0);                                          pParam->width, pParam->height, Data->iFcode, 2, 0);
553                                    Data->qpel_precision = 1;
554    
555                                  if((MotionFlags & XVID_ME_FASTREFINE8) && (!Data->rrv))                                  xvid_me_SubpelRefine(Data, CheckCandidate8, 0); /* qpel part */
556                                          SubpelRefine_Fast(Data, CheckCandidate8_qpel);                          }
                                 else  
                                         xvid_me_SubpelRefine(Data, CheckCandidate);  
557                  }                  }
558    
559                    if (sbest_q <= Data->iMinSAD[0]) /* we have not found a better match */
560                            Data->currentQMV[0] = vbest_q;
561    
562          }          }
563    
564          if (Data->rrv) {          if (Data->rrv) {
565                          Data->currentMV->x = RRV_MV_SCALEDOWN(Data->currentMV->x);                          Data->currentMV->x = RRV_MV_SCALEDOWN(Data->currentMV->x);
566                          Data->currentMV->y = RRV_MV_SCALEDOWN(Data->currentMV->y);                          Data->currentMV->y = RRV_MV_SCALEDOWN(Data->currentMV->y);
567          }          } else if(Data->qpel) {
   
         if(Data->qpel) {  
568                  pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x;                  pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x;
569                  pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y;                  pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y;
570                  pMB->qmvs[block] = *Data->currentQMV;                  pMB->qmvs[block] = *Data->currentQMV;
# Line 776  Line 717 
717                  }                  }
718          }          }
719    
720    
721            if(!Data->qpel) {
722                    /* halfpel mode */
723          if (MotionFlags & XVID_ME_HALFPELREFINE16)          if (MotionFlags & XVID_ME_HALFPELREFINE16)
724                          xvid_me_SubpelRefine(Data, CheckCandidate);                                  xvid_me_SubpelRefine(Data, CheckCandidate, 0);
725            } else {
726                    /* qpel mode */
727    
728          for(i = 0; i < 5; i++) {          for(i = 0; i < 5; i++) {
729                  Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* initialize qpel vectors */                  Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* initialize qpel vectors */
730                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
731          }          }
732                    if(MotionFlags & XVID_ME_FASTREFINE16 && MotionFlags & XVID_ME_QUARTERPELREFINE16) {
733          if (Data->qpel) {                          /* fast */
734                            get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
735                                                    pParam->width, pParam->height, Data->iFcode, 2, 0);
736                            FullRefine_Fast(Data, CheckCandidate, 0);
737                    } else {
738                            if(MotionFlags & (XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE16_RD)) {
739                                    /* full */
740                                    if (MotionFlags & XVID_ME_HALFPELREFINE16) {
741                                            xvid_me_SubpelRefine(Data, CheckCandidate, 0); /* hpel part */
742                                            for(i = 0; i < 5; i++) {
743                                                    Data->currentQMV[i].x = 2 * Data->currentMV[i].x;
744                                                    Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
745                                            }
746                                    }
747                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
748                                  pParam->width, pParam->height, Data->iFcode, 2, 0);                                  pParam->width, pParam->height, Data->iFcode, 2, 0);
749                  Data->qpel_precision = 1;                  Data->qpel_precision = 1;
750                  if (MotionFlags & XVID_ME_QUARTERPELREFINE16) {                                  if(MotionFlags & XVID_ME_QUARTERPELREFINE16)
751                          if(MotionFlags & XVID_ME_FASTREFINE16)                                          xvid_me_SubpelRefine(Data, CheckCandidate, 0); /* qpel part */
752                                  SubpelRefine_Fast(Data, CheckCandidate16_qpel);                          }
                         else  
                                 xvid_me_SubpelRefine(Data, CheckCandidate16_qpel);  
753                  }                  }
754          }          }
755    
# Line 809  Line 766 
766                  Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8);                  Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8);
767    
768                  if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_RD))) {                  if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_RD))) {
769                          /* chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, it will not be used */                          /* chroma is only used for comparison to INTER. if the comparison will be done in RD domain, it will not be used */
770                          int sumx = 0, sumy = 0;                          int sumx = 0, sumy = 0;
771    
772                          if (Data->qpel)                          if (Data->qpel)
# Line 866  Line 823 
823          if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED))          if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED))
824                  Flags &= ~(XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP);                  Flags &= ~(XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP);
825    
826            if (Flags & XVID_ME_FASTREFINE8)
827                    Flags &= ~XVID_ME_HALFPELREFINE8_RD;
828    
829            if (Flags & XVID_ME_FASTREFINE16)
830                    Flags &= ~XVID_ME_HALFPELREFINE16_RD;
831    
832          return Flags;          return Flags;
833  }  }
834    
# Line 909  Line 872 
872          Data.dctSpace = dct_space;          Data.dctSpace = dct_space;
873          Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);          Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);
874          Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices;          Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices;
         Data.iMinSAD2 = 0;  
875    
876          if ((current->vop_flags & XVID_VOP_REDUCED)) {          if ((current->vop_flags & XVID_VOP_REDUCED)) {
877                  mb_width = (pParam->width + 31) / 32;                  mb_width = (pParam->width + 31) / 32;
# Line 948  Line 910 
910                          /* initial skip decision */                          /* initial skip decision */
911                          /* no early skip for GMC (global vector = skip vector is unknown!)  */                          /* no early skip for GMC (global vector = skip vector is unknown!)  */
912                          if (current->coding_type != S_VOP)      { /* no fast SKIP for S(GMC)-VOPs */                          if (current->coding_type != S_VOP)      { /* no fast SKIP for S(GMC)-VOPs */
913                                  if (pMB->dquant == 0 && sad00 < pMB->quant * skip_thresh)                                  if (pMB->dquant == 0
914                                            && pMB->sad8[0] < pMB->quant * skip_thresh
915                                            && pMB->sad8[1] < pMB->quant * skip_thresh
916                                            && pMB->sad8[2] < pMB->quant * skip_thresh
917                                            && pMB->sad8[3] < pMB->quant * skip_thresh)
918    
919                                          if (Data.chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) {                                          if (Data.chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) {
920                                                  ZeroMacroblockP(pMB, sad00);                                                  ZeroMacroblockP(pMB, sad00);
921                                                  pMB->mode = MODE_NOT_CODED;                                                  pMB->mode = MODE_NOT_CODED;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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