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 $
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 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
33 /*****************************************************************************
34 * Local and extern prototypes.
35 *****************************************************************************/
36 static void motion_getfunctions( function_list_t * p_function_list );
38 /*****************************************************************************
39 * Build configuration tree.
40 *****************************************************************************/
45 SET_DESCRIPTION( _("motion compensation module") )
46 ADD_CAPABILITY( MOTION, 50 )
51 motion_getfunctions( &p_module->p_functions->motion );
54 MODULE_DEACTIVATE_START
55 MODULE_DEACTIVATE_STOP
57 /*****************************************************************************
58 * Simple motion compensation in C
59 *****************************************************************************/
61 #define avg2(a,b) ((a+b+1)>>1)
62 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
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]))
69 #define put(predictor,i) dest[i] = predictor (i)
70 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
72 // mc function template
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) \
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); \
99 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref, \
100 int stride, int height) \
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); \
113 } while (--height); \
116 // definitions of the actual mc functions
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 )
133 static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *,
137 /* Copying functions */
140 MC_put_o16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c
144 MC_put_o8_c, MC_put_x8_c, MC_put_y8_c, MC_put_xy8_c
148 /* Averaging functions */
151 MC_avg_o16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c
155 MC_avg_o8_c, MC_avg_x8_c, MC_avg_y8_c, MC_avg_xy8_c
160 #define list p_function_list->functions.motion
161 memcpy( list.ppppf_motion, ppppf_motion, sizeof( void * ) * 16 );