[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 1214, Tue Nov 18 21:41:21 2003 UTC revision 1215, Wed Nov 19 12:24:25 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.7 2003-11-18 21:41:21 edgomez Exp $   * $Id: estimation_pvop.c,v 1.1.2.8 2003-11-19 12:24:25 syskin 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 216  Line 216 
216          int best_sad = *data->iMinSAD;          int best_sad = *data->iMinSAD;
217          int xo, yo, xo2, yo2;          int xo, yo, xo2, yo2;
218          int size = 2;          int size = 2;
219          *data->iMinSAD2 = 0;          data->iMinSAD2 = 0;
220    
221          /* check all halfpixel positions near our best halfpel position */          /* check all halfpixel positions near our best halfpel position */
222          centerMV = *data->currentQMV;          centerMV = *data->currentQMV;
# Line 244  Line 244 
244          xo2 = second_best.x;          xo2 = second_best.x;
245          yo2 = second_best.y;          yo2 = second_best.y;
246    
247          *data->iMinSAD2 = 256 * 4096;          data->iMinSAD2 = 256 * 4096;
248    
249          if (yo == yo2) {          if (yo == yo2) {
250                  CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);                  CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);
251                  CHECK_CANDIDATE(xo, yo-1, 0);                  CHECK_CANDIDATE(xo, yo-1, 0);
252                  CHECK_CANDIDATE(xo, yo+1, 0);                  CHECK_CANDIDATE(xo, yo+1, 0);
253    
254                  if(best_sad <= *data->iMinSAD2) return;                  if(best_sad <= data->iMinSAD2) return;
255    
256                  if(data->currentQMV[0].x == data->currentQMV2[0].x) {                  if(data->currentQMV[0].x == data->currentQMV2.x) {
257                          CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0);                          CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0);
258                          CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0);                          CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0);
259                  } else {                  } else {
260                          CHECK_CANDIDATE((xo+xo2)>>1,                          CHECK_CANDIDATE((xo+xo2)>>1,
261                                  (data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, 0);                                  (data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2.y, 0);
262                  }                  }
263                  return;                  return;
264          }          }
# Line 268  Line 268 
268                  CHECK_CANDIDATE(xo-1, yo, 0);                  CHECK_CANDIDATE(xo-1, yo, 0);
269                  CHECK_CANDIDATE(xo+1, yo, 0);                  CHECK_CANDIDATE(xo+1, yo, 0);
270    
271                  if(best_sad < *data->iMinSAD2) return;                  if(best_sad < data->iMinSAD2) return;
272    
273                  if(data->currentQMV[0].y == data->currentQMV2[0].y) {                  if(data->currentQMV[0].y == data->currentQMV2.y) {
274                          CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0);                          CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0);
275                          CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0);                          CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0);
276                  } else {                  } else {
277                          CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0);                          CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2.x, (yo+yo2)>>1, 0);
278                  }                  }
279                  return;                  return;
280          }          }
# Line 282  Line 282 
282          CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0);          CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0);
283          CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);          CHECK_CANDIDATE((xo+xo2)>>1, yo, 0);
284    
285          if(best_sad <= *data->iMinSAD2) return;          if(best_sad <= data->iMinSAD2) return;
286    
287          CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0);          CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0);
288  }  }
# Line 581  Line 581 
581  }  }
582    
583  static void  static void
584  Search8(const SearchData * const OldData,  Search8(SearchData * const OldData,
585                  const int x, const int y,                  const int x, const int y,
586                  const uint32_t MotionFlags,                  const uint32_t MotionFlags,
587                  const MBParam * const pParam,                  const MBParam * const pParam,
# Line 592  Line 592 
592  {  {
593          int i = 0;          int i = 0;
594          CheckFunc * CheckCandidate;          CheckFunc * CheckCandidate;
595          Data->iMinSAD = OldData->iMinSAD + 1 + block;          *Data->iMinSAD = *(OldData->iMinSAD + 1 + block);
596          Data->currentMV = OldData->currentMV + 1 + block;          *Data->currentMV = *(OldData->currentMV + 1 + block);
597          Data->currentQMV = OldData->currentQMV + 1 + block;          *Data->currentQMV = *(OldData->currentQMV + 1 + block);
598    
599          if(Data->qpel) {          if(Data->qpel) {
600                  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 675 
675                  pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;                  pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;
676          }          }
677    
678            *(OldData->iMinSAD + 1 + block) = *Data->iMinSAD;
679            *(OldData->currentMV + 1 + block) = *Data->currentMV;
680            *(OldData->currentQMV + 1 + block) = *Data->currentQMV;
681    
682          pMB->mvs[block] = *Data->currentMV;          pMB->mvs[block] = *Data->currentMV;
683          pMB->sad8[block] = 4 * *Data->iMinSAD;          pMB->sad8[block] = 4 * *Data->iMinSAD;
684  }  }
# Line 708  Line 712 
712    
713          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp);          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp);
714    
715          Data->temp[5] = Data->temp[6] = 0; /* chroma-sad cache */          Data->chromaX = Data->chromaY = 0; /* chroma-sad cache */
716          i = Data->rrv ? 2 : 1;          i = Data->rrv ? 2 : 1;
717          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i;          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i;
718          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 728 
728          Data->lambda16 = xvid_me_lambda_vec16[pMB->quant];          Data->lambda16 = xvid_me_lambda_vec16[pMB->quant];
729          Data->lambda8 = xvid_me_lambda_vec8[pMB->quant];          Data->lambda8 = xvid_me_lambda_vec8[pMB->quant];
730          Data->qpel_precision = 0;          Data->qpel_precision = 0;
731          *Data->dir = 0;          Data->dir = 0;
732    
733          memset(Data->currentMV, 0, 5*sizeof(VECTOR));          memset(Data->currentMV, 0, 5*sizeof(VECTOR));
734    
# Line 768  Line 772 
772          else {          else {
773    
774                  MainSearchFunc * MainSearchPtr;                  MainSearchFunc * MainSearchPtr;
775                  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 */
776    
777                  if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;                  if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;
778                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;                  else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;
# Line 828  Line 832 
832                                  pParam->width, pParam->height, Data->iFcode, 2, 0);                                  pParam->width, pParam->height, Data->iFcode, 2, 0);
833                  Data->qpel_precision = 1;                  Data->qpel_precision = 1;
834                  if (MotionFlags & XVID_ME_QUARTERPELREFINE16) {                  if (MotionFlags & XVID_ME_QUARTERPELREFINE16) {
                         *Data->iMinSAD2 = 256 * 4096;  
835                          if(MotionFlags & XVID_ME_FASTREFINE16)                          if(MotionFlags & XVID_ME_FASTREFINE16)
836                                  SubpelRefine_Fast(Data, CheckCandidate16_qpel);                                  SubpelRefine_Fast(Data, CheckCandidate16_qpel);
837                          else                          else
# Line 934  Line 937 
937                  (current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1);                  (current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1);
938    
939          /* 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;  
940          DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);
941          SearchData Data;          SearchData Data;
942          memset(&Data, 0, sizeof(SearchData));          memset(&Data, 0, sizeof(SearchData));
943          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;  
944          Data.iFcode = current->fcode;          Data.iFcode = current->fcode;
945          Data.rounding = pParam->m_rounding_type;          Data.rounding = pParam->m_rounding_type;
946          Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0);          Data.qpel = (current->vol_flags & XVID_VOL_QUARTERPEL ? 1:0);
# Line 958  Line 948 
948          Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0;          Data.rrv = (current->vop_flags & XVID_VOP_REDUCED) ? 1:0;
949          Data.dctSpace = dct_space;          Data.dctSpace = dct_space;
950          Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);          Data.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT);
951            Data.iMinSAD2 = 0;
952    
953          if ((current->vop_flags & XVID_VOP_REDUCED)) {          if ((current->vop_flags & XVID_VOP_REDUCED)) {
954                  mb_width = (pParam->width + 31) / 32;                  mb_width = (pParam->width + 31) / 32;
# Line 984  Line 975 
975                                                          pParam->edged_width, pMB->sad8 );                                                          pParam->edged_width, pMB->sad8 );
976    
977                          if (Data.chroma) {                          if (Data.chroma) {
978                                  Data.temp[7] = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8,                                  Data.chromaSAD = sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8,
979                                                                          pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2)                                                                          pRef->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2)
980                                                                  + sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8,                                                                  + sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8,
981                                                                          pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);                                                                          pRef->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);
982                                  pMB->sad16 += Data.temp[7];                                  pMB->sad16 += Data.chromaSAD;
983                          }                          }
984    
985                          sad00 = pMB->sad16;                          sad00 = pMB->sad16;

Legend:
Removed from v.1214  
changed lines
  Added in v.1215

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