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