]> git.sesse.net Git - vlc/blob - src/video_decoder/vdec_motion_inner.c
* Borrowed LiViD's MMX and MMX EXT IDCT.
[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.12 2001/01/05 18:46:44 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 "config.h"
32 #include "common.h"
33 #include "threads.h"
34 #include "mtime.h"
35 #include "plugins.h"
36
37 #include "intf_msg.h"
38
39 #include "stream_control.h"
40 #include "input_ext-dec.h"
41
42 #include "video.h"
43 #include "video_output.h"
44
45 #include "vdec_idct.h"
46 #include "video_decoder.h"
47 #include "vdec_motion.h"
48
49 #include "vpar_blocks.h"
50 #include "vpar_headers.h"
51 #include "vpar_synchro.h"
52 #include "video_parser.h"
53 #include "video_fifo.h"
54
55 #define __MotionComponent_x_y_copy(width,height)                        \
56 void MotionComponent_x_y_copy_##width##_##height(yuv_data_t * p_src,    \
57                                                  yuv_data_t * p_dest,   \
58                                                  int i_stride)          \
59 {                                                                       \
60     int i_x, i_y;                                                       \
61                                                                         \
62     for( i_y = 0; i_y < height; i_y ++ )                                \
63     {                                                                   \
64         for( i_x = 0; i_x < width; i_x++ )                              \
65         {                                                               \
66             p_dest[i_x] = p_src[i_x];                                   \
67         }                                                               \
68         p_dest += i_stride;                                             \
69         p_src += i_stride;                                              \
70     }                                                                   \
71 }
72
73 #define __MotionComponent_X_y_copy(width,height)                        \
74 void MotionComponent_X_y_copy_##width##_##height(yuv_data_t * p_src,    \
75                                                  yuv_data_t * p_dest,   \
76                                                  int i_stride)          \
77 {                                                                       \
78     int i_x, i_y;                                                       \
79                                                                         \
80     for( i_y = 0; i_y < height; i_y ++ )                                \
81     {                                                                   \
82         for( i_x = 0; i_x < width; i_x++ )                              \
83         {                                                               \
84             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
85                                          + p_src[i_x + 1]               \
86                                          + 1) >> 1;                     \
87         }                                                               \
88         p_dest += i_stride;                                             \
89         p_src += i_stride;                                              \
90     }                                                                   \
91 }
92
93 #define __MotionComponent_x_Y_copy(width,height)                        \
94 void MotionComponent_x_Y_copy_##width##_##height(yuv_data_t * p_src,    \
95                                                  yuv_data_t * p_dest,   \
96                                                  int i_stride)          \
97 {                                                                       \
98     int i_x, i_y;                                                       \
99                                                                         \
100     for( i_y = 0; i_y < height; i_y ++ )                                \
101     {                                                                   \
102         for( i_x = 0; i_x < width; i_x++ )                              \
103         {                                                               \
104             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
105                                          + p_src[i_x + i_stride]        \
106                                          + 1) >> 1;                     \
107         }                                                               \
108         p_dest += i_stride;                                             \
109         p_src += i_stride;                                              \
110     }                                                                   \
111 }
112
113 #define __MotionComponent_X_Y_copy(width,height)                        \
114 void MotionComponent_X_Y_copy_##width##_##height(yuv_data_t * p_src,    \
115                                                  yuv_data_t * p_dest,   \
116                                                  int i_stride)          \
117 {                                                                       \
118     int i_x, i_y;                                                       \
119                                                                         \
120     for( i_y = 0; i_y < height; i_y ++ )                                \
121     {                                                                   \
122         for( i_x = 0; i_x < width; i_x++ )                              \
123         {                                                               \
124             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
125                                          + p_src[i_x + 1]               \
126                                          + p_src[i_x + i_stride]        \
127                                          + p_src[i_x + i_stride + 1]    \
128                                          + 2) >> 2;                     \
129         }                                                               \
130         p_dest += i_stride;                                             \
131         p_src += i_stride;                                              \
132     }                                                                   \
133 }
134
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,    \
138                                                 int i_stride)           \
139 {                                                                       \
140     int i_x, i_y;                                                       \
141     unsigned int i_dummy;                                               \
142                                                                         \
143     for( i_y = 0; i_y < height; i_y ++ )                                \
144     {                                                                   \
145         for( i_x = 0; i_x < width; i_x++ )                              \
146         {                                                               \
147             i_dummy = p_dest[i_x] + p_src[i_x];                         \
148             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
149         }                                                               \
150         p_dest += i_stride;                                             \
151         p_src += i_stride;                                              \
152     }                                                                   \
153 }
154
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,    \
158                                                 int i_stride)           \
159 {                                                                       \
160     int i_x, i_y;                                                       \
161     unsigned int i_dummy;                                               \
162                                                                         \
163     for( i_y = 0; i_y < height; i_y ++ )                                \
164     {                                                                   \
165         for( i_x = 0; i_x < width; i_x++ )                              \
166         {                                                               \
167             i_dummy = p_dest[i_x] + ((unsigned int)(p_src[i_x]          \
168                                                     + p_src[i_x + 1]    \
169                                                     + 1) >> 1);         \
170             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
171         }                                                               \
172         p_dest += i_stride;                                             \
173         p_src += i_stride;                                              \
174     }                                                                   \
175 }
176
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,    \
180                                                 int i_stride)           \
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_stride]   \
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 {                                                                       \
205     int i_x, i_y;                                                       \
206     unsigned int i_dummy;                                               \
207                                                                         \
208     for( i_y = 0; i_y < height; i_y ++ )                                \
209     {                                                                   \
210         for( i_x = 0; i_x < width; i_x++ )                              \
211         {                                                               \
212             i_dummy =                                                   \
213                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
214                                             + p_src[i_x + 1]            \
215                                             + p_src[i_x + i_stride]     \
216                                             + p_src[i_x + i_stride + 1] \
217                                             + 2) >> 2);                 \
218             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
219         }                                                               \
220         p_dest += i_stride;                                             \
221         p_src += i_stride;                                              \
222     }                                                                   \
223 }
224
225 #define __MotionComponents(width,height)        \
226 __MotionComponent_x_y_copy(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_avg(width,height)         \
231 __MotionComponent_X_y_avg(width,height)         \
232 __MotionComponent_x_Y_avg(width,height)         \
233 __MotionComponent_X_Y_avg(width,height)
234
235 __MotionComponents (16,16)      /* 444, 422, 420 */
236 __MotionComponents (16,8)       /* 444, 422, 420 */
237 __MotionComponents (8,8)        /* 422, 420 */
238 __MotionComponents (8,4)        /* 420 */
239 #if 0
240 __MotionComponents (8,16)       /* 422 */
241 #endif