]> git.sesse.net Git - vlc/blob - src/video_decoder/vdec_motion_inner.c
* Moved video_decoder's headers from include/ to src/video_decoder.
[vlc] / src / video_decoder / vdec_motion_inner.c
1 /*****************************************************************************
2  * vdec_motion_inner.c : motion compensation inner routines
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: vdec_motion_inner.c,v 1.10 2000/12/21 17:19:52 massiot Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Jean-Marc Dressler <polux@via.ecp.fr>
9  *          Michel Lespinasse <walken@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "defs.h"
30
31 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
32 #include <sys/uio.h>                                          /* for input.h */
33
34 #include "config.h"
35 #include "common.h"
36 #include "threads.h"
37 #include "mtime.h"
38 #include "plugins.h"
39
40 #include "intf_msg.h"
41
42 #include "stream_control.h"
43 #include "input_ext-dec.h"
44
45 #include "video.h"
46 #include "video_output.h"
47
48 #include "vdec_idct.h"
49 #include "video_decoder.h"
50 #include "vdec_motion.h"
51
52 #include "vpar_blocks.h"
53 #include "vpar_headers.h"
54 #include "vpar_synchro.h"
55 #include "video_parser.h"
56 #include "video_fifo.h"
57
58 #define __MotionComponent_x_y_copy(width,height)                        \
59 void MotionComponent_x_y_copy_##width##_##height(yuv_data_t * p_src,    \
60                                                  yuv_data_t * p_dest,   \
61                                                  int i_stride)          \
62 {                                                                       \
63     int i_x, i_y;                                                       \
64                                                                         \
65     for( i_y = 0; i_y < height; i_y ++ )                                \
66     {                                                                   \
67         for( i_x = 0; i_x < width; i_x++ )                              \
68         {                                                               \
69             p_dest[i_x] = p_src[i_x];                                   \
70         }                                                               \
71         p_dest += i_stride;                                             \
72         p_src += i_stride;                                              \
73     }                                                                   \
74 }
75
76 #define __MotionComponent_X_y_copy(width,height)                        \
77 void MotionComponent_X_y_copy_##width##_##height(yuv_data_t * p_src,    \
78                                                  yuv_data_t * p_dest,   \
79                                                  int i_stride)          \
80 {                                                                       \
81     int i_x, i_y;                                                       \
82                                                                         \
83     for( i_y = 0; i_y < height; i_y ++ )                                \
84     {                                                                   \
85         for( i_x = 0; i_x < width; i_x++ )                              \
86         {                                                               \
87             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
88                                          + p_src[i_x + 1]               \
89                                          + 1) >> 1;                     \
90         }                                                               \
91         p_dest += i_stride;                                             \
92         p_src += i_stride;                                              \
93     }                                                                   \
94 }
95
96 #define __MotionComponent_x_Y_copy(width,height)                        \
97 void MotionComponent_x_Y_copy_##width##_##height(yuv_data_t * p_src,    \
98                                                  yuv_data_t * p_dest,   \
99                                                  int i_stride)          \
100 {                                                                       \
101     int i_x, i_y;                                                       \
102                                                                         \
103     for( i_y = 0; i_y < height; i_y ++ )                                \
104     {                                                                   \
105         for( i_x = 0; i_x < width; i_x++ )                              \
106         {                                                               \
107             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
108                                          + p_src[i_x + i_stride]        \
109                                          + 1) >> 1;                     \
110         }                                                               \
111         p_dest += i_stride;                                             \
112         p_src += i_stride;                                              \
113     }                                                                   \
114 }
115
116 #define __MotionComponent_X_Y_copy(width,height)                        \
117 void MotionComponent_X_Y_copy_##width##_##height(yuv_data_t * p_src,    \
118                                                  yuv_data_t * p_dest,   \
119                                                  int i_stride)          \
120 {                                                                       \
121     int i_x, i_y;                                                       \
122                                                                         \
123     for( i_y = 0; i_y < height; i_y ++ )                                \
124     {                                                                   \
125         for( i_x = 0; i_x < width; i_x++ )                              \
126         {                                                               \
127             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
128                                          + p_src[i_x + 1]               \
129                                          + p_src[i_x + i_stride]        \
130                                          + p_src[i_x + i_stride + 1]    \
131                                          + 2) >> 2;                     \
132         }                                                               \
133         p_dest += i_stride;                                             \
134         p_src += i_stride;                                              \
135     }                                                                   \
136 }
137
138 #define __MotionComponent_x_y_avg(width,height)                         \
139 void MotionComponent_x_y_avg_##width##_##height(yuv_data_t * p_src,     \
140                                                 yuv_data_t * p_dest,    \
141                                                 int i_stride)           \
142 {                                                                       \
143     int i_x, i_y;                                                       \
144     unsigned int i_dummy;                                               \
145                                                                         \
146     for( i_y = 0; i_y < height; i_y ++ )                                \
147     {                                                                   \
148         for( i_x = 0; i_x < width; i_x++ )                              \
149         {                                                               \
150             i_dummy = p_dest[i_x] + p_src[i_x];                         \
151             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
152         }                                                               \
153         p_dest += i_stride;                                             \
154         p_src += i_stride;                                              \
155     }                                                                   \
156 }
157
158 #define __MotionComponent_X_y_avg(width,height)                         \
159 void MotionComponent_X_y_avg_##width##_##height(yuv_data_t * p_src,     \
160                                                 yuv_data_t * p_dest,    \
161                                                 int i_stride)           \
162 {                                                                       \
163     int i_x, i_y;                                                       \
164     unsigned int i_dummy;                                               \
165                                                                         \
166     for( i_y = 0; i_y < height; i_y ++ )                                \
167     {                                                                   \
168         for( i_x = 0; i_x < width; i_x++ )                              \
169         {                                                               \
170             i_dummy = p_dest[i_x] + ((unsigned int)(p_src[i_x]          \
171                                                     + p_src[i_x + 1]    \
172                                                     + 1) >> 1);         \
173             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
174         }                                                               \
175         p_dest += i_stride;                                             \
176         p_src += i_stride;                                              \
177     }                                                                   \
178 }
179
180 #define __MotionComponent_x_Y_avg(width,height)                         \
181 void MotionComponent_x_Y_avg_##width##_##height(yuv_data_t * p_src,     \
182                                                 yuv_data_t * p_dest,    \
183                                                 int i_stride)           \
184 {                                                                       \
185     int i_x, i_y;                                                       \
186     unsigned int i_dummy;                                               \
187                                                                         \
188     for( i_y = 0; i_y < height; i_y ++ )                                \
189     {                                                                   \
190         for( i_x = 0; i_x < width; i_x++ )                              \
191         {                                                               \
192             i_dummy =                                                   \
193                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
194                                               + p_src[i_x + i_stride]   \
195                                               + 1) >> 1);               \
196             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
197         }                                                               \
198         p_dest += i_stride;                                             \
199         p_src += i_stride;                                              \
200     }                                                                   \
201 }
202
203 #define __MotionComponent_X_Y_avg(width,height)                         \
204 void MotionComponent_X_Y_avg_##width##_##height(yuv_data_t * p_src,     \
205                                                 yuv_data_t * p_dest,    \
206                                                 int i_stride)           \
207 {                                                                       \
208     int i_x, i_y;                                                       \
209     unsigned int i_dummy;                                               \
210                                                                         \
211     for( i_y = 0; i_y < height; i_y ++ )                                \
212     {                                                                   \
213         for( i_x = 0; i_x < width; i_x++ )                              \
214         {                                                               \
215             i_dummy =                                                   \
216                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
217                                             + p_src[i_x + 1]            \
218                                             + p_src[i_x + i_stride]     \
219                                             + p_src[i_x + i_stride + 1] \
220                                             + 2) >> 2);                 \
221             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
222         }                                                               \
223         p_dest += i_stride;                                             \
224         p_src += i_stride;                                              \
225     }                                                                   \
226 }
227
228 #define __MotionComponents(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_copy(width,height)        \
233 __MotionComponent_x_y_avg(width,height)         \
234 __MotionComponent_X_y_avg(width,height)         \
235 __MotionComponent_x_Y_avg(width,height)         \
236 __MotionComponent_X_Y_avg(width,height)
237
238 __MotionComponents (16,16)      /* 444, 422, 420 */
239 __MotionComponents (16,8)       /* 444, 422, 420 */
240 __MotionComponents (8,8)        /* 422, 420 */
241 __MotionComponents (8,4)        /* 420 */
242 #if 0
243 __MotionComponents (8,16)       /* 422 */
244 #endif