]> git.sesse.net Git - vlc/blob - plugins/motion/vdec_motion_inner.c
* SDL compilation fix for FreeBSD.
[vlc] / plugins / motion / 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.3 2001/06/07 22:14:55 sam 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 #define MODULE_NAME motion
27 #include "modules_inner.h"
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include "defs.h"
33
34 #include "config.h"
35 #include "common.h"
36 #include "threads.h"
37 #include "mtime.h"
38
39 #include "video.h"
40
41 #define __MotionComponent_x_y_copy(width,height)                        \
42 void _M(MotionComponent_x_y_copy_##width##_##height)(yuv_data_t *p_src, \
43                                                  yuv_data_t *p_dest,    \
44                                                  int i_stride)          \
45 {                                                                       \
46     int i_x, i_y;                                                       \
47                                                                         \
48     for( i_y = 0; i_y < height; i_y ++ )                                \
49     {                                                                   \
50         for( i_x = 0; i_x < width; i_x++ )                              \
51         {                                                               \
52             p_dest[i_x] = p_src[i_x];                                   \
53         }                                                               \
54         p_dest += i_stride;                                             \
55         p_src += i_stride;                                              \
56     }                                                                   \
57 }
58
59 #define __MotionComponent_X_y_copy(width,height)                        \
60 void _M(MotionComponent_X_y_copy_##width##_##height)(yuv_data_t *p_src, \
61                                                  yuv_data_t * p_dest,   \
62                                                  int i_stride)          \
63 {                                                                       \
64     int i_x, i_y;                                                       \
65                                                                         \
66     for( i_y = 0; i_y < height; i_y ++ )                                \
67     {                                                                   \
68         for( i_x = 0; i_x < width; i_x++ )                              \
69         {                                                               \
70             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
71                                          + p_src[i_x + 1]               \
72                                          + 1) >> 1;                     \
73         }                                                               \
74         p_dest += i_stride;                                             \
75         p_src += i_stride;                                              \
76     }                                                                   \
77 }
78
79 #define __MotionComponent_x_Y_copy(width,height)                        \
80 void _M(MotionComponent_x_Y_copy_##width##_##height)(yuv_data_t *p_src, \
81                                                  yuv_data_t * p_dest,   \
82                                                  int i_stride)          \
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_stride]        \
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 _M(MotionComponent_X_Y_copy_##width##_##height)(yuv_data_t *p_src, \
101                                                  yuv_data_t * p_dest,   \
102                                                  int i_stride)          \
103 {                                                                       \
104     int i_x, i_y;                                                       \
105                                                                         \
106     for( i_y = 0; i_y < height; i_y ++ )                                \
107     {                                                                   \
108         for( i_x = 0; i_x < width; i_x++ )                              \
109         {                                                               \
110             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
111                                          + p_src[i_x + 1]               \
112                                          + p_src[i_x + i_stride]        \
113                                          + p_src[i_x + i_stride + 1]    \
114                                          + 2) >> 2;                     \
115         }                                                               \
116         p_dest += i_stride;                                             \
117         p_src += i_stride;                                              \
118     }                                                                   \
119 }
120
121 #define __MotionComponent_x_y_avg(width,height)                         \
122 void _M(MotionComponent_x_y_avg_##width##_##height)(yuv_data_t * p_src, \
123                                                 yuv_data_t * p_dest,    \
124                                                 int i_stride)           \
125 {                                                                       \
126     int i_x, i_y;                                                       \
127     unsigned int i_dummy;                                               \
128                                                                         \
129     for( i_y = 0; i_y < height; i_y ++ )                                \
130     {                                                                   \
131         for( i_x = 0; i_x < width; i_x++ )                              \
132         {                                                               \
133             i_dummy = p_dest[i_x] + p_src[i_x];                         \
134             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
135         }                                                               \
136         p_dest += i_stride;                                             \
137         p_src += i_stride;                                              \
138     }                                                                   \
139 }
140
141 #define __MotionComponent_X_y_avg(width,height)                         \
142 void _M(MotionComponent_X_y_avg_##width##_##height)(yuv_data_t * p_src, \
143                                                 yuv_data_t * p_dest,    \
144                                                 int i_stride)           \
145 {                                                                       \
146     int i_x, i_y;                                                       \
147     unsigned int i_dummy;                                               \
148                                                                         \
149     for( i_y = 0; i_y < height; i_y ++ )                                \
150     {                                                                   \
151         for( i_x = 0; i_x < width; i_x++ )                              \
152         {                                                               \
153             i_dummy = p_dest[i_x] + ((unsigned int)(p_src[i_x]          \
154                                                     + p_src[i_x + 1]    \
155                                                     + 1) >> 1);         \
156             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
157         }                                                               \
158         p_dest += i_stride;                                             \
159         p_src += i_stride;                                              \
160     }                                                                   \
161 }
162
163 #define __MotionComponent_x_Y_avg(width,height)                         \
164 void _M(MotionComponent_x_Y_avg_##width##_##height)(yuv_data_t * p_src, \
165                                                 yuv_data_t * p_dest,    \
166                                                 int i_stride)           \
167 {                                                                       \
168     int i_x, i_y;                                                       \
169     unsigned int i_dummy;                                               \
170                                                                         \
171     for( i_y = 0; i_y < height; i_y ++ )                                \
172     {                                                                   \
173         for( i_x = 0; i_x < width; i_x++ )                              \
174         {                                                               \
175             i_dummy =                                                   \
176                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
177                                               + p_src[i_x + i_stride]   \
178                                               + 1) >> 1);               \
179             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
180         }                                                               \
181         p_dest += i_stride;                                             \
182         p_src += i_stride;                                              \
183     }                                                                   \
184 }
185
186 #define __MotionComponent_X_Y_avg(width,height)                         \
187 void _M(MotionComponent_X_Y_avg_##width##_##height)(yuv_data_t * p_src, \
188                                                 yuv_data_t * p_dest,    \
189                                                 int i_stride)           \
190 {                                                                       \
191     int i_x, i_y;                                                       \
192     unsigned int i_dummy;                                               \
193                                                                         \
194     for( i_y = 0; i_y < height; i_y ++ )                                \
195     {                                                                   \
196         for( i_x = 0; i_x < width; i_x++ )                              \
197         {                                                               \
198             i_dummy =                                                   \
199                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
200                                             + p_src[i_x + 1]            \
201                                             + p_src[i_x + i_stride]     \
202                                             + p_src[i_x + i_stride + 1] \
203                                             + 2) >> 2);                 \
204             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
205         }                                                               \
206         p_dest += i_stride;                                             \
207         p_src += i_stride;                                              \
208     }                                                                   \
209 }
210
211 #define __MotionComponents(width,height)        \
212 __MotionComponent_x_y_copy(width,height)        \
213 __MotionComponent_X_y_copy(width,height)        \
214 __MotionComponent_x_Y_copy(width,height)        \
215 __MotionComponent_X_Y_copy(width,height)        \
216 __MotionComponent_x_y_avg(width,height)         \
217 __MotionComponent_X_y_avg(width,height)         \
218 __MotionComponent_x_Y_avg(width,height)         \
219 __MotionComponent_X_Y_avg(width,height)
220
221 __MotionComponents (16,16)      /* 444, 422, 420 */
222 __MotionComponents (16,8)       /* 444, 422, 420 */
223 __MotionComponents (8,8)        /* 422, 420 */
224 __MotionComponents (8,4)        /* 420 */
225 #if 0
226 __MotionComponents (8,16)       /* 422 */
227 #endif