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", "q3", "q4", "q5", "q6", "q7",
833 "q8", "q9", "q10", "q11", "memory");
837 "vld1.u8 {q0-q1}, [%[in1],:128]!\n"
838 "vld1.u8 {q2-q3}, [%[in2],:128]!\n"
839 "vhadd.u8 q4, q0, q2\n"
840 "vld1.u8 {q6-q7}, [%[in1],:128]!\n"
841 "vhadd.u8 q5, q1, q3\n"
842 "vld1.u8 {q8-q9}, [%[in2],:128]!\n"
843 "vhadd.u8 q10, q6, q8\n"
844 "vhadd.u8 q11, q7, q9\n"
845 "vst1.u8 {q4-q5}, [%[out],:128]!\n"
846 "vst1.u8 {q10-q11}, [%[out],:128]!\n"
847 : [out] "+r" (outp), [in1] "+r" (in1p), [in2] "+r" (in2p)
849 : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
850 "q8", "q9", "q10", "q11", "memory");
853 MergeGeneric (outp, in1p, in2p, n);
857 /*****************************************************************************
858 * RenderX: This algo works on a 8x8 block basic, it copies the top field
859 * and apply a process to recreate the bottom field :
860 * If a 8x8 block is classified as :
861 * - progressive: it applies a small blend (1,6,1)
863 * * in the MMX version: we do a ME between the 2 fields, if there is a
864 * good match we use MC to recreate the bottom field (with a small
866 * * otherwise: it recreates the bottom field by an edge oriented
868 *****************************************************************************/
870 /* XDeint8x8Detect: detect if a 8x8 block is interlaced.
871 * XXX: It need to access to 8x10
872 * We use more than 8 lines to help with scrolling (text)
873 * (and because XDeint8x8Frame use line 9)
874 * XXX: smooth/uniform area with noise detection doesn't works well
875 * but it's not really a problem because they don't have much details anyway
877 static inline int ssd( int a ) { return a*a; }
878 static inline int XDeint8x8DetectC( uint8_t *src, int i_src )
884 /* Detect interlacing */
886 for( y = 0; y < 7; y += 2 )
889 for( x = 0; x < 8; x++ )
891 fr += ssd(src[ x] - src[1*i_src+x]) +
892 ssd(src[i_src+x] - src[2*i_src+x]);
893 ff += ssd(src[ x] - src[2*i_src+x]) +
894 ssd(src[i_src+x] - src[3*i_src+x]);
896 if( ff < 6*fr/8 && fr > 32 )
902 return fc < 1 ? false : true;
904 #ifdef CAN_COMPILE_MMXEXT
905 static inline int XDeint8x8DetectMMXEXT( uint8_t *src, int i_src )
912 /* Detect interlacing */
914 pxor_r2r( mm7, mm7 );
915 for( y = 0; y < 9; y += 2 )
918 pxor_r2r( mm5, mm5 );
919 pxor_r2r( mm6, mm6 );
920 for( x = 0; x < 8; x+=4 )
922 movd_m2r( src[ x], mm0 );
923 movd_m2r( src[1*i_src+x], mm1 );
924 movd_m2r( src[2*i_src+x], mm2 );
925 movd_m2r( src[3*i_src+x], mm3 );
927 punpcklbw_r2r( mm7, mm0 );
928 punpcklbw_r2r( mm7, mm1 );
929 punpcklbw_r2r( mm7, mm2 );
930 punpcklbw_r2r( mm7, mm3 );
932 movq_r2r( mm0, mm4 );
934 psubw_r2r( mm1, mm0 );
935 psubw_r2r( mm2, mm4 );
937 psubw_r2r( mm1, mm2 );
938 psubw_r2r( mm1, mm3 );
940 pmaddwd_r2r( mm0, mm0 );
941 pmaddwd_r2r( mm4, mm4 );
942 pmaddwd_r2r( mm2, mm2 );
943 pmaddwd_r2r( mm3, mm3 );
944 paddd_r2r( mm0, mm2 );
945 paddd_r2r( mm4, mm3 );
946 paddd_r2r( mm2, mm5 );
947 paddd_r2r( mm3, mm6 );
950 movq_r2r( mm5, mm0 );
951 psrlq_i2r( 32, mm0 );
952 paddd_r2r( mm0, mm5 );
955 movq_r2r( mm6, mm0 );
956 psrlq_i2r( 32, mm0 );
957 paddd_r2r( mm0, mm6 );
960 if( ff < 6*fr/8 && fr > 32 )
969 static inline void XDeint8x8MergeC( uint8_t *dst, int i_dst,
970 uint8_t *src1, int i_src1,
971 uint8_t *src2, int i_src2 )
976 for( y = 0; y < 8; y += 2 )
978 memcpy( dst, src1, 8 );
981 for( x = 0; x < 8; x++ )
982 dst[x] = (src1[x] + 6*src2[x] + src1[i_src1+x] + 4 ) >> 3;
990 #ifdef CAN_COMPILE_MMXEXT
991 static inline void XDeint8x8MergeMMXEXT( uint8_t *dst, int i_dst,
992 uint8_t *src1, int i_src1,
993 uint8_t *src2, int i_src2 )
995 static const uint64_t m_4 = INT64_C(0x0004000400040004);
999 pxor_r2r( mm7, mm7 );
1000 for( y = 0; y < 8; y += 2 )
1002 for( x = 0; x < 8; x +=4 )
1004 movd_m2r( src1[x], mm0 );
1005 movd_r2m( mm0, dst[x] );
1007 movd_m2r( src2[x], mm1 );
1008 movd_m2r( src1[i_src1+x], mm2 );
1010 punpcklbw_r2r( mm7, mm0 );
1011 punpcklbw_r2r( mm7, mm1 );
1012 punpcklbw_r2r( mm7, mm2 );
1013 paddw_r2r( mm1, mm1 );
1014 movq_r2r( mm1, mm3 );
1015 paddw_r2r( mm3, mm3 );
1016 paddw_r2r( mm2, mm0 );
1017 paddw_r2r( mm3, mm1 );
1018 paddw_m2r( m_4, mm1 );
1019 paddw_r2r( mm1, mm0 );
1020 psraw_i2r( 3, mm0 );
1021 packuswb_r2r( mm7, mm0 );
1022 movd_r2m( mm0, dst[i_dst+x] );
1033 static inline void XDeint8x8Set( uint8_t *dst, int i_dst, uint8_t v )
1036 for( y = 0; y < 8; y++ )
1037 memset( &dst[y*i_dst], v, 8 );
1040 /* XDeint8x8FieldE: Stupid deinterlacing (1,0,1) for block that miss a
1043 * TODO: a better one for the inner part.
1045 static inline void XDeint8x8FieldEC( uint8_t *dst, int i_dst,
1046 uint8_t *src, int i_src )
1051 for( y = 0; y < 8; y += 2 )
1053 memcpy( dst, src, 8 );
1056 for( x = 0; x < 8; x++ )
1057 dst[x] = (src[x] + src[2*i_src+x] ) >> 1;
1062 #ifdef CAN_COMPILE_MMXEXT
1063 static inline void XDeint8x8FieldEMMXEXT( uint8_t *dst, int i_dst,
1064 uint8_t *src, int i_src )
1069 for( y = 0; y < 8; y += 2 )
1071 movq_m2r( src[0], mm0 );
1072 movq_r2m( mm0, dst[0] );
1075 movq_m2r( src[2*i_src], mm1 );
1076 pavgb_r2r( mm1, mm0 );
1078 movq_r2m( mm0, dst[0] );
1086 /* XDeint8x8Field: Edge oriented interpolation
1087 * (Need -4 and +5 pixels H, +1 line)
1089 static inline void XDeint8x8FieldC( uint8_t *dst, int i_dst,
1090 uint8_t *src, int i_src )
1095 for( y = 0; y < 8; y += 2 )
1097 memcpy( dst, src, 8 );
1100 for( x = 0; x < 8; x++ )
1102 uint8_t *src2 = &src[2*i_src];
1103 /* I use 8 pixels just to match the MMX version, but it's overkill
1104 * 5 would be enough (less isn't good) */
1105 const int c0 = abs(src[x-4]-src2[x-2]) + abs(src[x-3]-src2[x-1]) +
1106 abs(src[x-2]-src2[x+0]) + abs(src[x-1]-src2[x+1]) +
1107 abs(src[x+0]-src2[x+2]) + abs(src[x+1]-src2[x+3]) +
1108 abs(src[x+2]-src2[x+4]) + abs(src[x+3]-src2[x+5]);
1110 const int c1 = abs(src[x-3]-src2[x-3]) + abs(src[x-2]-src2[x-2]) +
1111 abs(src[x-1]-src2[x-1]) + abs(src[x+0]-src2[x+0]) +
1112 abs(src[x+1]-src2[x+1]) + abs(src[x+2]-src2[x+2]) +
1113 abs(src[x+3]-src2[x+3]) + abs(src[x+4]-src2[x+4]);
1115 const int c2 = abs(src[x-2]-src2[x-4]) + abs(src[x-1]-src2[x-3]) +
1116 abs(src[x+0]-src2[x-2]) + abs(src[x+1]-src2[x-1]) +
1117 abs(src[x+2]-src2[x+0]) + abs(src[x+3]-src2[x+1]) +
1118 abs(src[x+4]-src2[x+2]) + abs(src[x+5]-src2[x+3]);
1120 if( c0 < c1 && c1 <= c2 )
1121 dst[x] = (src[x-1] + src2[x+1]) >> 1;
1122 else if( c2 < c1 && c1 <= c0 )
1123 dst[x] = (src[x+1] + src2[x-1]) >> 1;
1125 dst[x] = (src[x+0] + src2[x+0]) >> 1;
1132 #ifdef CAN_COMPILE_MMXEXT
1133 static inline void XDeint8x8FieldMMXEXT( uint8_t *dst, int i_dst,
1134 uint8_t *src, int i_src )
1139 for( y = 0; y < 8; y += 2 )
1141 memcpy( dst, src, 8 );
1144 for( x = 0; x < 8; x++ )
1146 uint8_t *src2 = &src[2*i_src];
1149 movq_m2r( src[x-2], mm0 );
1150 movq_m2r( src[x-3], mm1 );
1151 movq_m2r( src[x-4], mm2 );
1153 psadbw_m2r( src2[x-4], mm0 );
1154 psadbw_m2r( src2[x-3], mm1 );
1155 psadbw_m2r( src2[x-2], mm2 );
1157 movd_r2m( mm0, c2 );
1158 movd_r2m( mm1, c1 );
1159 movd_r2m( mm2, c0 );
1161 if( c0 < c1 && c1 <= c2 )
1162 dst[x] = (src[x-1] + src2[x+1]) >> 1;
1163 else if( c2 < c1 && c1 <= c0 )
1164 dst[x] = (src[x+1] + src2[x-1]) >> 1;
1166 dst[x] = (src[x+0] + src2[x+0]) >> 1;
1175 /* NxN arbitray size (and then only use pixel in the NxN block)
1177 static inline int XDeintNxNDetect( uint8_t *src, int i_src,
1178 int i_height, int i_width )
1185 /* Detect interlacing */
1186 /* FIXME way too simple, need to be more like XDeint8x8Detect */
1189 for( y = 0; y < i_height - 2; y += 2 )
1191 const uint8_t *s = &src[y*i_src];
1192 for( x = 0; x < i_width; x++ )
1194 fr += ssd(s[ x] - s[1*i_src+x]);
1195 ff += ssd(s[ x] - s[2*i_src+x]);
1197 if( ff < fr && fr > i_width / 2 )
1201 return fc < 2 ? false : true;
1204 static inline void XDeintNxNFrame( uint8_t *dst, int i_dst,
1205 uint8_t *src, int i_src,
1206 int i_width, int i_height )
1211 for( y = 0; y < i_height; y += 2 )
1213 memcpy( dst, src, i_width );
1216 if( y < i_height - 2 )
1218 for( x = 0; x < i_width; x++ )
1219 dst[x] = (src[x] + 2*src[1*i_src+x] + src[2*i_src+x] + 2 ) >> 2;
1223 /* Blend last line */
1224 for( x = 0; x < i_width; x++ )
1225 dst[x] = (src[x] + src[1*i_src+x] ) >> 1;
1232 static inline void XDeintNxNField( uint8_t *dst, int i_dst,
1233 uint8_t *src, int i_src,
1234 int i_width, int i_height )
1239 for( y = 0; y < i_height; y += 2 )
1241 memcpy( dst, src, i_width );
1244 if( y < i_height - 2 )
1246 for( x = 0; x < i_width; x++ )
1247 dst[x] = (src[x] + src[2*i_src+x] ) >> 1;
1251 /* Blend last line */
1252 for( x = 0; x < i_width; x++ )
1253 dst[x] = (src[x] + src[i_src+x]) >> 1;
1260 static inline void XDeintNxN( uint8_t *dst, int i_dst, uint8_t *src, int i_src,
1261 int i_width, int i_height )
1263 if( XDeintNxNDetect( src, i_src, i_width, i_height ) )
1264 XDeintNxNField( dst, i_dst, src, i_src, i_width, i_height );
1266 XDeintNxNFrame( dst, i_dst, src, i_src, i_width, i_height );
1270 static inline int median( int a, int b, int c )
1272 int min = a, max =a;
1283 return a + b + c - min - max;
1289 static inline void XDeintBand8x8C( uint8_t *dst, int i_dst,
1290 uint8_t *src, int i_src,
1291 const int i_mbx, int i_modx )
1295 for( x = 0; x < i_mbx; x++ )
1298 if( ( s = XDeint8x8DetectC( src, i_src ) ) )
1300 if( x == 0 || x == i_mbx - 1 )
1301 XDeint8x8FieldEC( dst, i_dst, src, i_src );
1303 XDeint8x8FieldC( dst, i_dst, src, i_src );
1307 XDeint8x8MergeC( dst, i_dst,
1308 &src[0*i_src], 2*i_src,
1309 &src[1*i_src], 2*i_src );
1317 XDeintNxN( dst, i_dst, src, i_src, i_modx, 8 );
1319 #ifdef CAN_COMPILE_MMXEXT
1320 static inline void XDeintBand8x8MMXEXT( uint8_t *dst, int i_dst,
1321 uint8_t *src, int i_src,
1322 const int i_mbx, int i_modx )
1326 /* Reset current line */
1327 for( x = 0; x < i_mbx; x++ )
1330 if( ( s = XDeint8x8DetectMMXEXT( src, i_src ) ) )
1332 if( x == 0 || x == i_mbx - 1 )
1333 XDeint8x8FieldEMMXEXT( dst, i_dst, src, i_src );
1335 XDeint8x8FieldMMXEXT( dst, i_dst, src, i_src );
1339 XDeint8x8MergeMMXEXT( dst, i_dst,
1340 &src[0*i_src], 2*i_src,
1341 &src[1*i_src], 2*i_src );
1349 XDeintNxN( dst, i_dst, src, i_src, i_modx, 8 );
1353 static void RenderX( picture_t *p_outpic, picture_t *p_pic )
1357 /* Copy image and skip lines */
1358 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
1360 const int i_mby = ( p_outpic->p[i_plane].i_visible_lines + 7 )/8 - 1;
1361 const int i_mbx = p_outpic->p[i_plane].i_visible_pitch/8;
1363 const int i_mody = p_outpic->p[i_plane].i_visible_lines - 8*i_mby;
1364 const int i_modx = p_outpic->p[i_plane].i_visible_pitch - 8*i_mbx;
1366 const int i_dst = p_outpic->p[i_plane].i_pitch;
1367 const int i_src = p_pic->p[i_plane].i_pitch;
1371 for( y = 0; y < i_mby; y++ )
1373 uint8_t *dst = &p_outpic->p[i_plane].p_pixels[8*y*i_dst];
1374 uint8_t *src = &p_pic->p[i_plane].p_pixels[8*y*i_src];
1376 #ifdef CAN_COMPILE_MMXEXT
1377 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
1378 XDeintBand8x8MMXEXT( dst, i_dst, src, i_src, i_mbx, i_modx );
1381 XDeintBand8x8C( dst, i_dst, src, i_src, i_mbx, i_modx );
1384 /* Last line (C only)*/
1387 uint8_t *dst = &p_outpic->p[i_plane].p_pixels[8*y*i_dst];
1388 uint8_t *src = &p_pic->p[i_plane].p_pixels[8*y*i_src];
1390 for( x = 0; x < i_mbx; x++ )
1392 XDeintNxN( dst, i_dst, src, i_src, 8, i_mody );
1399 XDeintNxN( dst, i_dst, src, i_src, i_modx, i_mody );
1403 #ifdef CAN_COMPILE_MMXEXT
1404 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
1409 /*****************************************************************************
1410 * Yadif (Yet Another DeInterlacing Filter).
1411 *****************************************************************************/
1415 * 0: Output 1 frame for each frame.
1416 * 1: Output 1 frame for each field.
1417 * 2: Like 0 but skips spatial interlacing check.
1418 * 3: Like 1 but skips spatial interlacing check.
1420 * In vlc, only & 0x02 has meaning, as we do the & 0x01 ourself.
1425 /* I am unsure it is the right one */
1426 typedef intptr_t x86_reg;
1428 #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
1429 #define FFMAX(a,b) __MAX(a,b)
1430 #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
1431 #define FFMIN(a,b) __MIN(a,b)
1432 #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
1434 /* yadif.h comes from vf_yadif.c of mplayer project */
1437 static void RenderYadif( filter_t *p_filter, picture_t *p_dst, picture_t *p_src, int i_order, int i_field )
1439 filter_sys_t *p_sys = p_filter->p_sys;
1442 assert( i_order == 0 || i_order == 1 );
1443 assert( i_field == 0 || i_field == 1 );
1447 /* Duplicate the picture
1448 * TODO when the vout rework is finished, picture_Hold() might be enough
1449 * but becarefull, the pitches must match */
1450 picture_t *p_dup = picture_NewFromFormat( &p_src->format );
1452 picture_Copy( p_dup, p_src );
1454 /* Slide the history */
1455 if( p_sys->pp_history[0] )
1456 picture_Release( p_sys->pp_history[0] );
1457 for( int i = 1; i < HISTORY_SIZE; i++ )
1458 p_sys->pp_history[i-1] = p_sys->pp_history[i];
1459 p_sys->pp_history[HISTORY_SIZE-1] = p_dup;
1462 /* As the pitches must match, use ONLY pictures coming from picture_New()! */
1463 picture_t *p_prev = p_sys->pp_history[0];
1464 picture_t *p_cur = p_sys->pp_history[1];
1465 picture_t *p_next = p_sys->pp_history[2];
1467 /* Filter if we have all the pictures we need */
1468 if( p_prev && p_cur && p_next )
1471 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);
1472 #if defined(HAVE_YADIF_SSE2)
1473 if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
1474 filter = yadif_filter_line_mmx2;
1477 filter = yadif_filter_line_c;
1479 for( int n = 0; n < p_dst->i_planes; n++ )
1481 const plane_t *prevp = &p_prev->p[n];
1482 const plane_t *curp = &p_cur->p[n];
1483 const plane_t *nextp = &p_next->p[n];
1484 plane_t *dstp = &p_dst->p[n];
1486 for( int y = 1; y < dstp->i_visible_lines - 1; y++ )
1488 if( (y % 2) == i_field )
1490 vlc_memcpy( &dstp->p_pixels[y * dstp->i_pitch],
1491 &curp->p_pixels[y * curp->i_pitch], dstp->i_visible_pitch );
1495 struct vf_priv_s cfg;
1496 /* Spatial checks only when enough data */
1497 cfg.mode = (y >= 2 && y < dstp->i_visible_lines - 2) ? 0 : 2;
1499 assert( prevp->i_pitch == curp->i_pitch && curp->i_pitch == nextp->i_pitch );
1501 &dstp->p_pixels[y * dstp->i_pitch],
1502 &prevp->p_pixels[y * prevp->i_pitch],
1503 &curp->p_pixels[y * curp->i_pitch],
1504 &nextp->p_pixels[y * nextp->i_pitch],
1505 dstp->i_visible_pitch,
1507 (i_field ^ (i_order == i_field)) & 1 );
1510 /* We duplicate the first and last lines */
1512 vlc_memcpy(&dstp->p_pixels[(y-1) * dstp->i_pitch], &dstp->p_pixels[y * dstp->i_pitch], dstp->i_pitch);
1513 else if( y == dstp->i_visible_lines - 2 )
1514 vlc_memcpy(&dstp->p_pixels[(y+1) * dstp->i_pitch], &dstp->p_pixels[y * dstp->i_pitch], dstp->i_pitch);
1519 p_dst->date = (p_next->date - p_cur->date) * i_order / 2 + p_cur->date;
1523 /* Fallback to something simple
1524 * XXX it is wrong when we have 2 pictures, we should not output a picture */
1525 RenderX( p_dst, p_src );
1529 /*****************************************************************************
1530 * video filter2 functions
1531 *****************************************************************************/
1532 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
1534 filter_sys_t *p_sys = p_filter->p_sys;
1535 picture_t *p_pic_dst;
1537 /* Request output picture */
1538 p_pic_dst = filter_NewPicture( p_filter );
1539 if( p_pic_dst == NULL )
1541 picture_Release( p_pic );
1545 switch( p_sys->i_mode )
1547 case DEINTERLACE_DISCARD:
1548 RenderDiscard( p_filter, p_pic_dst, p_pic, 0 );
1551 case DEINTERLACE_BOB:
1553 RenderBob( p_filter, pp_outpic[0], p_pic, !p_pic->b_top_field_first );
1554 RenderBob( p_filter, pp_outpic[1], p_pic, p_pic->b_top_field_first );
1558 case DEINTERLACE_LINEAR:
1560 RenderLinear( p_filter, pp_outpic[0], p_pic, !p_pic->b_top_field_first );
1561 RenderLinear( p_filter, pp_outpic[1], p_pic, p_pic->b_top_field_first );
1563 msg_Err( p_filter, "doubling the frame rate is not supported yet" );
1564 picture_Release( p_pic_dst );
1565 picture_Release( p_pic );
1568 case DEINTERLACE_MEAN:
1569 RenderMean( p_filter, p_pic_dst, p_pic );
1572 case DEINTERLACE_BLEND:
1573 RenderBlend( p_filter, p_pic_dst, p_pic );
1577 RenderX( p_pic_dst, p_pic );
1580 case DEINTERLACE_YADIF:
1581 msg_Err( p_filter, "delaying frames is not supported yet" );
1582 //RenderYadif( p_vout, pp_outpic[0], p_pic, 0, 0 );
1583 picture_Release( p_pic_dst );
1584 picture_Release( p_pic );
1587 case DEINTERLACE_YADIF2X:
1588 msg_Err( p_filter, "doubling the frame rate is not supported yet" );
1589 //RenderYadif( p_vout, pp_outpic[0], p_pic, 0, !p_pic->b_top_field_first );
1590 //RenderYadif( p_vout, pp_outpic[1], p_pic, 1, p_pic->b_top_field_first );
1591 picture_Release( p_pic_dst );
1592 picture_Release( p_pic );
1596 picture_CopyProperties( p_pic_dst, p_pic );
1597 p_pic_dst->b_progressive = true;
1599 picture_Release( p_pic );
1603 static int Mouse( filter_t *p_filter,
1604 vlc_mouse_t *p_mouse, const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
1607 if( p_filter->p_sys->b_half_height )
1613 /*****************************************************************************
1615 *****************************************************************************/
1616 static int Open( vlc_object_t *p_this )
1618 filter_t *p_filter = (filter_t*)p_this;
1619 filter_sys_t *p_sys;
1621 if( !IsChromaSupported( p_filter->fmt_in.video.i_chroma ) )
1622 return VLC_EGENERIC;
1625 p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
1629 p_sys->i_mode = DEINTERLACE_BLEND;
1630 p_sys->b_double_rate = false;
1631 p_sys->b_half_height = true;
1633 #if defined(CAN_COMPILE_C_ALTIVEC)
1634 if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
1636 p_sys->pf_merge = MergeAltivec;
1637 p_sys->pf_end_merge = NULL;
1641 #if defined(CAN_COMPILE_SSE)
1642 if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
1644 p_sys->pf_merge = MergeSSE2;
1645 p_sys->pf_end_merge = EndMMX;
1649 #if defined(CAN_COMPILE_MMXEXT)
1650 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
1652 p_sys->pf_merge = MergeMMXEXT;
1653 p_sys->pf_end_merge = EndMMX;
1657 #if defined(CAN_COMPILE_3DNOW)
1658 if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
1660 p_sys->pf_merge = Merge3DNow;
1661 p_sys->pf_end_merge = End3DNow;
1665 #if defined __ARM_NEON__
1666 if( vlc_CPU() & CPU_CAPABILITY_NEON )
1668 p_sys->pf_merge = MergeNEON;
1669 p_sys->pf_end_merge = NULL;
1674 p_sys->pf_merge = MergeGeneric;
1675 p_sys->pf_end_merge = NULL;
1679 config_ChainParse( p_filter, FILTER_CFG_PREFIX, ppsz_filter_options,
1682 char *psz_mode = var_GetNonEmptyString( p_filter, FILTER_CFG_PREFIX "mode" );
1683 SetFilterMethod( p_filter, psz_mode, p_filter->fmt_in.video.i_chroma );
1688 GetOutputFormat( p_filter, &fmt, &p_filter->fmt_in.video );
1689 if( !p_filter->b_allow_fmt_out_change &&
1690 ( fmt.i_chroma != p_filter->fmt_in.video.i_chroma ||
1691 fmt.i_height != p_filter->fmt_in.video.i_height ) )
1693 Close( VLC_OBJECT(p_filter) );
1694 return VLC_EGENERIC;
1696 p_filter->fmt_out.video = fmt;
1697 p_filter->fmt_out.i_codec = fmt.i_chroma;
1698 p_filter->pf_video_filter = Deinterlace;
1699 p_filter->pf_video_mouse = Mouse;
1701 msg_Dbg( p_filter, "deinterlacing" );
1706 /*****************************************************************************
1707 * Close: clean up the filter
1708 *****************************************************************************/
1709 static void Close( vlc_object_t *p_this )
1711 filter_t *p_filter = (filter_t*)p_this;
1713 free( p_filter->p_sys );