* modules/*: sanitization of the modules description strings.
[vlc.git] / modules / codec / mpeg_video / motion / motion.c
1 /*****************************************************************************
2  * motion.c : C motion compensation module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: motion.c,v 1.3 2003/03/30 18:14:37 gbazin Exp $
6  *
7  * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
8  *          Michel Lespinasse <walken@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32
33 /*****************************************************************************
34  * Local prototype
35  *****************************************************************************/
36 static int Open ( vlc_object_t * );
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41 vlc_module_begin();
42     set_description( _("motion compensation") );
43     set_capability( "motion compensation", 50 );
44     add_shortcut( "c" );
45     set_callbacks( Open, NULL );
46 vlc_module_end();
47
48 /*****************************************************************************
49  * Simple motion compensation in C
50  *****************************************************************************/
51
52 #define avg2(a,b) ((a+b+1)>>1)
53 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
54
55 #define predict_o(i) (ref[i])
56 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
57 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
58 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
59
60 #define put(predictor,i) dest[i] = predictor (i)
61 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
62
63 /* mc function template */
64
65 #define MC_FUNC(op,xy)                                                      \
66 static void MC_##op##_##xy##16_c (yuv_data_t * dest, yuv_data_t * ref,      \
67                                  int stride, int height)                    \
68 {                                                                           \
69     do {                                                                    \
70         op (predict_##xy, 0);                                               \
71         op (predict_##xy, 1);                                               \
72         op (predict_##xy, 2);                                               \
73         op (predict_##xy, 3);                                               \
74         op (predict_##xy, 4);                                               \
75         op (predict_##xy, 5);                                               \
76         op (predict_##xy, 6);                                               \
77         op (predict_##xy, 7);                                               \
78         op (predict_##xy, 8);                                               \
79         op (predict_##xy, 9);                                               \
80         op (predict_##xy, 10);                                              \
81         op (predict_##xy, 11);                                              \
82         op (predict_##xy, 12);                                              \
83         op (predict_##xy, 13);                                              \
84         op (predict_##xy, 14);                                              \
85         op (predict_##xy, 15);                                              \
86         ref += stride;                                                      \
87         dest += stride;                                                     \
88     } while (--height);                                                     \
89 }                                                                           \
90 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref,       \
91                                 int stride, int height)                     \
92 {                                                                           \
93     do {                                                                    \
94         op (predict_##xy, 0);                                               \
95         op (predict_##xy, 1);                                               \
96         op (predict_##xy, 2);                                               \
97         op (predict_##xy, 3);                                               \
98         op (predict_##xy, 4);                                               \
99         op (predict_##xy, 5);                                               \
100         op (predict_##xy, 6);                                               \
101         op (predict_##xy, 7);                                               \
102         ref += stride;                                                      \
103         dest += stride;                                                     \
104     } while (--height);                                                     \
105 }
106
107 /* definitions of the actual mc functions */
108
109 MC_FUNC (put,o)
110 MC_FUNC (avg,o)
111 MC_FUNC (put,x)
112 MC_FUNC (avg,x)
113 MC_FUNC (put,y)
114 MC_FUNC (avg,y)
115 MC_FUNC (put,xy)
116 MC_FUNC (avg,xy)
117
118 /*****************************************************************************
119  * Functions exported as capabilities. They are declared as static so that
120  * we don't pollute the namespace too much.
121  *****************************************************************************/
122 static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *, int, int ) =
123 {
124     /* Copying functions */
125     {
126         /* Width == 16 */
127         { MC_put_o16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c },
128         /* Width == 8 */
129         { MC_put_o8_c,  MC_put_x8_c,  MC_put_y8_c, MC_put_xy8_c }
130     },
131     /* Averaging functions */
132     {
133         /* Width == 16 */
134         { MC_avg_o16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c },
135         /* Width == 8 */
136         { MC_avg_o8_c,  MC_avg_x8_c,  MC_avg_y8_c,  MC_avg_xy8_c }
137     }
138 };
139
140 static int Open ( vlc_object_t *p_this )
141 {
142     p_this->p_private = ppppf_motion;
143     return VLC_SUCCESS;
144 }
145