r553: Modern gccs require __attribute__((used)) for variables used only in assembly.
[cinelerra_cv/mob.git] / libmpeg3 / video / reconstruct.c
blobddb78460c904e1a3115078c2badfe02405905bd0
1 #include "mpeg3private.h"
2 #include "mpeg3protos.h"
3 #include <stdio.h>
5 #ifdef HAVE_MMX
6 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3)
7 #define USED __attribute__((used))
8 #else
9 #define USED
10 #endif
12 #ifdef HAVE_3Dnow
13 static inline void recva_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
15 __asm__(
16 ".align 8\n"
17 "1:"
18 "movq (%1), %%mm0\n" /* 8 s */
19 "movq 8(%1), %%mm1\n" /* 8 s */
20 "movq (%4), %%mm2\n" /* 8 s +lx */
21 "movq 8(%4), %%mm3\n" /* 8 s +lx **/
23 "pavgusb %%mm2, %%mm0\n"
24 "addl %3, %1\n"
25 "pavgusb %%mm3, %%mm1\n"
27 "movq (%2), %%mm2\n" /* 8 d */
28 "movq 8(%2), %%mm3\n" /* 8 d */
29 "pavgusb %%mm2, %%mm0\n"
30 "addl %3, %4\n"
31 "pavgusb %%mm3, %%mm1\n"
33 "movq %%mm0, (%2)\n"
34 "movq %%mm1, 8(%2)\n"
35 "addl %3, %2\n"
36 "loop 1b\n"
38 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
42 static inline void recvac_mmx(unsigned char *s, unsigned char *d, int lx,int lx2, int h)
44 __asm__(
45 ".align 8\n"
46 "1:"
47 "movq (%1), %%mm0\n" /* 8 s */
48 "movq (%4), %%mm2\n" /* 8 s +lx */
49 "addl %3, %1\n"
50 "pavgusb %%mm2, %%mm0\n"
51 "movq (%2), %%mm3\n" /* 8 d */
52 "addl %3, %4\n"
53 "pavgusb %%mm3, %%mm0\n"
54 "movq %%mm0, (%2)\n"
55 "addl %3, %2\n"
56 "loop 1b\n"
58 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
62 static inline void rech_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
64 __asm__ (
65 ".align 8\n"
66 "1:"
67 "movq (%1), %%mm0\n" /* 8 s */
68 "movq 8(%1), %%mm1\n" /* 8 s */
69 "movq 1(%1), %%mm2\n" /* 8 s */
70 "movq 9(%1), %%mm3\n" /* 8 s */
72 "pavgusb %%mm2, %%mm0\n"
73 "addl %3, %1\n"
74 "pavgusb %%mm3, %%mm1\n"
76 "movq %%mm0, (%2)\n"
77 "movq %%mm1, 8(%2)\n"
78 "addl %3, %2\n"
79 "loop 1b\n"
81 : "c" (h), "r" (s), "r" (d), "r" (lx2)
85 static inline void rechc_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
87 __asm__ (
88 ".align 8\n"
89 "1:"
90 "movq (%1), %%mm0\n" /* 8 s */
91 "movq 1(%1), %%mm2\n" /* 8 s +1 */
92 "addl %3, %1\n"
93 "pavgusb %%mm2, %%mm0\n"
94 "movq %%mm0, (%2)\n"
95 "addl %3, %2\n"
96 "loop 1b\n"
98 : "c" (h), "r" (s), "r" (d), "r" (lx2)
102 static inline void recha_mmx(unsigned char *s, unsigned char *d,int lx2, int h)
104 __asm__ (
105 ".align 8\n"
106 "1:"
107 "movq (%1), %%mm0\n" /* 8 s */
108 "movq 8(%1), %%mm1\n" /* 8 s */
109 "movq 1(%1), %%mm2\n" /* 8 s */
110 "movq 9(%1), %%mm3\n" /* 8 s */
112 "pavgusb %%mm2, %%mm0\n"
113 "addl %3, %1\n"
114 "pavgusb %%mm3, %%mm1\n"
116 "movq (%2), %%mm2\n" /* 8 d */
117 "movq 8(%2), %%mm3\n" /* 8 d */
118 "pavgusb %%mm2, %%mm0\n"
119 "pavgusb %%mm3, %%mm1\n"
121 "movq %%mm0, (%2)\n"
122 "movq %%mm1, 8(%2)\n"
123 "addl %3, %2\n"
124 "loop 1b\n"
126 : "c" (h), "r" (s), "r" (d), "r" (lx2)
130 static inline void rechac_mmx(unsigned char *s,unsigned char *d, int lx2, int h)
132 __asm__ (
133 ".align 8\n"
134 "1:"
135 "movq (%1), %%mm0\n" /* 8 s */
136 "movq 1(%1), %%mm2\n" /* 8 s */
138 "addl %3, %1\n"
139 "pavgusb %%mm2, %%mm0\n"
141 "movq (%2), %%mm1\n" /* 8 d */
142 "pavgusb %%mm1, %%mm0\n"
144 "movq %%mm0, (%2)\n"
145 "addl %3, %2\n"
146 "loop 1b\n"
148 : "c" (h), "r" (s), "r" (d), "r" (lx2)
152 static inline void rec4_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
154 __asm__ __volatile__(
155 "movq (%1), %%mm0\n" /* 8 s */
156 "movq 8(%1), %%mm1\n" /* 8 s */
157 "movq 1(%1), %%mm2\n" /* 8 s +1*/
158 "movq 9(%1), %%mm3\n" /* 8 s +1*/
159 ".align 8\n"
160 "1:"
161 "movq (%4), %%mm4\n" /* 8 s+lx */
162 "pavgusb %%mm2, %%mm0\n"
163 "movq 8(%4), %%mm5\n" /* 8 s+lx */
164 "pavgusb %%mm3, %%mm1\n"
166 "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/
167 "pavgusb %%mm4, %%mm0\n"
168 "movq 9(%4), %%mm7\n" /* 8 s+lx +1*/
169 "pavgusb %%mm5, %%mm1\n"
171 "pavgusb %%mm6, %%mm0\n"
172 "addl %3, %4\n"
173 "pavgusb %%mm7, %%mm1\n"
174 "movq %%mm0, (%2)\n"
175 "movq %%mm6, %%mm2\n"
176 "movq %%mm7, %%mm3\n"
177 "movq %%mm1, 8(%2)\n"
178 "movq %%mm4, %%mm0\n"
179 "movq %%mm5, %%mm1\n"
180 "addl %3, %2\n"
181 "loop 1b\n"
183 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
187 static inline void rec4c_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
189 __asm__ __volatile__(
190 "movq (%1), %%mm0\n" /* 8 s */
191 "movq 1(%1), %%mm2\n" /* 8 s +1*/
192 ".align 8\n"
193 "1:"
194 "movq (%4), %%mm4\n" /* 8 s+lx */
195 "pavgusb %%mm2, %%mm0\n"
197 "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/
198 "pavgusb %%mm4, %%mm0\n"
200 "addl %3, %4\n"
201 "pavgusb %%mm6, %%mm0\n"
202 "movq %%mm0, (%2)\n"
203 "movq %%mm6, %%mm2\n"
204 "movq %%mm4, %%mm0\n"
205 "addl %3, %2\n"
206 "loop 1b\n"
208 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
212 static inline void rec4a_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
214 __asm__ __volatile__(
215 "movq (%1), %%mm0\n" /* 8 s */
216 "movq 8(%1), %%mm1\n" /* 8 s */
217 "movq 1(%1), %%mm2\n" /* 8 s +1*/
218 "movq 9(%1), %%mm3\n" /* 8 s +1*/
219 ".align 8\n"
220 "1:"
221 "movq (%4), %%mm4\n" /* 8 s+lx */
222 "pavgusb %%mm2, %%mm0\n"
223 "movq 8(%4), %%mm5\n" /* 8 s+lx */
224 "pavgusb %%mm3, %%mm1\n"
226 "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/
227 "pavgusb %%mm4, %%mm0\n"
228 "movq 9(%4), %%mm7\n" /* 8 s+lx +1*/
229 "pavgusb %%mm5, %%mm1\n"
230 "movq (%2), %%mm2\n"
231 "pavgusb %%mm6, %%mm0\n"
232 "movq 8(%2), %%mm3\n"
234 "pavgusb %%mm2, %%mm0\n"
235 "addl %3, %4\n"
236 "pavgusb %%mm3, %%mm1\n"
237 "movq %%mm0, (%2)\n"
239 "pavgusb %%mm7, %%mm1\n"
240 "movq %%mm6, %%mm2\n"
241 "movq %%mm7, %%mm3\n"
242 "movq %%mm1, 8(%2)\n"
243 "movq %%mm4, %%mm0\n"
244 "movq %%mm5, %%mm1\n"
245 "addl %3, %2\n"
246 "loop 1b\n"
248 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
252 static inline void rec4ac_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
254 __asm__ __volatile__(
255 "movq (%1), %%mm0\n" /* 8 s */
256 "movq 1(%1), %%mm2\n" /* 8 s +1*/
257 ".align 8\n"
258 "1:"
259 "movq (%4), %%mm4\n" /* 8 s+lx */
260 "pavgusb %%mm2, %%mm0\n"
262 "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/
263 "pavgusb %%mm4, %%mm0\n"
264 "movq (%2), %%mm1\n" /* 8 d */
265 "pavgusb %%mm6, %%mm0\n"
266 "addl %3, %4\n"
267 "pavgusb %%mm1, %%mm0\n"
268 "movq %%mm6, %%mm2\n"
269 "movq %%mm0, (%2)\n"
270 "movq %%mm4, %%mm0\n"
271 "addl %3, %2\n"
272 "loop 1b\n"
274 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
278 #else // HAVE_3DNOW
279 static long long ADD_1 USED = 0x0101010101010101LL;
280 static long long MASK_AND USED = 0x7f7f7f7f7f7f7f7fLL;
281 #endif
283 static inline void rec_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
285 __asm__ __volatile__(
286 ".align 8\n"
287 "1:\t"
288 "movq ( %1 ), %%mm0\n" /* 8 s */
289 "movq 8( %1 ), %%mm2\n" /* 16 s */
290 "movq %%mm0, ( %2 )\n"
291 "addl %3, %1\n"
292 "movq %%mm2, 8( %2 )\n"
293 "decl %0\n"
294 "leal (%2, %3), %2\n"
295 "jnz 1b"
297 : "c" (h), "r" (s), "r" (d), "r" (lx2)
302 static inline void recc_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
304 __asm__ __volatile__(
305 ".align 8\n"
306 "1:\t"
307 "movq ( %1 ), %%mm0\n"
308 "addl %3, %1\n"
309 "movq %%mm0, ( %2 )\n"
310 "decl %0\n"
311 "leal (%2, %3), %2\n"
312 "jnz 1b"
314 : "c" (h), "r" (s), "r" (d), "r" (lx2)
319 static inline void reca_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
321 #ifdef HAVE_3Dnow
322 __asm__ (
323 ".align 8\n"
324 "1:"
325 "movq (%1), %%mm0\n" /* 8 s */
326 "movq (%2), %%mm2\n" /* 8 d */
327 "movq 8(%1), %%mm1\n" /* 8 s */
328 "movq 8(%2), %%mm3\n" /* 8 d */
329 "pavgusb %%mm2, %%mm0\n"
330 "addl %3, %1\n"
331 "pavgusb %%mm3, %%mm1\n"
333 "movq %%mm0, (%2)\n"
334 "movq %%mm1, 8(%2)\n"
335 "addl %3, %2\n"
336 "loop 1b\n"
338 : "c" (h), "r" (s), "r" (d), "r" (lx2)
340 #else /* No 3dnow */
341 __asm__ (
342 "movq MASK_AND, %%mm5\n"
343 "movq ADD_1, %%mm6\n"
344 "1:\t"
345 "movq (%1),%%mm0\n" /* Load 16 pixels from each row */
346 "movq (%2),%%mm1\n"
347 "movq 8(%1),%%mm2\n"
348 "movq 8(%2),%%mm3\n"
349 "psrlw $1,%%mm0\n" /* Shift pixels down */
350 "psrlw $1,%%mm1\n"
351 "pand %%mm5,%%mm0\n" /* Zero out significant bit */
352 "psrlw $1,%%mm2\n"
353 "pand %%mm5,%%mm1\n"
354 "psrlw $1,%%mm3\n"
355 "pand %%mm5,%%mm2\n"
356 "paddusb %%mm1,%%mm0\n" /* Add pixels */
357 "pand %%mm5,%%mm3\n"
358 "paddusb %%mm3,%%mm2\n"
359 "paddusb %%mm6,%%mm0\n" /* Add 1 to results */
360 "paddusb %%mm6,%%mm2\n"
361 "movq %%mm0,(%2)\n"
362 "addl %3,%1\n"
363 "movq %%mm2, 8(%2)\n"
364 "decl %0\n"
365 "leal (%2, %3), %2\n"
366 "jnz 1b\n"
368 : "c" (h), "r" (s), "r" (d), "r" (lx2)
370 #endif
374 static inline void recac_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
376 #ifdef HAVE_3Dnow
377 __asm__ (
378 ".align 8\n"
379 "1:"
380 "movq (%1), %%mm0\n" /* 8 s */
381 "movq (%2), %%mm2\n" /* 8 d */
382 "pavgusb %%mm2, %%mm0\n"
383 "addl %3, %1\n"
384 "movq %%mm0, (%2)\n"
385 "addl %3, %2\n"
386 "loop 1b\n"
388 : "c" (h), "r" (s), "r" (d), "r" (lx2)
390 #else /* No 3dnow */
391 __asm__ (
392 "movq MASK_AND, %%mm5\n"
393 "movq ADD_1, %%mm6\n"
394 "1:\t"
395 "movq (%1),%%mm0\n"
396 "movq (%2),%%mm1\n"
397 "psrlw $1,%%mm0\n"
398 "psrlw $1,%%mm1\n"
399 "pand %%mm5,%%mm0\n"
400 "pand %%mm5,%%mm1\n"
401 "paddusb %%mm1,%%mm0\n"
402 "paddusb %%mm6,%%mm0\n"
403 "addl %3,%1\n"
404 "movq %%mm0,(%2)\n"
405 "decl %0\n"
406 "leal (%2, %3), %2\n"
407 "jnz 1b\n"
409 : "c" (h), "r" (s), "r" (d), "r" (lx2)
411 #endif
415 static inline void recv_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
417 #ifdef HAVE_3Dnow
418 __asm__(
419 ".align 8\n"
420 "1:"
421 "movq (%1), %%mm0\n" /* 8 s */
422 "movq (%4), %%mm2\n" /* 8 s +lx */
423 "movq 8(%1), %%mm1\n" /* 8 s */
424 "movq 8(%4), %%mm3\n" /* 8 s +lx **/
426 "pavgusb %%mm2, %%mm0\n"
427 "addl %3, %1\n"
428 "pavgusb %%mm3, %%mm1\n"
430 "movq %%mm0, (%2)\n"
431 "addl %3, %4\n"
432 "movq %%mm1, 8(%2)\n"
433 "addl %3, %2\n"
434 "loop 1b\n"
436 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
438 #else
439 __asm__ (
440 "movq MASK_AND, %%mm5\n"
441 "movq ADD_1, %%mm6\n"
442 "1:\t"
443 "movq (%1), %%mm0\n" /* 8 s */
444 "movq (%4), %%mm1\n" /* 8 s +lx */
445 "movq 8(%1), %%mm2\n" /* 8 s */
446 "movq 8(%4), %%mm3\n" /* 8 s +lx **/
447 "psrlw $1,%%mm0\n"
448 "psrlw $1,%%mm1\n"
449 "pand %%mm5,%%mm0\n"
450 "psrlw $1,%%mm2\n"
451 "pand %%mm5,%%mm1\n"
452 "psrlw $1,%%mm3\n"
453 "pand %%mm5,%%mm2\n"
454 "paddusb %%mm1,%%mm0\n"
455 "pand %%mm5,%%mm3\n"
456 "paddusb %%mm3,%%mm2\n"
457 "paddusb %%mm6,%%mm0\n"
458 "paddusb %%mm6,%%mm2\n"
459 "movq %%mm0,(%2)\n"
460 "addl %3,%1\n"
461 "movq %%mm2, 8(%2)\n"
462 "addl %3,%4\n"
463 "decl %0\n"
464 "leal (%2, %3), %2\n"
465 "jnz 1b\n"
467 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
469 #endif
473 static inline void recvc_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
475 #ifdef HAVE_3Dnow
476 __asm__(
477 ".align 8\n"
478 "1:"
479 "movq (%1), %%mm0\n" /* 8 s */
480 "movq (%4), %%mm2\n" /* 8 s +lx */
481 "addl %3, %1\n"
482 "pavgusb %%mm2, %%mm0\n"
483 "addl %3, %4\n"
484 "movq %%mm0, (%2)\n"
485 "addl %3, %2\n"
486 "loop 1b\n"
488 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
490 #else
491 __asm__ (
492 "movq MASK_AND, %%mm5\n"
493 "movq ADD_1, %%mm6\n"
494 "1:\t"
495 "movq (%1), %%mm0\n" /* 8 s */
496 "movq (%4), %%mm1\n" /* 8 s +lx */
497 "psrlw $1,%%mm0\n"
498 "psrlw $1,%%mm1\n"
499 "pand %%mm5,%%mm0\n"
500 "pand %%mm5,%%mm1\n"
501 "paddusb %%mm1,%%mm0\n"
502 "addl %3,%1\n"
503 "paddusb %%mm6,%%mm0\n"
504 "addl %3,%4\n"
505 "movq %%mm0,(%2)\n"
506 "decl %0\n"
507 "leal (%2, %3), %2\n"
508 "jnz 1b\n"
510 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
512 #endif
515 #endif // HAVE_MMX
517 static inline void rec(unsigned char *s, unsigned char *d, int lx2, int h)
519 int j;
520 for(j = 0; j < h; j++, s += lx2, d += lx2)
522 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
523 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
524 d[8] = s[8]; d[9] = s[9]; d[10] = s[10]; d[11] = s[11];
525 d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15];
531 static inline void recc(unsigned char *s, unsigned char *d, int lx2, int h)
533 int j;
534 for(j = 0; j < h; j++, s += lx2, d += lx2)
536 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
537 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
541 static inline void reca(unsigned char *s, unsigned char *d, int lx2, int h)
543 int j;
544 for(j = 0; j < h; j++, s +=lx2, d +=lx2)
546 d[0] = (unsigned int)(d[0] + s[0] + 1) >> 1;
547 d[1] = (unsigned int)(d[1] + s[1] + 1) >> 1;
548 d[2] = (unsigned int)(d[2] + s[2] + 1) >> 1;
549 d[3] = (unsigned int)(d[3] + s[3] + 1) >> 1;
550 d[4] = (unsigned int)(d[4] + s[4] + 1) >> 1;
551 d[5] = (unsigned int)(d[5] + s[5] + 1) >> 1;
552 d[6] = (unsigned int)(d[6] + s[6] + 1) >> 1;
553 d[7] = (unsigned int)(d[7] + s[7] + 1) >> 1;
554 d[8] = (unsigned int)(d[8] + s[8] + 1) >> 1;
555 d[9] = (unsigned int)(d[9] + s[9] + 1) >> 1;
556 d[10] = (unsigned int)(d[10] + s[10] + 1) >> 1;
557 d[11] = (unsigned int)(d[11] + s[11] + 1) >> 1;
558 d[12] = (unsigned int)(d[12] + s[12] + 1) >> 1;
559 d[13] = (unsigned int)(d[13] + s[13] + 1) >> 1;
560 d[14] = (unsigned int)(d[14] + s[14] + 1) >> 1;
561 d[15] = (unsigned int)(d[15] + s[15] + 1) >> 1;
565 static inline void recac(unsigned char *s, unsigned char *d, int lx2, int h)
567 int j;
568 for(j = 0; j < h; j++, s += lx2, d += lx2)
570 d[0] = (unsigned int)(d[0] + s[0] + 1)>>1;
571 d[1] = (unsigned int)(d[1] + s[1] + 1)>>1;
572 d[2] = (unsigned int)(d[2] + s[2] + 1)>>1;
573 d[3] = (unsigned int)(d[3] + s[3] + 1)>>1;
574 d[4] = (unsigned int)(d[4] + s[4] + 1)>>1;
575 d[5] = (unsigned int)(d[5] + s[5] + 1)>>1;
576 d[6] = (unsigned int)(d[6] + s[6] + 1)>>1;
577 d[7] = (unsigned int)(d[7] + s[7] + 1)>>1;
581 static inline void recv(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
583 unsigned char *dp,*sp,*sp2;
584 int j;
585 sp = s;
586 sp2 = s + lx;
587 dp = d;
588 for(j = 0; j < h; j++)
590 dp[0] = (unsigned int)(sp[0] + sp2[0] + 1) >> 1;
591 dp[1] = (unsigned int)(sp[1] + sp2[1] + 1) >> 1;
592 dp[2] = (unsigned int)(sp[2] + sp2[2] + 1) >> 1;
593 dp[3] = (unsigned int)(sp[3] + sp2[3] + 1) >> 1;
594 dp[4] = (unsigned int)(sp[4] + sp2[4] + 1) >> 1;
595 dp[5] = (unsigned int)(sp[5] + sp2[5] + 1) >> 1;
596 dp[6] = (unsigned int)(sp[6] + sp2[6] + 1) >> 1;
597 dp[7] = (unsigned int)(sp[7] + sp2[7] + 1) >> 1;
598 dp[8] = (unsigned int)(sp[8] + sp2[8] + 1) >> 1;
599 dp[9] = (unsigned int)(sp[9] + sp2[9] + 1) >> 1;
600 dp[10] = (unsigned int)(sp[10] + sp2[10] + 1) >> 1;
601 dp[11] = (unsigned int)(sp[11] + sp2[11] + 1) >> 1;
602 dp[12] = (unsigned int)(sp[12] + sp2[12] + 1) >> 1;
603 dp[13] = (unsigned int)(sp[13] + sp2[13] + 1) >> 1;
604 dp[14] = (unsigned int)(sp[14] + sp2[14] + 1) >> 1;
605 dp[15] = (unsigned int)(sp[15] + sp2[15] + 1) >> 1;
606 sp+= lx2;
607 sp2+= lx2;
608 dp+= lx2;
612 static inline void recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
614 unsigned char *dp,*sp,*sp2;
615 int j;
617 sp = s;
618 sp2 = s+lx;
619 dp = d;
620 for(j = 0; j < h; j++)
622 dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
623 dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
624 dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
625 dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
626 dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
627 dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
628 dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
629 dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
630 sp+= lx2;
631 sp2+= lx2;
632 dp+= lx2;
637 static inline void recva(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
639 unsigned char *dp,*sp,*sp2;
640 int j;
642 sp = s;
643 sp2 = s+lx;
644 dp = d;
645 for (j=0; j<h; j++){
646 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
647 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
648 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
649 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
650 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
651 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
652 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
653 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
654 dp[8] = (dp[8] + ((unsigned int)(sp[8]+sp2[8]+1)>>1) + 1)>>1;
655 dp[9] = (dp[9] + ((unsigned int)(sp[9]+sp2[9]+1)>>1) + 1)>>1;
656 dp[10] = (dp[10] + ((unsigned int)(sp[10]+sp2[10]+1)>>1) + 1)>>1;
657 dp[11] = (dp[11] + ((unsigned int)(sp[11]+sp2[11]+1)>>1) + 1)>>1;
658 dp[12] = (dp[12] + ((unsigned int)(sp[12]+sp2[12]+1)>>1) + 1)>>1;
659 dp[13] = (dp[13] + ((unsigned int)(sp[13]+sp2[13]+1)>>1) + 1)>>1;
660 dp[14] = (dp[14] + ((unsigned int)(sp[14]+sp2[14]+1)>>1) + 1)>>1;
661 dp[15] = (dp[15] + ((unsigned int)(sp[15]+sp2[15]+1)>>1) + 1)>>1;
662 sp+= lx2;
663 sp2+= lx2;
664 dp+= lx2;
669 static inline void recvac(unsigned char *s, unsigned char *d, int lx,int lx2, int h){
670 unsigned char *dp,*sp,*sp2;
671 int j;
673 sp = s;
674 sp2 = s+lx;
675 dp = d;
676 for (j=0; j<h; j++){
677 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
678 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
679 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
680 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
681 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
682 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
683 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
684 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
685 sp+= lx2;
686 sp2+= lx2;
687 dp+= lx2;
692 static inline void rech(unsigned char *s, unsigned char *d, int lx2, int h){
693 unsigned char *dp,*sp;
694 unsigned int s1,s2;
695 int j;
697 sp = s;
698 dp = d;
699 for (j=0; j<h; j++){
700 s1=sp[0];
701 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
702 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
703 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
704 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
705 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
706 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
707 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
708 dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1;
709 dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1;
710 dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1;
711 dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1;
712 dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1;
713 dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1;
714 dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1;
715 dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1;
716 dp[15] = (unsigned int)(s2+sp[16]+1)>>1;
717 sp+= lx2;
718 dp+= lx2;
723 static inline void rechc(unsigned char *s,unsigned char *d, int lx2, int h){
724 unsigned char *dp,*sp;
725 unsigned int s1,s2;
726 int j;
728 sp = s;
729 dp = d;
730 for (j=0; j<h; j++){
731 s1=sp[0];
732 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
733 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
734 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
735 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
736 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
737 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
738 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
739 dp[7] = (unsigned int)(s2+sp[8]+1)>>1;
740 sp+= lx2;
741 dp+= lx2;
745 static inline void recha(unsigned char *s, unsigned char *d,int lx2, int h)
747 unsigned char *dp,*sp;
748 unsigned int s1,s2;
749 int j;
751 sp = s;
752 dp = d;
753 for (j = 0; j < h; j++)
755 s1 = sp[0];
756 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
757 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
758 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
759 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
760 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
761 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
762 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
763 dp[7] = (dp[7] + ((unsigned int)(s2 + (s1 = sp[8]) + 1) >> 1) + 1) >> 1;
764 dp[8] = (dp[8] + ((unsigned int)(s1 + (s2 = sp[9]) + 1) >> 1) + 1) >> 1;
765 dp[9] = (dp[9] + ((unsigned int)(s2 + (s1 = sp[10]) + 1) >> 1) + 1) >> 1;
766 dp[10] = (dp[10] + ((unsigned int)(s1 + (s2 = sp[11]) + 1) >> 1) + 1) >> 1;
767 dp[11] = (dp[11] + ((unsigned int)(s2 + (s1 = sp[12]) + 1) >> 1) + 1) >> 1;
768 dp[12] = (dp[12] + ((unsigned int)(s1 + (s2 = sp[13]) + 1) >> 1) + 1) >> 1;
769 dp[13] = (dp[13] + ((unsigned int)(s2 + (s1 = sp[14]) + 1) >> 1) + 1) >> 1;
770 dp[14] = (dp[14] + ((unsigned int)(s1 + (s2 = sp[15]) + 1) >> 1) + 1) >> 1;
771 dp[15] = (dp[15] + ((unsigned int)(s2 + sp[16] + 1) >> 1) + 1) >> 1;
772 sp += lx2;
773 dp += lx2;
778 static inline void rechac(unsigned char *s,unsigned char *d, int lx2, int h)
780 unsigned char *dp,*sp;
781 unsigned int s1,s2;
782 int j;
784 sp = s;
785 dp = d;
786 for(j = 0; j < h; j++)
788 s1 = sp[0];
789 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
790 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
791 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
792 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
793 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
794 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
795 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
796 dp[7] = (dp[7] + ((unsigned int)(s2 + sp[8] + 1) >> 1) + 1) >> 1;
797 sp += lx2;
798 dp += lx2;
803 static inline void rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
805 unsigned char *dp,*sp,*sp2;
806 unsigned int s1,s2,s3,s4;
807 int j;
809 sp = s;
810 sp2 = s+lx;
811 dp = d;
812 for (j=0; j<h; j++){
813 s1=sp[0]; s3=sp2[0];
814 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
815 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
816 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
817 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
818 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
819 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
820 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
821 dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2;
822 dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2;
823 dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2;
824 dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2;
825 dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2;
826 dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2;
827 dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2;
828 dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2;
829 dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2;
830 sp+= lx2;
831 sp2+= lx2;
832 dp+= lx2;
837 static inline void rec4c(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
839 unsigned char *dp,*sp,*sp2;
840 unsigned int s1,s2,s3,s4;
841 int j;
843 sp = s;
844 sp2 = s+lx;
845 dp = d;
846 for (j=0; j<h; j++){
847 s1=sp[0]; s3=sp2[0];
848 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
849 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
850 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
851 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
852 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
853 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
854 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
855 dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2;
856 sp+= lx2;
857 sp2+= lx2;
858 dp+= lx2;
863 static inline void rec4a(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
865 unsigned char *dp=d, *sp=s, *sp2=s+lx;
866 unsigned int s1, s2, s3, s4;
867 int j;
870 sp = s;
871 sp2 = s+lx;
872 dp = d;
874 for (j=0; j<h; j++){
875 s1=sp[0]; s3=sp2[0];
876 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
877 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
878 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
879 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
880 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
881 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
882 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
883 dp[7] = (dp[7] + ((unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2) + 1)>>1;
884 dp[8] = (dp[8] + ((unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2) + 1)>>1;
885 dp[9] = (dp[9] + ((unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2) + 1)>>1;
886 dp[10] = (dp[10] + ((unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2) + 1)>>1;
887 dp[11] = (dp[11] + ((unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2) + 1)>>1;
888 dp[12] = (dp[12] + ((unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2) + 1)>>1;
889 dp[13] = (dp[13] + ((unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2) + 1)>>1;
890 dp[14] = (dp[14] + ((unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2) + 1)>>1;
891 dp[15] = (dp[15] + ((unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2) + 1)>>1;
892 sp+= lx2;
893 sp2+= lx2;
894 dp+= lx2;
899 static inline void rec4ac(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
901 unsigned char *dp=d, *sp=s, *sp2=s+lx;
902 unsigned int s1,s2,s3,s4;
903 int j;
906 sp = s;
907 sp2 = s+lx;
908 dp = d;
910 for (j=0; j<h; j++)
912 s1=sp[0]; s3=sp2[0];
913 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
914 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
915 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
916 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
917 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
918 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
919 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
920 dp[7] = (dp[7] + ((unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2) + 1)>>1;
921 sp+= lx2;
922 sp2+= lx2;
923 dp+= lx2;
927 static inline
928 void recon_comp(mpeg3video_t *video,
929 unsigned char *src,
930 unsigned char *dst,
931 int lx,
932 int lx2,
933 int w,
934 int h,
935 int x,
936 int y,
937 int dx,
938 int dy,
939 int addflag)
941 int switcher;
942 unsigned char *s, *d;
944 /* half pel scaling */
945 switcher = (dx & 1) << 3 | (dy & 1) << 2 | w;
946 if(addflag) switcher |= 2;
947 /* origins */
948 s = src + lx * (y + (dy >> 1)) + x + (dx >> 1);
949 d = dst + lx * y + x;
951 // Accelerated functions
952 #ifdef HAVE_MMX
953 if(video->have_mmx)
955 switch(switcher)
957 case 0x3: reca_mmx(s, d, lx2, h); break;
958 case 0x2: recac_mmx(s, d, lx2, h); break;
959 case 0x1: rec_mmx(s, d, lx2, h); break;
960 case 0x0: recc_mmx(s, d, lx2, h); break;
961 case 0x7: recva_mmx(s, d, lx, lx2, h); break;
962 case 0x6: recvac_mmx(s, d, lx, lx2, h); break;
963 case 0x5: recv_mmx(s, d, lx, lx2, h); break;
964 case 0x4: recvc_mmx(s, d, lx, lx2, h); break;
965 case 0x9: rech_mmx(s, d, lx2, h); break;
966 case 0x8: rechc_mmx(s, d, lx2, h); break;
969 else
970 #endif
972 switch(switcher)
974 case 0x3: reca(s, d, lx2, h); break;
975 case 0x2: recac(s, d, lx2, h); break;
976 case 0x1: rec(s, d, lx2, h); break;
977 case 0x0: recc(s, d, lx2, h); break;
978 case 0x7: recva(s, d, lx, lx2, h); break;
979 case 0x6: recvac(s, d, lx, lx2, h); break;
980 case 0x5: recv(s, d, lx, lx2, h); break;
981 case 0x4: recvc(s, d, lx, lx2, h); break;
982 case 0x9: rech(s, d, lx2, h); break;
983 case 0x8: rechc(s, d, lx2, h); break;
987 // Unaccelerated functions
988 switch(switcher)
990 case 0xb: recha(s, d, lx2, h); break;
991 case 0xa: rechac(s, d, lx2, h); break;
992 case 0xf: rec4a(s, d, lx, lx2, h); break;
993 case 0xe: rec4ac(s, d, lx, lx2, h); break;
994 case 0xd: rec4(s, d, lx, lx2, h); break;
995 case 0xc: rec4c(s, d, lx, lx2, h); break;
1000 unsigned char *src[]; * prediction source buffer *
1001 int sfield; * prediction source field number (0 or 1) *
1002 unsigned char *dst[]; * prediction destination buffer *
1003 int dfield; * prediction destination field number (0 or 1)*
1004 int lx,lx2; * horizontal offsets *
1005 int w,h; * prediction block/sub-block width, height *
1006 int x,y; * pixel co-ordinates of top-left sample in current MB *
1007 int dx,dy; * horizontal, vertical motion vector *
1008 int addflag; * add prediction error to prediction ? *
1010 static void recon(mpeg3video_t *video,
1011 unsigned char *src[],
1012 int sfield,
1013 unsigned char *dst[],
1014 int dfield,
1015 int lx,
1016 int lx2,
1017 int w,
1018 int h,
1019 int x,
1020 int y,
1021 int dx,
1022 int dy,
1023 int addflag)
1026 /* Y */
1027 recon_comp(video, (src[0] + (sfield ? (lx2 >> 1) : 0)),
1028 dst[0] + (dfield ? (lx2 >> 1) : 0),
1029 lx, lx2, w, h, x, y, dx, dy, addflag);
1031 if(video->chroma_format != CHROMA444)
1033 lx >>= 1;
1034 dx /= 2;
1035 lx2 >>= 1;
1036 w = 0;
1037 x >>= 1;
1040 if(video->chroma_format == CHROMA420)
1042 h >>= 1;
1043 dy /= 2;
1044 y >>= 1;
1047 /* Cb */
1048 recon_comp(video, (src[1] + (sfield ? (lx2 >> 1) : 0)),
1049 dst[1] + (dfield ? (lx2 >> 1) : 0),
1050 lx, lx2, w, h, x, y, dx, dy, addflag);
1052 /* Cr */
1053 recon_comp(video, (src[2] + (sfield ? (lx2 >> 1) : 0)),
1054 dst[2] + (dfield ? (lx2 >> 1) : 0),
1055 lx, lx2, w, h, x, y, dx, dy, addflag);
1058 #define WIDTH 1
1060 int mpeg3video_reconstruct(mpeg3video_t *video,
1061 int bx,
1062 int by,
1063 int mb_type,
1064 int motion_type,
1065 int PMV[2][2][2],
1066 int mv_field_sel[2][2],
1067 int dmvector[2],
1068 int stwtype)
1070 int currentfield;
1071 unsigned char **predframe;
1072 int DMV[2][2];
1073 int stwtop, stwbot;
1075 stwtop = stwtype % 3; /* 0:temporal, 1 : (spat+temp) / 2, 2 : spatial */
1076 stwbot = stwtype / 3;
1078 if((mb_type & MB_FORWARD) || (video->pict_type == P_TYPE))
1080 if(video->pict_struct == FRAME_PICTURE)
1082 if((motion_type == MC_FRAME) || !(mb_type & MB_FORWARD))
1084 /* frame-based prediction */
1086 if(stwtop < 2)
1087 recon(video, video->oldrefframe, 0, video->newframe, 0,
1088 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1089 PMV[0][0][0], PMV[0][0][1], stwtop);
1091 if(stwbot < 2)
1092 recon(video, video->oldrefframe, 1, video->newframe, 1,
1093 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1094 PMV[0][0][0], PMV[0][0][1], stwbot);
1097 else if(motion_type == MC_FIELD) /* field-based prediction */
1099 /* top field prediction */
1100 if(stwtop < 2)
1101 recon(video, video->oldrefframe, mv_field_sel[0][0], video->newframe, 0,
1102 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
1103 PMV[0][0][0], PMV[0][0][1] >> 1, stwtop);
1105 /* bottom field prediction */
1106 if(stwbot < 2)
1107 recon(video, video->oldrefframe, mv_field_sel[1][0], video->newframe, 1,
1108 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
1109 PMV[1][0][0], PMV[1][0][1] >> 1, stwbot);
1111 else if(motion_type == MC_DMV)
1113 /* dual prime prediction */
1114 /* calculate derived motion vectors */
1115 mpeg3video_calc_dmv(video,
1116 DMV,
1117 dmvector,
1118 PMV[0][0][0],
1119 PMV[0][0][1] >> 1);
1121 if(stwtop < 2)
1123 /* predict top field from top field */
1124 recon(video, video->oldrefframe, 0, video->newframe, 0,
1125 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
1126 PMV[0][0][0], PMV[0][0][1] >> 1, 0);
1128 /* predict and add to top field from bottom field */
1129 recon(video, video->oldrefframe, 1, video->newframe, 0,
1130 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
1131 DMV[0][0], DMV[0][1], 1);
1134 if(stwbot < 2)
1136 /* predict bottom field from bottom field */
1137 recon(video, video->oldrefframe, 1, video->newframe, 1,
1138 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
1139 PMV[0][0][0], PMV[0][0][1]>>1, 0);
1141 /* predict and add to bottom field from top field */
1142 recon(video, video->oldrefframe, 0, video->newframe, 1,
1143 video->coded_picture_width << 1, video->coded_picture_width<<1, WIDTH, 8, bx, by>>1,
1144 DMV[1][0], DMV[1][1], 1);
1147 else
1148 /* invalid motion_type */
1149 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
1152 else
1154 /* TOP_FIELD or BOTTOM_FIELD */
1155 /* field picture */
1156 currentfield = (video->pict_struct == BOTTOM_FIELD);
1158 /* determine which frame to use for prediction */
1159 if((video->pict_type == P_TYPE) && video->secondfield
1160 && (currentfield != mv_field_sel[0][0]))
1161 predframe = video->refframe; /* same frame */
1162 else
1163 predframe = video->oldrefframe; /* previous frame */
1165 if((motion_type == MC_FIELD) || !(mb_type & MB_FORWARD))
1167 /* field-based prediction */
1168 if(stwtop < 2)
1169 recon(video, predframe,mv_field_sel[0][0],video->newframe,0,
1170 video->coded_picture_width << 1,video->coded_picture_width << 1,WIDTH,16,bx,by,
1171 PMV[0][0][0],PMV[0][0][1],stwtop);
1173 else
1174 if(motion_type == MC_16X8)
1176 if(stwtop < 2)
1178 recon(video, predframe, mv_field_sel[0][0], video->newframe, 0,
1179 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1180 PMV[0][0][0], PMV[0][0][1], stwtop);
1182 /* determine which frame to use for lower half prediction */
1183 if((video->pict_type==P_TYPE) && video->secondfield
1184 && (currentfield!=mv_field_sel[1][0]))
1185 predframe = video->refframe; /* same frame */
1186 else
1187 predframe = video->oldrefframe; /* previous frame */
1189 recon(video, predframe, mv_field_sel[1][0], video->newframe, 0,
1190 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
1191 PMV[1][0][0], PMV[1][0][1], stwtop);
1194 else
1195 if(motion_type == MC_DMV) /* dual prime prediction */
1197 if(video->secondfield)
1198 predframe = video->refframe; /* same frame */
1199 else
1200 predframe = video->oldrefframe; /* previous frame */
1202 /* calculate derived motion vectors */
1203 mpeg3video_calc_dmv(video,
1204 DMV,
1205 dmvector,
1206 PMV[0][0][0],
1207 PMV[0][0][1]);
1209 /* predict from field of same parity */
1210 recon(video, video->oldrefframe, currentfield, video->newframe, 0,
1211 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
1212 PMV[0][0][0], PMV[0][0][1], 0);
1214 /* predict from field of opposite parity */
1215 recon(video, predframe, !currentfield, video->newframe, 0,
1216 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
1217 DMV[0][0], DMV[0][1], 1);
1219 else
1220 /* invalid motion_type */
1221 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
1224 stwtop = stwbot = 1;
1227 if(mb_type & MB_BACKWARD)
1229 if(video->pict_struct == FRAME_PICTURE)
1231 if(motion_type == MC_FRAME)
1233 /* frame-based prediction */
1234 if(stwtop < 2)
1235 recon(video, video->refframe, 0, video->newframe, 0,
1236 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1237 PMV[0][1][0], PMV[0][1][1], stwtop);
1239 if(stwbot < 2)
1240 recon(video, video->refframe, 1, video->newframe, 1,
1241 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1242 PMV[0][1][0], PMV[0][1][1], stwbot);
1244 else
1246 /* field-based prediction */
1247 /* top field prediction */
1248 if(stwtop < 2)
1250 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
1251 (video->coded_picture_width << 1), (video->coded_picture_width<<1), WIDTH, 8, bx, (by >> 1),
1252 PMV[0][1][0], (PMV[0][1][1] >> 1), stwtop);
1255 /* bottom field prediction */
1256 if(stwbot < 2)
1258 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 1, (video->coded_picture_width << 1),
1259 (video->coded_picture_width << 1), WIDTH, 8, bx, (by>>1),
1260 PMV[1][1][0], (PMV[1][1][1]>>1), stwbot);
1264 else
1266 /* TOP_FIELD or BOTTOM_FIELD */
1267 /* field picture */
1268 if(motion_type == MC_FIELD)
1270 /* field-based prediction */
1271 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
1272 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
1273 PMV[0][1][0], PMV[0][1][1], stwtop);
1275 else if(motion_type==MC_16X8)
1277 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
1278 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1279 PMV[0][1][0], PMV[0][1][1], stwtop);
1281 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 0,
1282 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
1283 PMV[1][1][0], PMV[1][1][1], stwtop);
1285 else
1286 /* invalid motion_type */
1287 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
1290 } /* mb_type & MB_BACKWARD */
1291 return 0;