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