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

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

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

revision 1159, Mon Sep 29 16:58:37 2003 UTC revision 1160, Tue Sep 30 18:20:31 2003 UTC
# Line 19  Line 19 
19   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: gmc.c,v 1.1.2.4 2003-09-10 22:18:59 edgomez Exp $   * $Id: gmc.c,v 1.1.2.5 2003-09-30 18:20:31 edgomez Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 30  Line 30 
30    
31  #include <stdio.h>  #include <stdio.h>
32    
33  /* These are mainly the new GMC routines by -Skal- (C) 2003 */  /* ************************************************************
34     * Pts = 2 or 3
35  //////////////////////////////////////////////////////////   *
36  // Pts = 2 or 3   * Warning! *src is the global frame pointer (that is: adress
37     * of pixel 0,0), not the macroblock one.
38  // Warning! *src is the global frame pointer (that is: adress   * Conversely, *dst is the macroblock top-left adress.
39  // of pixel 0,0), not the macroblock one.   */
 // Conversely, *dst is the macroblock top-left adress.  
40    
41  void Predict_16x16_C(const NEW_GMC_DATA * const This,  void Predict_16x16_C(const NEW_GMC_DATA * const This,
42                                           uint8_t *dst, const uint8_t *src,                                           uint8_t *dst, const uint8_t *src,
# Line 192  Line 191 
191                  v = V >> 16; V += Dsp->dV[0]; vy += v;                  v = V >> 16; V += Dsp->dV[0]; vy += v;
192          }          }
193          }          }
194          vx -= (256*x+120) << (5+Dsp->accuracy); // 120 = 15*16/2          vx -= (256*x+120) << (5+Dsp->accuracy); /* 120 = 15*16/2 */
195          vy -= (256*y+120) << (5+Dsp->accuracy);          vy -= (256*y+120) << (5+Dsp->accuracy);
196    
197          mv->x = RSHIFT( vx, 8+Dsp->accuracy - qpel );          mv->x = RSHIFT( vx, 8+Dsp->accuracy - qpel );
198          mv->y = RSHIFT( vy, 8+Dsp->accuracy - qpel );          mv->y = RSHIFT( vy, 8+Dsp->accuracy - qpel );
199  }  }
200    
201  //////////////////////////////////////////////////////////  /* ************************************************************
202  // simplified version for 1 warp point   * simplified version for 1 warp point
203     */
204    
205  void Predict_1pt_16x16_C(const NEW_GMC_DATA * const This,  void Predict_1pt_16x16_C(const NEW_GMC_DATA * const This,
206                                                   uint8_t *Dst, const uint8_t *Src,                                                   uint8_t *Dst, const uint8_t *Src,
# Line 212  Line 212 
212          const int32_t Rounder = ( 128 - (rounding<<(2*rho)) ) << 16;          const int32_t Rounder = ( 128 - (rounding<<(2*rho)) ) << 16;
213    
214    
215          int32_t uo = This->Uo + (x<<8);  // ((16*x)<<4)          int32_t uo = This->Uo + (x<<8);  /* ((16*x)<<4) */
216          int32_t vo = This->Vo + (y<<8);          int32_t vo = This->Vo + (y<<8);
217          const uint32_t ri = MTab[uo & 15];          const uint32_t ri = MTab[uo & 15];
218          const uint32_t rj = MTab[vo & 15];          const uint32_t rj = MTab[vo & 15];
# Line 310  Line 310 
310          mv->y = RSHIFT(Dsp->Vo<<qpel, 3);          mv->y = RSHIFT(Dsp->Vo<<qpel, 3);
311  }  }
312    
313  //////////////////////////////////////////////////////////  /* *************************************************************
314     * Warning! It's Accuracy being passed, not 'resolution'!
315     */
         // Warning! It's Accuracy being passed, not 'resolution'!  
316    
317  void generate_GMCparameters( int nb_pts, const int accuracy,  void generate_GMCparameters( int nb_pts, const int accuracy,
318                                                                   const WARPPOINTS *const pts,                                                                   const WARPPOINTS *const pts,
# Line 325  Line 324 
324          gmc->accuracy = accuracy;          gmc->accuracy = accuracy;
325          gmc->num_wp = nb_pts;          gmc->num_wp = nb_pts;
326    
327          // reduce the number of points, if possible          /* reduce the number of points, if possible */
328          if (nb_pts<3 || (pts->duv[2].x==-pts->duv[1].y && pts->duv[2].y==pts->duv[1].x)) {          if (nb_pts<3 || (pts->duv[2].x==-pts->duv[1].y && pts->duv[2].y==pts->duv[1].x)) {
329          if (nb_pts<2 || (pts->duv[1].x==0 && pts->duv[1].y==0)) {          if (nb_pts<2 || (pts->duv[1].x==0 && pts->duv[1].y==0)) {
330                  if (nb_pts<1 || (pts->duv[0].x==0 && pts->duv[0].y==0)) {                  if (nb_pts<1 || (pts->duv[0].x==0 && pts->duv[0].y==0)) {
# Line 337  Line 336 
336          }          }
337          else nb_pts = 3;          else nb_pts = 3;
338    
339          // now, nb_pts stores the actual number of points required for interpolation          /* now, nb_pts stores the actual number of points required for interpolation */
340    
341          if (nb_pts<=1)          if (nb_pts<=1)
342          {          {
343          if (nb_pts==1) {          if (nb_pts==1) {
344                  // store as 4b fixed point                  /* store as 4b fixed point */
345                  gmc->Uo = pts->duv[0].x << accuracy;                  gmc->Uo = pts->duv[0].x << accuracy;
346                  gmc->Vo = pts->duv[0].y << accuracy;                  gmc->Vo = pts->duv[0].y << accuracy;
347                  gmc->Uco = ((pts->duv[0].x>>1) | (pts->duv[0].x&1)) << accuracy;         // DIV2RND()                  gmc->Uco = ((pts->duv[0].x>>1) | (pts->duv[0].x&1)) << accuracy;         /* DIV2RND() */
348                  gmc->Vco = ((pts->duv[0].y>>1) | (pts->duv[0].y&1)) << accuracy;         // DIV2RND()                  gmc->Vco = ((pts->duv[0].y>>1) | (pts->duv[0].y&1)) << accuracy;         /* DIV2RND() */
349          }          }
350          else {  // zero points?!          else {  /* zero points?! */
351                  gmc->Uo = gmc->Vo       = 0;                  gmc->Uo = gmc->Vo       = 0;
352                  gmc->Uco = gmc->Vco = 0;                  gmc->Uco = gmc->Vco = 0;
353          }          }
# Line 357  Line 356 
356          gmc->predict_8x8        = Predict_1pt_8x8_C;          gmc->predict_8x8        = Predict_1pt_8x8_C;
357          gmc->get_average_mv = get_average_mv_1pt_C;          gmc->get_average_mv = get_average_mv_1pt_C;
358          }          }
359          else {          // 2 or 3 points          else {          /* 2 or 3 points */
360          const int rho    = 3 - accuracy;        // = {3,2,1,0} for Acc={0,1,2,3}          const int rho    = 3 - accuracy;        /* = {3,2,1,0} for Acc={0,1,2,3} */
361          int Alpha = log2bin(width-1);          int Alpha = log2bin(width-1);
362          int Ws = 1 << Alpha;          int Ws = 1 << Alpha;
363    
364          gmc->dU[0] = 16*Ws + RDIV( 8*Ws*pts->duv[1].x, width );  // dU/dx          gmc->dU[0] = 16*Ws + RDIV( 8*Ws*pts->duv[1].x, width );  /* dU/dx */
365          gmc->dV[0] =             RDIV( 8*Ws*pts->duv[1].y, width );      // dV/dx          gmc->dV[0] =             RDIV( 8*Ws*pts->duv[1].y, width );      /* dV/dx */
366    
367  /*       disabled, because possibly buggy? */  /*       disabled, because possibly buggy? */
368    
369  /* if (nb_pts==2) {  #if 0
370                  gmc->dU[1] = -gmc->dV[0];       // -Sin          if (nb_pts==2) {
371                  gmc->dV[1] =    gmc->dU[0] ;    //      Cos                  gmc->dU[1] = -gmc->dV[0];       /* -Sin */
372                    gmc->dV[1] =    gmc->dU[0] ;    /* Cos */
373          }          }
374          else */          else
375    #endif
376          {          {
377                  const int Beta = log2bin(height-1);                  const int Beta = log2bin(height-1);
378                  const int Hs = 1<<Beta;                  const int Hs = 1<<Beta;
379                  gmc->dU[1] =             RDIV( 8*Hs*pts->duv[2].x, height );     // dU/dy                  gmc->dU[1] =             RDIV( 8*Hs*pts->duv[2].x, height );     /* dU/dy */
380                  gmc->dV[1] = 16*Hs + RDIV( 8*Hs*pts->duv[2].y, height );         // dV/dy                  gmc->dV[1] = 16*Hs + RDIV( 8*Hs*pts->duv[2].y, height );         /* dV/dy */
381                  if (Beta>Alpha) {                  if (Beta>Alpha) {
382                  gmc->dU[0] <<= (Beta-Alpha);                  gmc->dU[0] <<= (Beta-Alpha);
383                  gmc->dV[0] <<= (Beta-Alpha);                  gmc->dV[0] <<= (Beta-Alpha);
# Line 388  Line 389 
389                  gmc->dV[1] <<= Alpha - Beta;                  gmc->dV[1] <<= Alpha - Beta;
390                  }                  }
391          }          }
392                  // upscale to 16b fixed-point          /* upscale to 16b fixed-point */
393          gmc->dU[0] <<= (16-Alpha - rho);          gmc->dU[0] <<= (16-Alpha - rho);
394          gmc->dU[1] <<= (16-Alpha - rho);          gmc->dU[1] <<= (16-Alpha - rho);
395          gmc->dV[0] <<= (16-Alpha - rho);          gmc->dV[0] <<= (16-Alpha - rho);
# Line 407  Line 408 
408          }          }
409  }  }
410    
411  //////////////////////////////////////////////////////////  /* *******************************************************************
412     * quick and dirty routine to generate the full warped image
413  /* quick and dirty routine to generate the full warped image (pGMC != NULL)   * (pGMC != NULL) or just all average Motion Vectors (pGMC == NULL) */
         or just all average Motion Vectors (pGMC == NULL) */  
414    
415  void  void
416  generate_GMCimage(      const NEW_GMC_DATA *const gmc_data, // [input] precalculated data  generate_GMCimage(      const NEW_GMC_DATA *const gmc_data, /* [input] precalculated data */
417                                          const IMAGE *const pRef,                // [input]                                          const IMAGE *const pRef,                /* [input] */
418                                          const int mb_width,                                          const int mb_width,
419                                          const int mb_height,                                          const int mb_height,
420                                          const int stride,                                          const int stride,
421                                          const int stride2,                                          const int stride2,
422                                          const int fcode,                                // [input] some parameters...                                          const int fcode,                                /* [input] some parameters... */
423                                                  const int32_t quarterpel,               // [input] for rounding avgMV                                                  const int32_t quarterpel,               /* [input] for rounding avgMV */
424                                          const int reduced_resolution,   // [input] ignored                                          const int reduced_resolution,   /* [input] ignored */
425                                          const int32_t rounding,                 // [input] for rounding image data                                          const int32_t rounding,                 /* [input] for rounding image data */
426                                          MACROBLOCK *const pMBs,                 // [output] average motion vectors                                          MACROBLOCK *const pMBs,                 /* [output] average motion vectors */
427                                          IMAGE *const pGMC)                              // [output] full warped image                                          IMAGE *const pGMC)                              /* [output] full warped image */
428  {  {
429    
430          unsigned int mj,mi;          unsigned int mj,mi;

Legend:
Removed from v.1159  
changed lines
  Added in v.1160

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