[svn] / branches / dev-api-4 / xvidcore / src / motion / estimation_pvop.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/motion/estimation_pvop.c

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

revision 1194, Tue Oct 28 23:47:29 2003 UTC revision 1273, Thu Dec 18 02:02:08 2003 UTC
# Line 21  Line 21 
21   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23   *   *
24   * $Id: estimation_pvop.c,v 1.1.2.5 2003-10-28 23:47:29 Isibaar Exp $   * $Id: estimation_pvop.c,v 1.1.2.11 2003-12-18 02:02:08 Isibaar Exp $
25   *   *
26   ****************************************************************************/   ****************************************************************************/
27    
# Line 60  Line 60 
60  };  };
61    
62  static void  static void
63  CheckCandidate16(const int x, const int y, const 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; uint32_t t;
# Line 85  Line 85 
85          if (sad < data->iMinSAD[0]) {          if (sad < data->iMinSAD[0]) {
86                  data->iMinSAD[0] = sad;                  data->iMinSAD[0] = sad;
87                  data->currentMV[0].x = x; data->currentMV[0].y = y;                  data->currentMV[0].x = x; data->currentMV[0].y = y;
88                  *data->dir = Direction;                  data->dir = Direction;
89          }          }
90    
91  no16:  no16:
# Line 100  Line 100 
100  }  }
101    
102  static void  static void
103  CheckCandidate16_qpel(const int x, const int y, const SearchData * const data, const unsigned int Direction)  CheckCandidate16_qpel(const int x, const int y, SearchData * const data, const unsigned int Direction)
104  {  {
105          const uint8_t *Reference;          const uint8_t *Reference;
106          int32_t sad; uint32_t t;          int32_t sad; uint32_t t;
# Line 116  Line 116 
116          sad += (data->lambda16 * t * sad)>>10;          sad += (data->lambda16 * t * sad)>>10;
117          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;
118    
119          if (data->chroma && (sad < data->iMinSAD[0] || sad < data->iMinSAD2[0]) )          if (data->chroma && (sad < data->iMinSAD[0] || sad < data->iMinSAD2) )
120                  sad += xvid_me_ChromaSAD(((x/2) >> 1) + roundtab_79[(x/2) & 0x3],                  sad += xvid_me_ChromaSAD(((x/2) >> 1) + roundtab_79[(x/2) & 0x3],
121                                                                  ((y/2) >> 1) + roundtab_79[(y/2) & 0x3], data);                                                                  ((y/2) >> 1) + roundtab_79[(y/2) & 0x3], data);
122    
# Line 130  Line 130 
130                  data->iMinSAD[4] = data->temp[3]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; }                  data->iMinSAD[4] = data->temp[3]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; }
131    
132          if (sad < data->iMinSAD[0]) {          if (sad < data->iMinSAD[0]) {
133                  *(data->iMinSAD2) = *(data->iMinSAD);                  data->iMinSAD2 = *(data->iMinSAD);
134                  data->currentQMV2->x = data->currentQMV->x;                  data->currentQMV2.x = data->currentQMV->x;
135                  data->currentQMV2->y = data->currentQMV->y;                  data->currentQMV2.y = data->currentQMV->y;
136    
137                  data->iMinSAD[0] = sad;                  data->iMinSAD[0] = sad;
138                  data->currentQMV[0].x = x; data->currentQMV[0].y = y;                  data->currentQMV[0].x = x; data->currentQMV[0].y = y;
139          } else if (sad < *(data->iMinSAD2)) {          } else if (sad < data->iMinSAD2) {
140                  *(data->iMinSAD2) = sad;                  data->iMinSAD2 = sad;
141                  data->currentQMV2->x = x; data->currentQMV2->y = y;                  data->currentQMV2.x = x; data->currentQMV2.y = y;
142          }          }
143  }  }
144    
145  static void  static void
146  CheckCandidate8(const int x, const int y, const SearchData * const data, const unsigned int Direction)  CheckCandidate8(const int x, const int y, SearchData * const data, const unsigned int Direction)
147  {  {
148          int32_t sad; uint32_t t;          int32_t sad; uint32_t t;
149          const uint8_t * Reference;          const uint8_t * Reference;
# Line 168  Line 168 
168          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
169                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
170                  current->x = x; current->y = y;                  current->x = x; current->y = y;
171                  *data->dir = Direction;                  data->dir = Direction;
172          }          }
173  }  }
174    
175  static void  static void
176  CheckCandidate32(const int x, const int y, const SearchData * const data, const unsigned int Direction)  CheckCandidate32(const int x, const int y, SearchData * const data, const unsigned int Direction)
177  {  {
178          uint32_t t;          uint32_t t;
179          const uint8_t * Reference;          const uint8_t * Reference;
# Line 194  Line 194 
194          if (sad < data->iMinSAD[0]) {          if (sad < data->iMinSAD[0]) {
195                  data->iMinSAD[0] = sad;                  data->iMinSAD[0] = sad;
196                  data->currentMV[0].x = x; data->currentMV[0].y = y;                  data->currentMV[0].x = x; data->currentMV[0].y = y;
197                  *data->dir = Direction;                  data->dir = Direction;
198          }          }
199    
200          if (data->temp[0] < data->iMinSAD[1]) {          if (data->temp[0] < data->iMinSAD[1]) {
# Line 207  Line 207 
207                  data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; }                  data->iMinSAD[4] = data->temp[3]; data->currentMV[4].x = x; data->currentMV[4].y = y; }
208  }  }
209    
 static void  
 SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate)  
 {  
 /* Do a fast q-pel refinement */  
         VECTOR centerMV;  
         VECTOR second_best;  
         int best_sad = *data->iMinSAD;  
         int xo, yo, xo2, yo2;  
         int size = 2;  
         *data->iMinSAD2 = 0;  
   
         /* check all halfpixel positions near our best halfpel position */  
         centerMV = *data->currentQMV;  
         *data->iMinSAD = 256 * 4096;  
   
         CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0);  
         CHECK_CANDIDATE(centerMV.x + size, centerMV.y - size, 0);  
         CHECK_CANDIDATE(centerMV.x + size, centerMV.y, 0);  
         CHECK_CANDIDATE(centerMV.x + size, centerMV.y + size, 0);  
   
         CHECK_CANDIDATE(centerMV.x, centerMV.y + size, 0);  
         CHECK_CANDIDATE(centerMV.x - size, centerMV.y + size, 0);  
         CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0);  
         CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0);  
   
         second_best = *data->currentQMV;  
   
         /* after second_best has been found, go back to the vector we began with */  
   
         data->currentQMV[0] = centerMV;  
         *data->iMinSAD = best_sad;  
   
         xo = centerMV.x;  
         yo = centerMV.y;  
         xo2 = second_best.x;  
         yo2 = second_best.y;  
   
         *data->iMinSAD2 = 256 * 4096;  
   
         if (yo == yo2) {  
                 CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);  
                 CHECK_CANDIDATE(xo, yo-1, 0);  
                 CHECK_CANDIDATE(xo, yo+1, 0);  
   
                 if(best_sad <= *data->iMinSAD2) return;  
   
                 if(data->currentQMV[0].x == data->currentQMV2[0].x) {  
                         CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0);  
                         CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0);  
                 } else {  
                         CHECK_CANDIDATE((xo+xo2)>>1,  
                                 (data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, 0);  
                 }  
                 return;  
         }  
   
         if (xo == xo2) {  
                 CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0);  
                 CHECK_CANDIDATE(xo-1, yo, 0);  
                 CHECK_CANDIDATE(xo+1, yo, 0);  
   
                 if(best_sad < *data->iMinSAD2) return;  
   
                 if(data->currentQMV[0].y == data->currentQMV2[0].y) {  
                         CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0);  
                         CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0);  
                 } else {  
                         CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0);  
                 }  
                 return;  
         }  
   
         CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0);  
         CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);  
   
         if(best_sad <= *data->iMinSAD2) return;  
   
         CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0);  
 }  
   
210  int  int
211  xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference,  xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference,
212                                                          const int x, const int y,                                                          const int x, const int y,
# Line 479  Line 399 
399    
400          /* intra decision */          /* intra decision */
401    
402          if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */          if (iQuant > 10) InterBias += 60 * (iQuant - 10); /* to make high quants work */
403          if (y != 0)          if (y != 0)
404                  if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80;                  if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80;
405          if (x != 0)          if (x != 0)
# Line 581  Line 501 
501  }  }
502    
503  static void  static void
504  Search8(const SearchData * const OldData,  Search8(SearchData * const OldData,
505                  const int x, const int y,                  const int x, const int y,
506                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
507                  const MBParam * const pParam,                  const MBParam * const pParam,
# Line 592  Line 512 
512  {  {
513          int i = 0;          int i = 0;
514          CheckFunc * CheckCandidate;          CheckFunc * CheckCandidate;
515          Data->iMinSAD = OldData->iMinSAD + 1 + block;          *Data->iMinSAD = *(OldData->iMinSAD + 1 + block);
516          Data->currentMV = OldData->currentMV + 1 + block;          *Data->currentMV = *(OldData->currentMV + 1 + block);
517          Data->currentQMV = OldData->currentQMV + 1 + block;          *Data->currentQMV = *(OldData->currentQMV + 1 + block);
518    
519          if(Data->qpel) {          if(Data->qpel) {
520                  Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2, y/2, block);                  Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2, y/2, block);
# Line 675  Line 595 
595                  pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;                  pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;
596          }          }
597    
598            *(OldData->iMinSAD + 1 + block) = *Data->iMinSAD;
599            *(OldData->currentMV + 1 + block) = *Data->currentMV;
600            *(OldData->currentQMV + 1 + block) = *Data->currentQMV;
601    
602          pMB->mvs[block] = *Data->currentMV;          pMB->mvs[block] = *Data->currentMV;
603          pMB->sad8[block] = 4 * *Data->iMinSAD;          pMB->sad8[block] = 4 * *Data->iMinSAD;
604  }  }
# Line 708  Line 632 
632    
633          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp);          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp);
634    
635          Data->temp[5] = Data->temp[6] = 0; /* chroma-sad cache */          Data->chromaX = Data->chromaY = 0; /* chroma-sad cache */
636          i = Data->rrv ? 2 : 1;          i = Data->rrv ? 2 : 1;
637          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i;          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i;
638          Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i;          Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i;
# Line 724  Line 648 
648          Data->lambda16 = xvid_me_lambda_vec16[pMB->quant];          Data->lambda16 = xvid_me_lambda_vec16[pMB->quant];
649          Data->lambda8 = xvid_me_lambda_vec8[pMB->quant];          Data->lambda8 = xvid_me_lambda_vec8[pMB->quant];
650          Data->qpel_precision = 0;          Data->qpel_precision = 0;
651          *Data->dir = 0;          Data->dir = 0;
652    
653          memset(Data->currentMV, 0, 5*sizeof(VECTOR));          memset(Data->currentMV, 0, 5*sizeof(VECTOR));
654    
# Line 768  Line 692 
692          else {          else {
693    
694                  MainSearchFunc * MainSearchPtr;                  MainSearchFunc * MainSearchPtr;
695                  int mask = make_mask(pmv, i, *Data->dir); /* all vectors pmv[0..i-1] have been checked */                  int mask = make_mask(pmv, i, Data->dir); /* all vectors pmv[0..i-1] have been checked */
696    
697                  if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;                  if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;
698                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;
# Line 794  Line 718 
718                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
719    
720                                  CheckCandidate(startMV.x, startMV.y, Data, 255);                                  CheckCandidate(startMV.x, startMV.y, Data, 255);
721                                  MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate);                                  xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate);
722                                  if (bSAD < Data->iMinSAD[0]) {                                  if (bSAD < Data->iMinSAD[0]) {
723                                          Data->currentMV[0] = backupMV;                                          Data->currentMV[0] = backupMV;
724                                          Data->iMinSAD[0] = bSAD; }                                          Data->iMinSAD[0] = bSAD; }
# Line 806  Line 730 
730                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
731    
732                                  CheckCandidate(startMV.x, startMV.y, Data, 255);                                  CheckCandidate(startMV.x, startMV.y, Data, 255);
733                                  MainSearchPtr(startMV.x, startMV.y, Data, 255, CheckCandidate);                                  xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate);
734                                  if (bSAD < Data->iMinSAD[0]) {                                  if (bSAD < Data->iMinSAD[0]) {
735                                          Data->currentMV[0] = backupMV;                                          Data->currentMV[0] = backupMV;
736                                          Data->iMinSAD[0] = bSAD;                                          Data->iMinSAD[0] = bSAD;
# Line 933  Line 857 
857                  (current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1);                  (current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1);
858    
859          /* some pre-initialized thingies for SearchP */          /* some pre-initialized thingies for SearchP */
         int32_t temp[8]; uint32_t dir;  
         VECTOR currentMV[5];  
         VECTOR currentQMV[5];  
         VECTOR currentQMV2;  
         int32_t iMinSAD[5];  
         int32_t iMinSAD2;  
860          DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);
861          SearchData Data;          SearchData Data;
862          memset(&Data, 0, sizeof(SearchData));          memset(&Data, 0, sizeof(SearchData));
863          Data.iEdgedWidth = iEdgedWidth;          Data.iEdgedWidth = iEdgedWidth;
         Data.currentMV = currentMV;  
         Data.currentQMV = currentQMV;  
         Data.currentQMV2 = &currentQMV2;  
         Data.iMinSAD = iMinSAD;  
         Data.iMinSAD2 = &iMinSAD2;  
         Data.temp = temp;  
         Data.dir = &dir;  
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 = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0);          Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0);
# Line 957  Line 868 
868          Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0;          Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0;
869          Data.dctSpace = dct_space;          Data.dctSpace = dct_space;
870          Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);          Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);
871            Data.mpeg_quant_matrices = pParam->mpeg_quant_matrices;
872            Data.iMinSAD2 = 0;
873    
874          if ((current->vop_flags & XVID_VOP_REDUCED)) {          if ((current->vop_flags & XVID_VOP_REDUCED)) {
875                  mb_width = (pParam->width + 31) / 32;                  mb_width = (pParam->width + 31) / 32;
# Line 983  Line 896 
896                                                          pParam->edged_width, pMB->sad8 );                                                          pParam->edged_width, pMB->sad8 );
897    
898                          if (Data.chroma) {                          if (Data.chroma) {
899                                  Data.temp[7] = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8,                                  Data.chromaSAD = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8,
900                                                                          pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2)                                                                          pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2)
901                                                                  + sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8,                                                                  + sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8,
902                                                                          pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);                                                                          pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);
903                                  pMB->sad16 += Data.temp[7];                                  pMB->sad16 += Data.chromaSAD;
904                          }                          }
905    
906                          sad00 = pMB->sad16;                          sad00 = pMB->sad16;
# Line 1013  Line 926 
926                                                                            MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16,                                                                            MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16,
927                                                                            MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16,                                                                            MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16,
928                                                                            prevMB->sad16)));                                                                            prevMB->sad16)));
929                                          }                                          } else {
                                         else {  
930                                                  stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16,                                                  stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16,
931                                                                            MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16,                                                                            MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16,
932                                                                            MIN((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16,                                                                            MIN((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16,

Legend:
Removed from v.1194  
changed lines
  Added in v.1273

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