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