1 /*****************************************************************************
2 * motion.c : C motion compensation module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: motion.c,v 1.2 2002/08/08 00:35:11 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 /*****************************************************************************
35 *****************************************************************************/
36 static int Open ( vlc_object_t * );
38 /*****************************************************************************
40 *****************************************************************************/
42 set_description( _("motion compensation module") );
43 set_capability( "motion compensation", 50 );
45 set_callbacks( Open, NULL );
48 /*****************************************************************************
49 * Simple motion compensation in C
50 *****************************************************************************/
52 #define avg2(a,b) ((a+b+1)>>1)
53 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
55 #define predict_o(i) (ref[i])
56 #define predict_x(i) (avg2 (ref[i], ref[i+1]))
57 #define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
58 #define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
60 #define put(predictor,i) dest[i] = predictor (i)
61 #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
63 /* mc function template */
65 #define MC_FUNC(op,xy) \
66 static void MC_##op##_##xy##16_c (yuv_data_t * dest, yuv_data_t * ref, \
67 int stride, int height) \
70 op (predict_##xy, 0); \
71 op (predict_##xy, 1); \
72 op (predict_##xy, 2); \
73 op (predict_##xy, 3); \
74 op (predict_##xy, 4); \
75 op (predict_##xy, 5); \
76 op (predict_##xy, 6); \
77 op (predict_##xy, 7); \
78 op (predict_##xy, 8); \
79 op (predict_##xy, 9); \
80 op (predict_##xy, 10); \
81 op (predict_##xy, 11); \
82 op (predict_##xy, 12); \
83 op (predict_##xy, 13); \
84 op (predict_##xy, 14); \
85 op (predict_##xy, 15); \
90 static void MC_##op##_##xy##8_c (yuv_data_t * dest, yuv_data_t * ref, \
91 int stride, int height) \
94 op (predict_##xy, 0); \
95 op (predict_##xy, 1); \
96 op (predict_##xy, 2); \
97 op (predict_##xy, 3); \
98 op (predict_##xy, 4); \
99 op (predict_##xy, 5); \
100 op (predict_##xy, 6); \
101 op (predict_##xy, 7); \
104 } while (--height); \
107 /* definitions of the actual mc functions */
118 /*****************************************************************************
119 * Functions exported as capabilities. They are declared as static so that
120 * we don't pollute the namespace too much.
121 *****************************************************************************/
122 static void (* ppppf_motion[2][2][4])( yuv_data_t *, yuv_data_t *, int, int ) =
124 /* Copying functions */
127 { MC_put_o16_c, MC_put_x16_c, MC_put_y16_c, MC_put_xy16_c },
129 { MC_put_o8_c, MC_put_x8_c, MC_put_y8_c, MC_put_xy8_c }
131 /* Averaging functions */
134 { MC_avg_o16_c, MC_avg_x16_c, MC_avg_y16_c, MC_avg_xy16_c },
136 { MC_avg_o8_c, MC_avg_x8_c, MC_avg_y8_c, MC_avg_xy8_c }
140 static int Open ( vlc_object_t *p_this )
142 p_this->p_private = ppppf_motion;