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 $
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() */
37 #include "common.h" /* boolean_t, byte_t */
44 #include "modules_export.h"
46 /*****************************************************************************
47 * Local and extern prototypes.
48 *****************************************************************************/
49 static void motion_getfunctions( function_list_t * p_function_list );
51 /*****************************************************************************
52 * Build configuration tree.
53 *****************************************************************************/
55 ADD_WINDOW( "Configuration for motion compensation module" )
56 ADD_COMMENT( "Ha, ha -- nothing to configure yet" )
60 p_module->i_capabilities = MODULE_CAPABILITY_NULL
61 | MODULE_CAPABILITY_MOTION;
62 p_module->psz_longname = "motion compensation module";
66 motion_getfunctions( &p_module->p_functions->motion );
69 MODULE_DEACTIVATE_START
70 MODULE_DEACTIVATE_STOP
72 /*****************************************************************************
73 * motion_Probe: tests probe the CPU and return a score
74 *****************************************************************************/
75 static int motion_Probe( probedata_t *p_data )
77 if( TestMethod( MOTION_METHOD_VAR, "motion" )
78 || TestMethod( MOTION_METHOD_VAR, "c" ) )
83 /* This module always works */
87 /*****************************************************************************
88 * Simple motion compensation in C
89 *****************************************************************************/
91 #define avg2(a,b) ((a+b+1)>>1)
92 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
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]))
99 #define put(predictor,i) dest[i] = predictor (i)
100 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
102 // mc function template
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) \
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); \
127 } while (--height); \
129 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref, \
130 int stride, int height) \
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); \
143 } while (--height); \
146 // definitions of the actual mc functions
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 )
163 static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *,
167 /* Copying functions */
170 MC_put_16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c
174 MC_put_8_c, MC_put_x8_c, MC_put_y8_c, MC_put_xy8_c
178 /* Averaging functions */
181 MC_avg_16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c
185 MC_avg_8_c, MC_avg_x8_c, MC_avg_y8_c, MC_avg_xy8_c
190 p_function_list->pf_probe = motion_Probe;
192 #define list p_function_list->functions.motion
193 memcpy( list.ppppf_motion, ppppf_motion, sizeof( void * ) * 16 );