1 /*****************************************************************************
2 * algo_basic.c : Basic algorithms for the VLC deinterlacer
3 *****************************************************************************
4 * Copyright (C) 2000-2011 the VideoLAN team
7 * Author: Sam Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
26 #include <vlc_common.h>
27 #include <vlc_picture.h>
28 #include <vlc_filter.h>
31 #include "deinterlace.h" /* definition of p_sys, needed for Merge() */
33 #include "algo_basic.h"
35 /*****************************************************************************
36 * RenderDiscard: only keep TOP or BOTTOM field, discard the other.
37 *****************************************************************************/
39 void RenderDiscard( filter_t *p_filter,
40 picture_t *p_outpic, picture_t *p_pic, int i_field )
44 /* Copy image and skip lines */
45 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
47 uint8_t *p_in, *p_out_end, *p_out;
50 p_in = p_pic->p[i_plane].p_pixels
51 + i_field * p_pic->p[i_plane].i_pitch;
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;
57 switch( p_filter->fmt_in.video.i_chroma )
63 for( ; p_out < p_out_end ; )
65 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
67 p_out += p_outpic->p[i_plane].i_pitch;
68 p_in += 2 * p_pic->p[i_plane].i_pitch;
75 i_increment = 2 * p_pic->p[i_plane].i_pitch;
77 if( i_plane == Y_PLANE )
79 for( ; p_out < p_out_end ; )
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;
90 for( ; p_out < p_out_end ; )
92 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
93 p_out += p_outpic->p[i_plane].i_pitch;
105 /*****************************************************************************
106 * RenderBob: renders a BOB picture - simple copy
107 *****************************************************************************/
109 void RenderBob( filter_t *p_filter,
110 picture_t *p_outpic, picture_t *p_pic, int i_field )
114 /* Copy image and skip lines */
115 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
117 uint8_t *p_in, *p_out_end, *p_out;
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;
124 switch( p_filter->fmt_in.video.i_chroma )
129 /* For BOTTOM field we need to add the first line */
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;
137 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
139 for( ; p_out < p_out_end ; )
141 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
143 p_out += p_outpic->p[i_plane].i_pitch;
145 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
147 p_in += 2 * p_pic->p[i_plane].i_pitch;
148 p_out += p_outpic->p[i_plane].i_pitch;
151 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
153 /* For TOP field we need to add the last line */
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 );
164 /* For BOTTOM field we need to add the first line */
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;
172 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
174 if( i_plane == Y_PLANE )
176 for( ; p_out < p_out_end ; )
178 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
180 p_out += p_outpic->p[i_plane].i_pitch;
182 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
184 p_in += 2 * p_pic->p[i_plane].i_pitch;
185 p_out += p_outpic->p[i_plane].i_pitch;
190 for( ; p_out < p_out_end ; )
192 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
194 p_out += p_outpic->p[i_plane].i_pitch;
195 p_in += 2 * p_pic->p[i_plane].i_pitch;
199 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
201 /* For TOP field we need to add the last line */
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 );
213 /*****************************************************************************
214 * RenderLinear: BOB with linear interpolation
215 *****************************************************************************/
217 void RenderLinear( filter_t *p_filter,
218 picture_t *p_outpic, picture_t *p_pic, int i_field )
222 /* Copy image and skip lines */
223 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
225 uint8_t *p_in, *p_out_end, *p_out;
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;
232 /* For BOTTOM field we need to add the first line */
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;
240 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
242 for( ; p_out < p_out_end ; )
244 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
246 p_out += p_outpic->p[i_plane].i_pitch;
248 Merge( p_out, p_in, p_in + 2 * p_pic->p[i_plane].i_pitch,
249 p_pic->p[i_plane].i_pitch );
251 p_in += 2 * p_pic->p[i_plane].i_pitch;
252 p_out += p_outpic->p[i_plane].i_pitch;
255 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
257 /* For TOP field we need to add the last line */
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 );
268 /*****************************************************************************
269 * RenderMean: Half-resolution blender
270 *****************************************************************************/
272 void RenderMean( filter_t *p_filter,
273 picture_t *p_outpic, picture_t *p_pic )
277 /* Copy image and skip lines */
278 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
280 uint8_t *p_in, *p_out_end, *p_out;
282 p_in = p_pic->p[i_plane].p_pixels;
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;
288 /* All lines: mean value */
289 for( ; p_out < p_out_end ; )
291 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
292 p_pic->p[i_plane].i_pitch );
294 p_out += p_outpic->p[i_plane].i_pitch;
295 p_in += 2 * p_pic->p[i_plane].i_pitch;
301 /*****************************************************************************
302 * RenderBlend: Full-resolution blender
303 *****************************************************************************/
305 void RenderBlend( filter_t *p_filter,
306 picture_t *p_outpic, picture_t *p_pic )
310 /* Copy image and skip lines */
311 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
313 uint8_t *p_in, *p_out_end, *p_out;
315 p_in = p_pic->p[i_plane].p_pixels;
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;
321 switch( p_filter->fmt_in.video.i_chroma )
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;
330 /* Remaining lines: mean value */
331 for( ; p_out < p_out_end ; )
333 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
334 p_pic->p[i_plane].i_pitch );
336 p_out += p_outpic->p[i_plane].i_pitch;
337 p_in += p_pic->p[i_plane].i_pitch;
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;
347 /* Remaining lines: mean value */
348 if( i_plane == Y_PLANE )
350 for( ; p_out < p_out_end ; )
352 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
353 p_pic->p[i_plane].i_pitch );
355 p_out += p_outpic->p[i_plane].i_pitch;
356 p_in += p_pic->p[i_plane].i_pitch;
361 for( ; p_out < p_out_end ; )
363 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
364 p_pic->p[i_plane].i_pitch );
366 p_out += p_outpic->p[i_plane].i_pitch;
367 p_in += 2*p_pic->p[i_plane].i_pitch;