1
|
1 /*
|
|
2 * motion_comp.c
|
36
|
3 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
1
|
4 *
|
|
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
6 *
|
|
7 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * mpeg2dec is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
|
21
|
|
22 #include "config.h"
|
|
23
|
|
24 #include <stdio.h>
|
|
25 #include <inttypes.h>
|
|
26
|
|
27 #include "mpeg2_internal.h"
|
|
28 #include "mm_accel.h"
|
|
29
|
|
30 mc_functions_t mc_functions;
|
|
31
|
|
32 void motion_comp_init (void)
|
|
33 {
|
|
34
|
|
35 #ifdef ARCH_X86
|
|
36 if (config.flags & MM_ACCEL_X86_MMXEXT) {
|
1216
|
37 printf ("libmpeg2: Using MMXEXT for motion compensation\n");
|
1
|
38 mc_functions = mc_functions_mmxext;
|
|
39 } else if (config.flags & MM_ACCEL_X86_3DNOW) {
|
1216
|
40 printf ("libmpeg2: Using 3DNOW for motion compensation\n");
|
1
|
41 mc_functions = mc_functions_3dnow;
|
|
42 } else if (config.flags & MM_ACCEL_X86_MMX) {
|
1216
|
43 printf ("libmpeg2: Using MMX for motion compensation\n");
|
1
|
44 mc_functions = mc_functions_mmx;
|
|
45 } else
|
|
46 #endif
|
|
47 #ifdef LIBMPEG2_MLIB
|
|
48 if (config.flags & MM_ACCEL_MLIB) {
|
1216
|
49 printf ("libmpeg2: Using mlib for motion compensation\n");
|
1
|
50 mc_functions = mc_functions_mlib;
|
|
51 } else
|
|
52 #endif
|
|
53 {
|
1216
|
54 printf ("libmpeg2: No accelerated motion compensation found\n");
|
1
|
55 mc_functions = mc_functions_c;
|
|
56 }
|
|
57 }
|
|
58
|
|
59 #define avg2(a,b) ((a+b+1)>>1)
|
|
60 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
|
|
61
|
|
62 #define predict_(i) (ref[i])
|
|
63 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
|
|
64 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
|
|
65 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
|
|
66
|
|
67 #define put(predictor,i) dest[i] = predictor (i)
|
|
68 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
|
|
69
|
36
|
70 /* mc function template */
|
1
|
71
|
|
72 #define MC_FUNC(op,xy) \
|
|
73 static void MC_##op##_##xy##16_c (uint8_t * dest, uint8_t * ref,\
|
|
74 int stride, int height) \
|
|
75 { \
|
|
76 do { \
|
|
77 op (predict_##xy, 0); \
|
|
78 op (predict_##xy, 1); \
|
|
79 op (predict_##xy, 2); \
|
|
80 op (predict_##xy, 3); \
|
|
81 op (predict_##xy, 4); \
|
|
82 op (predict_##xy, 5); \
|
|
83 op (predict_##xy, 6); \
|
|
84 op (predict_##xy, 7); \
|
|
85 op (predict_##xy, 8); \
|
|
86 op (predict_##xy, 9); \
|
|
87 op (predict_##xy, 10); \
|
|
88 op (predict_##xy, 11); \
|
|
89 op (predict_##xy, 12); \
|
|
90 op (predict_##xy, 13); \
|
|
91 op (predict_##xy, 14); \
|
|
92 op (predict_##xy, 15); \
|
|
93 ref += stride; \
|
|
94 dest += stride; \
|
|
95 } while (--height); \
|
|
96 } \
|
|
97 static void MC_##op##_##xy##8_c (uint8_t * dest, uint8_t * ref, \
|
|
98 int stride, int height) \
|
|
99 { \
|
|
100 do { \
|
|
101 op (predict_##xy, 0); \
|
|
102 op (predict_##xy, 1); \
|
|
103 op (predict_##xy, 2); \
|
|
104 op (predict_##xy, 3); \
|
|
105 op (predict_##xy, 4); \
|
|
106 op (predict_##xy, 5); \
|
|
107 op (predict_##xy, 6); \
|
|
108 op (predict_##xy, 7); \
|
|
109 ref += stride; \
|
|
110 dest += stride; \
|
|
111 } while (--height); \
|
|
112 }
|
|
113
|
36
|
114 /* definitions of the actual mc functions */
|
1
|
115
|
|
116 MC_FUNC (put,)
|
|
117 MC_FUNC (avg,)
|
|
118 MC_FUNC (put,x)
|
|
119 MC_FUNC (avg,x)
|
|
120 MC_FUNC (put,y)
|
|
121 MC_FUNC (avg,y)
|
|
122 MC_FUNC (put,xy)
|
|
123 MC_FUNC (avg,xy)
|
|
124
|
|
125 MOTION_COMP_EXTERN (c)
|