[svn] / trunk / xvidcore / src / motion / motion_est.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/motion/motion_est.c

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

revision 1072, Thu Jun 19 10:06:40 2003 UTC revision 1074, Thu Jun 26 10:37:42 2003 UTC
# Line 667  Line 667 
667          for(i = 0; i < 4; i++) {          for(i = 0; i < 4; i++) {
668                  int s = 8*((i&1) + (i>>1)*data->iEdgedWidth);                  int s = 8*((i&1) + (i>>1)*data->iEdgedWidth);
669                  transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth);                  transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth);
670                  bits += data->temp[i] = Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, i);                  bits += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i);
671          }          }
672    
673          bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);          bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
674    
675            //8x8 blocks for inter4v mode
676          if (data->temp[0] + t < data->iMinSAD[1]) {          if (data->temp[0] + t < data->iMinSAD[1]) {
677                  data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; }                  data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; }
678          if (data->temp[1] < data->iMinSAD[2]) {          if (data->temp[1] < data->iMinSAD[2]) {
# Line 681  Line 682 
682          if (data->temp[3] < data->iMinSAD[4]) {          if (data->temp[3] < data->iMinSAD[4]) {
683                  data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; }                  data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; }
684    
   
685          bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;          bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len;
686    
687          if (bits >= data->iMinSAD[0]) return;          if (bits >= data->iMinSAD[0]) return;
# Line 693  Line 693 
693          //chroma U          //chroma U
694          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[4], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[4], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);
695          transfer_8to16subro(in, ptr, data->CurU, data->iEdgedWidth/2);          transfer_8to16subro(in, ptr, data->CurU, data->iEdgedWidth/2);
696          bits += Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 4);          bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4);
697          if (bits >= data->iMinSAD[0]) return;          if (bits >= data->iMinSAD[0]) return;
698    
699          //chroma V          //chroma V
700          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[5], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);          ptr = interpolate8x8_switch2(data->RefQ + 64, data->RefP[5], 0, 0, xc, yc,  data->iEdgedWidth/2, data->rounding);
701          transfer_8to16subro(in, ptr, data->CurV, data->iEdgedWidth/2);          transfer_8to16subro(in, ptr, data->CurV, data->iEdgedWidth/2);
702          bits += Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 5);          bits += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5);
703    
704          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len;
705    
# Line 708  Line 708 
708                  current[0].x = x; current[0].y = y;                  current[0].x = x; current[0].y = y;
709                  *dir = Direction;                  *dir = Direction;
710          }          }
   
711  }  }
   
712  static void  static void
713  CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
714  {  {
# Line 733  Line 731 
731          }          }
732    
733          transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth);          transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth);
734          bits = Block_CalcBits(coeff, in, data->iQuant, data->quant_type, &cbp, 5);          bits = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5);
735          bits += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);          bits += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0);
736    
737          if (bits < data->iMinSAD[0]) {          if (bits < data->iMinSAD[0]) {
# Line 975  Line 973 
973                          Data->iMinSAD[0] = sad;                          Data->iMinSAD[0] = sad;
974                  }                  }
975    
976                  /* 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?"
977                  if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))                  if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP))
978                          if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH)                          if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH)
979                                  if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {                                  if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) {
# Line 983  Line 981 
981                                          sad = 0;                                          sad = 0;
982                                  }                                  }
983    
984                  /* intra decision */                  // intra decision
985    
986                  if (iQuant > 8) InterBias += 100 * (iQuant - 8); // to make high quants work                  if (iQuant > 8) InterBias += 100 * (iQuant - 8); // to make high quants work
987                  if (y != 0)                  if (y != 0)
# Line 1089  Line 1087 
1087          VECTOR currentMV[5];          VECTOR currentMV[5];
1088          VECTOR currentQMV[5];          VECTOR currentQMV[5];
1089          int32_t iMinSAD[5];          int32_t iMinSAD[5];
1090          DECLARE_ALIGNED_MATRIX(dct_space, 2, 64, int16_t, CACHE_LINE);          DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE);
1091          SearchData Data;          SearchData Data;
1092          memset(&Data, 0, sizeof(SearchData));          memset(&Data, 0, sizeof(SearchData));
1093          Data.iEdgedWidth = iEdgedWidth;          Data.iEdgedWidth = iEdgedWidth;
# Line 2161  Line 2159 
2159          }          }
2160  }  }
2161    
2162  #define INTRA_THRESH    1700  #define INTRA_THRESH    2200
2163  #define INTER_THRESH    1200  #define INTER_THRESH    50
2164    #define INTRA_THRESH2   95
2165    
2166  int  int
2167  MEanalysis(     const IMAGE * const pRef,  MEanalysis(     const IMAGE * const pRef,
# Line 2177  Line 2176 
2176          int sSAD = 0;          int sSAD = 0;
2177          MACROBLOCK * const pMBs = Current->mbs;          MACROBLOCK * const pMBs = Current->mbs;
2178          const IMAGE * const pCurrent = &Current->image;          const IMAGE * const pCurrent = &Current->image;
2179          int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + 10*b_thresh;          int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + b_thresh;
2180          int s = 0, blocks = 0;          int s = 0, blocks = 0;
2181            int complexity = 0;
2182    
2183          int32_t iMinSAD[5], temp[5];          int32_t iMinSAD[5], temp[5];
2184          VECTOR currentMV[5];          VECTOR currentMV[5];
# Line 2190  Line 2190 
2190          Data.temp = temp;          Data.temp = temp;
2191          CheckCandidate = CheckCandidate32I;          CheckCandidate = CheckCandidate32I;
2192    
2193    
2194          if (intraCount != 0) {          if (intraCount != 0) {
2195                  if (intraCount < 10) // we're right after an I frame                  if (intraCount < 10) // we're right after an I frame
2196                          IntraThresh += 15* (intraCount - 10) * (intraCount - 10);                          IntraThresh += 15* (intraCount - 10) * (intraCount - 10);
# Line 2198  Line 2199 
2199                                  IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra;                                  IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra;
2200          }          }
2201    
2202          InterThresh -= (350 - 8*b_thresh) * bCount;          InterThresh -= 12 * bCount;
2203          if (InterThresh < 300 + 5*b_thresh) InterThresh = 300 + 5*b_thresh;          if (InterThresh < 15 + b_thresh) InterThresh = 15 + b_thresh;
2204    
2205          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
2206    
2207          for (y = 1; y < pParam->mb_height-1; y += 2) {          for (y = 1; y < pParam->mb_height-1; y += 2) {
2208                  for (x = 1; x < pParam->mb_width-1; x += 2) {                  for (x = 1; x < pParam->mb_width-1; x += 2) {
2209                          int i;                          int i;
2210                          blocks += 4;                          blocks += 10;
2211    
2212                          if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV;                          if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV;
2213                          else { //extrapolation of the vector found for last frame                          else { //extrapolation of the vector found for last frame
# Line 2221  Line 2222 
2222                          for (i = 0; i < 4; i++) {                          for (i = 0; i < 4; i++) {
2223                                  int dev;                                  int dev;
2224                                  MACROBLOCK *pMB = &pMBs[x+(i&1) + (y+(i>>1)) * pParam->mb_width];                                  MACROBLOCK *pMB = &pMBs[x+(i&1) + (y+(i>>1)) * pParam->mb_width];
                                 if (pMB->sad16 > IntraThresh) {  
2225                                          dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1)) * pParam->edged_width) * 16,                                          dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1)) * pParam->edged_width) * 16,
2226                                                                          pParam->edged_width);                                                                          pParam->edged_width);
2227    
2228                                    complexity += dev;
2229                                          if (dev + IntraThresh < pMB->sad16) {                                          if (dev + IntraThresh < pMB->sad16) {
2230                                                  pMB->mode = MODE_INTRA;                                                  pMB->mode = MODE_INTRA;
2231                                                  if (++intra > ((pParam->mb_height-2)*(pParam->mb_width-2))/2) return I_VOP;                                                  if (++intra > ((pParam->mb_height-2)*(pParam->mb_width-2))/2) return I_VOP;
2232                                          }                                          }
2233                                  }  
2234                                  if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) s++;                                  if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)
2235                                            if (dev > 500 && pMB->sad16 < 1000)
2236                                                    sSAD += 1000;
2237    
2238                                  sSAD += pMB->sad16;                                  sSAD += pMB->sad16;
2239                          }                          }
2240                  }                  }
2241          }          }
2242            complexity >>= 7;
2243    
2244          sSAD /= blocks;          sSAD /= complexity + 4*blocks;
   
         if (b_thresh < 20) {  
                 s = (10*s) / blocks;  
                 if (s > 4) sSAD += (s - 2) * (40 - 2*b_thresh); //static block - looks bad when in bframe...  
         }  
2245    
2246            if (intraCount > 12 && sSAD > INTRA_THRESH2 ) return I_VOP;
2247          if (sSAD > InterThresh ) return P_VOP;          if (sSAD > InterThresh ) return P_VOP;
2248          emms();          emms();
2249          return B_VOP;          return B_VOP;
# Line 2621  Line 2622 
2622          //chroma U          //chroma U
2623          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
2624          transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);          transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2);
2625          bits += Block_CalcBits(coeff, in, Data->iQuant, Data->quant_type, &cbp, 4);          bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4);
2626    
2627          if (bits >= *Data->iMinSAD) return bits;          if (bits >= *Data->iMinSAD) return bits;
2628    
2629          //chroma V          //chroma V
2630          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);          ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding);
2631          transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);          transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2);
2632          bits += Block_CalcBits(coeff, in, Data->iQuant, Data->quant_type, &cbp, 5);          bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5);
2633    
2634          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len;
2635    
# Line 2645  Line 2646 
2646          for(i = 0; i < 4; i++) {          for(i = 0; i < 4; i++) {
2647                  int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);                  int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth);
2648                  transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);                  transfer_8to16copy(in, Data->Cur + s, Data->iEdgedWidth);
2649                  bits += Block_CalcBitsIntra(coeff, in, Data->iQuant, Data->quant_type, &cbp, i, &dc);                  bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, &dc);
2650    
2651                  if (bits >= Data->iMinSAD[0]) return bits;                  if (bits >= Data->iMinSAD[0]) return bits;
2652          }          }
# Line 2654  Line 2655 
2655    
2656          //chroma U          //chroma U
2657          transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);          transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2);
2658          bits += Block_CalcBitsIntra(coeff, in, Data->iQuant, Data->quant_type, &cbp, 4, &dc);          bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, &dc);
2659    
2660          if (bits >= Data->iMinSAD[0]) return bits;          if (bits >= Data->iMinSAD[0]) return bits;
2661    
2662          //chroma V          //chroma V
2663          transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);          transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2);
2664          bits += Block_CalcBitsIntra(coeff, in, Data->iQuant, Data->quant_type, &cbp, 5, &dc);          bits += Block_CalcBitsIntra(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, &dc);
2665    
2666          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len;          bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTRA & 7) | ((cbp & 3) << 3)].len;
2667    

Legend:
Removed from v.1072  
changed lines
  Added in v.1074

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