1 /*****************************************************************************
2 * motion.c : C motion compensation module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: motion.c,v 1.9 2001/08/22 17:21:45 massiot Exp $
7 * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
8 * Michel Lespinasse <walken@zoy.org>
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.
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.
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 *****************************************************************************/
25 #define MODULE_NAME motion
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
33 #include <stdlib.h> /* malloc(), free() */
36 #include "common.h" /* boolean_t, byte_t */
42 #include "modules_export.h"
44 /*****************************************************************************
45 * Local and extern prototypes.
46 *****************************************************************************/
47 static void motion_getfunctions( function_list_t * p_function_list );
49 /*****************************************************************************
50 * Build configuration tree.
51 *****************************************************************************/
53 ADD_WINDOW( "Configuration for motion compensation module" )
54 ADD_COMMENT( "Ha, ha -- nothing to configure yet" )
58 p_module->i_capabilities = MODULE_CAPABILITY_NULL
59 | MODULE_CAPABILITY_MOTION;
60 p_module->psz_longname = "motion compensation module";
64 motion_getfunctions( &p_module->p_functions->motion );
67 MODULE_DEACTIVATE_START
68 MODULE_DEACTIVATE_STOP
70 /*****************************************************************************
71 * motion_Probe: tests probe the CPU and return a score
72 *****************************************************************************/
73 static int motion_Probe( probedata_t *p_data )
75 if( TestMethod( MOTION_METHOD_VAR, "motion" )
76 || TestMethod( MOTION_METHOD_VAR, "c" ) )
81 /* This module always works */
85 /*****************************************************************************
86 * Simple motion compensation in C
87 *****************************************************************************/
89 #define avg2(a,b) ((a+b+1)>>1)
90 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
92 #define predict_(i) (ref[i])
93 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
94 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
95 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
97 #define put(predictor,i) dest[i] = predictor (i)
98 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
100 // mc function template
102 #define MC_FUNC(op,xy) \
103 static void MC_##op##_##xy##16_c (yuv_data_t * dest, yuv_data_t * ref, \
104 int stride, int height) \
107 op (predict_##xy, 0); \
108 op (predict_##xy, 1); \
109 op (predict_##xy, 2); \
110 op (predict_##xy, 3); \
111 op (predict_##xy, 4); \
112 op (predict_##xy, 5); \
113 op (predict_##xy, 6); \
114 op (predict_##xy, 7); \
115 op (predict_##xy, 8); \
116 op (predict_##xy, 9); \
117 op (predict_##xy, 10); \
118 op (predict_##xy, 11); \
119 op (predict_##xy, 12); \
120 op (predict_##xy, 13); \
121 op (predict_##xy, 14); \
122 op (predict_##xy, 15); \
125 } while (--height); \
127 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref, \
128 int stride, int height) \
131 op (predict_##xy, 0); \
132 op (predict_##xy, 1); \
133 op (predict_##xy, 2); \
134 op (predict_##xy, 3); \
135 op (predict_##xy, 4); \
136 op (predict_##xy, 5); \
137 op (predict_##xy, 6); \
138 op (predict_##xy, 7); \
141 } while (--height); \
144 // definitions of the actual mc functions
155 /*****************************************************************************
156 * Functions exported as capabilities. They are declared as static so that
157 * we don't pollute the namespace too much.
158 *****************************************************************************/
159 static void motion_getfunctions( function_list_t * p_function_list )
161 static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *,
165 /* Copying functions */
168 MC_put_16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c
172 MC_put_8_c, MC_put_x8_c, MC_put_y8_c, MC_put_xy8_c
176 /* Averaging functions */
179 MC_avg_16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c
183 MC_avg_8_c, MC_avg_x8_c, MC_avg_y8_c, MC_avg_xy8_c
188 p_function_list->pf_probe = motion_Probe;
190 #define list p_function_list->functions.motion
191 memcpy( list.ppppf_motion, ppppf_motion, sizeof( void * ) * 16 );