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

Legend:
Removed from v.229  
changed lines
  Added in v.1077

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