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

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

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

revision 345, Sat Jul 27 23:47:01 2002 UTC revision 346, Sun Jul 28 02:55:41 2002 UTC
# Line 874  Line 874 
874          return iMinSAD;          return iMinSAD;
875  }  }
876    
877    #define CHECK_MV16_F_INTERPOL(X,Y) { \
878  #define CHECK_MV16_F_INTERPOL(X,Y,BX,BY) { \    if ( ((X) <= f_max_dx) && ((X) >= f_min_dx) \
879    if ( ((X) <= max_dx) && ((X) >= min_dx) \      && ((Y) <= f_max_dy) && ((Y) >= f_min_dy) ) \
     && ((Y) <= max_dy) && ((Y) >= min_dy) ) \  
   { \  
     iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \  
     iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\  
     if (iSAD < iMinSAD) \  
     {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \  
 }  
   
 #define CHECK_MV16_F_INTERPOL_DIR(X,Y,BX,BY,D) { \  
   if ( ((X) <= max_dx) && ((X) >= min_dx) \  
     && ((Y) <= max_dy) && ((Y) >= min_dy) ) \  
880    { \    { \
881      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16bi( cur, \
882      iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\                          get_ref(f_pRef, f_pRefH, f_pRefV, f_pRefHV, x, y, 16, X, Y, iEdgedWidth),       \
883                            get_ref(b_pRef, b_pRefH, b_pRefV, b_pRefHV, x, y, 16, b_currMV->x, b_currMV->y, iEdgedWidth),   \
884                            iEdgedWidth); \
885        iSAD += calc_delta_16((X) - f_center_x, (Y) - f_center_y, (uint8_t)f_iFcode, iQuant);\
886        iSAD += calc_delta_16(b_currMV->x - b_center_x, b_currMV->y - b_center_y, (uint8_t)b_iFcode, iQuant);\
887      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
888      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \      {  iMinSAD=iSAD; f_currMV->x=(X); f_currMV->y=(Y); } } \
889  }  }
890    
891  #define CHECK_MV16_F_INTERPOL_FOUND(X,Y,BX,BY,D) { \  #define CHECK_MV16_F_INTERPOL_FOUND(X,Y) { \
892    if ( ((X) <= max_dx) && ((X) >= min_dx) \    if ( ((X) <= f_max_dx) && ((X) >= f_min_dx) \
893      && ((Y) <= max_dy) && ((Y) >= min_dy) ) \      && ((Y) <= f_max_dy) && ((Y) >= f_min_dy) ) \
894    { \    { \
895      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16bi( cur, \
896      iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\                          get_ref(f_pRef, f_pRefH, f_pRefV, f_pRefHV, x, y, 16, X, Y, iEdgedWidth),       \
897                            get_ref(b_pRef, b_pRefH, b_pRefV, b_pRefHV, x, y, 16, b_currMV->x, b_currMV->y, iEdgedWidth),   \
898                            iEdgedWidth); \
899        iSAD += calc_delta_16((X) - f_center_x, (Y) - f_center_y, (uint8_t)f_iFcode, iQuant);\
900        iSAD += calc_delta_16(b_currMV->x - b_center_x, b_currMV->y - b_center_y, (uint8_t)b_iFcode, iQuant);\
901      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
902      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \      {  iMinSAD=iSAD; f_currMV->x=(X); f_currMV->y=(Y); iFound=0;} } \
903  }  }
904    
905    #define CHECK_MV16_B_INTERPOL(X,Y) { \
906  #define CHECK_MV16_B_INTERPOL(FX,FY,X,Y) { \    if ( ((X) <= b_max_dx) && ((X) >= b_min_dx) \
907    if ( ((X) <= max_dx) && ((X) >= min_dx) \      && ((Y) <= b_max_dy) && ((Y) >= b_min_dy) ) \
     && ((Y) <= max_dy) && ((Y) >= min_dy) ) \  
908    { \    { \
909      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16bi( cur, \
910      iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\                          get_ref(f_pRef, f_pRefH, f_pRefV, f_pRefHV, x, y, 16, f_currMV->x, f_currMV->y, iEdgedWidth),   \
911                            get_ref(b_pRef, b_pRefH, b_pRefV, b_pRefHV, x, y, 16, X, Y, iEdgedWidth),       \
912                            iEdgedWidth); \
913        iSAD += calc_delta_16(f_currMV->x - f_center_x, f_currMV->y - f_center_y, (uint8_t)f_iFcode, iQuant);\
914        iSAD += calc_delta_16((X) - b_center_x, (Y) - b_center_y, (uint8_t)b_iFcode, iQuant);\
915      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
916      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \      {  iMinSAD=iSAD; b_currMV->x=(X); b_currMV->y=(Y); } } \
917  }  }
918    
919    #define CHECK_MV16_B_INTERPOL_FOUND(X,Y) { \
920  #define CHECK_MV16_B_INTERPOL_DIR(FX,FY,X,Y,D) { \    if ( ((X) <= b_max_dx) && ((X) >= b_min_dx) \
921    if ( ((X) <= max_dx) && ((X) >= min_dx) \      && ((Y) <= b_max_dy) && ((Y) >= b_min_dy) ) \
     && ((Y) <= max_dy) && ((Y) >= min_dy) ) \  
922    { \    { \
923      iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \      iSAD = sad16bi( cur, \
924      iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\                          get_ref(f_pRef, f_pRefH, f_pRefV, f_pRefHV, x, y, 16, f_currMV->x, f_currMV->y, iEdgedWidth),   \
925                            get_ref(b_pRef, b_pRefH, b_pRefV, b_pRefHV, x, y, 16, X, Y, iEdgedWidth),       \
926                            iEdgedWidth); \
927        iSAD += calc_delta_16(f_currMV->x - f_center_x, f_currMV->y - f_center_y, (uint8_t)f_iFcode, iQuant);\
928        iSAD += calc_delta_16((X) - b_center_x, (Y) - b_center_y, (uint8_t)b_iFcode, iQuant);\
929      if (iSAD < iMinSAD) \      if (iSAD < iMinSAD) \
930      {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \      {  iMinSAD=iSAD; b_currMV->x=(X); b_currMV->y=(Y); iFound=0;} } \
931  }  }
932    
   
 #define CHECK_MV16_B_INTERPOL_FOUND(FX,FY,X,Y,D) { \  
   if ( ((X) <= max_dx) && ((X) >= min_dx) \  
     && ((Y) <= max_dy) && ((Y) >= min_dy) ) \  
   { \  
     iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \  
     iSAD += calc_delta_16((X) - center_x, (Y) - center_y, (uint8_t)iFcode, iQuant);\  
     if (iSAD < iMinSAD) \  
     {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \  
 }  
   
   
 #if (0==1)  
933  int32_t  int32_t
934  Diamond16_InterpolMainSearch(  Diamond16_InterpolMainSearch(
935                                          const uint8_t * const f_pRef,                                          const uint8_t * const f_pRef,
936                                           const uint8_t * const f_pRefH,                                           const uint8_t * const f_pRefH,
937                                           const uint8_t * const f_pRefV,                                           const uint8_t * const f_pRefV,
938                                           const uint8_t * const f_pRefHV,                                           const uint8_t * const f_pRefHV,
939    
940                                           const uint8_t * const cur,                                           const uint8_t * const cur,
941    
942                                          const uint8_t * const b_pRef,                                          const uint8_t * const b_pRef,
# Line 970  Line 961 
961                                     const int b_center_x,                                     const int b_center_x,
962                                     const int b_center_y,                                     const int b_center_y,
963    
964                                           const int32_t min_dx,                                      const int32_t f_min_dx,
965                                           const int32_t max_dx,                                          const int32_t f_max_dx,
966                                           const int32_t min_dy,                                          const int32_t f_min_dy,
967                                           const int32_t max_dy,                                          const int32_t f_max_dy,
968    
969                                        const int32_t b_min_dx,
970                                            const int32_t b_max_dx,
971                                            const int32_t b_min_dy,
972                                            const int32_t b_max_dy,
973    
974                                           const int32_t iEdgedWidth,                                           const int32_t iEdgedWidth,
975                                           const int32_t iDiamondSize,                                           const int32_t iDiamondSize,
976    
# Line 985  Line 982 
982  {  {
983  /* Do a diamond search around given starting point, return SAD of best */  /* Do a diamond search around given starting point, return SAD of best */
984    
         int32_t f_iDirection = 0;  
         int32_t b_iDirection = 0;  
985          int32_t iSAD;          int32_t iSAD;
986    
987          VECTOR f_backupMV;          VECTOR f_backupMV;
988          VECTOR b_backupMV;          VECTOR b_backupMV;
989    
990          f_backupMV.x = start_x;          f_currMV->x = f_start_x;
991          f_backupMV.y = start_y;          f_currMV->y = f_start_y;
992          b_backupMV.x = start_x;          b_currMV->x = b_start_x;
993          b_backupMV.y = start_y;          b_currMV->y = b_start_y;
994    
995  /* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */          do
996            {
997                    iFound = 1;
998    
999          CHECK_MV16_CANDIDATE_DIR(backupMV.x - iDiamondSize, backupMV.y, 1);                  f_backupMV = *f_currMV;
         CHECK_MV16_CANDIDATE_DIR(backupMV.x + iDiamondSize, backupMV.y, 2);  
         CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y - iDiamondSize, 3);  
         CHECK_MV16_CANDIDATE_DIR(backupMV.x, backupMV.y + iDiamondSize, 4);  
1000    
1001          if (iDirection)                  CHECK_MV16_F_INTERPOL_FOUND(f_backupMV.x - iDiamondSize, f_backupMV.y);
1002                  while (!iFound) {                  CHECK_MV16_F_INTERPOL_FOUND(f_backupMV.x + iDiamondSize, f_backupMV.y);
1003                          iFound = 1;                  CHECK_MV16_F_INTERPOL_FOUND(f_backupMV.x, f_backupMV.y - iDiamondSize);
1004                          backupMV = *currMV;                  CHECK_MV16_F_INTERPOL_FOUND(f_backupMV.x, f_backupMV.y + iDiamondSize);
1005    
1006                    b_backupMV = *b_currMV;
1007    
1008                    CHECK_MV16_B_INTERPOL_FOUND(b_backupMV.x - iDiamondSize, b_backupMV.y);
1009                    CHECK_MV16_B_INTERPOL_FOUND(b_backupMV.x + iDiamondSize, b_backupMV.y);
1010                    CHECK_MV16_B_INTERPOL_FOUND(b_backupMV.x, b_backupMV.y - iDiamondSize);
1011                    CHECK_MV16_B_INTERPOL_FOUND(b_backupMV.x, b_backupMV.y + iDiamondSize);
1012    
1013            } while (!iFound);
1014    
1015            return iMinSAD;
1016    }
1017    
1018    /* Sorry, these MACROS really got too large... I'll turn them into function soon! */
1019    
1020    #define CHECK_MV16_DIRECT_FOUND(X,Y) \
1021            if ( (X)>=(-32) && (X)<=(31) && ((Y)>=-32) && ((Y)<=31) ) \
1022            { int k;\
1023            VECTOR mvs,b_mvs;       \
1024            iSAD = 0;\
1025            for (k = 0; k < 4; k++) {       \
1026                                            mvs.x = (int32_t) ((TRB * directmv[k].x) / TRD + (X));          \
1027                        b_mvs.x = (int32_t) (((X) == 0)                                                     \
1028                                                                                    ? ((TRB - TRD) * directmv[k].x) / TRD   \
1029                                                : mvs.x - directmv[k].x);                           \
1030                                                                                                                                                                    \
1031                        mvs.y = (int32_t) ((TRB * directmv[k].y) / TRD + (Y));              \
1032                            b_mvs.y = (int32_t) (((Y) == 0)                                                         \
1033                                                                                    ? ((TRB - TRD) * directmv[k].y) / TRD   \
1034                                                : mvs.y - directmv[k].y);                           \
1035                                                                                                                                                                    \
1036      if ( (mvs.x <= max_dx) && (mvs.x >= min_dx) \
1037        && (mvs.y <= max_dy) && (mvs.y >= min_dy)  \
1038            && (b_mvs.x <= max_dx) && (b_mvs.x >= min_dx)  \
1039        && (b_mvs.y <= max_dy) && (b_mvs.y >= min_dy) ) { \
1040                iSAD += sad8bi( cur + 8*(k&1) + 8*(k>>1)*iEdgedWidth,                                                                                                       \
1041                            get_ref(f_pRef, f_pRefH, f_pRefV, f_pRefHV, 2*x+(k&1), 2*y+(k>>1), 8, \
1042                                            mvs.x, mvs.y, iEdgedWidth),                                                             \
1043                            get_ref(b_pRef, b_pRefH, b_pRefV, b_pRefHV, 2*x+(k&1), 2*y+(k>>1), 8, \
1044                                            b_mvs.x, b_mvs.y, iEdgedWidth),                                                         \
1045                            iEdgedWidth); \
1046                    }       \
1047            else    \
1048                    iSAD = 65535;   \
1049            } \
1050            iSAD += calc_delta_16((X),(Y), 1, iQuant);\
1051            if (iSAD < iMinSAD) \
1052                {  iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iFound=0; } \
1053    }
1054    
1055    
1056    
1057    int32_t
1058    Diamond16_DirectMainSearch(
1059                                            const uint8_t * const f_pRef,
1060                                            const uint8_t * const f_pRefH,
1061                                            const uint8_t * const f_pRefV,
1062                                            const uint8_t * const f_pRefHV,
1063    
1064                                            const uint8_t * const cur,
1065    
1066                                            const uint8_t * const b_pRef,
1067                                            const uint8_t * const b_pRefH,
1068                                            const uint8_t * const b_pRefV,
1069                                            const uint8_t * const b_pRefHV,
1070    
1071                                            const int x,
1072                                            const int y,
1073    
1074                                            const int TRB,
1075                                            const int TRD,
1076    
1077                                        const int start_x,
1078                                        const int start_y,
1079    
1080                                        int iMinSAD,
1081                                        VECTOR * const currMV,
1082                                            const VECTOR * const directmv,
1083    
1084                                        const int32_t min_dx,
1085                                            const int32_t max_dx,
1086                                            const int32_t min_dy,
1087                                            const int32_t max_dy,
1088    
1089                                            const int32_t iEdgedWidth,
1090                                            const int32_t iDiamondSize,
1091    
1092                                            const int32_t iQuant,
1093                                            int iFound)
1094    {
1095    /* Do a diamond search around given starting point, return SAD of best */
1096    
1097            int32_t iSAD;
1098    
1099            VECTOR backupMV;
1100    
                         if (iDirection != 2)  
                                 CHECK_MV16_CANDIDATE_FOUND(backupMV.x - iDiamondSize,  
                                                                                    backupMV.y, 1);  
                         if (iDirection != 1)  
                                 CHECK_MV16_CANDIDATE_FOUND(backupMV.x + iDiamondSize,  
                                                                                    backupMV.y, 2);  
                         if (iDirection != 4)  
                                 CHECK_MV16_CANDIDATE_FOUND(backupMV.x,  
                                                                                    backupMV.y - iDiamondSize, 3);  
                         if (iDirection != 3)  
                                 CHECK_MV16_CANDIDATE_FOUND(backupMV.x,  
                                                                                    backupMV.y + iDiamondSize, 4);  
         } else {  
1101                  currMV->x = start_x;                  currMV->x = start_x;
1102                  currMV->y = start_y;                  currMV->y = start_y;
1103          }  
1104    /* It's one search with full Diamond pattern, and only 3 of 4 for all following diamonds */
1105    
1106            do
1107            {
1108                    iFound = 1;
1109    
1110                    backupMV = *currMV;
1111    
1112                    CHECK_MV16_DIRECT_FOUND(backupMV.x - iDiamondSize, backupMV.y);
1113                    CHECK_MV16_DIRECT_FOUND(backupMV.x + iDiamondSize, backupMV.y);
1114                    CHECK_MV16_DIRECT_FOUND(backupMV.x, backupMV.y - iDiamondSize);
1115                    CHECK_MV16_DIRECT_FOUND(backupMV.x, backupMV.y + iDiamondSize);
1116    
1117            } while (!iFound);
1118    
1119          return iMinSAD;          return iMinSAD;
1120  }  }
 #endif  
1121    
1122    
1123  int32_t  int32_t
# Line 1278  Line 1368 
1368                                  const IMAGE * const pCur,                                  const IMAGE * const pCur,
1369                                  const int x,                                  const int x,
1370                                  const int y,                                  const int y,
1371                                  const int start_x,                                  const int start_x,      /* start is searched first, so it should contain the most */
1372                                  const int start_y,                                  const int start_y,  /* likely motion vector for this block */
1373                                  const int center_x,                                  const int center_x,     /* center is from where length of MVs is measured */
1374                                  const int center_y,                                  const int center_y,
1375                                  const uint32_t MotionFlags,                                  const uint32_t MotionFlags,
1376                                  const uint32_t iQuant,                                  const uint32_t iQuant,
# Line 2737  Line 2827 
2827                                  const IMAGE * const pCur,                                  const IMAGE * const pCur,
2828                                  const int x,                                  const int x,
2829                                  const int y,                                  const int y,
2830                          const int start_x,                                  const int start_x,              /* start should be most likely vector */
2831                          const int start_y,                          const int start_y,
2832                          const int center_x,                                  const int center_x,             /* center is from where length of MVs is measured */
2833                          const int center_y,                          const int center_y,
2834                                  const uint32_t MotionFlags,                                  const uint32_t MotionFlags,
2835                                  const uint32_t iQuant,                                  const uint32_t iQuant,
# Line 2768  Line 2858 
2858          int32_t iFound;          int32_t iFound;
2859    
2860          VECTOR newMV;          VECTOR newMV;
2861          VECTOR backupMV;                        /* just for PMVFAST */          VECTOR backupMV;
2862    
2863          VECTOR pmv[4];          VECTOR pmv[4];
2864          int32_t psad[4];          int32_t psad[4];
# Line 3023  Line 3113 
3113    
3114  /* ***********************************************************  /* ***********************************************************
3115          bvop motion estimation          bvop motion estimation
 // TODO: need to incorporate prediction here (eg. sad += calc_delta_16)  
3116  ***************************************************************/  ***************************************************************/
3117    
   
 #define DIRECT_PENALTY 0  
 #define DIRECT_UPPERLIMIT 256   // never use direct mode if SAD is larger than this  
   
3118  void  void
3119  MotionEstimationBVOP(MBParam * const pParam,  MotionEstimationBVOP(MBParam * const pParam,
3120                                           FRAMEINFO * const frame,                                           FRAMEINFO * const frame,
# Line 3052  Line 3137 
3137          const int mb_height = pParam->mb_height;          const int mb_height = pParam->mb_height;
3138          const int edged_width = pParam->edged_width;          const int edged_width = pParam->edged_width;
3139    
3140            const int32_t iWidth = pParam->width;
3141            const int32_t iHeight = pParam->height;
3142    
3143          int i, j, k;          int i, j, k;
3144    
3145          static const VECTOR zeroMV={0,0};          static const VECTOR zeroMV={0,0};
# Line 3059  Line 3147 
3147          int f_sad16;    /* forward (as usual) search */          int f_sad16;    /* forward (as usual) search */
3148          int b_sad16;    /* backward (only in b-frames) search */          int b_sad16;    /* backward (only in b-frames) search */
3149          int i_sad16;    /* interpolated (both direction, b-frames only) */          int i_sad16;    /* interpolated (both direction, b-frames only) */
3150          int d_sad16;    /* direct mode (assume linear motion) */          int d_sad16;    /* direct mode (assume almost linear motion) */
3151    
3152          int best_sad;          int best_sad;
3153    
3154          VECTOR f_predMV, b_predMV;      /* there is no prediction for direct mode*/          VECTOR f_predMV, b_predMV;      /* there is no prediction for direct mode*/
3155            VECTOR f_interpolMV, b_interpolMV;
3156          VECTOR pmv_dontcare;          VECTOR pmv_dontcare;
3157    
3158            int min_dx, max_dx, min_dy, max_dy;
3159            int f_min_dx, f_max_dx, f_min_dy, f_max_dy;
3160            int b_min_dx, b_max_dx, b_min_dy, b_max_dy;
3161    
3162          int f_count=0;          int f_count=0;
3163          int b_count=0;          int b_count=0;
3164          int i_count=0;          int i_count=0;
3165          int d_count=0;          int d_count=0;
         int s_count=0;  
3166    
3167          const int64_t TRB = (int32_t)time_pp - (int32_t)time_bp;          const int64_t TRB = (int32_t)time_pp - (int32_t)time_bp;
3168      const int64_t TRD = (int32_t)time_pp;      const int64_t TRD = (int32_t)time_pp;
# Line 3089  Line 3181 
3181    
3182                          mb->deltamv=zeroMV;                          mb->deltamv=zeroMV;
3183    
3184  /* special case, if collocated block is SKIPed: encoding is forward(0,0)  */  /* special case, if collocated block is SKIPed: encoding is forward (0,0), cpb=0 without further ado */
3185    
3186  #ifndef _DISABLE_SKIP  #ifndef _DISABLE_SKIP
3187                          if (b_mb->mode == MODE_INTER && b_mb->cbp == 0 &&                          if (b_mb->mode == MODE_INTER && b_mb->cbp == 0 &&
# Line 3103  Line 3195 
3195                          }                          }
3196  #endif  #endif
3197    
                         d_sad16 = DIRECT_PENALTY;  
   
3198                          if (b_mb->mode == MODE_INTER4V)                          if (b_mb->mode == MODE_INTER4V)
3199                          {                          {
3200                                    d_sad16 = 0;
3201                          /* same method of scaling as in decoder.c, so we copy from there */                          /* same method of scaling as in decoder.c, so we copy from there */
3202                      for (k = 0; k < 4; k++) {                      for (k = 0; k < 4; k++) {
3203    
# Line 3119  Line 3209 
3209                                              : mb->mvs[k].x - mb->directmv[k].x);                                              : mb->mvs[k].x - mb->directmv[k].x);
3210    
3211                      mb->mvs[k].y = (int32_t) ((TRB * mb->directmv[k].y) / TRD + mb->deltamv.y);                      mb->mvs[k].y = (int32_t) ((TRB * mb->directmv[k].y) / TRD + mb->deltamv.y);
3212                          mb->b_mvs[k].y = (int32_t) ((mb->directmv[k].y == 0)                          mb->b_mvs[k].y = (int32_t) ((mb->deltamv.y == 0)
3213                                                                                  ? ((TRB - TRD) * mb->directmv[k].y) / TRD                                                                                  ? ((TRB - TRD) * mb->directmv[k].y) / TRD
3214                                              : mb->mvs[k].y - mb->directmv[k].y);                                              : mb->mvs[k].y - mb->directmv[k].y);
3215    
# Line 3147  Line 3237 
3237                                                                          ? ((TRB - TRD) * mb->directmv[0].y) / TRD                                                                          ? ((TRB - TRD) * mb->directmv[0].y) / TRD
3238                                      : mb->mvs[0].y - mb->directmv[0].y);                                      : mb->mvs[0].y - mb->directmv[0].y);
3239    
3240                                  d_sad16 += sad16bi(frame->image.y + i * 16 + j * 16 * edged_width,                                  d_sad16 = sad16bi(frame->image.y + i * 16 + j * 16 * edged_width,
3241                                                    get_ref_mv(f_ref->y, f_refH->y, f_refV->y, f_refHV->y,                                                    get_ref_mv(f_ref->y, f_refH->y, f_refV->y, f_refHV->y,
3242                                                                  i, j, 16, &mb->mvs[0], edged_width),                                                                  i, j, 16, &mb->mvs[0], edged_width),
3243                                                    get_ref_mv(b_ref->y, b_refH->y, b_refV->y, b_refHV->y,                                                    get_ref_mv(b_ref->y, b_refH->y, b_refV->y, b_refHV->y,
# Line 3190  Line 3280 
3280                      i_sad16 += calc_delta_16(mb->b_mvs[0].x-b_predMV.x, mb->b_mvs[0].y-b_predMV.y,                      i_sad16 += calc_delta_16(mb->b_mvs[0].x-b_predMV.x, mb->b_mvs[0].y-b_predMV.y,
3281                                                                  frame->bcode, frame->quant);                                                                  frame->bcode, frame->quant);
3282    
3283                          // TODO: direct search                          get_range(&f_min_dx, &f_max_dx, &f_min_dy, &f_max_dy, i, j, 16, iWidth, iHeight,
3284                          // predictor + delta vector in range [-32,32] (fcode=1)                            frame->fcode);
3285                            get_range(&b_min_dx, &b_max_dx, &b_min_dy, &b_max_dy, i, j, 16, iWidth, iHeight,
3286                              frame->bcode);
3287    
3288    /* Interpolated MC motion vector search, this is tedious and more complicated because there are
3289       two values for everything, always one for backward and one for forward ME. Still, we don't gain
3290       much from this search, maybe it should simply be skipped and simply current i_sad16 value used
3291       as "optimal". */
3292    
3293                            i_sad16 = Diamond16_InterpolMainSearch(
3294                                                    f_ref->y, f_refH->y, f_refV->y, f_refHV->y,
3295                                                    frame->image.y + i * 16 + j * 16 * edged_width,
3296                                                    b_ref->y, b_refH->y, b_refV->y, b_refHV->y,
3297                                                    i, j,
3298                                                    mb->mvs[0].x, mb->mvs[0].y,
3299                                                    mb->b_mvs[0].x, mb->b_mvs[0].y,
3300                                                    i_sad16,
3301                                                    &f_interpolMV, &b_interpolMV,
3302                                                    f_predMV.x, f_predMV.y, b_predMV.x, b_predMV.y,
3303                                                    f_min_dx, f_max_dx, f_min_dy, f_max_dy,
3304                                                    b_min_dx, b_max_dx, b_min_dy, b_max_dy,
3305                                                    edged_width,  1,
3306                                                    frame->fcode, frame->bcode,frame->quant,0);
3307    
3308    
3309    /*  DIRECT MODE DELTA VECTOR SEARCH.
3310        This has to be made more effective, but at the moment I'm happy it's running at all */
3311    
3312    /* range is taken without fcode restriction, just a hack instead of writing down the dimensions, of course */
3313    
3314                            get_range(&min_dx, &max_dx, &min_dy, &max_dy, i, j, 16, iWidth, iHeight, 19);
3315    
3316                            d_sad16 = Diamond16_DirectMainSearch(
3317                                                    f_ref->y, f_refH->y, f_refV->y, f_refHV->y,
3318                                                    frame->image.y + i*16 + j*16*edged_width,
3319                                                    b_ref->y, b_refH->y, b_refV->y, b_refHV->y,
3320                                                    i, j,
3321                                                    TRB,TRD,
3322                                                    0,0,
3323                                                    d_sad16,
3324                                                    &mb->deltamv,
3325                                                    mb->directmv, // this has to be pre-initialized with b_mb->mvs[}
3326                                            min_dx, max_dx, min_dy, max_dy,
3327                                                    edged_width, 1, frame->quant, 0);
3328    
3329    
3330                          i_sad16 = 65535;  //                      i_sad16 = 65535;                /* remove the comment to disable any of the MODEs */
3331                          f_sad16 = 65535;  //                      f_sad16 = 65535;
3332                          b_sad16 = 65535;  //                      b_sad16 = 65535;
3333  //                      d_sad16 = 65535;  //                      d_sad16 = 65535;
3334    
3335                          if (f_sad16 < b_sad16) {                          if (f_sad16 < b_sad16) {
# Line 3216  Line 3350 
3350                                  if (b_mb->mode == MODE_INTER4V)                                  if (b_mb->mode == MODE_INTER4V)
3351                                  {                                  {
3352    
3353                                  /* same method of scaling as in decoder.c, so we copy from there */                                  /* how to calc vectors is defined in standard. mvs[] and b_mvs[] are only for motion compensation */
3354                                    /* for the bitstream, the value mb->deltamv is read directly */
3355    
3356                              for (k = 0; k < 4; k++) {                              for (k = 0; k < 4; k++) {
3357    
3358                                                  mb->mvs[k].x = (int32_t) ((TRB * mb->directmv[k].x) / TRD + mb->deltamv.x);                                                  mb->mvs[k].x = (int32_t) ((TRB * mb->directmv[k].x) / TRD + mb->deltamv.x);
# Line 3225  Line 3361 
3361                                                      : mb->mvs[k].x - mb->directmv[k].x);                                                      : mb->mvs[k].x - mb->directmv[k].x);
3362    
3363                              mb->mvs[k].y = (int32_t) ((TRB * mb->directmv[k].y) / TRD + mb->deltamv.y);                              mb->mvs[k].y = (int32_t) ((TRB * mb->directmv[k].y) / TRD + mb->deltamv.y);
3364                          mb->b_mvs[k].y = (int32_t) ((mb->directmv[k].y == 0)                          mb->b_mvs[k].y = (int32_t) ((mb->deltamv.y == 0)
3365                                                                                          ? ((TRB - TRD) * mb->directmv[k].y) / TRD                                                                                          ? ((TRB - TRD) * mb->directmv[k].y) / TRD
3366                                              : mb->mvs[k].y - mb->directmv[k].y);                                              : mb->mvs[k].y - mb->directmv[k].y);
3367                                          }                                          }
# Line 3240  Line 3376 
3376    
3377                              mb->mvs[0].y = (int32_t) ((TRB * mb->directmv[0].y) / TRD + mb->deltamv.y);                              mb->mvs[0].y = (int32_t) ((TRB * mb->directmv[0].y) / TRD + mb->deltamv.y);
3378    
3379                          mb->b_mvs[0].y = (int32_t) ((mb->directmv[0].y == 0)                          mb->b_mvs[0].y = (int32_t) ((mb->deltamv.y == 0)
3380                                                                                  ? ((TRB - TRD) * mb->directmv[0].y) / TRD                                                                                  ? ((TRB - TRD) * mb->directmv[0].y) / TRD
3381                                              : mb->mvs[0].y - mb->directmv[0].y);                                              : mb->mvs[0].y - mb->directmv[0].y);
3382    
# Line 3250  Line 3386 
3386    
3387                                  best_sad = d_sad16;                                  best_sad = d_sad16;
3388                                  mb->mode = MODE_DIRECT;                                  mb->mode = MODE_DIRECT;
                                 mb->mode = MODE_INTERPOLATE;            // direct mode still broken :-(  
3389                          }                          }
3390    
3391                          switch (mb->mode)                          switch (mb->mode)
# Line 3266  Line 3401 
3401                                          break;                                          break;
3402                                  case MODE_INTERPOLATE:                                  case MODE_INTERPOLATE:
3403                                          i_count++;                                          i_count++;
3404                                            mb->mvs[0] = f_interpolMV;
3405                                            mb->b_mvs[0] = b_interpolMV;
3406                                          f_predMV = mb->mvs[0];                                          f_predMV = mb->mvs[0];
3407                                          b_predMV = mb->b_mvs[0];                                          b_predMV = mb->b_mvs[0];
3408                                          break;                                          break;
# Line 3273  Line 3410 
3410                                          d_count++;                                          d_count++;
3411                                          break;                                          break;
3412                                  default:                                  default:
                                         s_count++;              // ???  
3413                                          break;                                          break;
3414                          }                          }
3415    
# Line 3281  Line 3417 
3417          }          }
3418    
3419  #ifdef _DEBUG_BFRAME_STAT  #ifdef _DEBUG_BFRAME_STAT
3420          fprintf(stderr,"B-Stat: F: %04d   B: %04d   I: %04d  D: %04d   S: %04d\n",          fprintf(stderr,"B-Stat: F: %04d   B: %04d   I: %04d  D: %04d\n",
3421                                  f_count,b_count,i_count,d_count,s_count);                                  f_count,b_count,i_count,d_count);
3422  #endif  #endif
3423    
3424  }  }

Legend:
Removed from v.345  
changed lines
  Added in v.346

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