]> git.sesse.net Git - vlc/blob - src/video_decoder/vdec_motion_inner.c
51f0f0b02b12facf10ec6614426c2f1b150114f3
[vlc] / src / video_decoder / vdec_motion_inner.c
1 /*****************************************************************************
2  * vdec_motion.c : motion compensation routines
3  * (c)1999 VideoLAN
4  *****************************************************************************/
5
6 /*****************************************************************************
7  * Preamble
8  *****************************************************************************/
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <sys/uio.h>
15
16 #include "config.h"
17 #include "common.h"
18 #include "mtime.h"
19 #include "vlc_thread.h"
20
21 #include "intf_msg.h"
22 #include "debug.h"                 /* XXX?? temporaire, requis par netlist.h */
23
24 #include "input.h"
25 #include "input_netlist.h"
26 #include "decoder_fifo.h"
27 #include "video.h"
28 #include "video_output.h"
29
30 #include "vdec_idct.h"
31 #include "video_decoder.h"
32 #include "vdec_motion.h"
33
34 #include "vpar_blocks.h"
35 #include "vpar_headers.h"
36 #include "vpar_synchro.h"
37 #include "video_parser.h"
38 #include "video_fifo.h"
39
40 #define __MotionComponent_x_y_copy(width,height)                        \
41 void MotionComponent_x_y_copy_##width##_##height(yuv_data_t * p_src,    \
42                                                  yuv_data_t * p_dest,   \
43                                                  int i_stride)          \
44 {                                                                       \
45     int i_x, i_y;                                                       \
46                                                                         \
47     for( i_y = 0; i_y < height; i_y ++ )                                \
48     {                                                                   \
49         for( i_x = 0; i_x < width; i_x++ )                              \
50         {                                                               \
51             p_dest[i_x] = p_src[i_x];                                   \
52         }                                                               \
53         p_dest += i_stride;                                             \
54         p_src += i_stride;                                              \
55     }                                                                   \
56 }
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] = (unsigned int)(p_src[i_x]                     \
70                                          + p_src[i_x + 1]               \
71                                          + 1) >> 1;                     \
72         }                                                               \
73         p_dest += i_stride;                                             \
74         p_src += i_stride;                                              \
75     }                                                                   \
76 }
77
78 #define __MotionComponent_x_Y_copy(width,height)                        \
79 void MotionComponent_x_Y_copy_##width##_##height(yuv_data_t * p_src,    \
80                                                  yuv_data_t * p_dest,   \
81                                                  int i_stride,          \
82                                                  int i_step)            \
83 {                                                                       \
84     int i_x, i_y;                                                       \
85                                                                         \
86     for( i_y = 0; i_y < height; i_y ++ )                                \
87     {                                                                   \
88         for( i_x = 0; i_x < width; i_x++ )                              \
89         {                                                               \
90             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
91                                          + p_src[i_x + i_step]          \
92                                          + 1) >> 1;                     \
93         }                                                               \
94         p_dest += i_stride;                                             \
95         p_src += i_stride;                                              \
96     }                                                                   \
97 }
98
99 #define __MotionComponent_X_Y_copy(width,height)                        \
100 void MotionComponent_X_Y_copy_##width##_##height(yuv_data_t * p_src,    \
101                                                  yuv_data_t * p_dest,   \
102                                                  int i_stride,          \
103                                                  int i_step)            \
104 {                                                                       \
105     int i_x, i_y;                                                       \
106                                                                         \
107     for( i_y = 0; i_y < height; i_y ++ )                                \
108     {                                                                   \
109         for( i_x = 0; i_x < width; i_x++ )                              \
110         {                                                               \
111             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
112                                          + p_src[i_x + 1]               \
113                                          + p_src[i_x + i_step]          \
114                                          + p_src[i_x + i_step + 1]      \
115                                          + 2) >> 2;                     \
116         }                                                               \
117         p_dest += i_stride;                                             \
118         p_src += i_stride;                                              \
119     }                                                                   \
120 }
121
122 #define __MotionComponent_x_y_avg(width,height)                         \
123 void MotionComponent_x_y_avg_##width##_##height(yuv_data_t * p_src,     \
124                                                 yuv_data_t * p_dest,    \
125                                                 int i_stride)           \
126 {                                                                       \
127     int i_x, i_y;                                                       \
128     unsigned int i_dummy;                                               \
129                                                                         \
130     for( i_y = 0; i_y < height; i_y ++ )                                \
131     {                                                                   \
132         for( i_x = 0; i_x < width; i_x++ )                              \
133         {                                                               \
134             i_dummy = p_dest[i_x] + p_src[i_x];                         \
135             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
136         }                                                               \
137         p_dest += i_stride;                                             \
138         p_src += i_stride;                                              \
139     }                                                                   \
140 }
141
142 #define __MotionComponent_X_y_avg(width,height)                         \
143 void MotionComponent_X_y_avg_##width##_##height(yuv_data_t * p_src,     \
144                                                 yuv_data_t * p_dest,    \
145                                                 int i_stride)           \
146 {                                                                       \
147     int i_x, i_y;                                                       \
148     unsigned int i_dummy;                                               \
149                                                                         \
150     for( i_y = 0; i_y < height; i_y ++ )                                \
151     {                                                                   \
152         for( i_x = 0; i_x < width; i_x++ )                              \
153         {                                                               \
154             i_dummy = p_dest[i_x] + ((unsigned int)(p_src[i_x]          \
155                                                     + p_src[i_x + 1]    \
156                                                     + 1) >> 1);         \
157             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
158         }                                                               \
159         p_dest += i_stride;                                             \
160         p_src += i_stride;                                              \
161     }                                                                   \
162 }
163
164 #define __MotionComponent_x_Y_avg(width,height)                         \
165 void MotionComponent_x_Y_avg_##width##_##height(yuv_data_t * p_src,     \
166                                                 yuv_data_t * p_dest,    \
167                                                 int i_stride,           \
168                                                 int i_step)             \
169 {                                                                       \
170     int i_x, i_y;                                                       \
171     unsigned int i_dummy;                                               \
172                                                                         \
173     for( i_y = 0; i_y < height; i_y ++ )                                \
174     {                                                                   \
175         for( i_x = 0; i_x < width; i_x++ )                              \
176         {                                                               \
177             i_dummy =                                                   \
178                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
179                                               + p_src[i_x + i_step]     \
180                                               + 1) >> 1);               \
181             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
182         }                                                               \
183         p_dest += i_stride;                                             \
184         p_src += i_stride;                                              \
185     }                                                                   \
186 }
187
188 #define __MotionComponent_X_Y_avg(width,height)                         \
189 void MotionComponent_X_Y_avg_##width##_##height(yuv_data_t * p_src,     \
190                                                 yuv_data_t * p_dest,    \
191                                                 int i_stride,           \
192                                                 int i_step)             \
193 {                                                                       \
194     int i_x, i_y;                                                       \
195     unsigned int i_dummy;                                               \
196                                                                         \
197     for( i_y = 0; i_y < height; i_y ++ )                                \
198     {                                                                   \
199         for( i_x = 0; i_x < width; i_x++ )                              \
200         {                                                               \
201             i_dummy =                                                   \
202                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
203                                               + p_src[i_x + 1]          \
204                                               + p_src[i_x + i_step]     \
205                                               + p_src[i_x + i_step + 1] \
206                                               + 2) >> 2);               \
207             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
208         }                                                               \
209         p_dest += i_stride;                                             \
210         p_src += i_stride;                                              \
211     }                                                                   \
212 }
213
214 #define __MotionComponents(width,height)        \
215 __MotionComponent_x_y_copy(width,height)        \
216 __MotionComponent_X_y_copy(width,height)        \
217 __MotionComponent_x_Y_copy(width,height)        \
218 __MotionComponent_X_Y_copy(width,height)        \
219 __MotionComponent_x_y_avg(width,height)         \
220 __MotionComponent_X_y_avg(width,height)         \
221 __MotionComponent_x_Y_avg(width,height)         \
222 __MotionComponent_X_Y_avg(width,height)
223
224 __MotionComponents (16,16)      /* 444, 422, 420 */
225 __MotionComponents (16,8)       /* 444, 422, 420 */
226 __MotionComponents (8,8)        /* 422, 420 */
227 __MotionComponents (8,4)        /* 420 */
228 #if 0
229 __MotionComponents (8,16)       /* 422 */
230 #endif