]> git.sesse.net Git - vlc/blob - plugins/motion/vdec_motion_inner.c
e3e53965e46fed252b09d263264cad03969f6ee5
[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.2 2001/06/07 15:27:44 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 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32
33 #include "config.h"
34 #include "common.h"
35 #include "threads.h"
36 #include "mtime.h"
37
38 #include "video.h"
39
40 #define __MotionComponent_x_y_copy(width,height)                        \
41 void _M(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 _M(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 _M(MotionComponent_x_Y_copy_##width##_##height)(yuv_data_t *p_src, \
80                                                  yuv_data_t * p_dest,   \
81                                                  int i_stride)          \
82 {                                                                       \
83     int i_x, i_y;                                                       \
84                                                                         \
85     for( i_y = 0; i_y < height; i_y ++ )                                \
86     {                                                                   \
87         for( i_x = 0; i_x < width; i_x++ )                              \
88         {                                                               \
89             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
90                                          + p_src[i_x + i_stride]        \
91                                          + 1) >> 1;                     \
92         }                                                               \
93         p_dest += i_stride;                                             \
94         p_src += i_stride;                                              \
95     }                                                                   \
96 }
97
98 #define __MotionComponent_X_Y_copy(width,height)                        \
99 void _M(MotionComponent_X_Y_copy_##width##_##height)(yuv_data_t *p_src, \
100                                                  yuv_data_t * p_dest,   \
101                                                  int i_stride)          \
102 {                                                                       \
103     int i_x, i_y;                                                       \
104                                                                         \
105     for( i_y = 0; i_y < height; i_y ++ )                                \
106     {                                                                   \
107         for( i_x = 0; i_x < width; i_x++ )                              \
108         {                                                               \
109             p_dest[i_x] = (unsigned int)(p_src[i_x]                     \
110                                          + p_src[i_x + 1]               \
111                                          + p_src[i_x + i_stride]        \
112                                          + p_src[i_x + i_stride + 1]    \
113                                          + 2) >> 2;                     \
114         }                                                               \
115         p_dest += i_stride;                                             \
116         p_src += i_stride;                                              \
117     }                                                                   \
118 }
119
120 #define __MotionComponent_x_y_avg(width,height)                         \
121 void _M(MotionComponent_x_y_avg_##width##_##height)(yuv_data_t * p_src, \
122                                                 yuv_data_t * p_dest,    \
123                                                 int i_stride)           \
124 {                                                                       \
125     int i_x, i_y;                                                       \
126     unsigned int i_dummy;                                               \
127                                                                         \
128     for( i_y = 0; i_y < height; i_y ++ )                                \
129     {                                                                   \
130         for( i_x = 0; i_x < width; i_x++ )                              \
131         {                                                               \
132             i_dummy = p_dest[i_x] + p_src[i_x];                         \
133             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
134         }                                                               \
135         p_dest += i_stride;                                             \
136         p_src += i_stride;                                              \
137     }                                                                   \
138 }
139
140 #define __MotionComponent_X_y_avg(width,height)                         \
141 void _M(MotionComponent_X_y_avg_##width##_##height)(yuv_data_t * p_src, \
142                                                 yuv_data_t * p_dest,    \
143                                                 int i_stride)           \
144 {                                                                       \
145     int i_x, i_y;                                                       \
146     unsigned int i_dummy;                                               \
147                                                                         \
148     for( i_y = 0; i_y < height; i_y ++ )                                \
149     {                                                                   \
150         for( i_x = 0; i_x < width; i_x++ )                              \
151         {                                                               \
152             i_dummy = p_dest[i_x] + ((unsigned int)(p_src[i_x]          \
153                                                     + p_src[i_x + 1]    \
154                                                     + 1) >> 1);         \
155             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
156         }                                                               \
157         p_dest += i_stride;                                             \
158         p_src += i_stride;                                              \
159     }                                                                   \
160 }
161
162 #define __MotionComponent_x_Y_avg(width,height)                         \
163 void _M(MotionComponent_x_Y_avg_##width##_##height)(yuv_data_t * p_src, \
164                                                 yuv_data_t * p_dest,    \
165                                                 int i_stride)           \
166 {                                                                       \
167     int i_x, i_y;                                                       \
168     unsigned int i_dummy;                                               \
169                                                                         \
170     for( i_y = 0; i_y < height; i_y ++ )                                \
171     {                                                                   \
172         for( i_x = 0; i_x < width; i_x++ )                              \
173         {                                                               \
174             i_dummy =                                                   \
175                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
176                                               + p_src[i_x + i_stride]   \
177                                               + 1) >> 1);               \
178             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
179         }                                                               \
180         p_dest += i_stride;                                             \
181         p_src += i_stride;                                              \
182     }                                                                   \
183 }
184
185 #define __MotionComponent_X_Y_avg(width,height)                         \
186 void _M(MotionComponent_X_Y_avg_##width##_##height)(yuv_data_t * p_src, \
187                                                 yuv_data_t * p_dest,    \
188                                                 int i_stride)           \
189 {                                                                       \
190     int i_x, i_y;                                                       \
191     unsigned int i_dummy;                                               \
192                                                                         \
193     for( i_y = 0; i_y < height; i_y ++ )                                \
194     {                                                                   \
195         for( i_x = 0; i_x < width; i_x++ )                              \
196         {                                                               \
197             i_dummy =                                                   \
198                 p_dest[i_x] + ((unsigned int)(p_src[i_x]                \
199                                             + p_src[i_x + 1]            \
200                                             + p_src[i_x + i_stride]     \
201                                             + p_src[i_x + i_stride + 1] \
202                                             + 2) >> 2);                 \
203             p_dest[i_x] = (i_dummy + 1) >> 1;                           \
204         }                                                               \
205         p_dest += i_stride;                                             \
206         p_src += i_stride;                                              \
207     }                                                                   \
208 }
209
210 #define __MotionComponents(width,height)        \
211 __MotionComponent_x_y_copy(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_avg(width,height)         \
216 __MotionComponent_X_y_avg(width,height)         \
217 __MotionComponent_x_Y_avg(width,height)         \
218 __MotionComponent_X_Y_avg(width,height)
219
220 __MotionComponents (16,16)      /* 444, 422, 420 */
221 __MotionComponents (16,8)       /* 444, 422, 420 */
222 __MotionComponents (8,8)        /* 422, 420 */
223 __MotionComponents (8,4)        /* 420 */
224 #if 0
225 __MotionComponents (8,16)       /* 422 */
226 #endif