]> git.sesse.net Git - vlc/blob - plugins/motion/motion.c
* ALL: the first libvlc commit.
[vlc] / plugins / 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.17 2002/06/01 12:32:00 sam 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 and extern prototypes.
35  *****************************************************************************/
36 static void motion_getfunctions( function_list_t * p_function_list );
37
38 /*****************************************************************************
39  * Build configuration tree.
40  *****************************************************************************/
41 MODULE_CONFIG_START
42 MODULE_CONFIG_STOP
43
44 MODULE_INIT_START
45     SET_DESCRIPTION( _("motion compensation module") )
46     ADD_CAPABILITY( MOTION, 50 )
47     ADD_SHORTCUT( "c" )
48 MODULE_INIT_STOP
49
50 MODULE_ACTIVATE_START
51     motion_getfunctions( &p_module->p_functions->motion );
52 MODULE_ACTIVATE_STOP
53
54 MODULE_DEACTIVATE_START
55 MODULE_DEACTIVATE_STOP
56
57 /*****************************************************************************
58  * Simple motion compensation in C
59  *****************************************************************************/
60
61 #define avg2(a,b) ((a+b+1)>>1)
62 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
63
64 #define predict_o(i) (ref[i])
65 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
66 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
67 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
68
69 #define put(predictor,i) dest[i] = predictor (i)
70 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
71
72 // mc function template
73
74 #define MC_FUNC(op,xy)                                                      \
75 static void MC_##op##_##xy##16_c (yuv_data_t * dest, yuv_data_t * ref,      \
76                                  int stride, int height)                    \
77 {                                                                           \
78     do {                                                                    \
79         op (predict_##xy, 0);                                               \
80         op (predict_##xy, 1);                                               \
81         op (predict_##xy, 2);                                               \
82         op (predict_##xy, 3);                                               \
83         op (predict_##xy, 4);                                               \
84         op (predict_##xy, 5);                                               \
85         op (predict_##xy, 6);                                               \
86         op (predict_##xy, 7);                                               \
87         op (predict_##xy, 8);                                               \
88         op (predict_##xy, 9);                                               \
89         op (predict_##xy, 10);                                              \
90         op (predict_##xy, 11);                                              \
91         op (predict_##xy, 12);                                              \
92         op (predict_##xy, 13);                                              \
93         op (predict_##xy, 14);                                              \
94         op (predict_##xy, 15);                                              \
95         ref += stride;                                                      \
96         dest += stride;                                                     \
97     } while (--height);                                                     \
98 }                                                                           \
99 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref,       \
100                                 int stride, int height)                     \
101 {                                                                           \
102     do {                                                                    \
103         op (predict_##xy, 0);                                               \
104         op (predict_##xy, 1);                                               \
105         op (predict_##xy, 2);                                               \
106         op (predict_##xy, 3);                                               \
107         op (predict_##xy, 4);                                               \
108         op (predict_##xy, 5);                                               \
109         op (predict_##xy, 6);                                               \
110         op (predict_##xy, 7);                                               \
111         ref += stride;                                                      \
112         dest += stride;                                                     \
113     } while (--height);                                                     \
114 }
115
116 // definitions of the actual mc functions
117
118 MC_FUNC (put,o)
119 MC_FUNC (avg,o)
120 MC_FUNC (put,x)
121 MC_FUNC (avg,x)
122 MC_FUNC (put,y)
123 MC_FUNC (avg,y)
124 MC_FUNC (put,xy)
125 MC_FUNC (avg,xy)
126
127 /*****************************************************************************
128  * Functions exported as capabilities. They are declared as static so that
129  * we don't pollute the namespace too much.
130  *****************************************************************************/
131 static void motion_getfunctions( function_list_t * p_function_list )
132 {
133     static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *,
134                                            int, int ) =
135     {
136         {
137             /* Copying functions */
138             {
139                 /* Width == 16 */
140                 MC_put_o16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c
141             },
142             {
143                 /* Width == 8 */
144                 MC_put_o8_c,  MC_put_x8_c,  MC_put_y8_c, MC_put_xy8_c
145             }
146         },
147         {
148             /* Averaging functions */
149             {
150                 /* Width == 16 */
151                 MC_avg_o16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c
152             },
153             {
154                 /* Width == 8 */
155                 MC_avg_o8_c,  MC_avg_x8_c,  MC_avg_y8_c,  MC_avg_xy8_c
156             }
157         }
158     };
159
160 #define list p_function_list->functions.motion
161     memcpy( list.ppppf_motion, ppppf_motion, sizeof( void * ) * 16 );
162 #undef list
163
164     return;
165 }