1 /*****************************************************************************
2 * deinterlace.c : deinterlacer plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2009 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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
38 #include <vlc_common.h>
39 #include <vlc_plugin.h>
40 #include <vlc_filter.h>
43 #ifdef CAN_COMPILE_MMXEXT
47 #define DEINTERLACE_DISCARD 1
48 #define DEINTERLACE_MEAN 2
49 #define DEINTERLACE_BLEND 3
50 #define DEINTERLACE_BOB 4
51 #define DEINTERLACE_LINEAR 5
52 #define DEINTERLACE_X 6
53 #define DEINTERLACE_YADIF 7
54 #define DEINTERLACE_YADIF2X 8
56 /*****************************************************************************
58 *****************************************************************************/
59 static int Open ( vlc_object_t * );
60 static void Close( vlc_object_t * );
62 #define MODE_TEXT N_("Deinterlace mode")
63 #define MODE_LONGTEXT N_("Deinterlace method to use for local playback.")
65 #define SOUT_MODE_TEXT N_("Streaming deinterlace mode")
66 #define SOUT_MODE_LONGTEXT N_("Deinterlace method to use for streaming.")
68 #define FILTER_CFG_PREFIX "sout-deinterlace-"
70 static const char *const mode_list[] = {
71 "discard", "blend", "mean", "bob", "linear", "x", "yadif", "yadif2x" };
72 static const char *const mode_list_text[] = {
73 N_("Discard"), N_("Blend"), N_("Mean"), N_("Bob"), N_("Linear"), "X", "Yadif", "Yadif (2x)" };
76 set_description( N_("Deinterlacing video filter") )
77 set_shortname( N_("Deinterlace" ))
78 set_capability( "video filter", 0 )
79 set_category( CAT_VIDEO )
80 set_subcategory( SUBCAT_VIDEO_VFILTER )
82 set_capability( "video filter2", 0 )
83 add_string( FILTER_CFG_PREFIX "mode", "blend", NULL, SOUT_MODE_TEXT,
84 SOUT_MODE_LONGTEXT, false )
85 change_string_list( mode_list, mode_list_text, 0 )
87 add_shortcut( "deinterlace" )
88 set_callbacks( Open, Close )
92 /*****************************************************************************
94 *****************************************************************************/
95 static void RenderDiscard( filter_t *, picture_t *, picture_t *, int );
96 static void RenderBob ( filter_t *, picture_t *, picture_t *, int );
97 static void RenderMean ( filter_t *, picture_t *, picture_t * );
98 static void RenderBlend ( filter_t *, picture_t *, picture_t * );
99 static void RenderLinear ( filter_t *, picture_t *, picture_t *, int );
100 static void RenderX ( picture_t *, picture_t * );
101 static void RenderYadif ( filter_t *, picture_t *, picture_t *, int, int );
103 static void MergeGeneric ( void *, const void *, const void *, size_t );
104 #if defined(CAN_COMPILE_C_ALTIVEC)
105 static void MergeAltivec ( void *, const void *, const void *, size_t );
107 #if defined(CAN_COMPILE_MMXEXT)
108 static void MergeMMXEXT ( void *, const void *, const void *, size_t );
110 #if defined(CAN_COMPILE_3DNOW)
111 static void Merge3DNow ( void *, const void *, const void *, size_t );
113 #if defined(CAN_COMPILE_SSE)
114 static void MergeSSE2 ( void *, const void *, const void *, size_t );
116 #if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)
117 static void EndMMX ( void );
119 #if defined(CAN_COMPILE_3DNOW)
120 static void End3DNow ( void );
122 #if defined __ARM_NEON__
123 static void MergeNEON (void *, const void *, const void *, size_t);
126 static const char *const ppsz_filter_options[] = {
130 #define HISTORY_SIZE (3)
133 int i_mode; /* Deinterlace mode */
134 bool b_double_rate; /* Shall we double the framerate? */
135 bool b_half_height; /* Shall be divide the height by 2 */
137 void (*pf_merge) ( void *, const void *, const void *, size_t );
138 void (*pf_end_merge) ( void );
141 picture_t *pp_history[HISTORY_SIZE];
144 /*****************************************************************************
145 * SetFilterMethod: setup the deinterlace method to use.
146 *****************************************************************************/
147 static void SetFilterMethod( filter_t *p_filter, const char *psz_method, vlc_fourcc_t i_chroma )
149 filter_sys_t *p_sys = p_filter->p_sys;
154 if( !strcmp( psz_method, "mean" ) )
156 p_sys->i_mode = DEINTERLACE_MEAN;
157 p_sys->b_double_rate = false;
158 p_sys->b_half_height = true;
160 else if( !strcmp( psz_method, "bob" )
161 || !strcmp( psz_method, "progressive-scan" ) )
163 p_sys->i_mode = DEINTERLACE_BOB;
164 p_sys->b_double_rate = true;
165 p_sys->b_half_height = false;
167 else if( !strcmp( psz_method, "linear" ) )
169 p_sys->i_mode = DEINTERLACE_LINEAR;
170 p_sys->b_double_rate = true;
171 p_sys->b_half_height = false;
173 else if( !strcmp( psz_method, "x" ) )
175 p_sys->i_mode = DEINTERLACE_X;
176 p_sys->b_double_rate = false;
177 p_sys->b_half_height = false;
179 else if( !strcmp( psz_method, "yadif" ) )
181 p_sys->i_mode = DEINTERLACE_YADIF;
182 p_sys->b_double_rate = false;
183 p_sys->b_half_height = false;
185 else if( !strcmp( psz_method, "yadif2x" ) )
187 p_sys->i_mode = DEINTERLACE_YADIF2X;
188 p_sys->b_double_rate = true;
189 p_sys->b_half_height = false;
191 else if( !strcmp( psz_method, "discard" ) )
193 const bool b_i422 = i_chroma == VLC_CODEC_I422 ||
194 i_chroma == VLC_CODEC_J422;
196 p_sys->i_mode = DEINTERLACE_DISCARD;
197 p_sys->b_double_rate = false;
198 p_sys->b_half_height = !b_i422;
202 if( strcmp( psz_method, "blend" ) )
204 "no valid deinterlace mode provided, using \"blend\"" );
206 p_sys->i_mode = DEINTERLACE_BLEND;
207 p_sys->b_double_rate = false;
208 p_sys->b_half_height = false;
211 msg_Dbg( p_filter, "using %s deinterlace method", psz_method );
214 static void GetOutputFormat( filter_t *p_filter,
215 video_format_t *p_dst, const video_format_t *p_src )
217 filter_sys_t *p_sys = p_filter->p_sys;
220 if( p_sys->b_half_height )
222 p_dst->i_height /= 2;
223 p_dst->i_visible_height /= 2;
224 p_dst->i_y_offset /= 2;
225 p_dst->i_sar_den *= 2;
228 if( p_src->i_chroma == VLC_CODEC_I422 ||
229 p_src->i_chroma == VLC_CODEC_J422 )
231 switch( p_sys->i_mode )
233 case DEINTERLACE_MEAN:
234 case DEINTERLACE_LINEAR:
236 case DEINTERLACE_YADIF:
237 case DEINTERLACE_YADIF2X:
238 p_dst->i_chroma = p_src->i_chroma;
241 p_dst->i_chroma = p_src->i_chroma == VLC_CODEC_I422 ? VLC_CODEC_I420 :
248 static bool IsChromaSupported( vlc_fourcc_t i_chroma )
250 return i_chroma == VLC_CODEC_I420 ||
251 i_chroma == VLC_CODEC_J420 ||
252 i_chroma == VLC_CODEC_YV12 ||
253 i_chroma == VLC_CODEC_I422 ||
254 i_chroma == VLC_CODEC_J422;
257 /*****************************************************************************
258 * RenderDiscard: only keep TOP or BOTTOM field, discard the other.
259 *****************************************************************************/
260 static void RenderDiscard( filter_t *p_filter,
261 picture_t *p_outpic, picture_t *p_pic, int i_field )
265 /* Copy image and skip lines */
266 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
268 uint8_t *p_in, *p_out_end, *p_out;
271 p_in = p_pic->p[i_plane].p_pixels
272 + i_field * p_pic->p[i_plane].i_pitch;
274 p_out = p_outpic->p[i_plane].p_pixels;
275 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
276 * p_outpic->p[i_plane].i_visible_lines;
278 switch( p_filter->fmt_in.video.i_chroma )
284 for( ; p_out < p_out_end ; )
286 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
288 p_out += p_outpic->p[i_plane].i_pitch;
289 p_in += 2 * p_pic->p[i_plane].i_pitch;
296 i_increment = 2 * p_pic->p[i_plane].i_pitch;
298 if( i_plane == Y_PLANE )
300 for( ; p_out < p_out_end ; )
302 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
303 p_out += p_outpic->p[i_plane].i_pitch;
304 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
305 p_out += p_outpic->p[i_plane].i_pitch;
311 for( ; p_out < p_out_end ; )
313 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
314 p_out += p_outpic->p[i_plane].i_pitch;
326 /*****************************************************************************
327 * RenderBob: renders a BOB picture - simple copy
328 *****************************************************************************/
329 static void RenderBob( filter_t *p_filter,
330 picture_t *p_outpic, picture_t *p_pic, int i_field )
334 /* Copy image and skip lines */
335 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
337 uint8_t *p_in, *p_out_end, *p_out;
339 p_in = p_pic->p[i_plane].p_pixels;
340 p_out = p_outpic->p[i_plane].p_pixels;
341 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
342 * p_outpic->p[i_plane].i_visible_lines;
344 switch( p_filter->fmt_in.video.i_chroma )
349 /* For BOTTOM field we need to add the first line */
352 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
353 p_in += p_pic->p[i_plane].i_pitch;
354 p_out += p_outpic->p[i_plane].i_pitch;
357 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
359 for( ; p_out < p_out_end ; )
361 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
363 p_out += p_outpic->p[i_plane].i_pitch;
365 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
367 p_in += 2 * p_pic->p[i_plane].i_pitch;
368 p_out += p_outpic->p[i_plane].i_pitch;
371 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
373 /* For TOP field we need to add the last line */
376 p_in += p_pic->p[i_plane].i_pitch;
377 p_out += p_outpic->p[i_plane].i_pitch;
378 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
384 /* For BOTTOM field we need to add the first line */
387 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
388 p_in += p_pic->p[i_plane].i_pitch;
389 p_out += p_outpic->p[i_plane].i_pitch;
392 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
394 if( i_plane == Y_PLANE )
396 for( ; p_out < p_out_end ; )
398 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
400 p_out += p_outpic->p[i_plane].i_pitch;
402 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
404 p_in += 2 * p_pic->p[i_plane].i_pitch;
405 p_out += p_outpic->p[i_plane].i_pitch;
410 for( ; p_out < p_out_end ; )
412 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
414 p_out += p_outpic->p[i_plane].i_pitch;
415 p_in += 2 * p_pic->p[i_plane].i_pitch;
419 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
421 /* For TOP field we need to add the last line */
424 p_in += p_pic->p[i_plane].i_pitch;
425 p_out += p_outpic->p[i_plane].i_pitch;
426 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
433 #define Merge p_filter->p_sys->pf_merge
434 #define EndMerge if(p_filter->p_sys->pf_end_merge) p_filter->p_sys->pf_end_merge
436 /*****************************************************************************
437 * RenderLinear: BOB with linear interpolation
438 *****************************************************************************/
439 static void RenderLinear( filter_t *p_filter,
440 picture_t *p_outpic, picture_t *p_pic, int i_field )
444 /* Copy image and skip lines */
445 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
447 uint8_t *p_in, *p_out_end, *p_out;
449 p_in = p_pic->p[i_plane].p_pixels;
450 p_out = p_outpic->p[i_plane].p_pixels;
451 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
452 * p_outpic->p[i_plane].i_visible_lines;
454 /* For BOTTOM field we need to add the first line */
457 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
458 p_in += p_pic->p[i_plane].i_pitch;
459 p_out += p_outpic->p[i_plane].i_pitch;
462 p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
464 for( ; p_out < p_out_end ; )
466 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
468 p_out += p_outpic->p[i_plane].i_pitch;
470 Merge( p_out, p_in, p_in + 2 * p_pic->p[i_plane].i_pitch,
471 p_pic->p[i_plane].i_pitch );
473 p_in += 2 * p_pic->p[i_plane].i_pitch;
474 p_out += p_outpic->p[i_plane].i_pitch;
477 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
479 /* For TOP field we need to add the last line */
482 p_in += p_pic->p[i_plane].i_pitch;
483 p_out += p_outpic->p[i_plane].i_pitch;
484 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
490 static void RenderMean( filter_t *p_filter,
491 picture_t *p_outpic, picture_t *p_pic )
495 /* Copy image and skip lines */
496 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
498 uint8_t *p_in, *p_out_end, *p_out;
500 p_in = p_pic->p[i_plane].p_pixels;
502 p_out = p_outpic->p[i_plane].p_pixels;
503 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
504 * p_outpic->p[i_plane].i_visible_lines;
506 /* All lines: mean value */
507 for( ; p_out < p_out_end ; )
509 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
510 p_pic->p[i_plane].i_pitch );
512 p_out += p_outpic->p[i_plane].i_pitch;
513 p_in += 2 * p_pic->p[i_plane].i_pitch;
519 static void RenderBlend( filter_t *p_filter,
520 picture_t *p_outpic, picture_t *p_pic )
524 /* Copy image and skip lines */
525 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
527 uint8_t *p_in, *p_out_end, *p_out;
529 p_in = p_pic->p[i_plane].p_pixels;
531 p_out = p_outpic->p[i_plane].p_pixels;
532 p_out_end = p_out + p_outpic->p[i_plane].i_pitch
533 * p_outpic->p[i_plane].i_visible_lines;
535 switch( p_filter->fmt_in.video.i_chroma )
540 /* First line: simple copy */
541 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
542 p_out += p_outpic->p[i_plane].i_pitch;
544 /* Remaining lines: mean value */
545 for( ; p_out < p_out_end ; )
547 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
548 p_pic->p[i_plane].i_pitch );
550 p_out += p_outpic->p[i_plane].i_pitch;
551 p_in += p_pic->p[i_plane].i_pitch;
557 /* First line: simple copy */
558 vlc_memcpy( p_out, p_in, p_pic->p[i_plane].i_pitch );
559 p_out += p_outpic->p[i_plane].i_pitch;
561 /* Remaining lines: mean value */
562 if( i_plane == Y_PLANE )
564 for( ; p_out < p_out_end ; )
566 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
567 p_pic->p[i_plane].i_pitch );
569 p_out += p_outpic->p[i_plane].i_pitch;
570 p_in += p_pic->p[i_plane].i_pitch;
576 for( ; p_out < p_out_end ; )
578 Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
579 p_pic->p[i_plane].i_pitch );
581 p_out += p_outpic->p[i_plane].i_pitch;
582 p_in += 2*p_pic->p[i_plane].i_pitch;
593 static void MergeGeneric( void *_p_dest, const void *_p_s1,
594 const void *_p_s2, size_t i_bytes )
596 uint8_t* p_dest = (uint8_t*)_p_dest;
597 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
598 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
599 uint8_t* p_end = p_dest + i_bytes - 8;
601 while( p_dest < p_end )
603 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
604 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
605 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
606 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
607 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
608 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
609 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
610 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
615 while( p_dest < p_end )
617 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
621 #if defined(CAN_COMPILE_MMXEXT)
622 static void MergeMMXEXT( void *_p_dest, const void *_p_s1, const void *_p_s2,
625 uint8_t* p_dest = (uint8_t*)_p_dest;
626 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
627 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
628 uint8_t* p_end = p_dest + i_bytes - 8;
629 while( p_dest < p_end )
631 __asm__ __volatile__( "movq %2,%%mm1;"
633 "movq %%mm1, %0" :"=m" (*p_dest):
643 while( p_dest < p_end )
645 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
650 #if defined(CAN_COMPILE_3DNOW)
651 static void Merge3DNow( void *_p_dest, const void *_p_s1, const void *_p_s2,
654 uint8_t* p_dest = (uint8_t*)_p_dest;
655 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
656 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
657 uint8_t* p_end = p_dest + i_bytes - 8;
658 while( p_dest < p_end )
660 __asm__ __volatile__( "movq %2,%%mm1;"
662 "movq %%mm1, %0" :"=m" (*p_dest):
672 while( p_dest < p_end )
674 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
679 #if defined(CAN_COMPILE_SSE)
680 static void MergeSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
683 uint8_t* p_dest = (uint8_t*)_p_dest;
684 const uint8_t *p_s1 = (const uint8_t *)_p_s1;
685 const uint8_t *p_s2 = (const uint8_t *)_p_s2;
687 while( (uintptr_t)p_s1 % 16 )
689 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
691 p_end = p_dest + i_bytes - 16;
692 while( p_dest < p_end )
694 __asm__ __volatile__( "movdqu %2,%%xmm1;"
696 "movdqu %%xmm1, %0" :"=m" (*p_dest):
706 while( p_dest < p_end )
708 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
713 #if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)
714 static void EndMMX( void )
716 __asm__ __volatile__( "emms" :: );
720 #if defined(CAN_COMPILE_3DNOW)
721 static void End3DNow( void )
723 __asm__ __volatile__( "femms" :: );
727 #ifdef CAN_COMPILE_C_ALTIVEC
728 static void MergeAltivec( void *_p_dest, const void *_p_s1,
729 const void *_p_s2, size_t i_bytes )
731 uint8_t *p_dest = (uint8_t *)_p_dest;
732 uint8_t *p_s1 = (uint8_t *)_p_s1;
733 uint8_t *p_s2 = (uint8_t *)_p_s2;
734 uint8_t *p_end = p_dest + i_bytes - 15;
736 /* Use C until the first 16-bytes aligned destination pixel */
737 while( (uintptr_t)p_dest & 0xF )
739 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
742 if( ( (int)p_s1 & 0xF ) | ( (int)p_s2 & 0xF ) )
744 /* Unaligned source */
745 vector unsigned char s1v, s2v, destv;
746 vector unsigned char s1oldv, s2oldv, s1newv, s2newv;
747 vector unsigned char perm1v, perm2v;
749 perm1v = vec_lvsl( 0, p_s1 );
750 perm2v = vec_lvsl( 0, p_s2 );
751 s1oldv = vec_ld( 0, p_s1 );
752 s2oldv = vec_ld( 0, p_s2 );
754 while( p_dest < p_end )
756 s1newv = vec_ld( 16, p_s1 );
757 s2newv = vec_ld( 16, p_s2 );
758 s1v = vec_perm( s1oldv, s1newv, perm1v );
759 s2v = vec_perm( s2oldv, s2newv, perm2v );
762 destv = vec_avg( s1v, s2v );
763 vec_st( destv, 0, p_dest );
773 vector unsigned char s1v, s2v, destv;
775 while( p_dest < p_end )
777 s1v = vec_ld( 0, p_s1 );
778 s2v = vec_ld( 0, p_s2 );
779 destv = vec_avg( s1v, s2v );
780 vec_st( destv, 0, p_dest );
790 while( p_dest < p_end )
792 *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
798 static void MergeNEON (void *restrict out, const void *in1,
799 const void *in2, size_t n)
802 const uint8_t *in1p = in1;
803 const uint8_t *in2p = in2;
804 size_t mis = ((uintptr_t)outp) & 15;
808 MergeGeneric (outp, in1p, in2p, mis);
815 uint8_t *end = outp + (n & ~15);
817 if ((((uintptr_t)in1p)|((uintptr_t)in2p)) & 15)
820 "vld1.u8 {q0-q1}, [%[in1]]!\n"
821 "vld1.u8 {q2-q3}, [%[in2]]!\n"
822 "vhadd.u8 q4, q0, q2\n"
823 "vld1.u8 {q6-q7}, [%[in1]]!\n"
824 "vhadd.u8 q5, q1, q3\n"
825 "vld1.u8 {q8-q9}, [%[in2]]!\n"
826 "vhadd.u8 q10, q6, q8\n"
827 "vhadd.u8 q11, q7, q9\n"
828 "vst1.u8 {q4-q5}, [%[out],:128]!\n"
829 "vst1.u8 {q10-q11}, [%[out],:128]!\n"
830 : [out] "+r" (outp), [in1] "+r" (in1p), [in2] "+r" (in2p)
832 : "q0", "q1", "q2", "memory");
836 "vld1.u8 {q0-q1}, [%[in1],:128]!\n"
837 "vld1.u8 {q2-q3}, [%[in2],:128]!\n"
838 "vhadd.u8 q4, q0, q2\n"
839 "vld1.u8 {q6-q7}, [%[in1],:128]!\n"
840 "vhadd.u8 q5, q1, q3\n"
841 "vld1.u8 {q8-q9}, [%[in2],:128]!\n"
842 "vhadd.u8 q10, q6, q8\n"
843 "vhadd.u8 q11, q7, q9\n"
844 "vst1.u8 {q4-q5}, [%[out],:128]!\n"
845 "vst1.u8 {q10-q11}, [%[out],:128]!\n"
846 : [out] "+r" (outp), [in1] "+r" (in1p), [in2] "+r" (in2p)
848 : "q0", "q1", "q2", "memory");
851 MergeGeneric (outp, in1p, in2p, n);
855 /*****************************************************************************
856 * RenderX: This algo works on a 8x8 block basic, it copies the top field
857 * and apply a process to recreate the bottom field :
858 * If a 8x8 block is classified as :
859 * - progressive: it applies a small blend (1,6,1)
861 * * in the MMX version: we do a ME between the 2 fields, if there is a
862 * good match we use MC to recreate the bottom field (with a small
864 * * otherwise: it recreates the bottom field by an edge oriented
866 *****************************************************************************/
868 /* XDeint8x8Detect: detect if a 8x8 block is interlaced.
869 * XXX: It need to access to 8x10
870 * We use more than 8 lines to help with scrolling (text)
871 * (and because XDeint8x8Frame use line 9)
872 * XXX: smooth/uniform area with noise detection doesn't works well
873 * but it's not really a problem because they don't have much details anyway
875 static inline int ssd( int a ) { return a*a; }
876 static inline int XDeint8x8DetectC( uint8_t *src, int i_src )
882 /* Detect interlacing */
884 for( y = 0; y < 7; y += 2 )
887 for( x = 0; x < 8; x++ )
889 fr += ssd(src[ x] - src[1*i_src+x]) +
890 ssd(src[i_src+x] - src[2*i_src+x]);
891 ff += ssd(src[ x] - src[2*i_src+x]) +
892 ssd(src[i_src+x] - src[3*i_src+x]);
894 if( ff < 6*fr/8 && fr > 32 )
900 return fc < 1 ? false : true;
902 #ifdef CAN_COMPILE_MMXEXT
903 static inline int XDeint8x8DetectMMXEXT( uint8_t *src, int i_src )
910 /* Detect interlacing */
912 pxor_r2r( mm7, mm7 );
913 for( y = 0; y < 9; y += 2 )
916 pxor_r2r( mm5, mm5 );
917 pxor_r2r( mm6, mm6 );
918 for( x = 0; x < 8; x+=4 )
920 movd_m2r( src[ x], mm0 );
921 movd_m2r( src[1*i_src+x], mm1 );
922 movd_m2r( src[2*i_src+x], mm2 );
923 movd_m2r( src[3*i_src+x], mm3 );
925 punpcklbw_r2r( mm7, mm0 );
926 punpcklbw_r2r( mm7, mm1 );
927 punpcklbw_r2r( mm7, mm2 );
928 punpcklbw_r2r( mm7, mm3 );
930 movq_r2r( mm0, mm4 );
932 psubw_r2r( mm1, mm0 );
933 psubw_r2r( mm2, mm4 );
935 psubw_r2r( mm1, mm2 );
936 psubw_r2r( mm1, mm3 );
938 pmaddwd_r2r( mm0, mm0 );
939 pmaddwd_r2r( mm4, mm4 );
940 pmaddwd_r2r( mm2, mm2 );
941 pmaddwd_r2r( mm3, mm3 );
942 paddd_r2r( mm0, mm2 );
943 paddd_r2r( mm4, mm3 );
944 paddd_r2r( mm2, mm5 );
945 paddd_r2r( mm3, mm6 );
948 movq_r2r( mm5, mm0 );
949 psrlq_i2r( 32, mm0 );
950 paddd_r2r( mm0, mm5 );
953 movq_r2r( mm6, mm0 );
954 psrlq_i2r( 32, mm0 );
955 paddd_r2r( mm0, mm6 );
958 if( ff < 6*fr/8 && fr > 32 )
967 static inline void XDeint8x8MergeC( uint8_t *dst, int i_dst,
968 uint8_t *src1, int i_src1,
969 uint8_t *src2, int i_src2 )
974 for( y = 0; y < 8; y += 2 )
976 memcpy( dst, src1, 8 );
979 for( x = 0; x < 8; x++ )
980 dst[x] = (src1[x] + 6*src2[x] + src1[i_src1+x] + 4 ) >> 3;
988 #ifdef CAN_COMPILE_MMXEXT
989 static inline void XDeint8x8MergeMMXEXT( uint8_t *dst, int i_dst,
990 uint8_t *src1, int i_src1,
991 uint8_t *src2, int i_src2 )
993 static const uint64_t m_4 = INT64_C(0x0004000400040004);
997 pxor_r2r( mm7, mm7 );
998 for( y = 0; y < 8; y += 2 )
1000 for( x = 0; x < 8; x +=4 )
1002 movd_m2r( src1[x], mm0 );
1003 movd_r2m( mm0, dst[x] );
1005 movd_m2r( src2[x], mm1 );
1006 movd_m2r( src1[i_src1+x], mm2 );
1008 punpcklbw_r2r( mm7, mm0 );
1009 punpcklbw_r2r( mm7, mm1 );
1010 punpcklbw_r2r( mm7, mm2 );
1011 paddw_r2r( mm1, mm1 );
1012 movq_r2r( mm1, mm3 );
1013 paddw_r2r( mm3, mm3 );
1014 paddw_r2r( mm2, mm0 );
1015 paddw_r2r( mm3, mm1 );
1016 paddw_m2r( m_4, mm1 );
1017 paddw_r2r( mm1, mm0 );
1018 psraw_i2r( 3, mm0 );
1019 packuswb_r2r( mm7, mm0 );
1020 movd_r2m( mm0, dst[i_dst+x] );
1031 static inline void XDeint8x8Set( uint8_t *dst, int i_dst, uint8_t v )
1034 for( y = 0; y < 8; y++ )
1035 memset( &dst[y*i_dst], v, 8 );
1038 /* XDeint8x8FieldE: Stupid deinterlacing (1,0,1) for block that miss a
1041 * TODO: a better one for the inner part.
1043 static inline void XDeint8x8FieldEC( uint8_t *dst, int i_dst,
1044 uint8_t *src, int i_src )
1049 for( y = 0; y < 8; y += 2 )
1051 memcpy( dst, src, 8 );
1054 for( x = 0; x < 8; x++ )
1055 dst[x] = (src[x] + src[2*i_src+x] ) >> 1;
1060 #ifdef CAN_COMPILE_MMXEXT
1061 static inline void XDeint8x8FieldEMMXEXT( uint8_t *dst, int i_dst,
1062 uint8_t *src, int i_src )
1067 for( y = 0; y < 8; y += 2 )
1069 movq_m2r( src[0], mm0 );
1070 movq_r2m( mm0, dst[0] );
1073 movq_m2r( src[2*i_src], mm1 );
1074 pavgb_r2r( mm1, mm0 );
1076 movq_r2m( mm0, dst[0] );
1084 /* XDeint8x8Field: Edge oriented interpolation
1085 * (Need -4 and +5 pixels H, +1 line)
1087 static inline void XDeint8x8FieldC( uint8_t *dst, int i_dst,
1088 uint8_t *src, int i_src )
1093 for( y = 0; y < 8; y += 2 )
1095 memcpy( dst, src, 8 );
1098 for( x = 0; x < 8; x++ )
1100 uint8_t *src2 = &src[2*i_src];
1101 /* I use 8 pixels just to match the MMX version, but it's overkill
1102 * 5 would be enough (less isn't good) */
1103 const int c0 = abs(src[x-4]-src2[x-2]) + abs(src[x-3]-src2[x-1]) +
1104 abs(src[x-2]-src2[x+0]) + abs(src[x-1]-src2[x+1]) +
1105 abs(src[x+0]-src2[x+2]) + abs(src[x+1]-src2[x+3]) +
1106 abs(src[x+2]-src2[x+4]) + abs(src[x+3]-src2[x+5]);
1108 const int c1 = abs(src[x-3]-src2[x-3]) + abs(src[x-2]-src2[x-2]) +
1109 abs(src[x-1]-src2[x-1]) + abs(src[x+0]-src2[x+0]) +
1110 abs(src[x+1]-src2[x+1]) + abs(src[x+2]-src2[x+2]) +
1111 abs(src[x+3]-src2[x+3]) + abs(src[x+4]-src2[x+4]);
1113 const int c2 = abs(src[x-2]-src2[x-4]) + abs(src[x-1]-src2[x-3]) +
1114 abs(src[x+0]-src2[x-2]) + abs(src[x+1]-src2[x-1]) +
1115 abs(src[x+2]-src2[x+0]) + abs(src[x+3]-src2[x+1]) +
1116 abs(src[x+4]-src2[x+2]) + abs(src[x+5]-src2[x+3]);
1118 if( c0 < c1 && c1 <= c2 )
1119 dst[x] = (src[x-1] + src2[x+1]) >> 1;
1120 else if( c2 < c1 && c1 <= c0 )
1121 dst[x] = (src[x+1] + src2[x-1]) >> 1;
1123 dst[x] = (src[x+0] + src2[x+0]) >> 1;
1130 #ifdef CAN_COMPILE_MMXEXT
1131 static inline void XDeint8x8FieldMMXEXT( uint8_t *dst, int i_dst,
1132 uint8_t *src, int i_src )
1137 for( y = 0; y < 8; y += 2 )
1139 memcpy( dst, src, 8 );
1142 for( x = 0; x < 8; x++ )
1144 uint8_t *src2 = &src[2*i_src];
1147 movq_m2r( src[x-2], mm0 );
1148 movq_m2r( src[x-3], mm1 );
1149 movq_m2r( src[x-4], mm2 );
1151 psadbw_m2r( src2[x-4], mm0 );
1152 psadbw_m2r( src2[x-3], mm1 );
1153 psadbw_m2r( src2[x-2], mm2 );
1155 movd_r2m( mm0, c2 );
1156 movd_r2m( mm1, c1 );
1157 movd_r2m( mm2, c0 );
1159 if( c0 < c1 && c1 <= c2 )
1160 dst[x] = (src[x-1] + src2[x+1]) >> 1;
1161 else if( c2 < c1 && c1 <= c0 )
1162 dst[x] = (src[x+1] + src2[x-1]) >> 1;
1164 dst[x] = (src[x+0] + src2[x+0]) >> 1;
1173 /* NxN arbitray size (and then only use pixel in the NxN block)
1175 static inline int XDeintNxNDetect( uint8_t *src, int i_src,
1176 int i_height, int i_width )
1183 /* Detect interlacing */
1184 /* FIXME way too simple, need to be more like XDeint8x8Detect */
1187 for( y = 0; y < i_height - 2; y += 2 )
1189 const uint8_t *s = &src[y*i_src];
1190 for( x = 0; x < i_width; x++ )
1192 fr += ssd(s[ x] - s[1*i_src+x]);
1193 ff += ssd(s[ x] - s[2*i_src+x]);
1195 if( ff < fr && fr > i_width / 2 )
1199 return fc < 2 ? false : true;
1202 static inline void XDeintNxNFrame( uint8_t *dst, int i_dst,
1203 uint8_t *src, int i_src,
1204 int i_width, int i_height )
1209 for( y = 0; y < i_height; y += 2 )
1211 memcpy( dst, src, i_width );
1214 if( y < i_height - 2 )
1216 for( x = 0; x < i_width; x++ )
1217 dst[x] = (src[x] + 2*src[1*i_src+x] + src[2*i_src+x] + 2 ) >> 2;
1221 /* Blend last line */
1222 for( x = 0; x < i_width; x++ )
1223 dst[x] = (src[x] + src[1*i_src+x] ) >> 1;
1230 static inline void XDeintNxNField( uint8_t *dst, int i_dst,
1231 uint8_t *src, int i_src,
1232 int i_width, int i_height )
1237 for( y = 0; y < i_height; y += 2 )
1239 memcpy( dst, src, i_width );
1242 if( y < i_height - 2 )
1244 for( x = 0; x < i_width; x++ )
1245 dst[x] = (src[x] + src[2*i_src+x] ) >> 1;
1249 /* Blend last line */
1250 for( x = 0; x < i_width; x++ )
1251 dst[x] = (src[x] + src[i_src+x]) >> 1;
1258 static inline void XDeintNxN( uint8_t *dst, int i_dst, uint8_t *src, int i_src,
1259 int i_width, int i_height )
1261 if( XDeintNxNDetect( src, i_src, i_width, i_height ) )
1262 XDeintNxNField( dst, i_dst, src, i_src, i_width, i_height );
1264 XDeintNxNFrame( dst, i_dst, src, i_src, i_width, i_height );
1268 static inline int median( int a, int b, int c )
1270 int min = a, max =a;
1281 return a + b + c - min - max;
1287 static inline void XDeintBand8x8C( uint8_t *dst, int i_dst,
1288 uint8_t *src, int i_src,
1289 const int i_mbx, int i_modx )
1293 for( x = 0; x < i_mbx; x++ )
1296 if( ( s = XDeint8x8DetectC( src, i_src ) ) )
1298 if( x == 0 || x == i_mbx - 1 )
1299 XDeint8x8FieldEC( dst, i_dst, src, i_src );
1301 XDeint8x8FieldC( dst, i_dst, src, i_src );
1305 XDeint8x8MergeC( dst, i_dst,
1306 &src[0*i_src], 2*i_src,
1307 &src[1*i_src], 2*i_src );
1315 XDeintNxN( dst, i_dst, src, i_src, i_modx, 8 );
1317 #ifdef CAN_COMPILE_MMXEXT
1318 static inline void XDeintBand8x8MMXEXT( uint8_t *dst, int i_dst,
1319 uint8_t *src, int i_src,
1320 const int i_mbx, int i_modx )
1324 /* Reset current line */
1325 for( x = 0; x < i_mbx; x++ )
1328 if( ( s = XDeint8x8DetectMMXEXT( src, i_src ) ) )
1330 if( x == 0 || x == i_mbx - 1 )
1331 XDeint8x8FieldEMMXEXT( dst, i_dst, src, i_src );
1333 XDeint8x8FieldMMXEXT( dst, i_dst, src, i_src );
1337 XDeint8x8MergeMMXEXT( dst, i_dst,
1338 &src[0*i_src], 2*i_src,
1339 &src[1*i_src], 2*i_src );
1347 XDeintNxN( dst, i_dst, src, i_src, i_modx, 8 );
1351 static void RenderX( picture_t *p_outpic, picture_t *p_pic )
1355 /* Copy image and skip lines */
1356 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1358 const int i_mby = ( p_outpic->p[i_plane].i_visible_lines + 7 )/8 - 1;
1359 const int i_mbx = p_outpic->p[i_plane].i_visible_pitch/8;
1361 const int i_mody = p_outpic->p[i_plane].i_visible_lines - 8*i_mby;
1362 const int i_modx = p_outpic->p[i_plane].i_visible_pitch - 8*i_mbx;
1364 const int i_dst = p_outpic->p[i_plane].i_pitch;
1365 const int i_src = p_pic->p[i_plane].i_pitch;
1369 for( y = 0; y < i_mby; y++ )
1371 uint8_t *dst = &p_outpic->p[i_plane].p_pixels[8*y*i_dst];
1372 uint8_t *src = &p_pic->p[i_plane].p_pixels[8*y*i_src];
1374 #ifdef CAN_COMPILE_MMXEXT
1375 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
1376 XDeintBand8x8MMXEXT( dst, i_dst, src, i_src, i_mbx, i_modx );
1379 XDeintBand8x8C( dst, i_dst, src, i_src, i_mbx, i_modx );
1382 /* Last line (C only)*/
1385 uint8_t *dst = &p_outpic->p[i_plane].p_pixels[8*y*i_dst];
1386 uint8_t *src = &p_pic->p[i_plane].p_pixels[8*y*i_src];
1388 for( x = 0; x < i_mbx; x++ )
1390 XDeintNxN( dst, i_dst, src, i_src, 8, i_mody );
1397 XDeintNxN( dst, i_dst, src, i_src, i_modx, i_mody );
1401 #ifdef CAN_COMPILE_MMXEXT
1402 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
1407 /*****************************************************************************
1408 * Yadif (Yet Another DeInterlacing Filter).
1409 *****************************************************************************/
1413 * 0: Output 1 frame for each frame.
1414 * 1: Output 1 frame for each field.
1415 * 2: Like 0 but skips spatial interlacing check.
1416 * 3: Like 1 but skips spatial interlacing check.
1418 * In vlc, only & 0x02 has meaning, as we do the & 0x01 ourself.
1423 /* I am unsure it is the right one */
1424 typedef intptr_t x86_reg;
1426 #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
1427 #define FFMAX(a,b) __MAX(a,b)
1428 #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
1429 #define FFMIN(a,b) __MIN(a,b)
1430 #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
1432 /* yadif.h comes from vf_yadif.c of mplayer project */
1435 static void RenderYadif( filter_t *p_filter, picture_t *p_dst, picture_t *p_src, int i_order, int i_field )
1437 filter_sys_t *p_sys = p_filter->p_sys;
1440 assert( i_order == 0 || i_order == 1 );
1441 assert( i_field == 0 || i_field == 1 );
1445 /* Duplicate the picture
1446 * TODO when the vout rework is finished, picture_Hold() might be enough
1447 * but becarefull, the pitches must match */
1448 picture_t *p_dup = picture_NewFromFormat( &p_src->format );
1450 picture_Copy( p_dup, p_src );
1452 /* Slide the history */
1453 if( p_sys->pp_history[0] )
1454 picture_Release( p_sys->pp_history[0] );
1455 for( int i = 1; i < HISTORY_SIZE; i++ )
1456 p_sys->pp_history[i-1] = p_sys->pp_history[i];
1457 p_sys->pp_history[HISTORY_SIZE-1] = p_dup;
1460 /* As the pitches must match, use ONLY pictures coming from picture_New()! */
1461 picture_t *p_prev = p_sys->pp_history[0];
1462 picture_t *p_cur = p_sys->pp_history[1];
1463 picture_t *p_next = p_sys->pp_history[2];
1465 /* Filter if we have all the pictures we need */
1466 if( p_prev && p_cur && p_next )
1469 void (*filter)(struct vf_priv_s *p, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int refs, int parity);
1470 #if defined(HAVE_YADIF_SSE2)
1471 if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
1472 filter = yadif_filter_line_mmx2;
1475 filter = yadif_filter_line_c;
1477 for( int n = 0; n < p_dst->i_planes; n++ )
1479 const plane_t *prevp = &p_prev->p[n];
1480 const plane_t *curp = &p_cur->p[n];
1481 const plane_t *nextp = &p_next->p[n];
1482 plane_t *dstp = &p_dst->p[n];
1484 for( int y = 1; y < dstp->i_visible_lines - 1; y++ )
1486 if( (y % 2) == i_field )
1488 vlc_memcpy( &dstp->p_pixels[y * dstp->i_pitch],
1489 &curp->p_pixels[y * curp->i_pitch], dstp->i_visible_pitch );
1493 struct vf_priv_s cfg;
1494 /* Spatial checks only when enough data */
1495 cfg.mode = (y >= 2 && y < dstp->i_visible_lines - 2) ? 0 : 2;
1497 assert( prevp->i_pitch == curp->i_pitch && curp->i_pitch == nextp->i_pitch );
1499 &dstp->p_pixels[y * dstp->i_pitch],
1500 &prevp->p_pixels[y * prevp->i_pitch],
1501 &curp->p_pixels[y * curp->i_pitch],
1502 &nextp->p_pixels[y * nextp->i_pitch],
1503 dstp->i_visible_pitch,
1505 (i_field ^ (i_order == i_field)) & 1 );
1508 /* We duplicate the first and last lines */
1510 vlc_memcpy(&dstp->p_pixels[(y-1) * dstp->i_pitch], &dstp->p_pixels[y * dstp->i_pitch], dstp->i_pitch);
1511 else if( y == dstp->i_visible_lines - 2 )
1512 vlc_memcpy(&dstp->p_pixels[(y+1) * dstp->i_pitch], &dstp->p_pixels[y * dstp->i_pitch], dstp->i_pitch);
1517 p_dst->date = (p_next->date - p_cur->date) * i_order / 2 + p_cur->date;
1521 /* Fallback to something simple
1522 * XXX it is wrong when we have 2 pictures, we should not output a picture */
1523 RenderX( p_dst, p_src );
1527 /*****************************************************************************
1528 * video filter2 functions
1529 *****************************************************************************/
1530 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
1532 filter_sys_t *p_sys = p_filter->p_sys;
1533 picture_t *p_pic_dst;
1535 /* Request output picture */
1536 p_pic_dst = filter_NewPicture( p_filter );
1537 if( p_pic_dst == NULL )
1539 picture_Release( p_pic );
1543 switch( p_sys->i_mode )
1545 case DEINTERLACE_DISCARD:
1546 RenderDiscard( p_filter, p_pic_dst, p_pic, 0 );
1549 case DEINTERLACE_BOB:
1551 RenderBob( p_filter, pp_outpic[0], p_pic, !p_pic->b_top_field_first );
1552 RenderBob( p_filter, pp_outpic[1], p_pic, p_pic->b_top_field_first );
1556 case DEINTERLACE_LINEAR:
1558 RenderLinear( p_filter, pp_outpic[0], p_pic, !p_pic->b_top_field_first );
1559 RenderLinear( p_filter, pp_outpic[1], p_pic, p_pic->b_top_field_first );
1561 msg_Err( p_filter, "doubling the frame rate is not supported yet" );
1562 picture_Release( p_pic_dst );
1563 picture_Release( p_pic );
1566 case DEINTERLACE_MEAN:
1567 RenderMean( p_filter, p_pic_dst, p_pic );
1570 case DEINTERLACE_BLEND:
1571 RenderBlend( p_filter, p_pic_dst, p_pic );
1575 RenderX( p_pic_dst, p_pic );
1578 case DEINTERLACE_YADIF:
1579 msg_Err( p_filter, "delaying frames is not supported yet" );
1580 //RenderYadif( p_vout, pp_outpic[0], p_pic, 0, 0 );
1581 picture_Release( p_pic_dst );
1582 picture_Release( p_pic );
1585 case DEINTERLACE_YADIF2X:
1586 msg_Err( p_filter, "doubling the frame rate is not supported yet" );
1587 //RenderYadif( p_vout, pp_outpic[0], p_pic, 0, !p_pic->b_top_field_first );
1588 //RenderYadif( p_vout, pp_outpic[1], p_pic, 1, p_pic->b_top_field_first );
1589 picture_Release( p_pic_dst );
1590 picture_Release( p_pic );
1594 picture_CopyProperties( p_pic_dst, p_pic );
1595 p_pic_dst->b_progressive = true;
1597 picture_Release( p_pic );
1601 static int Mouse( filter_t *p_filter,
1602 vlc_mouse_t *p_mouse, const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
1605 if( p_filter->p_sys->b_half_height )
1611 /*****************************************************************************
1613 *****************************************************************************/
1614 static int Open( vlc_object_t *p_this )
1616 filter_t *p_filter = (filter_t*)p_this;
1617 filter_sys_t *p_sys;
1619 if( !IsChromaSupported( p_filter->fmt_in.video.i_chroma ) )
1620 return VLC_EGENERIC;
1623 p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
1627 p_sys->i_mode = DEINTERLACE_BLEND;
1628 p_sys->b_double_rate = false;
1629 p_sys->b_half_height = true;
1631 #if defined(CAN_COMPILE_C_ALTIVEC)
1632 if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
1634 p_sys->pf_merge = MergeAltivec;
1635 p_sys->pf_end_merge = NULL;
1639 #if defined(CAN_COMPILE_SSE)
1640 if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
1642 p_sys->pf_merge = MergeSSE2;
1643 p_sys->pf_end_merge = EndMMX;
1647 #if defined(CAN_COMPILE_MMXEXT)
1648 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
1650 p_sys->pf_merge = MergeMMXEXT;
1651 p_sys->pf_end_merge = EndMMX;
1655 #if defined(CAN_COMPILE_3DNOW)
1656 if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
1658 p_sys->pf_merge = Merge3DNow;
1659 p_sys->pf_end_merge = End3DNow;
1663 #if defined __ARM_NEON__
1664 if( vlc_CPU() & CPU_CAPABILITY_NEON )
1666 p_sys->pf_merge = MergeNEON;
1667 p_sys->pf_end_merge = NULL;
1672 p_sys->pf_merge = MergeGeneric;
1673 p_sys->pf_end_merge = NULL;
1677 config_ChainParse( p_filter, FILTER_CFG_PREFIX, ppsz_filter_options,
1680 char *psz_mode = var_GetNonEmptyString( p_filter, FILTER_CFG_PREFIX "mode" );
1681 SetFilterMethod( p_filter, psz_mode, p_filter->fmt_in.video.i_chroma );
1686 GetOutputFormat( p_filter, &fmt, &p_filter->fmt_in.video );
1687 if( !p_filter->b_allow_fmt_out_change &&
1688 ( fmt.i_chroma != p_filter->fmt_in.video.i_chroma ||
1689 fmt.i_height != p_filter->fmt_in.video.i_height ) )
1691 Close( VLC_OBJECT(p_filter) );
1692 return VLC_EGENERIC;
1694 p_filter->fmt_out.video = fmt;
1695 p_filter->fmt_out.i_codec = fmt.i_chroma;
1696 p_filter->pf_video_filter = Deinterlace;
1697 p_filter->pf_video_mouse = Mouse;
1699 msg_Dbg( p_filter, "deinterlacing" );
1704 /*****************************************************************************
1705 * Close: clean up the filter
1706 *****************************************************************************/
1707 static void Close( vlc_object_t *p_this )
1709 filter_t *p_filter = (filter_t*)p_this;
1711 free( p_filter->p_sys );