summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/multimedia/opieplayer/libmpeg3/video/reconstruct.c
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/video/reconstruct.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmpeg3/video/reconstruct.c1290
1 files changed, 1290 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c b/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c
new file mode 100644
index 0000000..531f9c0
--- a/dev/null
+++ b/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c
@@ -0,0 +1,1290 @@
1#include "../libmpeg3.h"
2#include "../mpeg3protos.h"
3#include "mpeg3video.h"
4#include <stdio.h>
5
6#ifdef HAVE_MMX
7
8#ifdef HAVE_3Dnow
9static inline void recva_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
10{
11 __asm__(
12 ".align8\n"
13 "1:"
14 "movq (%1),%%mm0\n" /* 8 s */
15 "movq 8(%1),%%mm1\n" /* 8 s */
16 "movq (%4),%%mm2\n" /* 8 s +lx */
17 "movq 8(%4),%%mm3\n" /* 8 s +lx **/
18
19 "pavgusb %%mm2, %%mm0\n"
20 "addl %3, %1\n"
21 "pavgusb %%mm3, %%mm1\n"
22
23 "movq (%2),%%mm2\n" /* 8 d */
24 "movq 8(%2),%%mm3\n" /* 8 d */
25 "pavgusb %%mm2, %%mm0\n"
26 "addl %3, %4\n"
27 "pavgusb %%mm3, %%mm1\n"
28
29 "movq %%mm0,(%2)\n"
30 "movq %%mm1,8(%2)\n"
31 "addl %3, %2\n"
32 "loop 1b\n"
33 :
34 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
35 );
36}
37
38static inline void recvac_mmx(unsigned char *s, unsigned char *d, int lx,int lx2, int h)
39{
40 __asm__(
41 ".align8\n"
42 "1:"
43 "movq (%1),%%mm0\n" /* 8 s */
44 "movq (%4),%%mm2\n" /* 8 s +lx */
45 "addl %3, %1\n"
46 "pavgusb %%mm2, %%mm0\n"
47 "movq (%2),%%mm3\n" /* 8 d */
48 "addl %3, %4\n"
49 "pavgusb %%mm3, %%mm0\n"
50 "movq %%mm0,(%2)\n"
51 "addl %3, %2\n"
52 "loop 1b\n"
53 :
54 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
55 );
56}
57
58static inline void rech_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
59{
60 __asm__ (
61 ".align8\n"
62 "1:"
63 "movq (%1),%%mm0\n" /* 8 s */
64 "movq 8(%1),%%mm1\n" /* 8 s */
65 "movq 1(%1),%%mm2\n" /* 8 s */
66 "movq 9(%1),%%mm3\n" /* 8 s */
67
68 "pavgusb %%mm2, %%mm0\n"
69 "addl %3, %1\n"
70 "pavgusb %%mm3, %%mm1\n"
71
72 "movq %%mm0,(%2)\n"
73 "movq %%mm1,8(%2)\n"
74 "addl %3, %2\n"
75 "loop 1b\n"
76 :
77 : "c" (h), "r" (s), "r" (d), "r" (lx2)
78 );
79}
80
81static inline void rechc_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
82{
83 __asm__ (
84 ".align8\n"
85 "1:"
86 "movq (%1),%%mm0\n" /* 8 s */
87 "movq 1(%1),%%mm2\n" /* 8 s +1 */
88 "addl %3, %1\n"
89 "pavgusb %%mm2, %%mm0\n"
90 "movq %%mm0,(%2)\n"
91 "addl %3, %2\n"
92 "loop 1b\n"
93 :
94 : "c" (h), "r" (s), "r" (d), "r" (lx2)
95 );
96}
97
98static inline void recha_mmx(unsigned char *s, unsigned char *d,int lx2, int h)
99{
100 __asm__ (
101 ".align8\n"
102 "1:"
103 "movq (%1),%%mm0\n" /* 8 s */
104 "movq 8(%1),%%mm1\n" /* 8 s */
105 "movq 1(%1),%%mm2\n" /* 8 s */
106 "movq 9(%1),%%mm3\n" /* 8 s */
107
108 "pavgusb %%mm2, %%mm0\n"
109 "addl %3, %1\n"
110 "pavgusb %%mm3, %%mm1\n"
111
112 "movq (%2),%%mm2\n" /* 8 d */
113 "movq 8(%2),%%mm3\n" /* 8 d */
114 "pavgusb %%mm2, %%mm0\n"
115 "pavgusb %%mm3, %%mm1\n"
116
117 "movq %%mm0,(%2)\n"
118 "movq %%mm1,8(%2)\n"
119 "addl %3, %2\n"
120 "loop 1b\n"
121 :
122 : "c" (h), "r" (s), "r" (d), "r" (lx2)
123 );
124}
125
126static inline void rechac_mmx(unsigned char *s,unsigned char *d, int lx2, int h)
127{
128 __asm__ (
129 ".align8\n"
130 "1:"
131 "movq (%1),%%mm0\n" /* 8 s */
132 "movq 1(%1),%%mm2\n" /* 8 s */
133
134 "addl %3, %1\n"
135 "pavgusb %%mm2, %%mm0\n"
136
137 "movq (%2),%%mm1\n" /* 8 d */
138 "pavgusb %%mm1, %%mm0\n"
139
140 "movq %%mm0,(%2)\n"
141 "addl %3, %2\n"
142 "loop 1b\n"
143 :
144 : "c" (h), "r" (s), "r" (d), "r" (lx2)
145 );
146}
147
148static inline void rec4_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
149{
150 __asm__ __volatile__(
151 "movq (%1),%%mm0\n" /* 8 s */
152 "movq 8(%1),%%mm1\n" /* 8 s */
153 "movq 1(%1),%%mm2\n" /* 8 s +1*/
154 "movq 9(%1),%%mm3\n" /* 8 s +1*/
155 ".align 8\n"
156 "1:"
157 "movq (%4),%%mm4\n" /* 8 s+lx */
158 "pavgusb %%mm2, %%mm0\n"
159 "movq 8(%4),%%mm5\n" /* 8 s+lx */
160 "pavgusb %%mm3, %%mm1\n"
161
162 "movq 1(%4),%%mm6\n" /* 8 s+lx +1*/
163 "pavgusb %%mm4, %%mm0\n"
164 "movq 9(%4),%%mm7\n" /* 8 s+lx +1*/
165 "pavgusb %%mm5, %%mm1\n"
166
167 "pavgusb %%mm6, %%mm0\n"
168 "addl %3, %4\n"
169 "pavgusb %%mm7, %%mm1\n"
170 "movq %%mm0,(%2)\n"
171 "movq %%mm6,%%mm2\n"
172 "movq %%mm7,%%mm3\n"
173 "movq %%mm1,8(%2)\n"
174 "movq %%mm4,%%mm0\n"
175 "movq %%mm5,%%mm1\n"
176 "addl %3, %2\n"
177 "loop 1b\n"
178 :
179 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
180 );
181}
182
183static inline void rec4c_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
184{
185 __asm__ __volatile__(
186 "movq (%1),%%mm0\n" /* 8 s */
187 "movq 1(%1),%%mm2\n" /* 8 s +1*/
188 ".align 8\n"
189 "1:"
190 "movq (%4),%%mm4\n" /* 8 s+lx */
191 "pavgusb %%mm2, %%mm0\n"
192
193 "movq 1(%4),%%mm6\n" /* 8 s+lx +1*/
194 "pavgusb %%mm4, %%mm0\n"
195
196 "addl %3, %4\n"
197 "pavgusb %%mm6, %%mm0\n"
198 "movq %%mm0,(%2)\n"
199 "movq %%mm6,%%mm2\n"
200 "movq %%mm4,%%mm0\n"
201 "addl %3, %2\n"
202 "loop 1b\n"
203 :
204 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
205 );
206}
207
208static inline void rec4a_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
209{
210 __asm__ __volatile__(
211 "movq (%1),%%mm0\n" /* 8 s */
212 "movq 8(%1),%%mm1\n" /* 8 s */
213 "movq 1(%1),%%mm2\n" /* 8 s +1*/
214 "movq 9(%1),%%mm3\n" /* 8 s +1*/
215 ".align 8\n"
216 "1:"
217 "movq (%4),%%mm4\n" /* 8 s+lx */
218 "pavgusb %%mm2, %%mm0\n"
219 "movq 8(%4),%%mm5\n" /* 8 s+lx */
220 "pavgusb %%mm3, %%mm1\n"
221
222 "movq 1(%4),%%mm6\n" /* 8 s+lx +1*/
223 "pavgusb %%mm4, %%mm0\n"
224 "movq 9(%4),%%mm7\n" /* 8 s+lx +1*/
225 "pavgusb %%mm5, %%mm1\n"
226 "movq (%2),%%mm2\n"
227 "pavgusb %%mm6, %%mm0\n"
228 "movq 8(%2),%%mm3\n"
229
230 "pavgusb %%mm2, %%mm0\n"
231 "addl %3, %4\n"
232 "pavgusb %%mm3, %%mm1\n"
233 "movq %%mm0,(%2)\n"
234
235 "pavgusb %%mm7, %%mm1\n"
236 "movq %%mm6,%%mm2\n"
237 "movq %%mm7,%%mm3\n"
238 "movq %%mm1,8(%2)\n"
239 "movq %%mm4,%%mm0\n"
240 "movq %%mm5,%%mm1\n"
241 "addl %3, %2\n"
242 "loop 1b\n"
243 :
244 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
245 );
246}
247
248static inline void rec4ac_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
249{
250 __asm__ __volatile__(
251 "movq (%1),%%mm0\n" /* 8 s */
252 "movq 1(%1),%%mm2\n" /* 8 s +1*/
253 ".align 8\n"
254 "1:"
255 "movq (%4),%%mm4\n" /* 8 s+lx */
256 "pavgusb %%mm2, %%mm0\n"
257
258 "movq 1(%4),%%mm6\n" /* 8 s+lx +1*/
259 "pavgusb %%mm4, %%mm0\n"
260 "movq (%2),%%mm1\n" /* 8 d */
261 "pavgusb %%mm6, %%mm0\n"
262 "addl %3, %4\n"
263 "pavgusb %%mm1, %%mm0\n"
264 "movq %%mm6,%%mm2\n"
265 "movq %%mm0,(%2)\n"
266 "movq %%mm4,%%mm0\n"
267 "addl %3, %2\n"
268 "loop 1b\n"
269 :
270 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
271 );
272}
273
274#else // HAVE_3DNOW
275 static LONGLONG ADD_1 =0x0101010101010101LL;
276 static LONGLONG MASK_AND = 0x7f7f7f7f7f7f7f7fLL;
277#endif
278
279static inline void rec_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
280{
281 __asm__ __volatile__(
282 ".align 8\n"
283 "1:\t"
284 "movq ( %1 ), %%mm0\n" /* 8 s */
285 "movq 8( %1 ), %%mm2\n" /* 16 s */
286 "movq %%mm0, ( %2 )\n"
287 "addl %3, %1\n"
288 "movq %%mm2, 8( %2 )\n"
289 "decl %0\n"
290 "leal (%2, %3), %2\n"
291 "jnz 1b"
292 :
293 : "c" (h), "r" (s), "r" (d), "r" (lx2)
294 );
295}
296
297
298static inline void recc_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
299{
300 __asm__ __volatile__(
301 ".align 8\n"
302 "1:\t"
303 "movq ( %1 ), %%mm0\n"
304 "addl %3, %1\n"
305 "movq %%mm0, ( %2 )\n"
306 "decl %0\n"
307 "leal (%2, %3), %2\n"
308 "jnz 1b"
309 :
310 : "c" (h), "r" (s), "r" (d), "r" (lx2)
311 );
312}
313
314
315static inline void reca_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
316{
317#ifdef HAVE_3Dnow
318 __asm__ (
319 ".align8\n"
320 "1:"
321 "movq (%1),%%mm0\n" /* 8 s */
322 "movq (%2),%%mm2\n" /* 8 d */
323 "movq 8(%1),%%mm1\n" /* 8 s */
324 "movq 8(%2),%%mm3\n" /* 8 d */
325 "pavgusb %%mm2, %%mm0\n"
326 "addl %3, %1\n"
327 "pavgusb %%mm3, %%mm1\n"
328
329 "movq %%mm0,(%2)\n"
330 "movq %%mm1,8(%2)\n"
331 "addl %3, %2\n"
332 "loop 1b\n"
333 :
334 : "c" (h), "r" (s), "r" (d), "r" (lx2)
335 );
336#else /* No 3dnow */
337 __asm__ (
338 "movq MASK_AND, %%mm5\n"
339 "movq ADD_1, %%mm6\n"
340 "1:\t"
341 "movq (%1),%%mm0\n" /* Load 16 pixels from each row */
342 "movq (%2),%%mm1\n"
343 "movq 8(%1),%%mm2\n"
344 "movq 8(%2),%%mm3\n"
345 "psrlw $1,%%mm0\n" /* Shift pixels down */
346 "psrlw $1,%%mm1\n"
347 "pand %%mm5,%%mm0\n" /* Zero out significant bit */
348 "psrlw $1,%%mm2\n"
349 "pand %%mm5,%%mm1\n"
350 "psrlw $1,%%mm3\n"
351 "pand %%mm5,%%mm2\n"
352 "paddusb %%mm1,%%mm0\n" /* Add pixels */
353 "pand %%mm5,%%mm3\n"
354 "paddusb %%mm3,%%mm2\n"
355 "paddusb %%mm6,%%mm0\n" /* Add 1 to results */
356 "paddusb %%mm6,%%mm2\n"
357 "movq %%mm0,(%2)\n"
358 "addl %3,%1\n"
359 "movq %%mm2, 8(%2)\n"
360 "decl %0\n"
361 "leal (%2, %3), %2\n"
362 "jnz 1b\n"
363 :
364 : "c" (h), "r" (s), "r" (d), "r" (lx2)
365 );
366#endif
367}
368
369
370static inline void recac_mmx(unsigned char *s, unsigned char *d, int lx2, int h)
371{
372#ifdef HAVE_3Dnow
373 __asm__ (
374 ".align8\n"
375 "1:"
376 "movq (%1),%%mm0\n" /* 8 s */
377 "movq (%2),%%mm2\n" /* 8 d */
378 "pavgusb %%mm2, %%mm0\n"
379 "addl %3, %1\n"
380 "movq %%mm0,(%2)\n"
381 "addl %3, %2\n"
382 "loop 1b\n"
383 :
384 : "c" (h), "r" (s), "r" (d), "r" (lx2)
385 );
386#else /* No 3dnow */
387 __asm__ (
388 "movq MASK_AND, %%mm5\n"
389 "movq ADD_1, %%mm6\n"
390 "1:\t"
391 "movq (%1),%%mm0\n"
392 "movq (%2),%%mm1\n"
393 "psrlw $1,%%mm0\n"
394 "psrlw $1,%%mm1\n"
395 "pand %%mm5,%%mm0\n"
396 "pand %%mm5,%%mm1\n"
397 "paddusb %%mm1,%%mm0\n"
398 "paddusb %%mm6,%%mm0\n"
399 "addl %3,%1\n"
400 "movq %%mm0,(%2)\n"
401 "decl %0\n"
402 "leal (%2, %3), %2\n"
403 "jnz 1b\n"
404 :
405 : "c" (h), "r" (s), "r" (d), "r" (lx2)
406 );
407#endif
408}
409
410
411static inline void recv_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
412{
413#ifdef HAVE_3Dnow
414 __asm__(
415 ".align8\n"
416 "1:"
417 "movq (%1),%%mm0\n" /* 8 s */
418 "movq (%4),%%mm2\n" /* 8 s +lx */
419 "movq 8(%1),%%mm1\n" /* 8 s */
420 "movq 8(%4),%%mm3\n" /* 8 s +lx **/
421
422 "pavgusb %%mm2, %%mm0\n"
423 "addl %3, %1\n"
424 "pavgusb %%mm3, %%mm1\n"
425
426 "movq %%mm0,(%2)\n"
427 "addl %3, %4\n"
428 "movq %%mm1,8(%2)\n"
429 "addl %3, %2\n"
430 "loop 1b\n"
431 :
432 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
433 );
434#else
435 __asm__ (
436 "movq MASK_AND, %%mm5\n"
437 "movq ADD_1, %%mm6\n"
438 "1:\t"
439 "movq (%1),%%mm0\n" /* 8 s */
440 "movq (%4),%%mm1\n" /* 8 s +lx */
441 "movq 8(%1),%%mm2\n" /* 8 s */
442 "movq 8(%4),%%mm3\n" /* 8 s +lx **/
443 "psrlw $1,%%mm0\n"
444 "psrlw $1,%%mm1\n"
445 "pand %%mm5,%%mm0\n"
446 "psrlw $1,%%mm2\n"
447 "pand %%mm5,%%mm1\n"
448 "psrlw $1,%%mm3\n"
449 "pand %%mm5,%%mm2\n"
450 "paddusb %%mm1,%%mm0\n"
451 "pand %%mm5,%%mm3\n"
452 "paddusb %%mm3,%%mm2\n"
453 "paddusb %%mm6,%%mm0\n"
454 "paddusb %%mm6,%%mm2\n"
455 "movq %%mm0,(%2)\n"
456 "addl %3,%1\n"
457 "movq %%mm2, 8(%2)\n"
458 "addl %3,%4\n"
459 "decl %0\n"
460 "leal (%2, %3), %2\n"
461 "jnz 1b\n"
462 :
463 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
464 );
465#endif
466}
467
468
469static inline void recvc_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
470{
471#ifdef HAVE_3Dnow
472 __asm__(
473 ".align8\n"
474 "1:"
475 "movq (%1),%%mm0\n" /* 8 s */
476 "movq (%4),%%mm2\n" /* 8 s +lx */
477 "addl %3, %1\n"
478 "pavgusb %%mm2, %%mm0\n"
479 "addl %3, %4\n"
480 "movq %%mm0,(%2)\n"
481 "addl %3, %2\n"
482 "loop 1b\n"
483 :
484 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
485 );
486#else
487 __asm__ (
488 "movq MASK_AND, %%mm5\n"
489 "movq ADD_1, %%mm6\n"
490 "1:\t"
491 "movq (%1),%%mm0\n" /* 8 s */
492 "movq (%4),%%mm1\n" /* 8 s +lx */
493 "psrlw $1,%%mm0\n"
494 "psrlw $1,%%mm1\n"
495 "pand %%mm5,%%mm0\n"
496 "pand %%mm5,%%mm1\n"
497 "paddusb %%mm1,%%mm0\n"
498 "addl %3,%1\n"
499 "paddusb %%mm6,%%mm0\n"
500 "addl %3,%4\n"
501 "movq %%mm0,(%2)\n"
502 "decl %0\n"
503 "leal (%2, %3), %2\n"
504 "jnz 1b\n"
505 :
506 : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx)
507 );
508#endif
509}
510
511#endif // HAVE_MMX
512
513static inline void rec(unsigned char *s, unsigned char *d, int lx2, int h)
514{
515 int j;
516 for(j = 0; j < h; j++, s += lx2, d += lx2)
517 {
518 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
519 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
520 d[8] = s[8]; d[9] = s[9]; d[10] = s[10]; d[11] = s[11];
521 d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15];
522 }
523}
524
525
526
527static inline void recc(unsigned char *s, unsigned char *d, int lx2, int h)
528{
529 int j;
530 for(j = 0; j < h; j++, s += lx2, d += lx2)
531 {
532 d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];
533 d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
534 }
535}
536
537static inline void reca(unsigned char *s, unsigned char *d, int lx2, int h)
538{
539 int j;
540 for(j = 0; j < h; j++, s +=lx2, d +=lx2)
541 {
542 d[0] = (unsigned int)(d[0] + s[0] + 1) >> 1;
543 d[1] = (unsigned int)(d[1] + s[1] + 1) >> 1;
544 d[2] = (unsigned int)(d[2] + s[2] + 1) >> 1;
545 d[3] = (unsigned int)(d[3] + s[3] + 1) >> 1;
546 d[4] = (unsigned int)(d[4] + s[4] + 1) >> 1;
547 d[5] = (unsigned int)(d[5] + s[5] + 1) >> 1;
548 d[6] = (unsigned int)(d[6] + s[6] + 1) >> 1;
549 d[7] = (unsigned int)(d[7] + s[7] + 1) >> 1;
550 d[8] = (unsigned int)(d[8] + s[8] + 1) >> 1;
551 d[9] = (unsigned int)(d[9] + s[9] + 1) >> 1;
552 d[10] = (unsigned int)(d[10] + s[10] + 1) >> 1;
553 d[11] = (unsigned int)(d[11] + s[11] + 1) >> 1;
554 d[12] = (unsigned int)(d[12] + s[12] + 1) >> 1;
555 d[13] = (unsigned int)(d[13] + s[13] + 1) >> 1;
556 d[14] = (unsigned int)(d[14] + s[14] + 1) >> 1;
557 d[15] = (unsigned int)(d[15] + s[15] + 1) >> 1;
558 }
559}
560
561static inline void recac(unsigned char *s, unsigned char *d, int lx2, int h)
562{
563 int j;
564 for(j = 0; j < h; j++, s += lx2, d += lx2)
565 {
566 d[0] = (unsigned int)(d[0] + s[0] + 1)>>1;
567 d[1] = (unsigned int)(d[1] + s[1] + 1)>>1;
568 d[2] = (unsigned int)(d[2] + s[2] + 1)>>1;
569 d[3] = (unsigned int)(d[3] + s[3] + 1)>>1;
570 d[4] = (unsigned int)(d[4] + s[4] + 1)>>1;
571 d[5] = (unsigned int)(d[5] + s[5] + 1)>>1;
572 d[6] = (unsigned int)(d[6] + s[6] + 1)>>1;
573 d[7] = (unsigned int)(d[7] + s[7] + 1)>>1;
574 }
575}
576
577static inline void recv_(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
578{
579 unsigned char *dp,*sp,*sp2;
580 int j;
581 sp = s;
582 sp2 = s + lx;
583 dp = d;
584 for(j = 0; j < h; j++)
585 {
586 dp[0] = (unsigned int)(sp[0] + sp2[0] + 1) >> 1;
587 dp[1] = (unsigned int)(sp[1] + sp2[1] + 1) >> 1;
588 dp[2] = (unsigned int)(sp[2] + sp2[2] + 1) >> 1;
589 dp[3] = (unsigned int)(sp[3] + sp2[3] + 1) >> 1;
590 dp[4] = (unsigned int)(sp[4] + sp2[4] + 1) >> 1;
591 dp[5] = (unsigned int)(sp[5] + sp2[5] + 1) >> 1;
592 dp[6] = (unsigned int)(sp[6] + sp2[6] + 1) >> 1;
593 dp[7] = (unsigned int)(sp[7] + sp2[7] + 1) >> 1;
594 dp[8] = (unsigned int)(sp[8] + sp2[8] + 1) >> 1;
595 dp[9] = (unsigned int)(sp[9] + sp2[9] + 1) >> 1;
596 dp[10] = (unsigned int)(sp[10] + sp2[10] + 1) >> 1;
597 dp[11] = (unsigned int)(sp[11] + sp2[11] + 1) >> 1;
598 dp[12] = (unsigned int)(sp[12] + sp2[12] + 1) >> 1;
599 dp[13] = (unsigned int)(sp[13] + sp2[13] + 1) >> 1;
600 dp[14] = (unsigned int)(sp[14] + sp2[14] + 1) >> 1;
601 dp[15] = (unsigned int)(sp[15] + sp2[15] + 1) >> 1;
602 sp+= lx2;
603 sp2+= lx2;
604 dp+= lx2;
605 }
606}
607
608static inline void recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
609{
610 unsigned char *dp,*sp,*sp2;
611 int j;
612
613 sp = s;
614 sp2 = s+lx;
615 dp = d;
616 for(j = 0; j < h; j++)
617 {
618 dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1;
619 dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1;
620 dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1;
621 dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1;
622 dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1;
623 dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1;
624 dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1;
625 dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1;
626 sp+= lx2;
627 sp2+= lx2;
628 dp+= lx2;
629 }
630}
631
632
633static inline void recva(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
634{
635 unsigned char *dp,*sp,*sp2;
636 int j;
637
638 sp = s;
639 sp2 = s+lx;
640 dp = d;
641 for (j=0; j<h; j++){
642 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
643 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
644 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
645 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
646 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
647 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
648 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
649 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
650 dp[8] = (dp[8] + ((unsigned int)(sp[8]+sp2[8]+1)>>1) + 1)>>1;
651 dp[9] = (dp[9] + ((unsigned int)(sp[9]+sp2[9]+1)>>1) + 1)>>1;
652 dp[10] = (dp[10] + ((unsigned int)(sp[10]+sp2[10]+1)>>1) + 1)>>1;
653 dp[11] = (dp[11] + ((unsigned int)(sp[11]+sp2[11]+1)>>1) + 1)>>1;
654 dp[12] = (dp[12] + ((unsigned int)(sp[12]+sp2[12]+1)>>1) + 1)>>1;
655 dp[13] = (dp[13] + ((unsigned int)(sp[13]+sp2[13]+1)>>1) + 1)>>1;
656 dp[14] = (dp[14] + ((unsigned int)(sp[14]+sp2[14]+1)>>1) + 1)>>1;
657 dp[15] = (dp[15] + ((unsigned int)(sp[15]+sp2[15]+1)>>1) + 1)>>1;
658 sp+= lx2;
659 sp2+= lx2;
660 dp+= lx2;
661 }
662}
663
664
665static inline void recvac(unsigned char *s, unsigned char *d, int lx,int lx2, int h){
666 unsigned char *dp,*sp,*sp2;
667 int j;
668
669 sp = s;
670 sp2 = s+lx;
671 dp = d;
672 for (j=0; j<h; j++){
673 dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1;
674 dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1;
675 dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1;
676 dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1;
677 dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1;
678 dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1;
679 dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1;
680 dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1;
681 sp+= lx2;
682 sp2+= lx2;
683 dp+= lx2;
684 }
685}
686
687
688static inline void rech(unsigned char *s, unsigned char *d, int lx2, int h){
689 unsigned char *dp,*sp;
690 unsigned int s1,s2;
691 int j;
692
693 sp = s;
694 dp = d;
695 for (j=0; j<h; j++){
696 s1=sp[0];
697 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
698 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
699 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
700 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
701 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
702 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
703 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
704 dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1;
705 dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1;
706 dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1;
707 dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1;
708 dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1;
709 dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1;
710 dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1;
711 dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1;
712 dp[15] = (unsigned int)(s2+sp[16]+1)>>1;
713 sp+= lx2;
714 dp+= lx2;
715 }
716}
717
718
719static inline void rechc(unsigned char *s,unsigned char *d, int lx2, int h){
720 unsigned char *dp,*sp;
721 unsigned int s1,s2;
722 int j;
723
724 sp = s;
725 dp = d;
726 for (j=0; j<h; j++){
727 s1=sp[0];
728 dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1;
729 dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1;
730 dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1;
731 dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1;
732 dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1;
733 dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1;
734 dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1;
735 dp[7] = (unsigned int)(s2+sp[8]+1)>>1;
736 sp+= lx2;
737 dp+= lx2;
738 }
739}
740
741static inline void recha(unsigned char *s, unsigned char *d,int lx2, int h)
742{
743 unsigned char *dp,*sp;
744 unsigned int s1,s2;
745 int j;
746
747 sp = s;
748 dp = d;
749 for (j = 0; j < h; j++)
750 {
751 s1 = sp[0];
752 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
753 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
754 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
755 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
756 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
757 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
758 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
759 dp[7] = (dp[7] + ((unsigned int)(s2 + (s1 = sp[8]) + 1) >> 1) + 1) >> 1;
760 dp[8] = (dp[8] + ((unsigned int)(s1 + (s2 = sp[9]) + 1) >> 1) + 1) >> 1;
761 dp[9] = (dp[9] + ((unsigned int)(s2 + (s1 = sp[10]) + 1) >> 1) + 1) >> 1;
762 dp[10] = (dp[10] + ((unsigned int)(s1 + (s2 = sp[11]) + 1) >> 1) + 1) >> 1;
763 dp[11] = (dp[11] + ((unsigned int)(s2 + (s1 = sp[12]) + 1) >> 1) + 1) >> 1;
764 dp[12] = (dp[12] + ((unsigned int)(s1 + (s2 = sp[13]) + 1) >> 1) + 1) >> 1;
765 dp[13] = (dp[13] + ((unsigned int)(s2 + (s1 = sp[14]) + 1) >> 1) + 1) >> 1;
766 dp[14] = (dp[14] + ((unsigned int)(s1 + (s2 = sp[15]) + 1) >> 1) + 1) >> 1;
767 dp[15] = (dp[15] + ((unsigned int)(s2 + sp[16] + 1) >> 1) + 1) >> 1;
768 sp += lx2;
769 dp += lx2;
770 }
771}
772
773
774static inline void rechac(unsigned char *s,unsigned char *d, int lx2, int h)
775{
776 unsigned char *dp,*sp;
777 unsigned int s1,s2;
778 int j;
779
780 sp = s;
781 dp = d;
782 for(j = 0; j < h; j++)
783 {
784 s1 = sp[0];
785 dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1;
786 dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1;
787 dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1;
788 dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1;
789 dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1;
790 dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1;
791 dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1;
792 dp[7] = (dp[7] + ((unsigned int)(s2 + sp[8] + 1) >> 1) + 1) >> 1;
793 sp += lx2;
794 dp += lx2;
795 }
796}
797
798
799static inline void rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h)
800{
801 unsigned char *dp,*sp,*sp2;
802 unsigned int s1,s2,s3,s4;
803 int j;
804
805 sp = s;
806 sp2 = s+lx;
807 dp = d;
808 for (j=0; j<h; j++){
809 s1=sp[0]; s3=sp2[0];
810 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
811 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
812 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
813 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
814 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
815 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
816 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
817 dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2;
818 dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2;
819 dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2;
820 dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2;
821 dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2;
822 dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2;
823 dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2;
824 dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2;
825 dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2;
826 sp+= lx2;
827 sp2+= lx2;
828 dp+= lx2;
829 }
830}
831
832
833static inline void rec4c(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
834{
835 unsigned char *dp,*sp,*sp2;
836 unsigned int s1,s2,s3,s4;
837 int j;
838
839 sp = s;
840 sp2 = s+lx;
841 dp = d;
842 for (j=0; j<h; j++){
843 s1=sp[0]; s3=sp2[0];
844 dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2;
845 dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2;
846 dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2;
847 dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2;
848 dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2;
849 dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2;
850 dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2;
851 dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2;
852 sp+= lx2;
853 sp2+= lx2;
854 dp+= lx2;
855 }
856}
857
858
859static inline void rec4a(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
860{
861 unsigned char *dp=d, *sp=s, *sp2=s+lx;
862 unsigned int s1, s2, s3, s4;
863 int j;
864
865/*
866 sp = s;
867 sp2 = s+lx;
868 dp = d;
869*/
870 for (j=0; j<h; j++){
871 s1=sp[0]; s3=sp2[0];
872 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
873 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
874 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
875 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
876 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
877 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
878 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
879 dp[7] = (dp[7] + ((unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2) + 1)>>1;
880 dp[8] = (dp[8] + ((unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2) + 1)>>1;
881 dp[9] = (dp[9] + ((unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2) + 1)>>1;
882 dp[10] = (dp[10] + ((unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2) + 1)>>1;
883 dp[11] = (dp[11] + ((unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2) + 1)>>1;
884 dp[12] = (dp[12] + ((unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2) + 1)>>1;
885 dp[13] = (dp[13] + ((unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2) + 1)>>1;
886 dp[14] = (dp[14] + ((unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2) + 1)>>1;
887 dp[15] = (dp[15] + ((unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2) + 1)>>1;
888 sp+= lx2;
889 sp2+= lx2;
890 dp+= lx2;
891 }
892}
893
894
895static inline void rec4ac(unsigned char *s,unsigned char *d, int lx, int lx2, int h)
896{
897 unsigned char *dp=d, *sp=s, *sp2=s+lx;
898 unsigned int s1,s2,s3,s4;
899 int j;
900
901/*
902 sp = s;
903 sp2 = s+lx;
904 dp = d;
905*/
906 for (j=0; j<h; j++)
907 {
908 s1=sp[0]; s3=sp2[0];
909 dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1;
910 dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1;
911 dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1;
912 dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1;
913 dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1;
914 dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1;
915 dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1;
916 dp[7] = (dp[7] + ((unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2) + 1)>>1;
917 sp+= lx2;
918 sp2+= lx2;
919 dp+= lx2;
920 }
921}
922
923static inline
924void recon_comp(mpeg3video_t *video,
925 unsigned char *src,
926 unsigned char *dst,
927 int lx,
928 int lx2,
929 int w,
930 int h,
931 int x,
932 int y,
933 int dx,
934 int dy,
935 int addflag)
936{
937 int switcher;
938 unsigned char *s, *d;
939
940/* half pel scaling */
941 switcher = (dx & 1) << 3 | (dy & 1) << 2 | w;
942 if(addflag) switcher |= 2;
943/* origins */
944 s = src + lx * (y + (dy >> 1)) + x + (dx >> 1);
945 d = dst + lx * y + x;
946
947// Accelerated functions
948#ifdef HAVE_3Dnow
949 if(video->have_mmx)
950 {
951 switch(switcher)
952 {
953 case 0x3: reca_mmx(s, d, lx2, h); break;
954 case 0x2:recac_mmx(s, d, lx2, h); break;
955 case 0x1:rec_mmx(s, d, lx2, h); break;
956 case 0x0:recc_mmx(s, d, lx2, h); break;
957 case 0x7: recva_mmx(s, d, lx, lx2, h); break;
958 case 0x6: recvac_mmx(s, d, lx, lx2, h); break;
959 case 0x5:recv_mmx(s, d, lx, lx2, h); break;
960 case 0x4:recvc_mmx(s, d, lx, lx2, h); break;
961 case 0x9:rech_mmx(s, d, lx2, h); break;
962 case 0x8: rechc_mmx(s, d, lx2, h); break;
963 }
964 }
965 else
966#endif
967 {
968 switch(switcher)
969 {
970 case 0x3: reca(s, d, lx2, h); break;
971 case 0x2:recac(s, d, lx2, h); break;
972 case 0x1:rec(s, d, lx2, h); break;
973 case 0x0:recc(s, d, lx2, h); break;
974 case 0x7: recva(s, d, lx, lx2, h); break;
975 case 0x6: recvac(s, d, lx, lx2, h); break;
976 case 0x5:recv_(s, d, lx, lx2, h); break;
977 case 0x4:recvc(s, d, lx, lx2, h); break;
978 case 0x9:rech(s, d, lx2, h); break;
979 case 0x8: rechc(s, d, lx2, h); break;
980 }
981 }
982
983// Unaccelerated functions
984 switch(switcher)
985 {
986 case 0xb: recha(s, d, lx2, h); break;
987 case 0xa:rechac(s, d, lx2, h); break;
988 case 0xf: rec4a(s, d, lx, lx2, h); break;
989 case 0xe:rec4ac(s, d, lx, lx2, h); break;
990 case 0xd:rec4(s, d, lx, lx2, h); break;
991 case 0xc:rec4c(s, d, lx, lx2, h); break;
992 }
993}
994
995/*
996 unsigned char *src[]; * prediction source buffer *
997 int sfield; * prediction source field number (0 or 1) *
998 unsigned char *dst[]; * prediction destination buffer *
999 int dfield; * prediction destination field number (0 or 1)*
1000 int lx,lx2; * horizontal offsets *
1001 int w,h; * prediction block/sub-block width, height *
1002 int x,y; * pixel co-ordinates of top-left sample in current MB *
1003 int dx,dy; * horizontal, vertical motion vector *
1004 int addflag; * add prediction error to prediction ? *
1005*/
1006static void recon(mpeg3video_t *video,
1007 unsigned char *src[],
1008 int sfield,
1009 unsigned char *dst[],
1010 int dfield,
1011 int lx,
1012 int lx2,
1013 int w,
1014 int h,
1015 int x,
1016 int y,
1017 int dx,
1018 int dy,
1019 int addflag)
1020{
1021
1022/* Y */
1023 recon_comp(video, (src[0] + (sfield ? (lx2 >> 1) : 0)),
1024 dst[0] + (dfield ? (lx2 >> 1) : 0),
1025 lx, lx2, w, h, x, y, dx, dy, addflag);
1026
1027 if(video->chroma_format != CHROMA444)
1028 {
1029 lx >>= 1;
1030 dx /= 2;
1031 lx2 >>= 1;
1032 w = 0;
1033 x >>= 1;
1034 }
1035
1036 if(video->chroma_format == CHROMA420)
1037 {
1038 h >>= 1;
1039 dy /= 2;
1040 y >>= 1;
1041 }
1042
1043/* Cb */
1044 recon_comp(video, (src[1] + (sfield ? (lx2 >> 1) : 0)),
1045 dst[1] + (dfield ? (lx2 >> 1) : 0),
1046 lx, lx2, w, h, x, y, dx, dy, addflag);
1047
1048/* Cr */
1049 recon_comp(video, (src[2] + (sfield ? (lx2 >> 1) : 0)),
1050 dst[2] + (dfield ? (lx2 >> 1) : 0),
1051 lx, lx2, w, h, x, y, dx, dy, addflag);
1052}
1053
1054#define WIDTH 1
1055
1056int mpeg3video_reconstruct(mpeg3video_t *video,
1057 int bx,
1058 int by,
1059 int mb_type,
1060 int motion_type,
1061 int PMV[2][2][2],
1062 int mv_field_sel[2][2],
1063 int dmvector[2],
1064 int stwtype)
1065{
1066 int currentfield;
1067 unsigned char **predframe;
1068 int DMV[2][2];
1069 int stwtop, stwbot;
1070
1071 stwtop = stwtype % 3; /* 0:temporal, 1 : (spat+temp) / 2, 2 : spatial */
1072 stwbot = stwtype / 3;
1073
1074 if((mb_type & MB_FORWARD) || (video->pict_type == P_TYPE))
1075 {
1076 if(video->pict_struct == FRAME_PICTURE)
1077 {
1078 if((motion_type == MC_FRAME) || !(mb_type & MB_FORWARD))
1079 {
1080/* frame-based prediction */
1081 {
1082 if(stwtop < 2)
1083 recon(video, video->oldrefframe, 0, video->newframe, 0,
1084 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1085 PMV[0][0][0], PMV[0][0][1], stwtop);
1086
1087 if(stwbot < 2)
1088 recon(video, video->oldrefframe, 1, video->newframe, 1,
1089 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1090 PMV[0][0][0], PMV[0][0][1], stwbot);
1091 }
1092 }
1093 else if(motion_type == MC_FIELD) /* field-based prediction */
1094 {
1095/* top field prediction */
1096 if(stwtop < 2)
1097 recon(video, video->oldrefframe, mv_field_sel[0][0], video->newframe, 0,
1098 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
1099 PMV[0][0][0], PMV[0][0][1] >> 1, stwtop);
1100
1101/* bottom field prediction */
1102 if(stwbot < 2)
1103 recon(video, video->oldrefframe, mv_field_sel[1][0], video->newframe, 1,
1104 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1,
1105 PMV[1][0][0], PMV[1][0][1] >> 1, stwbot);
1106 }
1107 else if(motion_type == MC_DMV)
1108 {
1109/* dual prime prediction */
1110/* calculate derived motion vectors */
1111 mpeg3video_calc_dmv(video,
1112 DMV,
1113 dmvector,
1114 PMV[0][0][0],
1115 PMV[0][0][1] >> 1);
1116
1117 if(stwtop < 2)
1118 {
1119/* predict top field from top field */
1120 recon(video, video->oldrefframe, 0, video->newframe, 0,
1121 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
1122 PMV[0][0][0], PMV[0][0][1] >> 1, 0);
1123
1124/* predict and add to top field from bottom field */
1125 recon(video, video->oldrefframe, 1, video->newframe, 0,
1126 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
1127 DMV[0][0], DMV[0][1], 1);
1128 }
1129
1130 if(stwbot < 2)
1131 {
1132/* predict bottom field from bottom field */
1133 recon(video, video->oldrefframe, 1, video->newframe, 1,
1134 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1,
1135 PMV[0][0][0], PMV[0][0][1]>>1, 0);
1136
1137/* predict and add to bottom field from top field */
1138 recon(video, video->oldrefframe, 0, video->newframe, 1,
1139 video->coded_picture_width << 1, video->coded_picture_width<<1, WIDTH, 8, bx, by>>1,
1140 DMV[1][0], DMV[1][1], 1);
1141 }
1142 }
1143 else
1144/* invalid motion_type */
1145 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
1146 ;
1147 }
1148 else
1149 {
1150/* TOP_FIELD or BOTTOM_FIELD */
1151/* field picture */
1152 currentfield = (video->pict_struct == BOTTOM_FIELD);
1153
1154/* determine which frame to use for prediction */
1155 if((video->pict_type == P_TYPE) && video->secondfield
1156 && (currentfield != mv_field_sel[0][0]))
1157 predframe = video->refframe; /* same frame */
1158 else
1159 predframe = video->oldrefframe; /* previous frame */
1160
1161 if((motion_type == MC_FIELD) || !(mb_type & MB_FORWARD))
1162 {
1163/* field-based prediction */
1164 if(stwtop < 2)
1165 recon(video, predframe,mv_field_sel[0][0],video->newframe,0,
1166 video->coded_picture_width << 1,video->coded_picture_width << 1,WIDTH,16,bx,by,
1167 PMV[0][0][0],PMV[0][0][1],stwtop);
1168 }
1169 else
1170 if(motion_type == MC_16X8)
1171 {
1172 if(stwtop < 2)
1173 {
1174 recon(video, predframe, mv_field_sel[0][0], video->newframe, 0,
1175 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1176 PMV[0][0][0], PMV[0][0][1], stwtop);
1177
1178 /* determine which frame to use for lower half prediction */
1179 if((video->pict_type==P_TYPE) && video->secondfield
1180 && (currentfield!=mv_field_sel[1][0]))
1181 predframe = video->refframe; /* same frame */
1182 else
1183 predframe = video->oldrefframe; /* previous frame */
1184
1185 recon(video, predframe, mv_field_sel[1][0], video->newframe, 0,
1186 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
1187 PMV[1][0][0], PMV[1][0][1], stwtop);
1188 }
1189 }
1190 else
1191 if(motion_type == MC_DMV) /* dual prime prediction */
1192 {
1193 if(video->secondfield)
1194 predframe = video->refframe; /* same frame */
1195 else
1196 predframe = video->oldrefframe; /* previous frame */
1197
1198/* calculate derived motion vectors */
1199 mpeg3video_calc_dmv(video,
1200 DMV,
1201 dmvector,
1202 PMV[0][0][0],
1203 PMV[0][0][1]);
1204
1205/* predict from field of same parity */
1206 recon(video, video->oldrefframe, currentfield, video->newframe, 0,
1207 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
1208 PMV[0][0][0], PMV[0][0][1], 0);
1209
1210/* predict from field of opposite parity */
1211 recon(video, predframe, !currentfield, video->newframe, 0,
1212 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
1213 DMV[0][0], DMV[0][1], 1);
1214 }
1215 else
1216/* invalid motion_type */
1217 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
1218 ;
1219 }
1220 stwtop = stwbot = 1;
1221 }
1222
1223 if(mb_type & MB_BACKWARD)
1224 {
1225 if(video->pict_struct == FRAME_PICTURE)
1226 {
1227 if(motion_type == MC_FRAME)
1228 {
1229/* frame-based prediction */
1230 if(stwtop < 2)
1231 recon(video, video->refframe, 0, video->newframe, 0,
1232 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1233 PMV[0][1][0], PMV[0][1][1], stwtop);
1234
1235 if(stwbot < 2)
1236 recon(video, video->refframe, 1, video->newframe, 1,
1237 video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1238 PMV[0][1][0], PMV[0][1][1], stwbot);
1239 }
1240 else
1241 {
1242/* field-based prediction */
1243/* top field prediction */
1244 if(stwtop < 2)
1245 {
1246 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
1247 (video->coded_picture_width << 1), (video->coded_picture_width<<1), WIDTH, 8, bx, (by >> 1),
1248 PMV[0][1][0], (PMV[0][1][1] >> 1), stwtop);
1249 }
1250
1251/* bottom field prediction */
1252 if(stwbot < 2)
1253 {
1254 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 1, (video->coded_picture_width << 1),
1255 (video->coded_picture_width << 1), WIDTH, 8, bx, (by>>1),
1256 PMV[1][1][0], (PMV[1][1][1]>>1), stwbot);
1257 }
1258 }
1259 }
1260 else
1261 {
1262/* TOP_FIELD or BOTTOM_FIELD */
1263/* field picture */
1264 if(motion_type == MC_FIELD)
1265 {
1266/* field-based prediction */
1267 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
1268 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by,
1269 PMV[0][1][0], PMV[0][1][1], stwtop);
1270 }
1271 else if(motion_type==MC_16X8)
1272 {
1273 recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0,
1274 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by,
1275 PMV[0][1][0], PMV[0][1][1], stwtop);
1276
1277 recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 0,
1278 video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8,
1279 PMV[1][1][0], PMV[1][1][1], stwtop);
1280 }
1281 else
1282/* invalid motion_type */
1283 /* fprintf(stderr, "reconstruct: invalid motion_type\n"); */
1284 ;
1285 }
1286 } /* mb_type & MB_BACKWARD */
1287 return 0;
1288}
1289
1290