[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 702, Tue Dec 10 11:13:50 2002 UTC revision 704, Wed Dec 11 10:32:29 2002 UTC
# Line 282  Line 282 
282  }  }
283    
284  static void  static void
285    CheckCandidate32(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
286    {
287            int t;
288            const uint8_t * Reference;
289    
290            if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) || //non-zero integer value
291                    ( x > data->max_dx) || ( x < data->min_dx)
292                    || ( y > data->max_dy) || (y < data->min_dy)) return;
293    
294            switch ( ((x&1)<<1) + (y&1) ) {
295                    case 0 : Reference = data->Ref + x/2 + (y/2)*(data->iEdgedWidth); break;
296                    case 1 : Reference = data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); break;
297                    case 2 : Reference = data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); break;
298                    default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;
299            }
300    
301            t = d_mv_bits(RRV_MV_SCALEDOWN(x) - data->predMV.x,
302                                            RRV_MV_SCALEDOWN(y) - data->predMV.y, data->iFcode);
303    
304            data->temp[0] = sad32v_c(data->Cur, Reference, data->iEdgedWidth, data->temp + 1);
305    
306            data->temp[0] += (data->lambda16 * t * data->temp[0])/1000;
307            data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))/100;
308    
309            if (data->temp[0] < data->iMinSAD[0]) {
310                    data->iMinSAD[0] = data->temp[0];
311                    data->currentMV[0].x = x; data->currentMV[0].y = y;
312                    *dir = Direction; }
313    
314            if (data->temp[1] < data->iMinSAD[1]) {
315                    data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; }
316            if (data->temp[2] < data->iMinSAD[2]) {
317                    data->iMinSAD[2] = data->temp[2]; data->currentMV[2].x = x; data->currentMV[2].y = y; }
318            if (data->temp[3] < data->iMinSAD[3]) {
319                    data->iMinSAD[3] = data->temp[3]; data->currentMV[3].x = x; data->currentMV[3].y = y; }
320            if (data->temp[4] < data->iMinSAD[4]) {
321                    data->iMinSAD[4] = data->temp[4]; data->currentMV[4].x = x; data->currentMV[4].y = y; }
322    }
323    
324    static void
325  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)
326  {  {
327          int32_t sad;          int32_t sad;
# Line 292  Line 332 
332          if (( x > data->max_dx) || ( x < data->min_dx)          if (( x > data->max_dx) || ( x < data->min_dx)
333                  || ( y > data->max_dy) || (y < data->min_dy)) return;                  || ( y > data->max_dy) || (y < data->min_dy)) return;
334    
335            if (data->rrv) {
336                    if ( (!(x&1) && x !=0) || (!(y&1) && y !=0) ) return; //non-zero integer value
337                    t = d_mv_bits(RRV_MV_SCALEDOWN(x) - data->predMV.x,
338                                            RRV_MV_SCALEDOWN(y) - data->predMV.y, data->iFcode);
339            }
340    
341          if (data->qpel_precision) { // x and y are in 1/4 precision          if (data->qpel_precision) { // x and y are in 1/4 precision
342                  Reference = Interpolate16x16qpel(x, y, 0, data);                  Reference = Interpolate16x16qpel(x, y, 0, data);
343                  t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);                  t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);
# Line 304  Line 350 
350                          default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;                          default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;
351                  }                  }
352                  if (data->qpel) t = d_mv_bits(2*x - data->predMV.x, 2*y - data->predMV.y, data->iFcode);                  if (data->qpel) t = d_mv_bits(2*x - data->predMV.x, 2*y - data->predMV.y, data->iFcode);
353                  else t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);                  else if (!data->rrv) t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);
354                  current = data->currentMV;                  current = data->currentMV;
355          }          }
356    
# Line 663  Line 709 
709  static __inline int  static __inline int
710  SkipDecisionP(const IMAGE * current, const IMAGE * reference,  SkipDecisionP(const IMAGE * current, const IMAGE * reference,
711                                                          const int x, const int y,                                                          const int x, const int y,
712                                                          const uint32_t iEdgedWidth, const uint32_t iQuant)                                                          const uint32_t iEdgedWidth, const uint32_t iQuant, int rrv)
713    
714  {  {
715  /*      keep repeating checks for all b-frames before this P frame,  /*      keep repeating checks for all b-frames before this P frame,
716          to make sure that SKIP is possible (todo)          to make sure that SKIP is possible (todo)
717          how: if skip is not possible set sad00 to a very high value */          how: if skip is not possible set sad00 to a very high value */
718            if(rrv) {
719                    uint32_t sadC = sad16(current->u + x*16 + y*(iEdgedWidth/2)*16,
720                                                    reference->u + x*16 + y*(iEdgedWidth/2)*16, iEdgedWidth/2, 256*4096);
721                    if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0;
722                    sadC += sad16(current->v + (x + y*(iEdgedWidth/2))*16,
723                                                    reference->v + (x + y*(iEdgedWidth/2))*16, iEdgedWidth/2, 256*4096);
724                    if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP*4) return 0;
725                    return 1;
726            } else {
727          uint32_t sadC = sad8(current->u + x*8 + y*(iEdgedWidth/2)*8,          uint32_t sadC = sad8(current->u + x*8 + y*(iEdgedWidth/2)*8,
728                                          reference->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2);                                          reference->u + x*8 + y*(iEdgedWidth/2)*8, iEdgedWidth/2);
729          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;
730          sadC += sad8(current->v + (x + y*(iEdgedWidth/2))*8,          sadC += sad8(current->v + (x + y*(iEdgedWidth/2))*8,
731                                          reference->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);                                          reference->v + (x + y*(iEdgedWidth/2))*8, iEdgedWidth/2);
732          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;          if (sadC > iQuant * MAX_CHROMA_SAD_FOR_SKIP) return 0;
   
733          return 1;          return 1;
734  }  }
735    }
736    
737  static __inline void  static __inline void
738  SkipMacroblockP(MACROBLOCK *pMB, const int32_t sad)  SkipMacroblockP(MACROBLOCK *pMB, const int32_t sad)
# Line 708  Line 762 
762    
763          const VECTOR zeroMV = { 0, 0 };          const VECTOR zeroMV = { 0, 0 };
764    
765          int mb_width = pParam->mb_width;          uint32_t mb_width = pParam->mb_width;
766          int mb_height = pParam->mb_height;          uint32_t mb_height = pParam->mb_height;
767    
768          uint32_t x, y;          uint32_t x, y;
769          uint32_t iIntra = 0;          uint32_t iIntra = 0;
# Line 722  Line 776 
776          VECTOR currentQMV[5];          VECTOR currentQMV[5];
777          int32_t iMinSAD[5];          int32_t iMinSAD[5];
778          SearchData Data;          SearchData Data;
779            memset(&Data, 0, sizeof(SearchData));
780          Data.iEdgedWidth = pParam->edged_width;          Data.iEdgedWidth = pParam->edged_width;
781          Data.currentMV = currentMV;          Data.currentMV = currentMV;
782          Data.currentQMV = currentQMV;          Data.currentQMV = currentQMV;
# Line 731  Line 786 
786          Data.rounding = pParam->m_rounding_type;          Data.rounding = pParam->m_rounding_type;
787          Data.qpel = pParam->m_quarterpel;          Data.qpel = pParam->m_quarterpel;
788          Data.chroma = current->global_flags & XVID_ME_COLOUR;          Data.chroma = current->global_flags & XVID_ME_COLOUR;
789            Data.rrv = current->global_flags & XVID_REDUCED;
790    
791          if ((current->global_flags & XVID_REDUCED))          if ((current->global_flags & XVID_REDUCED)) {
         {  
792                  mb_width = (pParam->width + 31) / 32;                  mb_width = (pParam->width + 31) / 32;
793                  mb_height = (pParam->height + 31) / 32;                  mb_height = (pParam->height + 31) / 32;
794                    Data.qpel = Data.chroma = 0;
795          }          }
796    
797          if((qimage = (uint8_t *) malloc(32 * pParam->edged_width)) == NULL)          if((qimage = (uint8_t *) malloc(32 * pParam->edged_width)) == NULL)
# Line 749  Line 805 
805                  for (x = 0; x < mb_width; x++)  {                  for (x = 0; x < mb_width; x++)  {
806                          MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width];                          MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width];
807    
808                          pMB->sad16                          if (Data.rrv) pMB->sad16 =
809                                  = sad16v(pCurrent->y + (x + y * pParam->edged_width) * 16,                                  sad32v_c(pCurrent->y + (x + y * pParam->edged_width) * 32,
810                                                            pRef->y + (x + y * pParam->edged_width) * 32,
811                                                            pParam->edged_width, pMB->sad8 );
812    
813                            else pMB->sad16 =
814                                    sad16v(pCurrent->y + (x + y * pParam->edged_width) * 16,
815                                                          pRef->y + (x + y * pParam->edged_width) * 16,                                                          pRef->y + (x + y * pParam->edged_width) * 16,
816                                                          pParam->edged_width, pMB->sad8 );                                                          pParam->edged_width, pMB->sad8 );
817    
# Line 779  Line 840 
840  //initial skip decision  //initial skip decision
841  /* no early skip for GMC (global vector = skip vector is unknown!)  */  /* no early skip for GMC (global vector = skip vector is unknown!)  */
842                          if (current->coding_type == P_VOP)      { /* no fast SKIP for S(GMC)-VOPs */                          if (current->coding_type == P_VOP)      { /* no fast SKIP for S(GMC)-VOPs */
843                                  if (pMB->dquant == NO_CHANGE && sad00 < pMB->quant * INITIAL_SKIP_THRESH)                                  if (pMB->dquant == NO_CHANGE && sad00 < pMB->quant * INITIAL_SKIP_THRESH  * (Data.rrv ? 4:1) )
844                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, pParam->edged_width, pMB->quant)) {                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, pParam->edged_width, pMB->quant, Data.rrv)) {
845                                                  SkipMacroblockP(pMB, sad00);                                                  SkipMacroblockP(pMB, sad00);
846                                                  continue;                                                  continue;
847                                          }                                          }
# Line 794  Line 855 
855  /* final skip decision, a.k.a. "the vector you found, really that good?" */  /* final skip decision, a.k.a. "the vector you found, really that good?" */
856                          if (current->coding_type == P_VOP)      {                          if (current->coding_type == P_VOP)      {
857                                  if ( (pMB->dquant == NO_CHANGE) && (sad00 < pMB->quant * MAX_SAD00_FOR_SKIP)                                  if ( (pMB->dquant == NO_CHANGE) && (sad00 < pMB->quant * MAX_SAD00_FOR_SKIP)
858                                  && ((100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH) )                                          && ((100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1)) )
859                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, pParam->edged_width, pMB->quant)) {                                          if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, pParam->edged_width, pMB->quant, Data.rrv)) {
860                                                  SkipMacroblockP(pMB, sad00);                                                  SkipMacroblockP(pMB, sad00);
861                                                  continue;                                                  continue;
862                                          }                                          }
# Line 811  Line 872 
872                                  if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80;                                  if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80;
873    
874                          if (Data.chroma) InterBias += 50; // to compensate bigger SAD                          if (Data.chroma) InterBias += 50; // to compensate bigger SAD
875                            if (Data.rrv) InterBias *= 4; //??
876    
877                          if (InterBias < pMB->sad16)  {                          if (InterBias < pMB->sad16)  {
878                                  const int32_t deviation =                                  int32_t deviation;
879                                          dev16(pCurrent->y + (x + y * pParam->edged_width) * 16,                                  if (Data.rrv) {
880                                            deviation = dev16(pCurrent->y + (x + y * pParam->edged_width) * 32,
881                                                                                    pParam->edged_width)
882                                                    + dev16(pCurrent->y + (x + y * pParam->edged_width) * 32 + 16,
883                                                                                    pParam->edged_width)
884                                                    + dev16(pCurrent->y + (x + y * pParam->edged_width) * 32 + 16 * pParam->edged_width,
885                                                                                    pParam->edged_width)
886                                                    + dev16(pCurrent->y + (x + y * pParam->edged_width) * 32 + 16 * (pParam->edged_width+1),
887                                                                                    pParam->edged_width);
888                                    } else
889                                            deviation = dev16(pCurrent->y + (x + y * pParam->edged_width) * 16,
890                                                    pParam->edged_width);                                                    pParam->edged_width);
891    
892                                  if (deviation < (pMB->sad16 - InterBias)) {                                  if (deviation < (pMB->sad16 - InterBias)) {
# Line 862  Line 934 
934  }  }
935    
936  static __inline void  static __inline void
937  PreparePredictionsP(VECTOR * const pmv, int x, int y, const int iWcount,  PreparePredictionsP(VECTOR * const pmv, int x, int y, int iWcount,
938                          const int iHcount, const MACROBLOCK * const prevMB)                          int iHcount, const MACROBLOCK * const prevMB, int rrv)
939  {  {
940    
941  //this function depends on get_pmvdata which means that it sucks. It should get the predictions by itself  //this function depends on get_pmvdata which means that it sucks. It should get the predictions by itself
942            if (rrv) { iWcount /= 2; iHcount /= 2; }
943    
944          if ( (y != 0) && (x != (iWcount-1)) ) {         // [5] top-right neighbour          if ( (y != 0) && (x < (iWcount-1)) ) {          // [5] top-right neighbour
945                  pmv[5].x = EVEN(pmv[3].x);                  pmv[5].x = EVEN(pmv[3].x);
946                  pmv[5].y = EVEN(pmv[3].y);                  pmv[5].y = EVEN(pmv[3].y);
947          } else pmv[5].x = pmv[5].y = 0;          } else pmv[5].x = pmv[5].y = 0;
# Line 880  Line 953 
953      else pmv[4].x = pmv[4].y = 0;      else pmv[4].x = pmv[4].y = 0;
954    
955          // [1] median prediction          // [1] median prediction
956          pmv[1].x = EVEN(pmv[0].x); pmv[1].y = EVEN(pmv[0].y);          if (rrv) { //median is in halfzero-precision
957                    pmv[1].x = RRV_MV_SCALEUP(pmv[0].x);
958                    pmv[1].y = RRV_MV_SCALEUP(pmv[0].y);
959            } else { pmv[1].x = EVEN(pmv[0].x); pmv[1].y = EVEN(pmv[0].y); }
960    
961          pmv[0].x = pmv[0].y = 0; // [0] is zero; not used in the loop (checked before) but needed here for make_mask          pmv[0].x = pmv[0].y = 0; // [0] is zero; not used in the loop (checked before) but needed here for make_mask
962    
963          pmv[2].x = EVEN(prevMB->mvs[0].x); // [2] is last frame          pmv[2].x = EVEN(prevMB->mvs[0].x); // [2] is last frame
964          pmv[2].y = EVEN(prevMB->mvs[0].y);          pmv[2].y = EVEN(prevMB->mvs[0].y);
965    
966          if ((x != iWcount-1) && (y != iHcount-1)) {          if ((x < iWcount-1) && (y < iHcount-1)) {
967                  pmv[6].x = EVEN((prevMB+1+iWcount)->mvs[0].x); //[6] right-down neighbour in last frame                  pmv[6].x = EVEN((prevMB+1+iWcount)->mvs[0].x); //[6] right-down neighbour in last frame
968                  pmv[6].y = EVEN((prevMB+1+iWcount)->mvs[0].y);                  pmv[6].y = EVEN((prevMB+1+iWcount)->mvs[0].y);
969          } else pmv[6].x = pmv[6].y = 0;          } else pmv[6].x = pmv[6].y = 0;
970    
971            if (rrv) {
972                    int i;
973                    for (i = 0; i < 7; i++) {
974                            pmv[i].x = RRV_MV_SCALEDOWN(pmv[i].x);
975                            pmv[i].x = RRV_MV_SCALEUP(pmv[i].x); // a trick
976                    }
977            }
978  }  }
979    
980  static void  static void
# Line 914  Line 998 
998          int i, iDirection = 255, mask, threshA;          int i, iDirection = 255, mask, threshA;
999          VECTOR pmv[7];          VECTOR pmv[7];
1000    
1001          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, 0, pmv, Data->temp);  //has to be changed to get_pmv(2)()          if (Data->rrv) {
1002                    i = (pParam->width + 31) / 32;
1003                    get_range_rrv(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 32,
1004                                                    pParam->width, pParam->height, Data->iFcode);
1005            } else {
1006                    i = pParam->mb_width;
1007          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
1008                  pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel);                  pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel);
1009            }
1010    
1011          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16;          i = pParam->mb_width; // XXXX
1012          Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8;          get_pmvdata2(pMBs, i, 0, x, y, 0, pmv, Data->temp);  //has to be changed to get_pmv(2)()
         Data->CurU = pCur->u + (x + y * (Data->iEdgedWidth/2)) * 8;  
1013    
1014          Data->Ref = pRef->y + (x + Data->iEdgedWidth*y) * 16;          if (Data->rrv) i = 2; else i = 1;
1015          Data->RefH = pRefH + (x + Data->iEdgedWidth*y) * 16;          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16*i;
1016          Data->RefV = pRefV + (x + Data->iEdgedWidth*y) * 16;          Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8*i;
1017          Data->RefHV = pRefHV + (x + Data->iEdgedWidth*y) * 16;          Data->CurU = pCur->u + (x + y * (Data->iEdgedWidth/2)) * 8*i;
1018          Data->RefCV = pRef->v + (x + y * (Data->iEdgedWidth/2)) * 8;  
1019          Data->RefCU = pRef->u + (x + y * (Data->iEdgedWidth/2)) * 8;          Data->Ref = pRef->y + (x + Data->iEdgedWidth*y) * 16*i;
1020            Data->RefH = pRefH + (x + Data->iEdgedWidth*y) * 16*i;
1021            Data->RefV = pRefV + (x + Data->iEdgedWidth*y) * 16*i;
1022            Data->RefHV = pRefHV + (x + Data->iEdgedWidth*y) * 16*i;
1023            Data->RefCV = pRef->v + (x + y * (Data->iEdgedWidth/2)) * 8*i;
1024            Data->RefCU = pRef->u + (x + y * (Data->iEdgedWidth/2)) * 8*i;
1025    
1026          Data->lambda16 = lambda_vec16[iQuant];          Data->lambda16 = lambda_vec16[iQuant];
1027          Data->lambda8 = lambda_vec8[iQuant];          Data->lambda8 = lambda_vec8[iQuant];
1028          Data->qpel_precision = 0;          Data->qpel_precision = 0;
1029    
         if (!(MotionFlags & PMV_HALFPEL16)) {  
                 Data->min_dx = EVEN(Data->min_dx);  
                 Data->max_dx = EVEN(Data->max_dx);  
                 Data->min_dy = EVEN(Data->min_dy);  
                 Data->max_dy = EVEN(Data->max_dy); }  
   
1030          if (pMB->dquant != NO_CHANGE) inter4v = 0;          if (pMB->dquant != NO_CHANGE) inter4v = 0;
1031    
1032          for(i = 0;  i < 5; i++)          for(i = 0;  i < 5; i++)
# Line 961  Line 1049 
1049                  if (threshA > 1024) threshA = 1024; }                  if (threshA > 1024) threshA = 1024; }
1050    
1051          PreparePredictionsP(pmv, x, y, pParam->mb_width, pParam->mb_height,          PreparePredictionsP(pmv, x, y, pParam->mb_width, pParam->mb_height,
1052                                          prevMBs + x + y * pParam->mb_width);                                          prevMBs + x + y * pParam->mb_width, Data->rrv);
1053    
1054          if (inter4v || Data->chroma) CheckCandidate = CheckCandidate16;          if (Data->rrv) CheckCandidate = CheckCandidate32;
1055            else if (inter4v || Data->chroma) CheckCandidate = CheckCandidate16;
1056          else CheckCandidate = CheckCandidate16no4v; //for extra speed          else CheckCandidate = CheckCandidate16no4v; //for extra speed
1057    
1058  /* main loop. checking all predictions */  /* main loop. checking all predictions */
# Line 994  Line 1083 
1083                  if (MotionFlags & PMV_EXTSEARCH16) {                  if (MotionFlags & PMV_EXTSEARCH16) {
1084                          int32_t bSAD;                          int32_t bSAD;
1085                          VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0];                          VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0];
1086                            if (Data->rrv) {
1087                                    startMV.x = RRV_MV_SCALEUP(startMV.x);
1088                                    startMV.y = RRV_MV_SCALEUP(startMV.y);
1089                            } else
1090                          if (!(MotionFlags & PMV_HALFPELREFINE16)) // who's gonna use extsearch and no halfpel?                          if (!(MotionFlags & PMV_HALFPELREFINE16)) // who's gonna use extsearch and no halfpel?
1091                                  startMV.x = EVEN(startMV.x); startMV.y = EVEN(startMV.y);                                  startMV.x = EVEN(startMV.x); startMV.y = EVEN(startMV.y);
1092                          if (!(MVequal(startMV, backupMV))) {                          if (!(MVequal(startMV, backupMV))) {
# Line 1007  Line 1100 
1100                          }                          }
1101    
1102                          backupMV = Data->currentMV[0];                          backupMV = Data->currentMV[0];
1103                          if (MotionFlags & PMV_HALFPELREFINE16) startMV.x = startMV.y = 1;                          if (!MotionFlags & PMV_HALFPELREFINE16 || Data->rrv) startMV.x = startMV.y = 0;
1104                          else startMV.x = startMV.y = 0;                          else startMV.x = startMV.y = 1;
1105                          if (!(MVequal(startMV, backupMV))) {                          if (!(MVequal(startMV, backupMV))) {
1106                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;                                  bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
1107    
# Line 1028  Line 1121 
1121                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;                  Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
1122          }          }
1123    
1124          if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) {          if((!Data->rrv) && (pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) {
1125    
1126                  Data->qpel_precision = 1;                  Data->qpel_precision = 1;
1127                  get_range_qpel(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,                  get_range_qpel(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
# Line 1045  Line 1138 
1138                  Data8.iEdgedWidth = Data->iEdgedWidth;                  Data8.iEdgedWidth = Data->iEdgedWidth;
1139                  Data8.RefQ = Data->RefQ;                  Data8.RefQ = Data->RefQ;
1140                  Data8.qpel = Data->qpel;                  Data8.qpel = Data->qpel;
1141                    Data8.rrv = Data->rrv;
1142                  Search8(Data, 2*x, 2*y, MotionFlags, pParam, pMB, pMBs, 0, &Data8);                  Search8(Data, 2*x, 2*y, MotionFlags, pParam, pMB, pMBs, 0, &Data8);
1143                  Search8(Data, 2*x + 1, 2*y, MotionFlags, pParam, pMB, pMBs, 1, &Data8);                  Search8(Data, 2*x + 1, 2*y, MotionFlags, pParam, pMB, pMBs, 1, &Data8);
1144                  Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8);                  Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8);
# Line 1067  Line 1161 
1161                  }                  }
1162          }          }
1163    
1164            if (Data->rrv) {
1165                            Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x);
1166                            Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y);
1167            }
1168          if (!(inter4v) ||          if (!(inter4v) ||
1169                  (Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] +                  (Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] +
1170                          Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant )) {                          Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant )) {
# Line 1105  Line 1203 
1203                  const int block,                  const int block,
1204                  SearchData * const Data)                  SearchData * const Data)
1205  {  {
1206            int i = 0;
1207          Data->iMinSAD = OldData->iMinSAD + 1 + block;          Data->iMinSAD = OldData->iMinSAD + 1 + block;
1208          Data->currentMV = OldData->currentMV + 1 + block;          Data->currentMV = OldData->currentMV + 1 + block;
1209          Data->currentQMV = OldData->currentQMV + 1 + block;          Data->currentQMV = OldData->currentQMV + 1 + block;
1210    
1211          if(pParam->m_quarterpel) {          if(pParam->m_quarterpel) {
1212                  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);
1213                  if (block != 0) *(Data->iMinSAD) += (Data->lambda8 *                  if (block != 0) i = d_mv_bits(  Data->currentQMV->x - Data->predMV.x,
1214                                                                          d_mv_bits(      Data->currentQMV->x - Data->predMV.x,                                                                                  Data->currentQMV->y - Data->predMV.y, Data->iFcode);
                                                                                                 Data->currentQMV->y - Data->predMV.y,  
                                                                                                 Data->iFcode) * (*Data->iMinSAD + NEIGH_8X8_BIAS))/100;  
1215          } else {          } else {
1216                  Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);                  Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);
1217                  if (block != 0) *(Data->iMinSAD) += (Data->lambda8 *                  if (block != 0) {
1218                                                                          d_mv_bits(      Data->currentMV->x - Data->predMV.x,                          if (Data->rrv) i = d_mv_bits(   RRV_MV_SCALEDOWN(Data->currentMV->x) - Data->predMV.x,
1219                                                                                                  Data->currentMV->y - Data->predMV.y,                                                                                          RRV_MV_SCALEDOWN(Data->currentMV->y) - Data->predMV.y,
1220                                                                                                  Data->iFcode) * (*Data->iMinSAD + NEIGH_8X8_BIAS))/100;                                                                                          Data->iFcode);
1221                            else i = d_mv_bits(     Data->currentMV->x - Data->predMV.x,
1222                                                                    Data->currentMV->y - Data->predMV.y, Data->iFcode);
1223                    }
1224          }          }
1225    
1226            *(Data->iMinSAD) += (Data->lambda8 * i * (*Data->iMinSAD + NEIGH_8X8_BIAS))/100;
1227    
1228          if (MotionFlags & (PMV_EXTSEARCH8|PMV_HALFPELREFINE8)) {          if (MotionFlags & (PMV_EXTSEARCH8|PMV_HALFPELREFINE8)) {
1229                    if (Data->rrv) i = 2; else i = 1;
1230    
1231                  Data->Ref = OldData->Ref + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->Ref = OldData->Ref + i*8 * ((block&1) + pParam->edged_width*(block>>1));
1232                  Data->RefH = OldData->RefH + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->RefH = OldData->RefH + i*8 * ((block&1) + pParam->edged_width*(block>>1));
1233                  Data->RefV = OldData->RefV + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->RefV = OldData->RefV + i*8 * ((block&1) + pParam->edged_width*(block>>1));
1234                  Data->RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->RefHV = OldData->RefHV + i*8 * ((block&1) + pParam->edged_width*(block>>1));
1235    
1236                  Data->Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->Cur = OldData->Cur + i*8 * ((block&1) + pParam->edged_width*(block>>1));
1237                  Data->qpel_precision = 0;                  Data->qpel_precision = 0;
1238    
1239                    if (Data->rrv) {
1240                            get_range_rrv(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
1241                                            pParam->width, pParam->height, OldData->iFcode);
1242                            CheckCandidate = CheckCandidate16no4v;
1243                    } else {
1244                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,
1245                                  pParam->width, pParam->height, OldData->iFcode - pParam->m_quarterpel);                                  pParam->width, pParam->height, OldData->iFcode - pParam->m_quarterpel);
1246                  CheckCandidate = CheckCandidate8;                  CheckCandidate = CheckCandidate8;
1247                    }
1248    
1249                  if (MotionFlags & PMV_EXTSEARCH8) {                  if (MotionFlags & PMV_EXTSEARCH8) {
1250                          int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD                          int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD
# Line 1164  Line 1273 
1273                          }                          }
1274                  }                  }
1275    
1276                  if(pParam->m_quarterpel) {                  if(!Data->rrv && pParam->m_quarterpel) {
1277                          if((!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) &&                          if((!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) &&
1278                                  (MotionFlags & PMV_QUARTERPELREFINE8)) {                                  (MotionFlags & PMV_QUARTERPELREFINE8)) {
1279                          Data->qpel_precision = 1;                          Data->qpel_precision = 1;
# Line 1175  Line 1284 
1284                  }                  }
1285          }          }
1286    
1287            if (Data->rrv) {
1288                            Data->currentMV->x = RRV_MV_SCALEDOWN(Data->currentMV->x);
1289                            Data->currentMV->y = RRV_MV_SCALEDOWN(Data->currentMV->y);
1290            }
1291    
1292          if(pParam->m_quarterpel) {          if(pParam->m_quarterpel) {
1293                  pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x;                  pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x;
1294                  pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y;                  pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y;
1295                  pMB->qmvs[block] = *(Data->currentQMV);                  pMB->qmvs[block] = *(Data->currentQMV);
1296          }          } else {
         else {  
1297                  pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x;                  pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x;
1298                  pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;                  pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;
1299          }          }
# Line 1666  Line 1779 
1779          int32_t iMinSAD;          int32_t iMinSAD;
1780          VECTOR currentMV[3];          VECTOR currentMV[3];
1781          VECTOR currentQMV[3];          VECTOR currentQMV[3];
1782            memset(&Data, 0, sizeof(SearchData));
1783          Data.iEdgedWidth = pParam->edged_width;          Data.iEdgedWidth = pParam->edged_width;
1784          Data.currentMV = currentMV; Data.currentQMV = currentQMV;          Data.currentMV = currentMV; Data.currentQMV = currentQMV;
1785          Data.iMinSAD = &iMinSAD;          Data.iMinSAD = &iMinSAD;
# Line 2062  Line 2176 
2176                          int intraCount, //number of non-I frames after last I frame; 0 if we force P/B frame                          int intraCount, //number of non-I frames after last I frame; 0 if we force P/B frame
2177                          int bCount) // number if B frames in a row                          int bCount) // number if B frames in a row
2178  {  {
         int mb_width = pParam->mb_width;  
         int mb_height = pParam->mb_height;  
   
2179          uint32_t x, y, intra = 0;          uint32_t x, y, intra = 0;
2180          int sSAD = 0;          int sSAD = 0;
2181          MACROBLOCK * const pMBs = Current->mbs;          MACROBLOCK * const pMBs = Current->mbs;
# Line 2080  Line 2191 
2191          Data.iFcode = Current->fcode;          Data.iFcode = Current->fcode;
2192          CheckCandidate = CheckCandidate16no4vI;          CheckCandidate = CheckCandidate16no4vI;
2193    
         if ((Current->global_flags & XVID_REDUCED))  
         {  
                 mb_width = (pParam->width + 31) / 32;  
                 mb_height = (pParam->height + 31) / 32;  
         }  
   
   
2194          if (intraCount < 10) // we're right after an I frame          if (intraCount < 10) // we're right after an I frame
2195                  IntraThresh += 4 * (intraCount - 10) * (intraCount - 10);                  IntraThresh += 4 * (intraCount - 10) * (intraCount - 10);
2196          else          else
# Line 2099  Line 2203 
2203    
2204          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
2205    
2206          for (y = 1; y < mb_height-1; y++) {          for (y = 1; y < pParam->mb_height-1; y++) {
2207                  for (x = 1; x < mb_width-1; x++) {                  for (x = 1; x < pParam->mb_width-1; x++) {
2208                          int sad, dev;                          int sad, dev;
2209                          MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width];                          MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width];
2210    
# Line 2112  Line 2216 
2216                                                            pParam->edged_width);                                                            pParam->edged_width);
2217                                  if (dev + IntraThresh < sad) {                                  if (dev + IntraThresh < sad) {
2218                                          pMB->mode = MODE_INTRA;                                          pMB->mode = MODE_INTRA;
2219                                          if (++intra > (mb_height-2)*(mb_width-2)/2) return 2;  // I frame                                          if (++intra > (pParam->mb_height-2)*(pParam->mb_width-2)/2) return 2;  // I frame
2220                                  }                                  }
2221                          }                          }
2222                          sSAD += sad;                          sSAD += sad;
2223                  }                  }
2224          }          }
2225          sSAD /= (mb_height-2)*(mb_width-2);          sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2);
2226          if (sSAD > InterThresh ) return 1; //P frame          if (sSAD > InterThresh ) return 1; //P frame
2227          emms();          emms();
2228          return 0; // B frame          return 0; // B frame
2229    
2230  }  }
2231    
 int  
 FindFcode(      const MBParam * const pParam,  
                         const FRAMEINFO * const current)  
 {  
         int mb_width = pParam->mb_width;  
         int mb_height = pParam->mb_height;  
   
         uint32_t x, y;  
         int max = 0, min = 0, i;  
   
   
         if ((current->global_flags & XVID_REDUCED))  
         {  
                 mb_width = (pParam->width + 31) / 32;  
                 mb_height = (pParam->height + 31) / 32;  
         }  
   
   
         for (y = 0; y < mb_height; y++) {  
                 for (x = 0; x < mb_width; x++) {  
   
                         MACROBLOCK *pMB = &current->mbs[x + y * pParam->mb_width];  
                         for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4:1); i++) {  
                                 if (pMB->mvs[i].x > max) max = pMB->mvs[i].x;  
                                 if (pMB->mvs[i].y > max) max = pMB->mvs[i].y;  
   
                                 if (pMB->mvs[i].x < min) min = pMB->mvs[i].x;  
                                 if (pMB->mvs[i].y < min) min = pMB->mvs[i].y;  
                         }  
                 }  
         }  
   
         min = -min;  
         max += 1;  
         if (min > max) max = min;  
         if (pParam->m_quarterpel) max *= 2;  
   
         for (i = 1; (max > 32 << (i - 1)); i++);  
         return i;  
 }  
   
2232  static void  static void
2233  CheckGMC(int x, int y, const int dir, int * iDirection,  CheckGMC(int x, int y, const int dir, int * iDirection,
2234                  const MACROBLOCK * const pMBs, uint32_t * bestcount, VECTOR * GMC,                  const MACROBLOCK * const pMBs, uint32_t * bestcount, VECTOR * GMC,

Legend:
Removed from v.702  
changed lines
  Added in v.704

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