1 /*****************************************************************************
2 * vdec_motion.c : motion compensation routines
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <sys/types.h> /* on BSD, uio.h needs types.h */
28 #include <sys/uio.h> /* for input.h */
39 #include "decoder_fifo.h"
41 #include "video_output.h"
43 #include "vdec_idct.h"
44 #include "video_decoder.h"
45 #include "vdec_motion.h"
47 #include "vpar_blocks.h"
48 #include "vpar_headers.h"
49 #include "vpar_synchro.h"
50 #include "video_parser.h"
51 #include "video_fifo.h"
53 #define __MotionComponent_x_y_copy(width,height) \
54 void MotionComponent_x_y_copy_##width##_##height(yuv_data_t * p_src, \
55 yuv_data_t * p_dest, \
60 for( i_y = 0; i_y < height; i_y ++ ) \
62 for( i_x = 0; i_x < width; i_x++ ) \
64 p_dest[i_x] = p_src[i_x]; \
71 #define __MotionComponent_X_y_copy(width,height) \
72 void MotionComponent_X_y_copy_##width##_##height(yuv_data_t * p_src, \
73 yuv_data_t * p_dest, \
78 for( i_y = 0; i_y < height; i_y ++ ) \
80 for( i_x = 0; i_x < width; i_x++ ) \
82 p_dest[i_x] = (unsigned int)(p_src[i_x] \
91 #define __MotionComponent_x_Y_copy(width,height) \
92 void MotionComponent_x_Y_copy_##width##_##height(yuv_data_t * p_src, \
93 yuv_data_t * p_dest, \
99 for( i_y = 0; i_y < height; i_y ++ ) \
101 for( i_x = 0; i_x < width; i_x++ ) \
103 p_dest[i_x] = (unsigned int)(p_src[i_x] \
104 + p_src[i_x + i_step] \
107 p_dest += i_stride; \
112 #define __MotionComponent_X_Y_copy(width,height) \
113 void MotionComponent_X_Y_copy_##width##_##height(yuv_data_t * p_src, \
114 yuv_data_t * p_dest, \
120 for( i_y = 0; i_y < height; i_y ++ ) \
122 for( i_x = 0; i_x < width; i_x++ ) \
124 p_dest[i_x] = (unsigned int)(p_src[i_x] \
126 + p_src[i_x + i_step] \
127 + p_src[i_x + i_step + 1] \
130 p_dest += i_stride; \
135 #define __MotionComponent_x_y_avg(width,height) \
136 void MotionComponent_x_y_avg_##width##_##height(yuv_data_t * p_src, \
137 yuv_data_t * p_dest, \
141 unsigned int i_dummy; \
143 for( i_y = 0; i_y < height; i_y ++ ) \
145 for( i_x = 0; i_x < width; i_x++ ) \
147 i_dummy = p_dest[i_x] + p_src[i_x]; \
148 p_dest[i_x] = (i_dummy + 1) >> 1; \
150 p_dest += i_stride; \
155 #define __MotionComponent_X_y_avg(width,height) \
156 void MotionComponent_X_y_avg_##width##_##height(yuv_data_t * p_src, \
157 yuv_data_t * p_dest, \
161 unsigned int i_dummy; \
163 for( i_y = 0; i_y < height; i_y ++ ) \
165 for( i_x = 0; i_x < width; i_x++ ) \
167 i_dummy = p_dest[i_x] + ((unsigned int)(p_src[i_x] \
170 p_dest[i_x] = (i_dummy + 1) >> 1; \
172 p_dest += i_stride; \
177 #define __MotionComponent_x_Y_avg(width,height) \
178 void MotionComponent_x_Y_avg_##width##_##height(yuv_data_t * p_src, \
179 yuv_data_t * p_dest, \
184 unsigned int i_dummy; \
186 for( i_y = 0; i_y < height; i_y ++ ) \
188 for( i_x = 0; i_x < width; i_x++ ) \
191 p_dest[i_x] + ((unsigned int)(p_src[i_x] \
192 + p_src[i_x + i_step] \
194 p_dest[i_x] = (i_dummy + 1) >> 1; \
196 p_dest += i_stride; \
201 #define __MotionComponent_X_Y_avg(width,height) \
202 void MotionComponent_X_Y_avg_##width##_##height(yuv_data_t * p_src, \
203 yuv_data_t * p_dest, \
208 unsigned int i_dummy; \
210 for( i_y = 0; i_y < height; i_y ++ ) \
212 for( i_x = 0; i_x < width; i_x++ ) \
215 p_dest[i_x] + ((unsigned int)(p_src[i_x] \
217 + p_src[i_x + i_step] \
218 + p_src[i_x + i_step + 1] \
220 p_dest[i_x] = (i_dummy + 1) >> 1; \
222 p_dest += i_stride; \
227 #define __MotionComponents(width,height) \
228 __MotionComponent_x_y_copy(width,height) \
229 __MotionComponent_X_y_copy(width,height) \
230 __MotionComponent_x_Y_copy(width,height) \
231 __MotionComponent_X_Y_copy(width,height) \
232 __MotionComponent_x_y_avg(width,height) \
233 __MotionComponent_X_y_avg(width,height) \
234 __MotionComponent_x_Y_avg(width,height) \
235 __MotionComponent_X_Y_avg(width,height)
237 __MotionComponents (16,16) /* 444, 422, 420 */
238 __MotionComponents (16,8) /* 444, 422, 420 */
239 __MotionComponents (8,8) /* 422, 420 */
240 __MotionComponents (8,4) /* 420 */
242 __MotionComponents (8,16) /* 422 */