]> git.sesse.net Git - vlc/blob - plugins/motion/motion.c
fc5496794fff2a24e6c92816c38fbdf7d9cff4a5
[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.11 2001/11/28 15:08:05 massiot 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 #define MODULE_NAME motion
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include <stdlib.h>                                      /* malloc(), free() */
34 #include <string.h>
35
36 #include "config.h"
37 #include "common.h"                                     /* boolean_t, byte_t */
38 #include "intf_msg.h"
39 #include "threads.h"
40 #include "mtime.h"
41 #include "tests.h"
42
43 #include "modules.h"
44 #include "modules_export.h"
45
46 /*****************************************************************************
47  * Local and extern prototypes.
48  *****************************************************************************/
49 static void motion_getfunctions( function_list_t * p_function_list );
50
51 /*****************************************************************************
52  * Build configuration tree.
53  *****************************************************************************/
54 MODULE_CONFIG_START
55 ADD_WINDOW( "Configuration for motion compensation module" )
56     ADD_COMMENT( "Ha, ha -- nothing to configure yet" )
57 MODULE_CONFIG_STOP
58
59 MODULE_INIT_START
60     p_module->i_capabilities = MODULE_CAPABILITY_NULL
61                                 | MODULE_CAPABILITY_MOTION;
62     p_module->psz_longname = "motion compensation module";
63 MODULE_INIT_STOP
64
65 MODULE_ACTIVATE_START
66     motion_getfunctions( &p_module->p_functions->motion );
67 MODULE_ACTIVATE_STOP
68
69 MODULE_DEACTIVATE_START
70 MODULE_DEACTIVATE_STOP
71
72 /*****************************************************************************
73  * motion_Probe: tests probe the CPU and return a score
74  *****************************************************************************/
75 static int motion_Probe( probedata_t *p_data )
76 {
77     if( TestMethod( MOTION_METHOD_VAR, "motion" )
78          || TestMethod( MOTION_METHOD_VAR, "c" ) )
79     {
80         return( 999 );
81     }
82
83     /* This module always works */
84     return( 50 );
85 }
86
87 /*****************************************************************************
88  * Simple motion compensation in C
89  *****************************************************************************/
90
91 #define avg2(a,b) ((a+b+1)>>1)
92 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
93
94 #define predict_(i) (ref[i])
95 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
96 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
97 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
98
99 #define put(predictor,i) dest[i] = predictor (i)
100 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
101
102 // mc function template
103
104 #define MC_FUNC(op,xy)                                                                                \
105 static void MC_##op##_##xy##16_c (yuv_data_t * dest, yuv_data_t * ref,      \
106                                  int stride, int height)                    \
107 {                                                                           \
108     do {                                                                    \
109         op (predict_##xy, 0);                                               \
110         op (predict_##xy, 1);                                               \
111         op (predict_##xy, 2);                                               \
112         op (predict_##xy, 3);                                               \
113         op (predict_##xy, 4);                                               \
114         op (predict_##xy, 5);                                               \
115         op (predict_##xy, 6);                                               \
116         op (predict_##xy, 7);                                               \
117         op (predict_##xy, 8);                                               \
118         op (predict_##xy, 9);                                               \
119         op (predict_##xy, 10);                                              \
120         op (predict_##xy, 11);                                              \
121         op (predict_##xy, 12);                                              \
122         op (predict_##xy, 13);                                              \
123         op (predict_##xy, 14);                                              \
124         op (predict_##xy, 15);                                              \
125         ref += stride;                                                      \
126         dest += stride;                                                     \
127     } while (--height);                                                     \
128 }                                                                           \
129 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref,       \
130                                 int stride, int height)                     \
131 {                                                                           \
132     do {                                                                    \
133         op (predict_##xy, 0);                                               \
134         op (predict_##xy, 1);                                               \
135         op (predict_##xy, 2);                                               \
136         op (predict_##xy, 3);                                               \
137         op (predict_##xy, 4);                                               \
138         op (predict_##xy, 5);                                               \
139         op (predict_##xy, 6);                                               \
140         op (predict_##xy, 7);                                               \
141         ref += stride;                                                      \
142         dest += stride;                                                     \
143     } while (--height);                                                     \
144 }
145
146 // definitions of the actual mc functions
147
148 MC_FUNC (put,)
149 MC_FUNC (avg,)
150 MC_FUNC (put,x)
151 MC_FUNC (avg,x)
152 MC_FUNC (put,y)
153 MC_FUNC (avg,y)
154 MC_FUNC (put,xy)
155 MC_FUNC (avg,xy)
156
157 /*****************************************************************************
158  * Functions exported as capabilities. They are declared as static so that
159  * we don't pollute the namespace too much.
160  *****************************************************************************/
161 static void motion_getfunctions( function_list_t * p_function_list )
162 {
163     static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *,
164                                            int, int ) =
165     {
166         {
167             /* Copying functions */
168             {
169                 /* Width == 16 */
170                 MC_put_16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c
171             },
172             {
173                 /* Width == 8 */
174                 MC_put_8_c,  MC_put_x8_c,  MC_put_y8_c, MC_put_xy8_c
175             }
176         },
177         {
178             /* Averaging functions */
179             {
180                 /* Width == 16 */
181                 MC_avg_16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c
182             },
183             {
184                 /* Width == 8 */
185                 MC_avg_8_c,  MC_avg_x8_c,  MC_avg_y8_c,  MC_avg_xy8_c
186             }
187         }
188     };
189
190     p_function_list->pf_probe = motion_Probe;
191
192 #define list p_function_list->functions.motion
193     memcpy( list.ppppf_motion, ppppf_motion, sizeof( void * ) * 16 );
194 #undef list
195
196     return;
197 }