[cvs] / xvidcore / src / motion / motion_comp.c Repository:
ViewVC logotype

Diff of /xvidcore/src/motion/motion_comp.c

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

revision 1.18.2.5, Mon Jun 9 01:22:04 2003 UTC revision 1.19, Sat Mar 22 13:41:11 2003 UTC
# Line 1  Line 1 
1  /*  // 30.10.2002   corrected qpel chroma rounding
2   * 30.10.2002   corrected qpel chroma rounding  // 04.10.2002   added qpel support to MBMotionCompensation
3   * 04.10.2002   added qpel support to MBMotionCompensation  // 01.05.2002   updated MBMotionCompensationBVOP
4   * 01.05.2002   updated MBMotionCompensationBVOP  // 14.04.2002   bframe compensation
  * 14.04.2002   bframe compensation  
  */  
5    
6  #include <stdio.h>  #include <stdio.h>
7    
# Line 14  Line 12 
12  #include "../utils/timer.h"  #include "../utils/timer.h"
13  #include "motion.h"  #include "motion.h"
14    
15    #ifndef ABS
16    #define ABS(X) (((X)>0)?(X):-(X))
17    #endif
18    #ifndef SIGN
19    #define SIGN(X) (((X)>0)?1:-1)
20    #endif
21    
22  #ifndef RSHIFT  #ifndef RSHIFT
23  #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))  #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
24  #endif  #endif
# Line 29  Line 34 
34  {  {
35          int length = 1 << (fcode+4);          int length = 1 << (fcode+4);
36    
37  #if 0  //      if (quarterpel) value *= 2;
         if (quarterpel) value *= 2;  
 #endif  
38    
39          if (value < -length)          if (value < -length)
40                  return -length;                  return -length;
# Line 90  Line 93 
93                                                                                          (uint8_t *) ref, tmp + 32,                                                                                          (uint8_t *) ref, tmp + 32,
94                                                                                          tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);                                                                                          tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);
95                                  ptr = tmp;                                  ptr = tmp;
96                          } else ptr =  ref + (y + dy/4)*stride + x + dx/4; /* fullpixel position */                          } else ptr =  ref + (y + dy/4)*stride + x + dx/4; // fullpixel position
97    
98                  } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);                  } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);
99    
# Line 103  Line 106 
106                  transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8,                  transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8,
107                                                          ptr + 8*stride + 8, stride);                                                          ptr + 8*stride + 8, stride);
108    
109          } else { /* reduced_resolution */          } else { //reduced_resolution
110    
111                  x *= 2; y *= 2;                  x *= 2; y *= 2;
112    
# Line 152  Line 155 
155                                                                                  (uint8_t *) ref, tmp + 32,                                                                                  (uint8_t *) ref, tmp + 32,
156                                                                                  tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);                                                                                  tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);
157                                  ptr = tmp;                                  ptr = tmp;
158                          } else ptr = ref + (y + dy/4)*stride + x + dx/4; /* fullpixel position */                          } else ptr = ref + (y + dy/4)*stride + x + dx/4; // fullpixel position
159                  } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);                  } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);
160    
161                          transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride);                          transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride);
162    
163          } else { /* reduced_resolution */          } else { //reduced_resolution
164    
165                  x *= 2; y *= 2;                  x *= 2; y *= 2;
166    
# Line 320  Line 323 
323                  dx = (dx >> 1) + roundtab_79[dx & 0x3];                  dx = (dx >> 1) + roundtab_79[dx & 0x3];
324                  dy = (dy >> 1) + roundtab_79[dy & 0x3];                  dy = (dy >> 1) + roundtab_79[dy & 0x3];
325    
326          } else {                                        /* mode == MODE_INTER4V */          } else {                                        // mode == MODE_INTER4V
327                  int k, sumx = 0, sumy = 0;                  int k, sumx = 0, sumy = 0;
328                  const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs);                  const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs);
329    
# Line 367  Line 370 
370          const uint32_t edged_width = pParam->edged_width;          const uint32_t edged_width = pParam->edged_width;
371          int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy;          int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy;
372          int k;          int k;
373          const int quarterpel = pParam->vol_flags & XVID_VOL_QUARTERPEL;          const int quarterpel = pParam->m_quarterpel;
374          const uint8_t * ptr1, * ptr2;          const uint8_t * ptr1, * ptr2;
375          uint8_t * const tmp = f_refv->u;          uint8_t * const tmp = f_refv->u;
376          const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs);          const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs);
# Line 418  Line 421 
421                                          (uint8_t *) f_ref->y, tmp + 32,                                          (uint8_t *) f_ref->y, tmp + 32,
422                                          tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0);                                          tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0);
423                                  ptr1 = tmp;                                  ptr1 = tmp;
424                          } else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; /* fullpixel position */                          } else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; // fullpixel position
425    
426                          if ((b_dx&3) | (b_dy&3)) {                          if ((b_dx&3) | (b_dy&3)) {
427                                  interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16,                                  interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16,
428                                          (uint8_t *) b_ref->y, tmp + 32,                                          (uint8_t *) b_ref->y, tmp + 32,
429                                          tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0);                                          tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0);
430                                  ptr2 = tmp + 16;                                  ptr2 = tmp + 16;
431                          } else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; /* fullpixel position */                          } else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; // fullpixel position
432    
433                          b_dx /= 2;                          b_dx /= 2;
434                          b_dy /= 2;                          b_dy /= 2;
# Line 454  Line 457 
457    
458                  break;                  break;
459    
460          default: /* MODE_DIRECT (or MODE_DIRECT_NONE_MV in case of bframes decoding) */          default: // MODE_DIRECT (or MODE_DIRECT_NONE_MV in case of bframes decoding)
461                  sumx = sumy = b_sumx = b_sumy = 0;                  sumx = sumy = b_sumx = b_sumy = 0;
462    
463                  for (k = 0; k < 4; k++) {                  for (k = 0; k < 4; k++) {
# Line 504  Line 507 
507                  break;                  break;
508          }          }
509    
510          /* v block-based chroma interpolation for direct and interpolate modes */          // uv block-based chroma interpolation for direct and interpolate modes
511          transfer_8to16sub2(&dct_codes[4 * 64],          transfer_8to16sub2(&dct_codes[4 * 64],
512                                                  cur->u + (j * 8) * edged_width / 2 + (i * 8),                                                  cur->u + (j * 8) * edged_width / 2 + (i * 8),
513                                                  interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j,                                                  interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j,
# Line 539  Line 542 
542          gmc->W = width;          gmc->W = width;
543          gmc->H = height;          gmc->H = height;
544    
545          gmc->rho = 4 - log2bin(res-1);  /* = {3,2,1,0} for res={2,4,8,16} */          gmc->rho = 4 - log2bin(res-1);  // = {3,2,1,0} for res={2,4,8,16}
546    
547          gmc->alpha = log2bin(gmc->W-1);          gmc->alpha = log2bin(gmc->W-1);
548          gmc->Ws = (1 << gmc->alpha);          gmc->Ws = (1 << gmc->alpha);
# Line 576  Line 579 
579  }  }
580    
581  void  void
582  generate_GMCimage(      const GMC_DATA *const gmc_data, /* [input] precalculated data */  generate_GMCimage(      const GMC_DATA *const gmc_data, // [input] precalculated data
583                                          const IMAGE *const pRef,                /* [input] */                                          const IMAGE *const pRef,                // [input]
584                                          const int mb_width,                                          const int mb_width,
585                                          const int mb_height,                                          const int mb_height,
586                                          const int stride,                                          const int stride,
587                                          const int stride2,                                          const int stride2,
588                                          const int fcode,                                /* [input] some parameters... */                                          const int fcode,                                // [input] some parameters...
589                                          const int32_t quarterpel,               /* [input] for rounding avgMV */                                          const int32_t quarterpel,               // [input] for rounding avgMV
590                                          const int reduced_resolution,   /* [input] ignored */                                          const int reduced_resolution,   // [input] ignored
591                                          const int32_t rounding,                 /* [input] for rounding image data */                                          const int32_t rounding,                 // [input] for rounding image data
592                                          MACROBLOCK *const pMBs,                 /* [output] average motion vectors */                                          MACROBLOCK *const pMBs,                 // [output] average motion vectors
593                                          IMAGE *const pGMC)                              /* [output] full warped image */                                          IMAGE *const pGMC)                              // [output] full warped image
594  {  {
595    
596          unsigned int mj,mi;          unsigned int mj,mi;
# Line 674  Line 677 
677                          if (G< -1) G=-1;                          if (G< -1) G=-1;
678                          else if (G>H) G=H;                          else if (G>H) G=H;
679    
680                          {        /* MMX-like bilinear... */                          {        // MMX-like bilinear...
681                                  const int offset = G*stride + F;                                  const int offset = G*stride + F;
682                                  uint32_t f0, f1;                                  uint32_t f0, f1;
683                                  f0 = pRef->y[ offset +0 ];                                  f0 = pRef->y[ offset +0 ];
# Line 755  Line 758 
758          }          }
759    
760    
761          avgMV.x -= 16*((256*mi+120)<<4);        /* 120 = 15*16/2 */          avgMV.x -= 16*((256*mi+120)<<4);        // 120 = 15*16/2
762          avgMV.y -= 16*((256*mj+120)<<4);          avgMV.y -= 16*((256*mj+120)<<4);
763    
764          avgMV.x = RSHIFT( avgMV.x, (4+7-quarterpel) );          avgMV.x = RSHIFT( avgMV.x, (4+7-quarterpel) );
# Line 768  Line 771 
771    
772  #ifdef OLD_GRUEL_GMC  #ifdef OLD_GRUEL_GMC
773  void  void
774  generate_GMCparameters( const int num_wp,                       /* [input]: number of warppoints */  generate_GMCparameters( const int num_wp,                       // [input]: number of warppoints
775                                                  const int res,                  /* [input]: resolution */                                                  const int res,                  // [input]: resolution
776                                                  const WARPPOINTS *const warp, /* [input]: warp points */                                                  const WARPPOINTS *const warp, // [input]: warp points
777                                                  const int width, const int height,                                                  const int width, const int height,
778                                                  GMC_DATA *const gmc)    /* [output] precalculated parameters */                                                  GMC_DATA *const gmc)    // [output] precalculated parameters
779  {  {
780    
781  /* We follow mainly two sources: The original standard, which is ugly, and the  /* We follow mainly two sources: The original standard, which is ugly, and the
# Line 832  Line 835 
835          int dv0 = warp->duv[0].y;          int dv0 = warp->duv[0].y;
836          int du1 = warp->duv[1].x;          int du1 = warp->duv[1].x;
837          int dv1 = warp->duv[1].y;          int dv1 = warp->duv[1].y;
838  #if 0  //      int du2 = warp->duv[2].x;
839          int du2 = warp->duv[2].x;  //      int dv2 = warp->duv[2].y;
         int dv2 = warp->duv[2].y;  
 #endif  
840    
841          gmc->num_wp = num_wp;          gmc->num_wp = num_wp;
842    
# Line 850  Line 851 
851          gmc->alpha = log2bin(gmc->W-1);          gmc->alpha = log2bin(gmc->W-1);
852          gmc->Ws= 1<<gmc->alpha;          gmc->Ws= 1<<gmc->alpha;
853    
854  #if 0  //      gmc->beta = log2bin(gmc->H-1);
855          gmc->beta = log2bin(gmc->H-1);  //      gmc->Hs= 1<<gmc->beta;
         gmc->Hs= 1<<gmc->beta;  
 #endif  
856    
857  #if 0  //      printf("du0=%d dv0=%d du1=%d dv1=%d s=%d sigma=%d W=%d alpha=%d, Ws=%d, rho=%d\n",du0,dv0,du1,dv1,gmc->s,gmc->sigma,gmc->W,gmc->alpha,gmc->Ws,gmc->rho);
         printf("du0=%d dv0=%d du1=%d dv1=%d s=%d sigma=%d W=%d alpha=%d, Ws=%d, rho=%d\n",du0,dv0,du1,dv1,gmc->s,gmc->sigma,gmc->W,gmc->alpha,gmc->Ws,gmc->rho);  
 #endif  
858    
859          /*          /* i2s is only needed for num_wp >= 3, etc.  */
860           * i2s is only needed for num_wp >= 3, etc.          /* the 's' values are in 1/s pel resolution */
          * the 's' values are in 1/s pel resolution  
          */  
861          gmc->i0s = res/2 * ( du0 );          gmc->i0s = res/2 * ( du0 );
862          gmc->j0s = res/2 * ( dv0 );          gmc->j0s = res/2 * ( dv0 );
863          gmc->i1s = res/2 * (2*width + du1 + du0 );          gmc->i1s = res/2 * (2*width + du1 + du0 );
864          gmc->j1s = res/2 * ( dv1 + dv0 );          gmc->j1s = res/2 * ( dv1 + dv0 );
865  #if 0  //      gmc->i2s = res/2 * ( du2 + du0 );
866          gmc->i2s = res/2 * ( du2 + du0 );  //      gmc->j2s = res/2 * (2*height + dv2 + dv0 );
         gmc->j2s = res/2 * (2*height + dv2 + dv0 );  
 #endif  
867    
868          /* i2s and i2ss are only needed for num_wp == 3, etc.  */          /* i2s and i2ss are only needed for num_wp == 3, etc.  */
869    
# Line 878  Line 871 
871          gmc->i1ss = 16*gmc->Ws + ROUNDED_DIV(((gmc->W-gmc->Ws)*(gmc->r*gmc->i0s) + gmc->Ws*(gmc->r*gmc->i1s - 16*gmc->W)),gmc->W);          gmc->i1ss = 16*gmc->Ws + ROUNDED_DIV(((gmc->W-gmc->Ws)*(gmc->r*gmc->i0s) + gmc->Ws*(gmc->r*gmc->i1s - 16*gmc->W)),gmc->W);
872          gmc->j1ss = ROUNDED_DIV( ((gmc->W - gmc->Ws)*(gmc->r*gmc->j0s) + gmc->Ws*gmc->r*gmc->j1s) ,gmc->W );          gmc->j1ss = ROUNDED_DIV( ((gmc->W - gmc->Ws)*(gmc->r*gmc->j0s) + gmc->Ws*gmc->r*gmc->j1s) ,gmc->W );
873    
874  #if 0  //      gmc->i2ss = ROUNDED_DIV( ((gmc->H - gmc->Hs)*(gmc->r*gmc->i0s) + gmc->Hs*(gmc->r*gmc->i2s)), gmc->H);
875          gmc->i2ss = ROUNDED_DIV( ((gmc->H - gmc->Hs)*(gmc->r*gmc->i0s) + gmc->Hs*(gmc->r*gmc->i2s)), gmc->H);  //      gmc->j2ss = 16*gmc->Hs + ROUNDED_DIV( ((gmc->H-gmc->Hs)*(gmc->r*gmc->j0s) + gmc->Ws*(gmc->r*gmc->j2s - 16*gmc->H)), gmc->H);
         gmc->j2ss = 16*gmc->Hs + ROUNDED_DIV( ((gmc->H-gmc->Hs)*(gmc->r*gmc->j0s) + gmc->Ws*(gmc->r*gmc->j2s - 16*gmc->H)), gmc->H);  
 #endif  
876    
877          return;          return;
878  }  }
879    
880  void  void
881  generate_GMCimage(      const GMC_DATA *const gmc_data,         /* [input] precalculated data */  generate_GMCimage(      const GMC_DATA *const gmc_data,         // [input] precalculated data
882                                          const IMAGE *const pRef,                        /* [input] */                                          const IMAGE *const pRef,                        // [input]
883                                          const int mb_width,                                          const int mb_width,
884                                          const int mb_height,                                          const int mb_height,
885                                          const int stride,                                          const int stride,
886                                          const int stride2,                                          const int stride2,
887                                          const int fcode,                                        /* [input] some parameters... */                                          const int fcode,                                        // [input] some parameters...
888                                          const int32_t quarterpel,                       /* [input] for rounding avgMV */                                          const int32_t quarterpel,                       // [input] for rounding avgMV
889                                          const int reduced_resolution,           /* [input] ignored */                                          const int reduced_resolution,           // [input] ignored
890                                          const int32_t rounding,                 /* [input] for rounding image data */                                          const int32_t rounding,                 // [input] for rounding image data
891                                          MACROBLOCK *const pMBs,         /* [output] average motion vectors */                                          MACROBLOCK *const pMBs,         // [output] average motion vectors
892                                          IMAGE *const pGMC)                      /* [output] full warped image */                                          IMAGE *const pGMC)                      // [output] full warped image
893  {  {
894    
895          unsigned int mj,mi;          unsigned int mj,mi;
# Line 960  Line 951 
951    
952          const int i1ss = gmc_data->i1ss;          const int i1ss = gmc_data->i1ss;
953          const int j1ss = gmc_data->j1ss;          const int j1ss = gmc_data->j1ss;
954  #if 0  //      const int i2ss = gmc_data->i2ss;
955          const int i2ss = gmc_data->i2ss;  //      const int j2ss = gmc_data->j2ss;
         const int j2ss = gmc_data->j2ss;  
 #endif  
956    
957          const int alpha = gmc_data->alpha;          const int alpha = gmc_data->alpha;
958          const int Ws    = gmc_data->Ws;          const int Ws    = gmc_data->Ws;
959    
960  #if 0  //      const int beta  = gmc_data->beta;
961          const int beta  = gmc_data->beta;  //      const int Hs    = gmc_data->Hs;
         const int Hs    = gmc_data->Hs;  
 #endif  
962    
963          int I,J;          int I,J;
964          VECTOR avgMV = {0,0};          VECTOR avgMV = {0,0};
# Line 985  Line 972 
972  /* this naive implementation (with lots of multiplications) isn't slower (rather faster) than  /* this naive implementation (with lots of multiplications) isn't slower (rather faster) than
973     working incremental. Don't ask me why... maybe the whole this is memory bound? */     working incremental. Don't ask me why... maybe the whole this is memory bound? */
974    
975                  const int ri= F & (s-1); /* fractional part of pelwise MV X */                  const int ri= F & (s-1); // fractional part of pelwise MV X
976                  const int rj= G & (s-1); /* fractional part of pelwise MV Y */                  const int rj= G & (s-1); // fractional part of pelwise MV Y
977    
978                  int Y00,Y01,Y10,Y11;                  int Y00,Y01,Y10,Y11;
979    
# Line 1009  Line 996 
996                  else if (G>H)                  else if (G>H)
997                          G=H;            /* dito */                          G=H;            /* dito */
998    
999                  Y00 = pRef->y[ G*stride + F ];                          /* Lumi values */                  Y00 = pRef->y[ G*stride + F ];                          // Lumi values
1000                  Y01 = pRef->y[ G*stride + F+1 ];                  Y01 = pRef->y[ G*stride + F+1 ];
1001                  Y10 = pRef->y[ G*stride + F+stride ];                  Y10 = pRef->y[ G*stride + F+stride ];
1002                  Y11 = pRef->y[ G*stride + F+stride+1 ];                  Y11 = pRef->y[ G*stride + F+stride+1 ];
# Line 1036  Line 1023 
1023                  int Gc=((-r*j0s+j1ss)*(4*I+1) +(-r*i0s+i1ss)*(4*J+1) +2*Ws*r*j0s                  int Gc=((-r*j0s+j1ss)*(4*I+1) +(-r*i0s+i1ss)*(4*J+1) +2*Ws*r*j0s
1024                                                  -16*Ws +(1<<(alpha+rho+1))) >>(alpha+rho+2);                                                  -16*Ws +(1<<(alpha+rho+1))) >>(alpha+rho+2);
1025    
1026                  const int ri= Fc & (s-1); /* fractional part of pelwise MV X */                  const int ri= Fc & (s-1); // fractional part of pelwise MV X
1027                  const int rj= Gc & (s-1); /* fractional part of pelwise MV Y */                  const int rj= Gc & (s-1); // fractional part of pelwise MV Y
1028    
1029                  int C00,C01,C10,C11;                  int C00,C01,C10,C11;
1030    
# Line 1054  Line 1041 
1041                          Gc=H/2;         /* dito */                          Gc=H/2;         /* dito */
1042    
1043  /* now calculate U data */  /* now calculate U data */
1044                  C00 = pRef->u[ Gc*stride2 + Fc ];                               /* chroma-value Cb */                  C00 = pRef->u[ Gc*stride2 + Fc ];                               // chroma-value Cb
1045                  C01 = pRef->u[ Gc*stride2 + Fc+1 ];                  C01 = pRef->u[ Gc*stride2 + Fc+1 ];
1046                  C10 = pRef->u[ (Gc+1)*stride2 + Fc ];                  C10 = pRef->u[ (Gc+1)*stride2 + Fc ];
1047                  C11 = pRef->u[ (Gc+1)*stride2 + Fc+1 ];                  C11 = pRef->u[ (Gc+1)*stride2 + Fc+1 ];
# Line 1067  Line 1054 
1054                  pGMC->u[J*stride2+I] = (uint8_t)C00;                                                                            /* output 1 U-pixel */                  pGMC->u[J*stride2+I] = (uint8_t)C00;                                                                            /* output 1 U-pixel */
1055    
1056  /* now calculate V data */  /* now calculate V data */
1057                  C00 = pRef->v[ Gc*stride2 + Fc ];                               /* chroma-value Cr */                  C00 = pRef->v[ Gc*stride2 + Fc ];                               // chroma-value Cr
1058                  C01 = pRef->v[ Gc*stride2 + Fc+1 ];                  C01 = pRef->v[ Gc*stride2 + Fc+1 ];
1059                  C10 = pRef->v[ (Gc+1)*stride2 + Fc ];                  C10 = pRef->v[ (Gc+1)*stride2 + Fc ];
1060                  C11 = pRef->v[ (Gc+1)*stride2 + Fc+1 ];                  C11 = pRef->v[ (Gc+1)*stride2 + Fc+1 ];

Legend:
Removed from v.1.18.2.5  
changed lines
  Added in v.1.19

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