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

Annotation of /branches/dev-api-3/xvidcore/src/motion/motion_comp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 152 - (view) (download)
Original Path: trunk/xvidcore/src/motion/motion_comp.c

1 : suxen_drol 152 // 01.05.2002 updated MBMotionCompensationBVOP
2 : suxen_drol 118 // 14.04.2002 bframe compensation
3 :    
4 : Isibaar 3 #include "../encoder.h"
5 :     #include "../utils/mbfunctions.h"
6 :     #include "../image/interpolate8x8.h"
7 :     #include "../utils/timer.h"
8 : suxen_drol 118 #include "motion.h"
9 : Isibaar 3
10 :     #define ABS(X) (((X)>0)?(X):-(X))
11 :     #define SIGN(X) (((X)>0)?1:-1)
12 :    
13 :     static __inline void compensate8x8_halfpel(
14 :     int16_t * const dct_codes,
15 :     uint8_t * const cur,
16 :     const uint8_t * const ref,
17 :     const uint8_t * const refh,
18 :     const uint8_t * const refv,
19 :     const uint8_t * const refhv,
20 :     const uint32_t x, const uint32_t y,
21 :     const int32_t dx, const int dy,
22 :     const uint32_t stride)
23 :     {
24 :     int32_t ddx,ddy;
25 :    
26 :     switch ( ((dx&1)<<1) + (dy&1) ) // ((dx%2)?2:0)+((dy%2)?1:0)
27 :     {
28 :     case 0 :
29 :     ddx = dx/2;
30 :     ddy = dy/2;
31 :     transfer_8to16sub(dct_codes, cur + y*stride + x,
32 :     ref + (y+ddy)*stride + x+ddx, stride);
33 :     break;
34 :    
35 :     case 1 :
36 :     ddx = dx/2;
37 :     ddy = (dy-1)/2;
38 :     transfer_8to16sub(dct_codes, cur + y*stride + x,
39 :     refv + (y+ddy)*stride + x+ddx, stride);
40 :     break;
41 :    
42 :     case 2 :
43 :     ddx = (dx-1)/2;
44 :     ddy = dy/2;
45 :     transfer_8to16sub(dct_codes, cur + y*stride + x,
46 :     refh + (y+ddy)*stride + x+ddx, stride);
47 :     break;
48 :    
49 :     default : // case 3:
50 :     ddx = (dx-1)/2;
51 :     ddy = (dy-1)/2;
52 :     transfer_8to16sub(dct_codes, cur + y*stride + x,
53 :     refhv + (y+ddy)*stride + x+ddx, stride);
54 :     break;
55 :     }
56 :     }
57 :    
58 :    
59 :    
60 :     void MBMotionCompensation(
61 : edgomez 78 MACROBLOCK * const mb,
62 :     const uint32_t i,
63 :     const uint32_t j,
64 :     const IMAGE * const ref,
65 :     const IMAGE * const refh,
66 :     const IMAGE * const refv,
67 :     const IMAGE * const refhv,
68 :     IMAGE * const cur,
69 :     int16_t *dct_codes,
70 :     const uint32_t width,
71 :     const uint32_t height,
72 :     const uint32_t edged_width,
73 :     const uint32_t rounding)
74 : Isibaar 3 {
75 :     static const uint32_t roundtab[16] =
76 :     { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
77 :    
78 :    
79 :     if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
80 :     {
81 :     int32_t dx = mb->mvs[0].x;
82 :     int32_t dy = mb->mvs[0].y;
83 :    
84 : edgomez 78 compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
85 :     16*i, 16*j, dx, dy, edged_width);
86 :     compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
87 :     16*i + 8, 16*j, dx, dy, edged_width);
88 :     compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
89 :     16*i, 16*j + 8, dx, dy, edged_width);
90 :     compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
91 :     16*i + 8, 16*j + 8, dx, dy, edged_width);
92 : Isibaar 3
93 :     dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2;
94 :     dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2;
95 :    
96 : suxen_drol 152 /* uv-image-based compensation */
97 :     #ifdef BFRAMES
98 :     compensate8x8_halfpel(&dct_codes[4*64], cur->u, ref->u, refh->u, refv->u, refhv->u,
99 : edgomez 78 8*i, 8*j, dx, dy, edged_width/2);
100 : suxen_drol 152 compensate8x8_halfpel(&dct_codes[5*64], cur->v, ref->v, refh->v, refv->v, refhv->v,
101 :     8*i, 8*j, dx, dy, edged_width/2);
102 :     #else
103 : Isibaar 3 /* uv-block-based compensation */
104 :     interpolate8x8_switch(refv->u, ref->u, 8*i, 8*j, dx, dy, edged_width/2, rounding);
105 : edgomez 78 transfer_8to16sub(&dct_codes[4*64],
106 :     cur->u + 8*j*edged_width/2 + 8*i,
107 :     refv->u + 8*j*edged_width/2 + 8*i, edged_width/2);
108 : Isibaar 3
109 :     interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding);
110 : edgomez 78 transfer_8to16sub(&dct_codes[5*64],
111 :     cur->v + 8*j*edged_width/2 + 8*i,
112 :     refv->v + 8*j*edged_width/2 + 8*i, edged_width/2);
113 : suxen_drol 152 #endif
114 : Isibaar 3 }
115 :     else // mode == MODE_INTER4V
116 :     {
117 :     int32_t sum, dx, dy;
118 :    
119 : edgomez 78 compensate8x8_halfpel(&dct_codes[0*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
120 :     16*i, 16*j, mb->mvs[0].x, mb->mvs[0].y, edged_width);
121 :     compensate8x8_halfpel(&dct_codes[1*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
122 :     16*i + 8, 16*j, mb->mvs[1].x, mb->mvs[1].y, edged_width);
123 :     compensate8x8_halfpel(&dct_codes[2*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
124 :     16*i, 16*j + 8, mb->mvs[2].x, mb->mvs[2].y, edged_width);
125 :     compensate8x8_halfpel(&dct_codes[3*64], cur->y, ref->y, refh->y, refv->y, refhv->y,
126 :     16*i + 8, 16*j + 8, mb->mvs[3].x, mb->mvs[3].y, edged_width);
127 : Isibaar 3
128 :     sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x;
129 :     dx = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);
130 :    
131 :     sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y;
132 :     dy = (sum ? SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0);
133 :    
134 : suxen_drol 152 /* uv-image-based compensation */
135 :     #ifdef BFRAMES
136 :     compensate8x8_halfpel(&dct_codes[4*64], cur->u, ref->u, refh->u, refv->u, refhv->u,
137 : edgomez 78 8*i, 8*j, dx, dy, edged_width/2);
138 : suxen_drol 152 compensate8x8_halfpel(&dct_codes[5*64], cur->v, ref->v, refh->v, refv->v, refhv->v,
139 :     8*i, 8*j, dx, dy, edged_width/2);
140 :     #else
141 : Isibaar 3 /* uv-block-based compensation */
142 :     interpolate8x8_switch(refv->u, ref->u, 8*i, 8*j, dx, dy, edged_width/2, rounding);
143 : edgomez 78 transfer_8to16sub(&dct_codes[4*64],
144 :     cur->u + 8*j*edged_width/2 + 8*i,
145 :     refv->u + 8*j*edged_width/2 + 8*i, edged_width/2);
146 : Isibaar 3
147 :     interpolate8x8_switch(refv->v, ref->v, 8*i, 8*j, dx, dy, edged_width/2, rounding);
148 : edgomez 78 transfer_8to16sub(&dct_codes[5*64],
149 :     cur->v + 8*j*edged_width/2 + 8*i,
150 :     refv->v + 8*j*edged_width/2 + 8*i, edged_width/2);
151 : suxen_drol 152 #endif
152 : Isibaar 3 }
153 :     }
154 : suxen_drol 118
155 :    
156 :     void MBMotionCompensationBVOP(
157 :     MBParam * pParam,
158 :     MACROBLOCK * const mb,
159 :     const uint32_t i,
160 :     const uint32_t j,
161 :     IMAGE * const cur,
162 :     const IMAGE * const f_ref,
163 :     const IMAGE * const f_refh,
164 :     const IMAGE * const f_refv,
165 :     const IMAGE * const f_refhv,
166 :     const IMAGE * const b_ref,
167 :     const IMAGE * const b_refh,
168 :     const IMAGE * const b_refv,
169 :     const IMAGE * const b_refhv,
170 : suxen_drol 152 int16_t * dct_codes)
171 : suxen_drol 118 {
172 :     static const uint32_t roundtab[16] =
173 :     { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
174 :    
175 :     const int32_t edged_width = pParam->edged_width;
176 :     int32_t dx, dy;
177 :     int32_t b_dx, b_dy;
178 :     int x = i;
179 :     int y = j;
180 :    
181 :    
182 :    
183 :     switch(mb->mode)
184 :     {
185 :     case MODE_FORWARD :
186 :     dx = mb->mvs[0].x;
187 :     dy = mb->mvs[0].y;
188 :    
189 :     transfer_8to16sub_c(
190 : suxen_drol 152 &dct_codes[0*64],
191 : suxen_drol 118 cur->y + (j*16)*edged_width + (i*16),
192 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
193 :     i*16, j*16, 1, dx, dy, edged_width),
194 :     edged_width);
195 :    
196 :     transfer_8to16sub(
197 : suxen_drol 152 &dct_codes[1*64],
198 : suxen_drol 118 cur->y + (j*16)*edged_width + (i*16+8),
199 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
200 :     i*16+8, j*16, 1, dx, dy, edged_width),
201 :     edged_width);
202 :    
203 :     transfer_8to16sub_c(
204 : suxen_drol 152 &dct_codes[2*64],
205 : suxen_drol 118 cur->y + (j*16+8)*edged_width + (i*16),
206 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
207 :     i*16, j*16+8, 1, dx, dy, edged_width),
208 :     edged_width);
209 :    
210 :     transfer_8to16sub(
211 : suxen_drol 152 &dct_codes[3*64],
212 : suxen_drol 118 cur->y + (j*16+8)*edged_width + (i*16+8),
213 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
214 :     i*16+8, j*16+8, 1, dx, dy, edged_width),
215 :     edged_width);
216 :    
217 :    
218 :     dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2;
219 :     dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2;
220 :    
221 :     /* uv-image-based compensation */
222 : suxen_drol 152 compensate8x8_halfpel(&dct_codes[4*64], cur->u, f_ref->u, f_refh->u, f_refv->u, f_refhv->u,
223 : suxen_drol 118 8*i, 8*j, dx, dy, edged_width/2);
224 : suxen_drol 152 compensate8x8_halfpel(&dct_codes[5*64], cur->v, f_ref->v, f_refh->v, f_refv->v, f_refhv->v,
225 : suxen_drol 118 8*i, 8*j, dx, dy, edged_width/2);
226 :    
227 :     break;
228 :    
229 :     case MODE_BACKWARD :
230 :     b_dx = mb->b_mvs[0].x;
231 :     b_dy = mb->b_mvs[0].y;
232 :    
233 :     transfer_8to16sub_c(
234 : suxen_drol 152 &dct_codes[0*64],
235 : suxen_drol 118 cur->y + (j*16)*edged_width + (i*16),
236 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
237 :     i*16, j*16, 1, b_dx, b_dy, edged_width),
238 :     edged_width);
239 :    
240 :     transfer_8to16sub(
241 : suxen_drol 152 &dct_codes[1*64],
242 : suxen_drol 118 cur->y + (j*16)*edged_width + (i*16+8),
243 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
244 :     i*16+8, j*16, 1, b_dx, b_dy, edged_width),
245 :     edged_width);
246 :    
247 :     transfer_8to16sub_c(
248 : suxen_drol 152 &dct_codes[2*64],
249 : suxen_drol 118 cur->y + (j*16+8)*edged_width + (i*16),
250 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
251 :     i*16, j*16+8, 1, b_dx, b_dy, edged_width),
252 :     edged_width);
253 :    
254 :     transfer_8to16sub(
255 : suxen_drol 152 &dct_codes[3*64],
256 : suxen_drol 118 cur->y + (j*16+8)*edged_width + (i*16+8),
257 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
258 :     i*16+8, j*16+8, 1, b_dx, b_dy, edged_width),
259 :     edged_width);
260 :    
261 :     b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2;
262 :     b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2;
263 :    
264 :     /* uv-image-based compensation */
265 : suxen_drol 152 compensate8x8_halfpel(&dct_codes[4*64], cur->u,
266 : suxen_drol 118 b_ref->u, b_refh->u, b_refv->u, b_refhv->u,
267 :     8*i, 8*j, b_dx, b_dy, edged_width/2);
268 : suxen_drol 152 compensate8x8_halfpel(&dct_codes[5*64], cur->v,
269 : suxen_drol 118 b_ref->v, b_refh->v, b_refv->v, b_refhv->v,
270 :     8*i, 8*j, b_dx, b_dy, edged_width/2);
271 :    
272 :     break;
273 :    
274 :    
275 :     case MODE_INTERPOLATE :
276 :     dx = mb->mvs[0].x;
277 :     dy = mb->mvs[0].y;
278 :     b_dx = mb->b_mvs[0].x;
279 :     b_dy = mb->b_mvs[0].y;
280 :    
281 :     transfer_8to16sub2_c(
282 : suxen_drol 152 &dct_codes[0*64],
283 : suxen_drol 118 cur->y + (i*16) + (j*16)*edged_width,
284 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
285 :     16*i, 16*j, 1, dx, dy, edged_width),
286 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
287 :     16*i, 16*j, 1, b_dx, b_dy, edged_width),
288 :     edged_width);
289 :    
290 :     transfer_8to16sub2_c(
291 : suxen_drol 152 &dct_codes[1*64],
292 : suxen_drol 118 cur->y + (i*16+8) + (j*16)*edged_width,
293 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
294 :     16*i+8, 16*j, 1, dx, dy, edged_width),
295 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
296 :     16*i+8, 16*j, 1, b_dx, b_dy, edged_width),
297 :     edged_width);
298 :    
299 :     transfer_8to16sub2_c(
300 : suxen_drol 152 &dct_codes[2*64],
301 : suxen_drol 118 cur->y + (i*16) + (j*16+8)*edged_width,
302 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
303 :     16*i, 16*j+8, 1, dx, dy, edged_width),
304 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
305 :     16*i, 16*j+8, 1, b_dx, b_dy, edged_width),
306 :     edged_width);
307 :    
308 :     transfer_8to16sub2_c(
309 : suxen_drol 152 &dct_codes[3*64],
310 : suxen_drol 118 cur->y + (i*16+8) + (j*16+8)*edged_width,
311 :     get_ref(f_ref->y, f_refh->y, f_refv->y, f_refhv->y,
312 :     16*i + 8, 16*j + 8, 1, dx, dy, edged_width),
313 :     get_ref(b_ref->y, b_refh->y, b_refv->y, b_refhv->y,
314 :     16*i + 8, 16*j + 8, 1, b_dx, b_dy, edged_width),
315 :     edged_width);
316 :    
317 :    
318 :     dx = (dx & 3) ? (dx >> 1) | 1 : dx / 2;
319 :     dy = (dy & 3) ? (dy >> 1) | 1 : dy / 2;
320 :    
321 :     b_dx = (b_dx & 3) ? (b_dx >> 1) | 1 : b_dx / 2;
322 :     b_dy = (b_dy & 3) ? (b_dy >> 1) | 1 : b_dy / 2;
323 :    
324 :     transfer_8to16sub2_c(
325 : suxen_drol 152 &dct_codes[4*64],
326 : suxen_drol 118 cur->u + (y*8)*edged_width/2 + (x*8),
327 :     get_ref(f_ref->u, f_refh->u, f_refv->u, f_refhv->u,
328 :     8*i, 8*j, 1, dx, dy, edged_width/2),
329 :     get_ref(b_ref->u, b_refh->u, b_refv->u, b_refhv->u,
330 :     8*i, 8*j, 1, b_dx, b_dy, edged_width/2),
331 :     edged_width/2);
332 :    
333 :     transfer_8to16sub2_c(
334 : suxen_drol 152 &dct_codes[5*64],
335 : suxen_drol 118 cur->v + (y*8)*edged_width/2 + (x*8),
336 :     get_ref(f_ref->v, f_refh->v, f_refv->v, f_refhv->v,
337 :     8*i, 8*j, 1, dx, dy, edged_width/2),
338 :     get_ref(b_ref->v, b_refh->v, b_refv->v, b_refhv->v,
339 :     8*i, 8*j, 1, b_dx, b_dy, edged_width/2),
340 :     edged_width/2);
341 :    
342 :     break;
343 :    
344 :     case MODE_DIRECT :
345 :     // todo
346 :     break;
347 :     }
348 :    
349 :     }

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