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

Diff of /branches/dev-api-3/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 78, Thu Mar 28 20:57:25 2002 UTC branches/dev-api-3/xvidcore/src/motion/motion_comp.c revision 701, Mon Dec 9 10:47:05 2002 UTC
# Line 1  Line 1 
1    // 30.10.2002   corrected qpel chroma rounding
2    // 04.10.2002   added qpel support to MBMotionCompensation
3    // 01.05.2002   updated MBMotionCompensationBVOP
4    // 14.04.2002   bframe compensation
5    
6  #include "../encoder.h"  #include "../encoder.h"
7  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
8  #include "../image/interpolate8x8.h"  #include "../image/interpolate8x8.h"
9    #include "../image/reduced.h"
10  #include "../utils/timer.h"  #include "../utils/timer.h"
11    #include "motion.h"
12    
13  #define ABS(X) (((X)>0)?(X):-(X))  #define ABS(X) (((X)>0)?(X):-(X))
14  #define SIGN(X) (((X)>0)?1:-1)  #define SIGN(X) (((X)>0)?1:-1)
15    
16  static __inline void compensate8x8_halfpel(  
17                                  int16_t * const dct_codes,  // decode an inter macroblock
18    
19    static void
20    rrv_mv_scaleup(VECTOR * mv)
21    {
22            if (mv->x > 0) {
23                    mv->x = 2*mv->x - 1;
24            } else if (mv->x < 0) {
25                    mv->x = 2*mv->x + 1;
26            }
27    
28            if (mv->y > 0) {
29                    mv->y = 2*mv->y - 1;
30            } else if (mv->y < 0) {
31                    mv->y = 2*mv->y + 1;
32            }
33    }
34    
35    
36    static __inline void
37    compensate16x16_interpolate(int16_t * const dct_codes,
38                                  uint8_t * const cur,                                  uint8_t * const cur,
39                                  const uint8_t * const ref,                                  const uint8_t * const ref,
40                                  const uint8_t * const refh,                                  const uint8_t * const refh,
41                                  const uint8_t * const refv,                                                      uint8_t * const refv,
42                                  const uint8_t * const refhv,                                  const uint8_t * const refhv,
43                                  const uint32_t x, const uint32_t y,                                                      uint32_t x,
44                                  const int32_t dx,  const int dy,                                                      uint32_t y,
45                                  const uint32_t stride)                                                      const int32_t dx,
46                                                        const int32_t dy,
47                                                        const uint32_t stride,
48                                                        const uint32_t quarterpel,
49                                                            const int reduced_resolution,
50                                                            const uint32_t rounding)
51  {  {
         int32_t ddx,ddy;  
52    
53          switch ( ((dx&1)<<1) + (dy&1) )   // ((dx%2)?2:0)+((dy%2)?1:0)          if (reduced_resolution)
54      {      {
     case 0 :  
                 ddx = dx/2;  
                 ddy = dy/2;  
                 transfer_8to16sub(dct_codes, cur + y*stride + x,  
                                 ref + (y+ddy)*stride + x+ddx, stride);  
                 break;  
55    
56      case 1 :                  /* XXX: todo */
57                  ddx = dx/2;  
58                  ddy = (dy-1)/2;                  VECTOR mv;
59                  transfer_8to16sub(dct_codes, cur + y*stride + x,                  int i,j;
60                                  refv + (y+ddy)*stride + x+ddx, stride);                  uint8_t tmp[18*18];
61                  break;  
62                    x*=2;
63                    y*=2;
64    
65                    mv.x = dx;
66                    mv.y = dy;
67                    rrv_mv_scaleup(&mv);
68    
69                    interpolate32x32_switch(
70                            refv, ref, x, y, mv.x, mv.y, stride, rounding);
71    
72                    for (j = 0; j < 32; j++)
73                    for (i = 0; i < 32; i++)
74                            cur[(y+j)*stride + x + i] -= refv[(y+j)*stride + x + i];
75    
76                    filter_18x18_to_8x8(dct_codes,     cur + y*stride + x, stride);
77                    filter_18x18_to_8x8(dct_codes+64,  cur + y*stride + x + 16, stride);
78                    filter_18x18_to_8x8(dct_codes+128, cur + (y+16)*stride + x, stride);
79                    filter_18x18_to_8x8(dct_codes+192, cur + (y+16)*stride + x + 16, stride);
80    
81                    /*
82                    for (j = 0; j < 16; j++)
83                    for (i = 0; i < 16; i++)
84                            tmp[(j+1)*18 + i+1] = refv[ (y+j)*stride + x+i];
85    
86                    for (i = 1; i < 17; i++)
87                    {
88                            tmp[ 0*18 + i] = tmp[ 1*18 + i];
89                            tmp[17*18 + i] = tmp[16*18 + i];
90                    }
91    
92                    for (i = 0; i < 18; i++)
93                    {
94                            tmp[ i*18 + 0] = tmp[i*18 + 1];
95                            tmp[ i*18 + 17] = tmp[i*18 + 16];
96                    }
97                    filter_18x18_to_8x8(dct_codes, tmp, 18);
98    
99    
100                    for (j = 0; j < 16; j++)
101                    for (i = 0; i < 16; i++)
102                            tmp[(j+1)*18 + i+1] = refv[ (y+j)*stride + x+i + 16];
103    
104                    for (i = 1; i < 17; i++)
105                    {
106                            tmp[ 0*18 + i] = tmp[ 1*18 + i];
107                            tmp[17*18 + i] = tmp[16*18 + i];
108                    }
109    
110                    for (i = 0; i < 18; i++)
111                    {
112                            tmp[ i*18 + 0] = tmp[i*18 + 1];
113                            tmp[ i*18 + 17] = tmp[i*18 + 16];
114                    }
115                    filter_18x18_to_8x8(dct_codes+64, tmp, 18);
116    
117                    for (j = 0; j < 16; j++)
118                    for (i = 0; i < 16; i++)
119                            tmp[(j+1)*18 + i+1] = refv[ (y+16+j)*stride + x+i];
120    
121                    for (i = 1; i < 17; i++)
122                    {
123                            tmp[ 0*18 + i] = tmp[ 1*18 + i];
124                            tmp[17*18 + i] = tmp[16*18 + i];
125                    }
126    
127                    for (i = 0; i < 18; i++)
128                    {
129                            tmp[ i*18 + 0] = tmp[i*18 + 1];
130                            tmp[ i*18 + 17] = tmp[i*18 + 16];
131                    }
132                    filter_18x18_to_8x8(dct_codes+128, tmp, 18);
133    
134                    for (j = 0; j < 16; j++)
135                    for (i = 0; i < 16; i++)
136                            tmp[(j+1)*18 + i+1] = refv[ (y+16+j)*stride + x+i + 16];
137    
138                    for (i = 1; i < 17; i++)
139                    {
140                            tmp[ 0*18 + i] = tmp[ 1*18 + i];
141                            tmp[17*18 + i] = tmp[16*18 + i];
142                    }
143    
144                    for (i = 0; i < 18; i++)
145                    {
146                            tmp[ i*18 + 0] = tmp[i*18 + 1];
147                            tmp[ i*18 + 17] = tmp[i*18 + 16];
148                    }
149                    filter_18x18_to_8x8(dct_codes+192, tmp, 18);
150                    */
151    
152    
153                    //memset(dct_codes, 0, sizeof(uint16_t) * 64 * 4);
154    
155            }else{
156                    if(quarterpel) {
157                            interpolate16x16_quarterpel((uint8_t *) refv, (uint8_t *) ref, (uint8_t *) refh,
158                                    (uint8_t *) refh + 64, (uint8_t *) refhv, x, y, dx, dy, stride, rounding);
159    
     case 2 :  
                 ddx = (dx-1)/2;  
                 ddy = dy/2;  
160                  transfer_8to16sub(dct_codes, cur + y*stride + x,                  transfer_8to16sub(dct_codes, cur + y*stride + x,
161                                  refh + (y+ddy)*stride + x+ddx, stride);                                                            refv + y*stride + x, stride);
162                  break;                          transfer_8to16sub(dct_codes+64, cur + y*stride + x + 8,
163                                                              refv + y*stride + x + 8, stride);
164                            transfer_8to16sub(dct_codes+128, cur + y*stride + x + 8*stride,
165                                                              refv + y*stride + x + 8*stride, stride);
166                            transfer_8to16sub(dct_codes+192, cur + y*stride + x + 8*stride + 8,
167                                                              refv + y*stride + x + 8*stride+8, stride);
168    
169                    }
170                    else
171                    {
172                            const uint8_t * reference;
173    
174                            switch (((dx & 1) << 1) + (dy & 1))     // ((dx%2)?2:0)+((dy%2)?1:0)
175                            {
176                            case 0: reference = ref + ((y + dy / 2) * stride + x + dx / 2); break;
177                            case 1: reference = refv + ((y + (dy-1) / 2) * stride + x + dx / 2); break;
178                            case 2: reference = refh + ((y + dy / 2) * stride + x + (dx-1) / 2); break;
179          default :       // case 3:          default :       // case 3:
180                  ddx = (dx-1)/2;                                  reference = refhv + ((y + (dy-1) / 2) * stride + x + (dx-1) / 2); break;
181                  ddy = (dy-1)/2;                          }
182                  transfer_8to16sub(dct_codes, cur + y*stride + x,                  transfer_8to16sub(dct_codes, cur + y*stride + x,
183                                  refhv + (y+ddy)*stride + x+ddx, stride);                                                                    reference, stride);
184                  break;                          transfer_8to16sub(dct_codes+64, cur + y * stride + x + 8,
185                                                                      reference + 8, stride);
186                            transfer_8to16sub(dct_codes+128, cur + y * stride + x + 8*stride,
187                                                                      reference + 8*stride, stride);
188                            transfer_8to16sub(dct_codes+192, cur + y * stride + x + 8*stride+8,
189                                                                      reference + 8*stride + 8, stride);
190                    }
191      }      }
192  }  }
193    
194    static __inline void
195    compensate8x8_interpolate(int16_t * const dct_codes,
196                                                      uint8_t * const cur,
197                                                      const uint8_t * const ref,
198                                                      const uint8_t * const refh,
199                                                      const uint8_t * const refv,
200                                                      const uint8_t * const refhv,
201                                                      const uint32_t x,
202                                                      const uint32_t y,
203                                                      const int32_t dx,
204                                                      const int32_t dy,
205                                                      const uint32_t stride,
206                                                      const uint32_t quarterpel,
207                                                      const int reduced_resolution,
208                                                      const uint32_t rounding)
209    {
210            if (reduced_resolution)
211            {
212                    // XXX: todo
213            } else {
214    
215                    if(quarterpel) {
216                            interpolate8x8_quarterpel((uint8_t *) refv, (uint8_t *) ref, (uint8_t *) refh,
217                                    (uint8_t *) refh + 64, (uint8_t *) refhv, x, y, dx, dy, stride, rounding);
218    
219  void MBMotionCompensation(                          transfer_8to16sub(dct_codes, cur + y*stride + x,
220          MACROBLOCK * const mb,                                                            refv + y*stride + x, stride);
221                    }
222                    else
223                    {
224                            const uint8_t * reference;
225    
226                            switch (((dx & 1) << 1) + (dy & 1))     // ((dx%2)?2:0)+((dy%2)?1:0)
227                            {
228                            case 0: reference = ref + ((y + dy / 2) * stride + x + dx / 2); break;
229                            case 1: reference = refv + ((y + (dy-1) / 2) * stride + x + dx / 2); break;
230                            case 2: reference = refh + ((y + dy / 2) * stride + x + (dx-1) / 2); break;
231                            default:                                        // case 3:
232                                    reference = refhv + ((y + (dy-1) / 2) * stride + x + (dx-1) / 2); break;
233                            }
234                            transfer_8to16sub(dct_codes, cur + y * stride + x,
235                                                                      reference, stride);
236                    }
237            }
238    }
239    
240    void
241    MBMotionCompensation(MACROBLOCK * const mb,
242          const uint32_t i,          const uint32_t i,
243          const uint32_t j,          const uint32_t j,
244          const IMAGE * const ref,          const IMAGE * const ref,
# Line 66  Line 250 
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 quarterpel,
254                                             const int reduced_resolution,
255          const uint32_t rounding)          const uint32_t rounding)
256  {  {
         static const uint32_t roundtab[16] =  
                 { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };  
257    
258            if (mb->mode == MODE_NOT_CODED || mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) {
259    
260                    int32_t dx = (quarterpel ? mb->qmvs[0].x : mb->mvs[0].x);
261                    int32_t dy = (quarterpel ? mb->qmvs[0].y : mb->mvs[0].y);
262    
263                    if ( (mb->mode == MODE_NOT_CODED) && (dx==0) && (dy==0) ) {     /* quick copy */
264                            transfer16x16_copy(cur->y + 16 * (i + j * edged_width),
265                                                               ref->y + 16 * (i + j * edged_width),
266                                                               edged_width);
267    
268                            transfer8x8_copy(cur->u + 8 * (i + j * edged_width/2),
269                                                                    ref->u + 8 * (i + j * edged_width/2),
270                                                                    edged_width / 2);
271                            transfer8x8_copy(cur->v + 8 * (i + j * edged_width/2),
272                                                                    ref->v + 8 * (i + j * edged_width/2),
273                                                                    edged_width / 2);
274                            return;
275                    }
276            /* quick MODE_NOT_CODED for GMC with MV!=(0,0) is still needed */
277    
278                    compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y,
279                                                      refv->y, refhv->y, 16 * i, 16 * j, dx, dy,
280                                                      edged_width, quarterpel, reduced_resolution, rounding);
281    
282          if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)                  if (quarterpel)
283          {          {
284                  int32_t dx = mb->mvs[0].x;                          dx /= 2;
285                  int32_t dy = mb->mvs[0].y;                          dy /= 2;
286                    }
287    
288                  compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y,                  dx = (dx >> 1) + roundtab_79[dx & 0x3];
289                                        16*i,     16*j,     dx, dy, edged_width);                  dy = (dy >> 1) + roundtab_79[dy & 0x3];
                 compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y,  
                                       16*i + 8, 16*j,     dx, dy, 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  
                    compensate8x8_halfpel(dct_codes[4], cur->u, ref->u, refh->u, refv->u, refhv->u,  
                    8*i, 8*j, dx, dy, edged_width/2);  
                    compensate8x8_halfpel(dct_codes[5], cur->v, ref->v, refh->v, refv->v, refhv->v,  
                    8*i, 8*j, dx, dy, edged_width/2);            */  
290    
291                  /* uv-block-based compensation */                  /* uv-block-based compensation */
292                  interpolate8x8_switch(refv->u, ref->u, 8*i, 8*j, dx, dy, edged_width/2, rounding);                  if (reduced_resolution)
293                    {
294                            // XXX: todo
295                    }else{
296                  transfer_8to16sub(&dct_codes[4*64],                  transfer_8to16sub(&dct_codes[4*64],
297                                    cur->u + 8*j*edged_width/2 + 8*i,                                    cur->u + 8*j*edged_width/2 + 8*i,
298                                    refv->u + 8*j*edged_width/2 + 8*i, edged_width/2);                                                                  interpolate8x8_switch2(refv->u, ref->u, 8 * i, 8 * j,
299                                                                                                                    dx, dy, edged_width / 2, rounding),
300                                                                    edged_width / 2);
301    
                 interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding);  
302                  transfer_8to16sub(&dct_codes[5*64],                  transfer_8to16sub(&dct_codes[5*64],
303                                    cur->v + 8*j*edged_width/2 + 8*i,                                    cur->v + 8*j*edged_width/2 + 8*i,
304                                    refv->v + 8*j*edged_width/2 + 8*i, edged_width/2);                                                                  interpolate8x8_switch2(refv->u, ref->v, 8 * i, 8 * j,
305                                                                                                                    dx, dy, edged_width / 2, rounding),
306                                                                    edged_width / 2);
307                    }
308    
309            } else {                                        // mode == MODE_INTER4V
310                    int32_t sum, dx, dy;
311                    VECTOR *mvs;
312    
313                    if(quarterpel)
314                            mvs = mb->qmvs;
315                    else
316                            mvs = mb->mvs;
317    
318                    if (reduced_resolution)
319                    {
320                            ///XXX: todo
321                    }else{
322    
323                            compensate8x8_interpolate(&dct_codes[0 * 64], cur->y, ref->y, refh->y,
324                                                              refv->y, refhv->y, 16 * i, 16 * j, mvs[0].x,
325                                                              mvs[0].y, edged_width, quarterpel, reduced_resolution, rounding);
326                            compensate8x8_interpolate(&dct_codes[1 * 64], cur->y, ref->y, refh->y,
327                                                                      refv->y, refhv->y, 16 * i + 8, 16 * j,
328                                                                      mvs[1].x, mvs[1].y, edged_width, quarterpel, reduced_resolution, rounding);
329                            compensate8x8_interpolate(&dct_codes[2 * 64], cur->y, ref->y, refh->y,
330                                                                      refv->y, refhv->y, 16 * i, 16 * j + 8,
331                                                                      mvs[2].x, mvs[2].y, edged_width, quarterpel, reduced_resolution, rounding);
332                            compensate8x8_interpolate(&dct_codes[3 * 64], cur->y, ref->y, refh->y,
333                                                                      refv->y, refhv->y, 16 * i + 8, 16 * j + 8,
334                                                                      mvs[3].x, mvs[3].y, edged_width, quarterpel, reduced_resolution, rounding);
335          }          }
336          else    // mode == MODE_INTER4V  
337                    if(quarterpel)
338                            sum = (mvs[0].x / 2) + (mvs[1].x / 2) + (mvs[2].x / 2) + (mvs[3].x / 2);
339                    else
340                            sum = mvs[0].x + mvs[1].x + mvs[2].x + mvs[3].x;
341    
342                    dx = (sum >> 3) + roundtab_76[sum & 0xf];
343    
344                    if(quarterpel)
345                            sum = (mvs[0].y / 2) + (mvs[1].y / 2) + (mvs[2].y / 2) + (mvs[3].y / 2);
346                    else
347                            sum = mvs[0].y + mvs[1].y + mvs[2].y + mvs[3].y;
348    
349                    dy = (sum >> 3) + roundtab_76[sum & 0xf];
350    
351                    /* uv-block-based compensation */
352                    if (reduced_resolution)
353          {          {
354                  int32_t sum, dx, dy;                          //XXX: todo
355                    }else{
356                            transfer_8to16sub(&dct_codes[4 * 64],
357                                                                    cur->u + 8 * j * edged_width / 2 + 8 * i,
358                                                                    interpolate8x8_switch2(refv->u, ref->u, 8 * i, 8 * j,
359                                                                                                                    dx, dy, edged_width / 2, rounding),
360                                                                    edged_width / 2);
361    
362                  compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y,                          transfer_8to16sub(&dct_codes[5 * 64],
363                                        16*i,     16*j,     mb->mvs[0].x, mb->mvs[0].y, edged_width);                                                                  cur->v + 8 * j * edged_width / 2 + 8 * i,
364                  compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y,                                                                  interpolate8x8_switch2(refv->u, ref->v, 8 * i, 8 * j,
365                                        16*i + 8, 16*j,     mb->mvs[1].x, mb->mvs[1].y, edged_width);                                                                                                                  dx, dy, edged_width / 2, rounding),
366                  compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y,                                                                  edged_width / 2);
367                                        16*i,     16*j + 8, mb->mvs[2].x, mb->mvs[2].y, edged_width);                  }
368                  compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y,          }
369                                        16*i + 8, 16*j + 8, mb->mvs[3].x, mb->mvs[3].y, edged_width);  }
370    
                 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);  
371    
372                  sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;  void
373                  dy = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);  MBMotionCompensationBVOP(MBParam * pParam,
374                                                     MACROBLOCK * const mb,
375                                                     const uint32_t i,
376                                                     const uint32_t j,
377                                                     IMAGE * const cur,
378                                                     const IMAGE * const f_ref,
379                                                     const IMAGE * const f_refh,
380                                                     const IMAGE * const f_refv,
381                                                     const IMAGE * const f_refhv,
382                                                     const IMAGE * const b_ref,
383                                                     const IMAGE * const b_refh,
384                                                     const IMAGE * const b_refv,
385                                                     const IMAGE * const b_refhv,
386                                                     int16_t * dct_codes)
387    {
388            static const uint32_t roundtab[16] =
389                    { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
390    
391            const int32_t edged_width = pParam->edged_width;
392            int32_t dx, dy;
393            int32_t b_dx, b_dy;
394            int k,sum;
395            int x = i;
396            int y = j;
397            uint32_t quarterpel = pParam->m_quarterpel;
398    
399            switch (mb->mode) {
400            case MODE_FORWARD:
401    
402                    if (quarterpel) {
403                            dx = mb->qmvs[0].x;
404                            dy = mb->qmvs[0].y;
405                    } else {
406                            dx = mb->mvs[0].x;
407                            dy = mb->mvs[0].y;
408                    }
409    
410                    compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, f_ref->y, f_refh->y,
411                                                      f_refv->y, f_refhv->y, 16 * i, 16 * j, dx,
412                                                      dy, edged_width, quarterpel, 0 /*reduced_resolution*/, 0);
413    
414                    if (quarterpel) {
415                            dx /= 2;
416                            dy /= 2;
417                    }
418    
419                  /* uv-image-based compensation                  dx = (dx >> 1) + roundtab_79[dx & 0x3];
420                     compensate8x8_halfpel(dct_codes[4], cur->u, ref->u, refh->u, refv->u, refhv->u,                  dy = (dy >> 1) + roundtab_79[dy & 0x3];
                    8*i, 8*j, dx, dy, edged_width/2);  
                    compensate8x8_halfpel(dct_codes[5], cur->v, ref->v, refh->v, refv->v, refhv->v,  
                    8*i, 8*j, dx, dy, edged_width/2);            */  
421    
422                  /* uv-block-based compensation */                  /* uv-block-based compensation */
                 interpolate8x8_switch(refv->u, ref->u, 8*i, 8*j, dx, dy, edged_width/2, rounding);  
423                  transfer_8to16sub(&dct_codes[4*64],                  transfer_8to16sub(&dct_codes[4*64],
424                                    cur->u + 8*j*edged_width/2 + 8*i,                                    cur->u + 8*j*edged_width/2 + 8*i,
425                                    refv->u + 8*j*edged_width/2 + 8*i, edged_width/2);                                                          interpolate8x8_switch2(f_refv->u, f_ref->u, 8 * i, 8 * j,
426                                                                                                            dx, dy, edged_width / 2, 0),
427    
428                                                      edged_width / 2);
429    
                 interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding);  
430                  transfer_8to16sub(&dct_codes[5*64],                  transfer_8to16sub(&dct_codes[5*64],
431                                    cur->v + 8*j*edged_width/2 + 8*i,                                    cur->v + 8*j*edged_width/2 + 8*i,
432                                    refv->v + 8*j*edged_width/2 + 8*i, edged_width/2);                                                          interpolate8x8_switch2(f_refv->u, f_ref->v, 8 * i, 8 * j,
433                                                                                                            dx, dy, edged_width / 2, 0),
434    
435                                                      edged_width / 2);
436    
437                    break;
438    
439            case MODE_BACKWARD:
440                    if (quarterpel) {
441                            b_dx = mb->b_qmvs[0].x;
442                            b_dy = mb->b_qmvs[0].y;
443                    } else {
444                            b_dx = mb->b_mvs[0].x;
445                            b_dy = mb->b_mvs[0].y;
446                    }
447    
448                    compensate16x16_interpolate(&dct_codes[0 * 64], cur->y, b_ref->y, b_refh->y,
449                                                      b_refv->y, b_refhv->y, 16 * i, 16 * j, b_dx,
450                                                      b_dy, edged_width, quarterpel, 0 /*reduced_resolution*/, 0);
451    
452                    if (quarterpel) {
453                            b_dx /= 2;
454                            b_dy /= 2;
455                    }
456    
457                    b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3];
458                    b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3];
459    
460    
461                    /* uv-block-based compensation */
462                    transfer_8to16sub(&dct_codes[4 * 64],
463                                                            cur->u + 8 * j * edged_width / 2 + 8 * i,
464                                                            interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j,
465                                                                                                            b_dx, b_dy, edged_width / 2, 0),
466    
467                                                            edged_width / 2);
468    
469                    transfer_8to16sub(&dct_codes[5 * 64],
470                                                            cur->v + 8 * j * edged_width / 2 + 8 * i,
471                                                            interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j,
472                                                                                                            b_dx, b_dy, edged_width / 2, 0),
473    
474                                                            edged_width / 2);
475    
476                    break;
477    
478            case MODE_INTERPOLATE:          /* _could_ use DIRECT, but would be overkill (no 4MV there) */
479            case MODE_DIRECT_NO4V:
480    
481                    if (quarterpel) {
482                            dx = mb->qmvs[0].x;
483                            dy = mb->qmvs[0].y;
484                            b_dx = mb->b_qmvs[0].x;
485                            b_dy = mb->b_qmvs[0].y;
486    
487                            interpolate16x16_quarterpel((uint8_t *) f_refv->y, (uint8_t *) f_ref->y, (uint8_t *) f_refh->y,
488                                    (uint8_t *) f_refh->y + 64, (uint8_t *) f_refhv->y, 16*i, 16*j, dx, dy, edged_width, 0);
489                            interpolate16x16_quarterpel((uint8_t *) b_refv->y, (uint8_t *) b_ref->y, (uint8_t *) b_refh->y,
490                                    (uint8_t *) b_refh->y + 64, (uint8_t *) b_refhv->y, 16*i, 16*j, b_dx, b_dy, edged_width, 0);
491    
492                            for (k = 0; k < 4; k++) {
493                                    transfer_8to16sub2(&dct_codes[k * 64],
494                                                                    cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
495                                                                    f_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
496                                                                    b_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
497                                                                    edged_width);
498                            }
499                            b_dx /= 2;
500                            b_dy /= 2;
501                            dx /= 2;
502                            dy /= 2;
503    
504                    } else {
505                            dx = mb->mvs[0].x;
506                            dy = mb->mvs[0].y;
507                            b_dx = mb->b_mvs[0].x;
508                            b_dy = mb->b_mvs[0].y;
509    
510                            for (k = 0; k < 4; k++) {
511                                    transfer_8to16sub2(&dct_codes[k * 64],
512                                                                    cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
513                                                                    get_ref(f_ref->y, f_refh->y, f_refv->y,
514                                                                                    f_refhv->y, 2*i + (k&1), 2*j + (k>>1), 8, dx, dy,
515                                                                                    edged_width),
516                                                                    get_ref(b_ref->y, b_refh->y, b_refv->y,
517                                                                                    b_refhv->y, 2*i + (k&1), 2 * j+(k>>1), 8, b_dx, b_dy,
518                                                                                    edged_width),
519                                                                    edged_width);
520                            }
521    
522                    }
523    
524    
525                    dx = (dx >> 1) + roundtab_79[dx & 0x3];
526                    dy = (dy >> 1) + roundtab_79[dy & 0x3];
527    
528                    b_dx = (b_dx >> 1) + roundtab_79[b_dx & 0x3];
529                    b_dy = (b_dy >> 1) + roundtab_79[b_dy & 0x3];
530    
531                    transfer_8to16sub2(&dct_codes[4 * 64],
532                                                            cur->u + (y * 8) * edged_width / 2 + (x * 8),
533                                                            interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j,
534                                                                                                            b_dx, b_dy, edged_width / 2, 0),
535                                                            interpolate8x8_switch2(f_refv->u + 8, f_ref->u, 8 * i, 8 * j,
536                                                                                                            dx, dy, edged_width / 2, 0),
537                                                            edged_width / 2);
538    
539                    transfer_8to16sub2(&dct_codes[5 * 64],
540                                                            cur->v + (y * 8) * edged_width / 2 + (x * 8),
541                                                            interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j,
542                                                                                                            b_dx, b_dy, edged_width / 2, 0),
543                                                            interpolate8x8_switch2(f_refv->u + 8, f_ref->v, 8 * i, 8 * j,
544                                                                                                            dx, dy, edged_width / 2, 0),
545                                                            edged_width / 2);
546    
547                    break;
548    
549            case MODE_DIRECT:
550                    if (quarterpel) {
551                            for (k=0;k<4;k++) {
552    
553                                    dx = mb->qmvs[k].x;
554                                    dy = mb->qmvs[k].y;
555                                    b_dx = mb->b_qmvs[k].x;
556                                    b_dy = mb->b_qmvs[k].y;
557    
558                                    interpolate8x8_quarterpel((uint8_t *) f_refv->y,
559                                            (uint8_t *) f_ref->y,
560                                            (uint8_t *) f_refh->y,
561                                            (uint8_t *) f_refh->y + 64,
562                                            (uint8_t *) f_refhv->y,
563                                            16*i + (k&1)*8, 16*j + (k>>1)*8, dx, dy, edged_width, 0);
564                                    interpolate8x8_quarterpel((uint8_t *) b_refv->y,
565                                            (uint8_t *) b_ref->y,
566                                            (uint8_t *) b_refh->y,
567                                            (uint8_t *) b_refh->y + 64,
568                                            (uint8_t *) b_refhv->y,
569                                            16*i + (k&1)*8, 16*j + (k>>1)*8, b_dx, b_dy, edged_width, 0);
570    
571    
572                                    transfer_8to16sub2(&dct_codes[k * 64],
573                                                                    cur->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
574                                                                    f_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
575                                                                    b_refv->y + (i * 16+(k&1)*8) + (j * 16+((k>>1)*8)) * edged_width,
576                                                                    edged_width);
577                            }
578                            sum = mb->qmvs[0].y/2 + mb->qmvs[1].y/2 + mb->qmvs[2].y/2 + mb->qmvs[3].y/2;
579                            dy = (sum >> 3) + roundtab_76[sum & 0xf];
580                            sum = mb->qmvs[0].x/2 + mb->qmvs[1].x/2 + mb->qmvs[2].x/2 + mb->qmvs[3].x/2;
581                            dx = (sum >> 3) + roundtab_76[sum & 0xf];
582    
583                            sum = mb->b_qmvs[0].y/2 + mb->b_qmvs[1].y/2 + mb->b_qmvs[2].y/2 + mb->b_qmvs[3].y/2;
584                            b_dy = (sum >> 3) + roundtab_76[sum & 0xf];
585                            sum = mb->b_qmvs[0].x/2 + mb->b_qmvs[1].x/2 + mb->b_qmvs[2].x/2 + mb->b_qmvs[3].x/2;
586                            b_dx = (sum >> 3) + roundtab_76[sum & 0xf];
587    
588                    } else {
589                            for (k=0;k<4;k++) {
590                                    dx = mb->mvs[k].x;
591                                    dy = mb->mvs[k].y;
592    
593                                    b_dx = mb->b_mvs[k].x;
594                                    b_dy = mb->b_mvs[k].y;
595    
596                                    transfer_8to16sub2(&dct_codes[k * 64],
597                                                                    cur->y + (i*16 + (k&1)*8) + (j*16 + (k>>1)*8 ) * edged_width,
598                                                                    get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
599                                                                                    2*i + (k&1), 2*j + (k>>1), 8, dx, dy,
600                                                                                    edged_width),
601                                                                    get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
602                                                                                    2*i + (k&1), 2*j + (k>>1), 8, b_dx, b_dy,
603                                                                                    edged_width),
604                                                                    edged_width);
605                            }
606    
607                            sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x;
608                            dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
609    
610                            sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;
611                            dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
612    
613                            sum = mb->b_mvs[0].x + mb->b_mvs[1].x + mb->b_mvs[2].x + mb->b_mvs[3].x;
614                            b_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
615    
616                            sum = mb->b_mvs[0].y + mb->b_mvs[1].y + mb->b_mvs[2].y + mb->b_mvs[3].y;
617                            b_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2));
618    
619                    }
620                    transfer_8to16sub2(&dct_codes[4 * 64],
621                                                            cur->u + (y * 8) * edged_width / 2 + (x * 8),
622                                                            interpolate8x8_switch2(f_refv->u, b_ref->u, 8 * i, 8 * j,
623                                                                                                            b_dx, b_dy, edged_width / 2, 0),
624                                                            interpolate8x8_switch2(f_refv->u + 8, f_ref->u, 8 * i, 8 * j, dx, dy,
625                                                              edged_width / 2, 0),
626                                                            edged_width / 2);
627    
628                    transfer_8to16sub2(&dct_codes[5 * 64],
629                                                            cur->v + (y * 8) * edged_width / 2 + (x * 8),
630                                                            interpolate8x8_switch2(f_refv->u, b_ref->v, 8 * i, 8 * j,
631                                                                                                            b_dx, b_dy, edged_width / 2, 0),
632                                                            interpolate8x8_switch2(f_refv->u + 8, f_ref->v, 8 * i, 8 * j,
633                                                                                                            dx, dy, edged_width / 2, 0),
634                                                            edged_width / 2);
635    
636    
637                    break;
638          }          }
639  }  }

Legend:
Removed from v.78  
changed lines
  Added in v.701

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