]> git.sesse.net Git - vlc/blob - modules/video_filter/deinterlace/algo_basic.c
deinterlace: u_cpu is used only if MMXEXT can be compiled
[vlc] / modules / video_filter / deinterlace / algo_basic.c
1 /*****************************************************************************
2  * algo_basic.c : Basic algorithms for the VLC deinterlacer
3  *****************************************************************************
4  * Copyright (C) 2000-2011 the VideoLAN team
5  * $Id$
6  *
7  * Author: Sam Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <stdint.h>
25
26 #include <vlc_common.h>
27 #include <vlc_picture.h>
28 #include <vlc_filter.h>
29
30 #include "merge.h"
31 #include "deinterlace.h" /* definition of p_sys, needed for Merge() */
32
33 #include "algo_basic.h"
34
35 /*****************************************************************************
36  * RenderDiscard: only keep TOP or BOTTOM field, discard the other.
37  *****************************************************************************/
38
39 void RenderDiscard( filter_t *p_filter,
40                     picture_t *p_outpic, picture_t *p_pic, int i_field )
41 {
42     int i_plane;
43
44     /* Copy image and skip lines */
45     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
46     {
47         uint8_t *p_in, *p_out_end, *p_out;
48         int i_increment;
49
50         p_in = p_pic->p[i_plane].p_pixels
51                    + i_field * p_pic->p[i_plane].i_pitch;
52
53         p_out = p_outpic->p[i_plane].p_pixels;
54         p_out_end = p_out + p_outpic->p[i_plane].i_pitch
55                              * p_outpic->p[i_plane].i_visible_lines;
56
57         switch( p_filter->fmt_in.video.i_chroma )
58         {
59         case VLC_CODEC_I420:
60         case VLC_CODEC_J420:
61         case VLC_CODEC_YV12:
62
63             for( ; p_out < p_out_end ; )
64             {
65                 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
66
67                 p_out += p_outpic->p[i_plane].i_pitch;
68                 p_in += 2 * p_pic->p[i_plane].i_pitch;
69             }
70             break;
71
72         case VLC_CODEC_I422:
73         case VLC_CODEC_J422:
74
75             i_increment = 2 * p_pic->p[i_plane].i_pitch;
76
77             if( i_plane == Y_PLANE )
78             {
79                 for( ; p_out < p_out_end ; )
80                 {
81                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
82                     p_out += p_outpic->p[i_plane].i_pitch;
83                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
84                     p_out += p_outpic->p[i_plane].i_pitch;
85                     p_in += i_increment;
86                 }
87             }
88             else
89             {
90                 for( ; p_out < p_out_end ; )
91                 {
92                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
93                     p_out += p_outpic->p[i_plane].i_pitch;
94                     p_in += i_increment;
95                 }
96             }
97             break;
98
99         default:
100             break;
101         }
102     }
103 }
104
105 /*****************************************************************************
106  * RenderBob: renders a BOB picture - simple copy
107  *****************************************************************************/
108
109 void RenderBob( filter_t *p_filter,
110                 picture_t *p_outpic, picture_t *p_pic, int i_field )
111 {
112     int i_plane;
113
114     /* Copy image and skip lines */
115     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
116     {
117         uint8_t *p_in, *p_out_end, *p_out;
118
119         p_in = p_pic->p[i_plane].p_pixels;
120         p_out = p_outpic->p[i_plane].p_pixels;
121         p_out_end = p_out + p_outpic->p[i_plane].i_pitch
122                              * p_outpic->p[i_plane].i_visible_lines;
123
124         switch( p_filter->fmt_in.video.i_chroma )
125         {
126             case VLC_CODEC_I420:
127             case VLC_CODEC_J420:
128             case VLC_CODEC_YV12:
129                 /* For BOTTOM field we need to add the first line */
130                 if( i_field == 1 )
131                 {
132                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
133                     p_in += p_pic->p[i_plane].i_pitch;
134                     p_out += p_outpic->p[i_plane].i_pitch;
135                 }
136
137                 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
138
139                 for( ; p_out < p_out_end ; )
140                 {
141                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
142
143                     p_out += p_outpic->p[i_plane].i_pitch;
144
145                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
146
147                     p_in += 2 * p_pic->p[i_plane].i_pitch;
148                     p_out += p_outpic->p[i_plane].i_pitch;
149                 }
150
151                 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
152
153                 /* For TOP field we need to add the last line */
154                 if( i_field == 0 )
155                 {
156                     p_in += p_pic->p[i_plane].i_pitch;
157                     p_out += p_outpic->p[i_plane].i_pitch;
158                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
159                 }
160                 break;
161
162             case VLC_CODEC_I422:
163             case VLC_CODEC_J422:
164                 /* For BOTTOM field we need to add the first line */
165                 if( i_field == 1 )
166                 {
167                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
168                     p_in += p_pic->p[i_plane].i_pitch;
169                     p_out += p_outpic->p[i_plane].i_pitch;
170                 }
171
172                 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
173
174                 if( i_plane == Y_PLANE )
175                 {
176                     for( ; p_out < p_out_end ; )
177                     {
178                         vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
179
180                         p_out += p_outpic->p[i_plane].i_pitch;
181
182                         vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
183
184                         p_in += 2 * p_pic->p[i_plane].i_pitch;
185                         p_out += p_outpic->p[i_plane].i_pitch;
186                     }
187                 }
188                 else
189                 {
190                     for( ; p_out < p_out_end ; )
191                     {
192                         vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
193
194                         p_out += p_outpic->p[i_plane].i_pitch;
195                         p_in += 2 * p_pic->p[i_plane].i_pitch;
196                     }
197                 }
198
199                 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
200
201                 /* For TOP field we need to add the last line */
202                 if( i_field == 0 )
203                 {
204                     p_in += p_pic->p[i_plane].i_pitch;
205                     p_out += p_outpic->p[i_plane].i_pitch;
206                     vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
207                 }
208                 break;
209         }
210     }
211 }
212
213 /*****************************************************************************
214  * RenderLinear: BOB with linear interpolation
215  *****************************************************************************/
216
217 void RenderLinear( filter_t *p_filter,
218                    picture_t *p_outpic, picture_t *p_pic, int i_field )
219 {
220     int i_plane;
221
222     /* Copy image and skip lines */
223     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
224     {
225         uint8_t *p_in, *p_out_end, *p_out;
226
227         p_in = p_pic->p[i_plane].p_pixels;
228         p_out = p_outpic->p[i_plane].p_pixels;
229         p_out_end = p_out + p_outpic->p[i_plane].i_pitch
230                              * p_outpic->p[i_plane].i_visible_lines;
231
232         /* For BOTTOM field we need to add the first line */
233         if( i_field == 1 )
234         {
235             vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
236             p_in += p_pic->p[i_plane].i_pitch;
237             p_out += p_outpic->p[i_plane].i_pitch;
238         }
239
240         p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
241
242         for( ; p_out < p_out_end ; )
243         {
244             vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
245
246             p_out += p_outpic->p[i_plane].i_pitch;
247
248             Merge( p_out, p_in, p_in + 2 * p_pic->p[i_plane].i_pitch,
249                    p_pic->p[i_plane].i_pitch );
250
251             p_in += 2 * p_pic->p[i_plane].i_pitch;
252             p_out += p_outpic->p[i_plane].i_pitch;
253         }
254
255         vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
256
257         /* For TOP field we need to add the last line */
258         if( i_field == 0 )
259         {
260             p_in += p_pic->p[i_plane].i_pitch;
261             p_out += p_outpic->p[i_plane].i_pitch;
262             vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
263         }
264     }
265     EndMerge();
266 }
267
268 /*****************************************************************************
269  * RenderMean: Half-resolution blender
270  *****************************************************************************/
271
272 void RenderMean( filter_t *p_filter,
273                  picture_t *p_outpic, picture_t *p_pic )
274 {
275     int i_plane;
276
277     /* Copy image and skip lines */
278     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
279     {
280         uint8_t *p_in, *p_out_end, *p_out;
281
282         p_in = p_pic->p[i_plane].p_pixels;
283
284         p_out = p_outpic->p[i_plane].p_pixels;
285         p_out_end = p_out + p_outpic->p[i_plane].i_pitch
286                              * p_outpic->p[i_plane].i_visible_lines;
287
288         /* All lines: mean value */
289         for( ; p_out < p_out_end ; )
290         {
291             Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
292                    p_pic->p[i_plane].i_pitch );
293
294             p_out += p_outpic->p[i_plane].i_pitch;
295             p_in += 2 * p_pic->p[i_plane].i_pitch;
296         }
297     }
298     EndMerge();
299 }
300
301 /*****************************************************************************
302  * RenderBlend: Full-resolution blender
303  *****************************************************************************/
304
305 void RenderBlend( filter_t *p_filter,
306                   picture_t *p_outpic, picture_t *p_pic )
307 {
308     int i_plane;
309
310     /* Copy image and skip lines */
311     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
312     {
313         uint8_t *p_in, *p_out_end, *p_out;
314
315         p_in = p_pic->p[i_plane].p_pixels;
316
317         p_out = p_outpic->p[i_plane].p_pixels;
318         p_out_end = p_out + p_outpic->p[i_plane].i_pitch
319                              * p_outpic->p[i_plane].i_visible_lines;
320
321         switch( p_filter->fmt_in.video.i_chroma )
322         {
323             case VLC_CODEC_I420:
324             case VLC_CODEC_J420:
325             case VLC_CODEC_YV12:
326                 /* First line: simple copy */
327                 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
328                 p_out += p_outpic->p[i_plane].i_pitch;
329
330                 /* Remaining lines: mean value */
331                 for( ; p_out < p_out_end ; )
332                 {
333                     Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
334                            p_pic->p[i_plane].i_pitch );
335
336                     p_out += p_outpic->p[i_plane].i_pitch;
337                     p_in  += p_pic->p[i_plane].i_pitch;
338                 }
339                 break;
340
341             case VLC_CODEC_I422:
342             case VLC_CODEC_J422:
343                 /* First line: simple copy */
344                 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
345                 p_out += p_outpic->p[i_plane].i_pitch;
346
347                 /* Remaining lines: mean value */
348                 if( i_plane == Y_PLANE )
349                 {
350                     for( ; p_out < p_out_end ; )
351                     {
352                         Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
353                                p_pic->p[i_plane].i_pitch );
354
355                         p_out += p_outpic->p[i_plane].i_pitch;
356                         p_in  += p_pic->p[i_plane].i_pitch;
357                     }
358                 }
359                 else
360                 {
361                     for( ; p_out < p_out_end ; )
362                     {
363                         Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
364                                p_pic->p[i_plane].i_pitch );
365
366                         p_out += p_outpic->p[i_plane].i_pitch;
367                         p_in  += 2*p_pic->p[i_plane].i_pitch;
368                     }
369                 }
370                 break;
371         }
372     }
373     EndMerge();
374 }