[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 1077, Sat Jun 28 15:54:16 2003 UTC revision 1161, Wed Oct 1 23:23:01 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      GMC interpolation module   *  - GMC interpolation module -
5     *
6     *  Copyright(C) 2002-2003 Pascal Massimino <skal@planet-d.net>
7   *   *
8   *      This program is free software; you can redistribute it and/or modify   *      This program is free software; you can redistribute it and/or modify
9   *      it under the terms of the GNU General Public License as published by   *      it under the terms of the GNU General Public License as published by
# Line 15  Line 17 
17   *   *
18   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
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., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21     *
22     * $Id: gmc.c,v 1.1.2.6 2003-10-01 23:23:01 edgomez Exp $
23   *   *
24   *************************************************************************/   ****************************************************************************/
25    
26  #include "../portab.h"  #include "../portab.h"
27  #include "../global.h"  #include "../global.h"
28  #include "../encoder.h"  #include "../encoder.h"
29  #include "gmc.h"  #include "gmc.h"
 #include "motion_est.h"  
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 57  Line 58 
58    int i, j;    int i, j;
59    
60    dst += 16;    dst += 16;
61    for (j=16; j>0; --j)          for (j=16; j>0; --j) {
   {  
62      int U = Uo, V = Vo;      int U = Uo, V = Vo;
63      Uo += dUy; Vo += dVy;      Uo += dUy; Vo += dVy;
64      for (i=-16; i<0; ++i)                  for (i=-16; i<0; ++i) {
65      {                          unsigned int f0, f1, ri = 16, rj = 16;
       unsigned int f0, f1, ri, rj;  
66        int Offset;        int Offset;
   
67        int u = ( U >> 16 ) << rho;        int u = ( U >> 16 ) << rho;
68        int v = ( V >> 16 ) << rho;        int v = ( V >> 16 ) << rho;
69    
70        U += dUx; V += dVx;        U += dUx; V += dVx;
71    
72        ri = 16;                          if (u > 0 && u <= W) { ri = MTab[u&15]; Offset = u>>4;  }
       if ((uint32_t)u<=(uint32_t)W) { ri = MTab[u&15]; Offset = u>>4;  }  
73        else if (u>W) Offset = W>>4;        else if (u>W) Offset = W>>4;
74        else Offset = -1;        else Offset = -1;
75    
76        rj = 16;                          if (v > 0 && v <= H) { rj = MTab[v&15]; Offset += (v>>4)*srcstride; }
       if ((uint32_t)v<=(uint32_t)H) { rj = MTab[v&15]; Offset += (v>>4)*srcstride; }  
77        else if (v>H) Offset += (H>>4)*srcstride;        else if (v>H) Offset += (H>>4)*srcstride;
78            else Offset -= srcstride;            else Offset -= srcstride;
79    
# Line 95  Line 92 
92    }    }
93  }  }
94    
   
95  void Predict_8x8_C(const NEW_GMC_DATA * const This,  void Predict_8x8_C(const NEW_GMC_DATA * const This,
96                     uint8_t *uDst, const uint8_t *uSrc,                     uint8_t *uDst, const uint8_t *uSrc,
97                     uint8_t *vDst, const uint8_t *vSrc,                     uint8_t *vDst, const uint8_t *vSrc,
# Line 118  Line 114 
114    
115    uDst += 8;    uDst += 8;
116    vDst += 8;    vDst += 8;
117    for (j=8; j>0; --j)          for (j=8; j>0; --j) {
   {  
118      int32_t U = Uo, V = Vo;      int32_t U = Uo, V = Vo;
119      Uo += dUy; Vo += dVy;      Uo += dUy; Vo += dVy;
120    
121      for (i=-8; i<0; ++i)                  for (i=-8; i<0; ++i) {
     {  
122        int Offset;        int Offset;
123        uint32_t f0, f1, ri, rj;        uint32_t f0, f1, ri, rj;
124        int32_t u, v;        int32_t u, v;
# Line 133  Line 127 
127        v = ( V >> 16 ) << rho;        v = ( V >> 16 ) << rho;
128        U += dUx; V += dVx;        U += dUx; V += dVx;
129    
130        if ((uint32_t)u<=(uint32_t)W) {                          if (u > 0 && u <= W) {
131          ri = MTab[u&15];          ri = MTab[u&15];
132          Offset = u>>4;          Offset = u>>4;
133        }                          } else {
       else {  
134          ri = 16;          ri = 16;
135          if (u>W) Offset = W>>4;          if (u>W) Offset = W>>4;
136          else Offset = -1;          else Offset = -1;
137        }        }
138        if ((uint32_t)v<=(uint32_t)H) {  
139                            if (v > 0 && v <= H) {
140          rj = MTab[v&15];          rj = MTab[v&15];
141          Offset += (v>>4)*srcstride;          Offset += (v>>4)*srcstride;
142        }                          } else {
       else {  
143          rj = 16;          rj = 16;
144          if (v>H) Offset += (H>>4)*srcstride;          if (v>H) Offset += (H>>4)*srcstride;
145                  else Offset -= srcstride;                  else Offset -= srcstride;
# Line 179  Line 172 
172    }    }
173  }  }
174    
175    void get_average_mv_C(const NEW_GMC_DATA * const Dsp, VECTOR * const mv,
 void get_average_mv_C(NEW_GMC_DATA *Dsp, VECTOR * const mv,  
176                        int x, int y, int qpel)                        int x, int y, int qpel)
177  {  {
178    int i, j;    int i, j;
# Line 199  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 220  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 255  Line 247 
247    }    }
248  }  }
249    
   
250  void Predict_1pt_8x8_C(const NEW_GMC_DATA * const This,  void Predict_1pt_8x8_C(const NEW_GMC_DATA * const This,
251                         uint8_t *uDst, const uint8_t *uSrc,                         uint8_t *uDst, const uint8_t *uSrc,
252                         uint8_t *vDst, const uint8_t *vSrc,                         uint8_t *vDst, const uint8_t *vSrc,
# Line 312  Line 303 
303    }    }
304  }  }
305    
306    void get_average_mv_1pt_C(const NEW_GMC_DATA * const Dsp, VECTOR * const mv,
 void get_average_mv_1pt_C(NEW_GMC_DATA *Dsp, VECTOR * const mv,  
307                            int x, int y, int qpel)                            int x, int y, int qpel)
308  {  {
309    mv->x = RSHIFT(Dsp->Uo<<qpel, 3);    mv->x = RSHIFT(Dsp->Uo<<qpel, 3);
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 335  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 347  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 367  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 398  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 417  Line 408 
408    }    }
409  }  }
410    
411  //////////////////////////////////////////////////////////  /* *******************************************************************
412     * quick and dirty routine to generate the full warped image
413     * (pGMC != NULL) or just all average Motion Vectors (pGMC == NULL) */
 /* quick and dirty routine to generate the full warped image (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.1077  
changed lines
  Added in v.1161

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