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

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

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

trunk/xvidcore/src/motion/motion_comp.c revision 437, Sat Sep 7 09:12:22 2002 UTC branches/dev-api-4/xvidcore/src/motion/motion_comp.c revision 1125, Fri Aug 22 15:52:35 2003 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Motion Compensation module -   *  - Motion Compensation related code  -
5   *   *
6   *  Copyright(C) 2002 Michael Militzer <michael@xvid.org>   *  Copyright(C) 2002 Peter Ross <pross@xvid.org>
7   *  Copyright(C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>   *               2003 Christoph Lampert <gruel@web.de>
  *  Copyright(C) 2002 Christoph Lampert <gruel@web.de>  
  *  
  *  This program is an implementation of a part of one or more MPEG-4  
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
8   *   *
9   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
10   *  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 30  Line 20 
20   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   *************************************************************************/   * $Id: motion_comp.c,v 1.18.2.8 2003-08-22 15:52:35 Isibaar Exp $
24     *
25     ****************************************************************************/
26    
27    #include <stdio.h>
28    
29  #include "../encoder.h"  #include "../encoder.h"
30  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
31  #include "../image/interpolate8x8.h"  #include "../image/interpolate8x8.h"
32    #include "../image/qpel.h"
33    #include "../image/reduced.h"
34  #include "../utils/timer.h"  #include "../utils/timer.h"
35  #include "motion.h"  #include "motion.h"
36    
37  #define ABS(X) (((X)>0)?(X):-(X))  #ifndef RSHIFT
38  #define SIGN(X) (((X)>0)?1:-1)  #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
39    #endif
40    
41    /* assume b>0 */
42    #ifndef RDIV
43    #define RDIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
44    #endif
45    
46    
47    /* This is borrowed from   bitstream.c  until we find a common solution */
48    
49    static uint32_t __inline
50    log2bin(uint32_t value)
51    {
52    /* Changed by Chenm001 */
53    #if !defined(_MSC_VER)
54            int n = 0;
55    
56            while (value) {
57                    value >>= 1;
58                    n++;
59            }
60            return n;
61    #else
62            __asm {
63                    bsr eax, value
64                    inc eax
65            }
66    #endif
67    }
68    
69    
70  static __inline void  static __inline void
71  compensate8x8_halfpel(int16_t * const dct_codes,  compensate16x16_interpolate(int16_t * const dct_codes,
72                                            uint8_t * const cur,                                            uint8_t * const cur,
73                                            const uint8_t * const ref,                                            const uint8_t * const ref,
74                                            const uint8_t * const refh,                                            const uint8_t * const refh,
75                                            const uint8_t * const refv,                                            const uint8_t * const refv,
76                                            const uint8_t * const refhv,                                            const uint8_t * const refhv,
77                                            const uint32_t x,                                                          uint8_t * const tmp,
78                                            const uint32_t y,                                                          uint32_t x,
79                                                            uint32_t y,
80                                            const int32_t dx,                                            const int32_t dx,
81                                            const int dy,                                                          const int32_t dy,
82                                            const uint32_t stride)                                                          const int32_t stride,
83                                                            const int quarterpel,
84                                                            const int reduced_resolution,
85                                                            const int32_t rounding)
86  {  {
87          int32_t ddx, ddy;          const uint8_t * ptr;
88    
89          switch (((dx & 1) << 1) + (dy & 1))     // ((dx%2)?2:0)+((dy%2)?1:0)          if (!reduced_resolution) {
         {  
         case 0:  
                 ddx = dx / 2;  
                 ddy = dy / 2;  
                 transfer_8to16sub(dct_codes, cur + y * stride + x,  
                                                   ref + (int) ((y + ddy) * stride + x + ddx), stride);  
                 break;  
90    
91          case 1:                  if(quarterpel) {
92                  ddx = dx / 2;                          if ((dx&3) | (dy&3)) {
93                  ddy = (dy - 1) / 2;  #if defined(ARCH_IS_IA32) /* new_interpolate is only faster on x86 (MMX) machines */
94                  transfer_8to16sub(dct_codes, cur + y * stride + x,                                  new_interpolate16x16_quarterpel(tmp - y * stride - x,
95                                                    refv + (int) ((y + ddy) * stride + x + ddx), stride);                                                                                          (uint8_t *) ref, tmp + 32,
96                  break;                                                                                          tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);
97    #else
98                                    interpolate16x16_quarterpel(tmp - y * stride - x,
99                                                                                            (uint8_t *) ref, tmp + 32,
100                                                                                            tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);
101    #endif
102                                    ptr = tmp;
103                            } else ptr =  ref + (y + dy/4)*stride + x + dx/4; /* fullpixel position */
104    
105          case 2:                  } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);
                 ddx = (dx - 1) / 2;  
                 ddy = dy / 2;  
                 transfer_8to16sub(dct_codes, cur + y * stride + x,  
                                                   refh + (int) ((y + ddy) * stride + x + ddx), stride);  
                 break;  
106    
         default:                                        // case 3:  
                 ddx = (dx - 1) / 2;  
                 ddy = (dy - 1) / 2;  
107                  transfer_8to16sub(dct_codes, cur + y * stride + x,                  transfer_8to16sub(dct_codes, cur + y * stride + x,
108                                                    refhv + (int) ((y + ddy) * stride + x + ddx), stride);                                                          ptr, stride);
109                  break;                  transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8,
110                                                            ptr + 8, stride);
111                    transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride,
112                                                            ptr + 8*stride, stride);
113                    transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8,
114                                                            ptr + 8*stride + 8, stride);
115    
116            } else { /* reduced_resolution */
117    
118                    x *= 2; y *= 2;
119    
120                    ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);
121    
122                    filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride);
123                    filter_diff_18x18_to_8x8(dct_codes, ptr, stride);
124    
125                    filter_18x18_to_8x8(dct_codes+64, cur+y*stride + x + 16, stride);
126                    filter_diff_18x18_to_8x8(dct_codes+64, ptr + 16, stride);
127    
128                    filter_18x18_to_8x8(dct_codes+128, cur+(y+16)*stride + x, stride);
129                    filter_diff_18x18_to_8x8(dct_codes+128, ptr + 16*stride, stride);
130    
131                    filter_18x18_to_8x8(dct_codes+192, cur+(y+16)*stride + x + 16, stride);
132                    filter_diff_18x18_to_8x8(dct_codes+192, ptr + 16*stride + 16, stride);
133    
134                    transfer32x32_copy(cur + y*stride + x, ptr, stride);
135          }          }
136  }  }
137    
138    static __inline void
139    compensate8x8_interpolate(      int16_t * const dct_codes,
140                                                            uint8_t * const cur,
141                                                            const uint8_t * const ref,
142                                                            const uint8_t * const refh,
143                                                            const uint8_t * const refv,
144                                                            const uint8_t * const refhv,
145                                                            uint8_t * const tmp,
146                                                            uint32_t x,
147                                                            uint32_t y,
148                                                            const int32_t dx,
149                                                            const int32_t dy,
150                                                            const int32_t stride,
151                                                            const int32_t quarterpel,
152                                                            const int reduced_resolution,
153                                                            const int32_t rounding)
154    {
155            const uint8_t * ptr;
156    
157            if (!reduced_resolution) {
158    
159                    if(quarterpel) {
160                            if ((dx&3) | (dy&3)) {
161    #if defined(ARCH_IS_IA32) /* new_interpolate is only faster on x86 (MMX) machines */
162                                    new_interpolate8x8_quarterpel(tmp - y*stride - x,
163                                                                                    (uint8_t *) ref, tmp + 32,
164                                                                                    tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);
165    #else
166                                    interpolate8x8_quarterpel(tmp - y*stride - x,
167                                                                                    (uint8_t *) ref, tmp + 32,
168                                                                                    tmp + 64, tmp + 96, x, y, dx, dy, stride, rounding);
169    #endif
170                                    ptr = tmp;
171                            } else ptr = ref + (y + dy/4)*stride + x + dx/4; /* fullpixel position */
172                    } else ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);
173    
174                            transfer_8to16sub(dct_codes, cur + y * stride + x, ptr, stride);
175    
176            } else { /* reduced_resolution */
177    
178                    x *= 2; y *= 2;
179    
180                    ptr = get_ref(ref, refh, refv, refhv, x, y, 1, dx, dy, stride);
181    
182                    filter_18x18_to_8x8(dct_codes, cur+y*stride + x, stride);
183                    filter_diff_18x18_to_8x8(dct_codes, ptr, stride);
184    
185                    transfer16x16_copy(cur + y*stride + x, ptr, stride);
186            }
187    }
188    
189    /* XXX: slow, inelegant... */
190    static void
191    interpolate18x18_switch(uint8_t * const cur,
192                                                    const uint8_t * const refn,
193                                                    const uint32_t x,
194                                                    const uint32_t y,
195                                                    const int32_t dx,
196                                                    const int dy,
197                                                    const int32_t stride,
198                                                    const int32_t rounding)
199    {
200            interpolate8x8_switch(cur, refn, x-1, y-1, dx, dy, stride, rounding);
201            interpolate8x8_switch(cur, refn, x+7, y-1, dx, dy, stride, rounding);
202            interpolate8x8_switch(cur, refn, x+9, y-1, dx, dy, stride, rounding);
203    
204            interpolate8x8_switch(cur, refn, x-1, y+7, dx, dy, stride, rounding);
205            interpolate8x8_switch(cur, refn, x+7, y+7, dx, dy, stride, rounding);
206            interpolate8x8_switch(cur, refn, x+9, y+7, dx, dy, stride, rounding);
207    
208            interpolate8x8_switch(cur, refn, x-1, y+9, dx, dy, stride, rounding);
209            interpolate8x8_switch(cur, refn, x+7, y+9, dx, dy, stride, rounding);
210            interpolate8x8_switch(cur, refn, x+9, y+9, dx, dy, stride, rounding);
211    }
212    
213    static void
214    CompensateChroma(       int dx, int dy,
215                                            const int i, const int j,
216                                            IMAGE * const Cur,
217                                            const IMAGE * const Ref,
218                                            uint8_t * const temp,
219                                            int16_t * const coeff,
220                                            const int32_t stride,
221                                            const int rounding,
222                                            const int rrv)
223    { /* uv-block-based compensation */
224    
225            if (!rrv) {
226                    transfer_8to16sub(coeff, Cur->u + 8 * j * stride + 8 * i,
227                                                            interpolate8x8_switch2(temp, Ref->u, 8 * i, 8 * j,
228                                                                                                            dx, dy, stride, rounding),
229                                                            stride);
230                    transfer_8to16sub(coeff + 64, Cur->v + 8 * j * stride + 8 * i,
231                                                            interpolate8x8_switch2(temp, Ref->v, 8 * i, 8 * j,
232                                                                                                            dx, dy, stride, rounding),
233                                                            stride);
234            } else {
235                    uint8_t * current, * reference;
236    
237                    current = Cur->u + 16*j*stride + 16*i;
238                    reference = temp - 16*j*stride - 16*i;
239                    interpolate18x18_switch(reference, Ref->u, 16*i, 16*j, dx, dy, stride, rounding);
240                    filter_18x18_to_8x8(coeff, current, stride);
241                    filter_diff_18x18_to_8x8(coeff, temp, stride);
242                    transfer16x16_copy(current, temp, stride);
243    
244                    current = Cur->v + 16*j*stride + 16*i;
245                    interpolate18x18_switch(reference, Ref->v, 16*i, 16*j, dx, dy, stride, rounding);
246                    filter_18x18_to_8x8(coeff + 64, current, stride);
247                    filter_diff_18x18_to_8x8(coeff + 64, temp, stride);
248                    transfer16x16_copy(current, temp, stride);
249            }
250    }
251    
252  void  void
253  MBMotionCompensation(MACROBLOCK * const mb,  MBMotionCompensation(MACROBLOCK * const mb,
# Line 98  Line 257 
257                                           const IMAGE * const refh,                                           const IMAGE * const refh,
258                                           const IMAGE * const refv,                                           const IMAGE * const refv,
259                                           const IMAGE * const refhv,                                           const IMAGE * const refhv,
260                                            const IMAGE * const refGMC,
261                                           IMAGE * const cur,                                           IMAGE * const cur,
262                                           int16_t * dct_codes,                                           int16_t * dct_codes,
263                                           const uint32_t width,                                           const uint32_t width,
264                                           const uint32_t height,                                           const uint32_t height,
265                                           const uint32_t edged_width,                                           const uint32_t edged_width,
266                                           const uint32_t rounding)                                          const int32_t quarterpel,
267                                            const int reduced_resolution,
268                                            const int32_t rounding)
269  {  {
270          static const uint32_t roundtab[16] =          int32_t dx;
271                  { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };          int32_t dy;
272    
273            uint8_t * const tmp = refv->u;
274    
275          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {          if ( (!reduced_resolution) && (mb->mode == MODE_NOT_CODED) ) {  /* quick copy for early SKIP */
276                  int32_t dx = mb->mvs[0].x;  /* early SKIP is only activated in P-VOPs, not in S-VOPs, so mcsel can never be 1 */
                 int32_t dy = mb->mvs[0].y;  
277    
278                  compensate8x8_halfpel(&dct_codes[0 * 64], cur->y, ref->y, refh->y,                  transfer16x16_copy(cur->y + 16 * (i + j * edged_width),
279                                                            refv->y, refhv->y, 16 * i, 16 * j, dx, dy,                                                    ref->y + 16 * (i + j * edged_width),
                                                           edged_width);  
                 compensate8x8_halfpel(&dct_codes[1 * 64], cur->y, ref->y, refh->y,  
                                                           refv->y, refhv->y, 16 * i + 8, 16 * j, dx, dy,  
280                                                            edged_width);                                                            edged_width);
                 compensate8x8_halfpel(&dct_codes[2 * 64], cur->y, ref->y, refh->y,  
                                                           refv->y, refhv->y, 16 * i, 16 * j + 8, dx, dy,  
                                                           edged_width);  
                 compensate8x8_halfpel(&dct_codes[3 * 64], cur->y, ref->y, refh->y,  
                                                           refv->y, refhv->y, 16 * i + 8, 16 * j + 8, dx,  
                                                           dy, edged_width);  
   
                 dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2;  
                 dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2;  
   
                 /* uv-image-based compensation */  
   
                 interpolate8x8_switch(refv->u, ref->u, 8 * i, 8 * j, dx, dy,  
                                                           edged_width / 2, rounding);  
                 transfer_8to16sub(&dct_codes[4 * 64],  
                                                   cur->u + 8 * j * edged_width / 2 + 8 * i,  
                                                   refv->u + 8 * j * edged_width / 2 + 8 * i,  
                                                   edged_width / 2);  
281    
282                  interpolate8x8_switch(refv->v, ref->v, 8 * i, 8 * j, dx, dy,                  transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2),
283                                                            edged_width / 2, rounding);                                                          ref->u + 8 * (i + j * edged_width/2),
284                  transfer_8to16sub(&dct_codes[5 * 64],                                                          edged_width / 2);
285                                                    cur->v + 8 * j * edged_width / 2 + 8 * i,                  transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2),
286                                                    refv->v + 8 * j * edged_width / 2 + 8 * i,                                                          ref->v + 8 * (i + j * edged_width/2),
287                                                    edged_width / 2);                                                    edged_width / 2);
288                    return;
289            }
290    
291            if ((mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER
292                                    || mb->mode == MODE_INTER_Q)) {
293    
294            /* reduced resolution + GMC:  not possible */
295    
296                    if (mb->mcsel) {
297    
298                            /* call normal routine once, easier than "if (mcsel)"ing all the time */
299    
300                            transfer_8to16sub(&dct_codes[0*64], cur->y + 16*j*edged_width + 16*i,
301                                                                                            refGMC->y + 16*j*edged_width + 16*i, edged_width);
302                            transfer_8to16sub(&dct_codes[1*64], cur->y + 16*j*edged_width + 16*i+8,
303                                                                                            refGMC->y + 16*j*edged_width + 16*i+8, edged_width);
304                            transfer_8to16sub(&dct_codes[2*64], cur->y + (16*j+8)*edged_width + 16*i,
305                                                                                            refGMC->y + (16*j+8)*edged_width + 16*i, edged_width);
306                            transfer_8to16sub(&dct_codes[3*64], cur->y + (16*j+8)*edged_width + 16*i+8,
307                                                                                            refGMC->y + (16*j+8)*edged_width + 16*i+8, edged_width);
308    
309    /* lumi is needed earlier for mode decision, but chroma should be done block-based, but it isn't, yet. */
310    
311                            transfer_8to16sub(&dct_codes[4 * 64], cur->u + 8 *j*edged_width/2 + 8*i,
312                                                                    refGMC->u + 8 *j*edged_width/2 + 8*i, edged_width/2);
313    
314                            transfer_8to16sub(&dct_codes[5 * 64], cur->v + 8*j* edged_width/2 + 8*i,
315                                                                    refGMC->v + 8*j* edged_width/2 + 8*i, edged_width/2);
316    
317                            return;
318                    }
319    
320                    /* ordinary compensation */
321    
322                    dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x);
323                    dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y);
324    
325                    if (reduced_resolution) {
326                            dx = RRV_MV_SCALEUP(dx);
327                            dy = RRV_MV_SCALEUP(dy);
328                    }
329    
330                    compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y,
331                                                            refv->y, refhv->y, tmp, 16 * i, 16 * j, dx, dy,
332                                                            edged_width, quarterpel, reduced_resolution, rounding);
333    
334                    if (quarterpel) { dx /= 2; dy /= 2; }
335    
336                    dx = (dx >> 1) + roundtab_79[dx & 0x3];
337                    dy = (dy >> 1) + roundtab_79[dy & 0x3];
338    
339            } else {                                        /* mode == MODE_INTER4V */
340                    int k, sumx = 0, sumy = 0;
341                    const VECTOR * const mvs = (quarterpel ? mb->qmvs : mb->mvs);
342    
343                    for (k = 0; k < 4; k++) {
344                            dx = mvs[k].x;
345                            dy = mvs[k].y;
346                            sumx += quarterpel ? dx/2 : dx;
347                            sumy += quarterpel ? dy/2 : dy;
348    
349                            if (reduced_resolution){
350                                    dx = RRV_MV_SCALEUP(dx);
351                                    dy = RRV_MV_SCALEUP(dy);
352                            }
353    
354                            compensate8x8_interpolate(&dct_codes[k * 64], cur->y, ref->y, refh->y,
355                                                                            refv->y, refhv->y, tmp, 16 * i + 8*(k&1), 16 * j + 8*(k>>1), dx,
356                                                                            dy, edged_width, quarterpel, reduced_resolution, rounding);
357                    }
358                    dx = (sumx >> 3) + roundtab_76[sumx & 0xf];
359                    dy = (sumy >> 3) + roundtab_76[sumy & 0xf];
360            }
361    
362          } else                                          // mode == MODE_INTER4V          CompensateChroma(dx, dy, i, j, cur, ref, tmp,
363                                            &dct_codes[4 * 64], edged_width / 2, rounding, reduced_resolution);
364    }
365    
366    
367    void
368    MBMotionCompensationBVOP(MBParam * pParam,
369                                                    MACROBLOCK * const mb,
370                                                    const uint32_t i,
371                                                    const uint32_t j,
372                                                    IMAGE * const cur,
373                                                    const IMAGE * const f_ref,
374                                                    const IMAGE * const f_refh,
375                                                    const IMAGE * const f_refv,
376                                                    const IMAGE * const f_refhv,
377                                                    const IMAGE * const b_ref,
378                                                    const IMAGE * const b_refh,
379                                                    const IMAGE * const b_refv,
380                                                    const IMAGE * const b_refhv,
381                                                    int16_t * dct_codes)
382          {          {
383                  int32_t sum, dx, dy;          const uint32_t edged_width = pParam->edged_width;
384            int32_t dx, dy, b_dx, b_dy, sumx, sumy, b_sumx, b_sumy;
385            int k;
386            const int quarterpel = pParam->vol_flags & XVID_VOL_QUARTERPEL;
387            const uint8_t * ptr1, * ptr2;
388            uint8_t * const tmp = f_refv->u;
389            const VECTOR * const fmvs = (quarterpel ? mb->qmvs : mb->mvs);
390            const VECTOR * const bmvs = (quarterpel ? mb->b_qmvs : mb->b_mvs);
391    
392            switch (mb->mode) {
393            case MODE_FORWARD:
394                    dx = fmvs->x; dy = fmvs->y;
395    
396                    compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y,
397                                                            f_refv->y, f_refhv->y, tmp, 16 * i, 16 * j, dx,
398                                                            dy, edged_width, quarterpel, 0, 0);
399    
400                    if (quarterpel) { dx /= 2; dy /= 2; }
401    
402                    CompensateChroma(       (dx >> 1) + roundtab_79[dx & 0x3],
403                                                            (dy >> 1) + roundtab_79[dy & 0x3],
404                                                            i, j, cur, f_ref, tmp,
405                                                            &dct_codes[4 * 64], edged_width / 2, 0, 0);
406    
407                    return;
408    
409            case MODE_BACKWARD:
410                    b_dx = bmvs->x; b_dy = bmvs->y;
411    
412                    compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y,
413                                                                                    b_refv->y, b_refhv->y, tmp, 16 * i, 16 * j, b_dx,
414                                                                                    b_dy, edged_width, quarterpel, 0, 0);
415    
416                    if (quarterpel) { b_dx /= 2; b_dy /= 2; }
417    
418                    CompensateChroma(       (b_dx >> 1) + roundtab_79[b_dx & 0x3],
419                                                            (b_dy >> 1) + roundtab_79[b_dy & 0x3],
420                                                            i, j, cur, b_ref, tmp,
421                                                            &dct_codes[4 * 64], edged_width / 2, 0, 0);
422    
423                    return;
424    
425            case MODE_INTERPOLATE: /* _could_ use DIRECT, but would be overkill (no 4MV there) */
426            case MODE_DIRECT_NO4V:
427                    dx = fmvs->x; dy = fmvs->y;
428                    b_dx = bmvs->x; b_dy = bmvs->y;
429    
430                    if (quarterpel) {
431    
432                            if ((dx&3) | (dy&3)) {
433                                    interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width,
434                                            (uint8_t *) f_ref->y, tmp + 32,
435                                            tmp + 64, tmp + 96, 16*i, 16*j, dx, dy, edged_width, 0);
436                                    ptr1 = tmp;
437                            } else ptr1 = f_ref->y + (16*j + dy/4)*edged_width + 16*i + dx/4; /* fullpixel position */
438    
439                            if ((b_dx&3) | (b_dy&3)) {
440                                    interpolate16x16_quarterpel(tmp - i * 16 - j * 16 * edged_width + 16,
441                                            (uint8_t *) b_ref->y, tmp + 32,
442                                            tmp + 64, tmp + 96, 16*i, 16*j, b_dx, b_dy, edged_width, 0);
443                                    ptr2 = tmp + 16;
444                            } else ptr2 = b_ref->y + (16*j + b_dy/4)*edged_width + 16*i + b_dx/4; /* fullpixel position */
445    
446                            b_dx /= 2;
447                            b_dy /= 2;
448                            dx /= 2;
449                            dy /= 2;
450    
451                    } else {
452                            ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
453                                                            i, j, 16, dx, dy, edged_width);
454    
455                            ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
456                                                            i, j, 16, b_dx, b_dy, edged_width);
457                    }
458                    for (k = 0; k < 4; k++)
459                                    transfer_8to16sub2(&dct_codes[k * 64],
460                                                                            cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
461                                                                            ptr1 + (k&1)*8 + (k>>1)*8*edged_width,
462                                                                            ptr2 + (k&1)*8 + (k>>1)*8*edged_width, edged_width);
463    
464    
465                    dx = (dx >> 1) + roundtab_79[dx & 0x3];
466                    dy = (dy >> 1) + roundtab_79[dy & 0x3];
467    
468                    b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3];
469                    b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3];
470    
471                    break;
472    
473            default: /* MODE_DIRECT (or MODE_DIRECT_NONE_MV in case of bframes decoding) */
474                    sumx = sumy = b_sumx = b_sumy = 0;
475    
476                    for (k = 0; k < 4; k++) {
477    
478                            dx = fmvs[k].x; dy = fmvs[k].y;
479                            b_dx = bmvs[k].x; b_dy = bmvs[k].y;
480    
481                  compensate8x8_halfpel(&dct_codes[0 * 64], cur->y, ref->y, refh->y,                          if (quarterpel) {
482                                                            refv->y, refhv->y, 16 * i, 16 * j, mb->mvs[0].x,                                  sumx += dx/2; sumy += dy/2;
483                                                            mb->mvs[0].y, edged_width);                                  b_sumx += b_dx/2; b_sumy += b_dy/2;
484                  compensate8x8_halfpel(&dct_codes[1 * 64], cur->y, ref->y, refh->y,  
485                                                            refv->y, refhv->y, 16 * i + 8, 16 * j,                                  if ((dx&3) | (dy&3)) {
486                                                            mb->mvs[1].x, mb->mvs[1].y, edged_width);                                          interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width,
487                  compensate8x8_halfpel(&dct_codes[2 * 64], cur->y, ref->y, refh->y,                                                  (uint8_t *) f_ref->y,
488                                                            refv->y, refhv->y, 16 * i, 16 * j + 8,                                                  tmp + 32, tmp + 64, tmp + 96,
489                                                            mb->mvs[2].x, mb->mvs[2].y, edged_width);                                                  16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0);
490                  compensate8x8_halfpel(&dct_codes[3 * 64], cur->y, ref->y, refh->y,                                          ptr1 = tmp;
491                                                            refv->y, refhv->y, 16 * i + 8, 16 * j + 8,                                  } else ptr1 = f_ref->y + (16*j + (k>>1)*8 + dy/4)*edged_width + 16*i + (k&1)*8 + dx/4;
492                                                            mb->mvs[3].x, mb->mvs[3].y, edged_width);  
493                                    if ((b_dx&3) | (b_dy&3)) {
494                  sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x;                                          interpolate8x8_quarterpel(tmp - (i * 16+(k&1)*8) - (j * 16+((k>>1)*8)) * edged_width + 16,
495                  dx = (sum ? SIGN(sum) *                                                  (uint8_t *) b_ref->y,
496                            (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);                                                  tmp + 16, tmp + 32, tmp + 48,
497                                                    16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0);
498                  sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;                                          ptr2 = tmp + 16;
499                  dy = (sum ? SIGN(sum) *                                  } else ptr2 = b_ref->y + (16*j + (k>>1)*8 + b_dy/4)*edged_width + 16*i + (k&1)*8 + b_dx/4;
500                            (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);                          } else {
501                                    sumx += dx; sumy += dy;
502                  /* uv-block-based compensation */                                  b_sumx += b_dx; b_sumy += b_dy;
503                  interpolate8x8_switch(refv->u, ref->u, 8 * i, 8 * j, dx, dy,  
504                                                            edged_width / 2, rounding);                                  ptr1 = get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
505                  transfer_8to16sub(&dct_codes[4 * 64],                                                                  2*i + (k&1), 2*j + (k>>1), 8, dx, dy, edged_width);
506                                                    cur->u + 8 * j * edged_width / 2 + 8 * i,                                  ptr2 = get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
507                                                    refv->u + 8 * j * edged_width / 2 + 8 * i,                                                                  2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy,  edged_width);
508                            }
509                            transfer_8to16sub2(&dct_codes[k * 64],
510                                                                    cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
511                                                                    ptr1, ptr2,     edged_width);
512    
513                    }
514    
515                    dx = (sumx >> 3) + roundtab_76[sumx & 0xf];
516                    dy = (sumy >> 3) + roundtab_76[sumy & 0xf];
517                    b_dx = (b_sumx >> 3) + roundtab_76[b_sumx & 0xf];
518                    b_dy = (b_sumy >> 3) + roundtab_76[b_sumy & 0xf];
519    
520                    break;
521            }
522    
523            /* v block-based chroma interpolation for direct and interpolate modes */
524            transfer_8to16sub2(&dct_codes[4 * 64],
525                                                    cur->u + (j * 8) * edged_width / 2 + (i * 8),
526                                                    interpolate8x8_switch2(tmp, b_ref->u, 8 * i, 8 * j,
527                                                                                                    b_dx, b_dy, edged_width / 2, 0),
528                                                    interpolate8x8_switch2(tmp + 8, f_ref->u, 8 * i, 8 * j,
529                                                                                                    dx, dy, edged_width / 2, 0),
530                                                    edged_width / 2);                                                    edged_width / 2);
531    
532                  interpolate8x8_switch(refv->v, ref->v, 8 * i, 8 * j, dx, dy,          transfer_8to16sub2(&dct_codes[5 * 64],
533                                                            edged_width / 2, rounding);                                                  cur->v + (j * 8) * edged_width / 2 + (i * 8),
534                  transfer_8to16sub(&dct_codes[5 * 64],                                                  interpolate8x8_switch2(tmp, b_ref->v, 8 * i, 8 * j,
535                                                    cur->v + 8 * j * edged_width / 2 + 8 * i,                                                                                                  b_dx, b_dy, edged_width / 2, 0),
536                                                    refv->v + 8 * j * edged_width / 2 + 8 * i,                                                  interpolate8x8_switch2(tmp + 8, f_ref->v, 8 * i, 8 * j,
537                                                                                                    dx, dy, edged_width / 2, 0),
538                                                    edged_width / 2);                                                    edged_width / 2);
539          }          }
 }  

Legend:
Removed from v.437  
changed lines
  Added in v.1125

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