2 * filter_deinterlace.c -- deinterlace filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "filter_deinterlace.h"
22 #include "deinterlace.h"
24 #include <framework/mlt_frame.h>
32 static int filter_get_image( mlt_frame
this, uint8_t **image
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
35 int deinterlace
= mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "consumer_deinterlace" );
37 // Pop the service off the stack
38 mlt_filter filter
= mlt_frame_pop_service( this );
40 // Determine if we need a writable version or not
41 if ( deinterlace
&& !writable
)
42 writable
= !mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "progressive" );
44 // Get the input image
45 error
= mlt_frame_get_image( this, image
, format
, width
, height
, writable
);
47 // Check that we want progressive and we aren't already progressive
48 if ( deinterlace
&& *format
== mlt_image_yuv422
&& *image
!= NULL
&& !mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "progressive" ) )
50 // Determine deinterlace method
51 char *method_str
= mlt_properties_get( MLT_FILTER_PROPERTIES( filter
), "method" );
52 int method
= DEINTERLACE_LINEARBLEND
;
53 char *frame_method_str
= mlt_properties_get( MLT_FRAME_PROPERTIES( this ), "deinterlace_method" );
55 if ( frame_method_str
!= NULL
)
56 method_str
= frame_method_str
;
58 if ( method_str
== NULL
)
59 method
= DEINTERLACE_LINEARBLEND
;
60 else if ( strcmp( method_str
, "bob" ) == 0 )
61 method
= DEINTERLACE_BOB
;
62 else if ( strcmp( method_str
, "weave" ) == 0 )
63 method
= DEINTERLACE_BOB
;
64 else if ( strcmp( method_str
, "greedy" ) == 0 )
65 method
= DEINTERLACE_GREEDY
;
66 else if ( strcmp( method_str
, "onefield" ) == 0 )
67 method
= DEINTERLACE_ONEFIELD
;
69 // Deinterlace the image
70 deinterlace_yuv( *image
, image
, *width
* 2, *height
, method
);
72 // Make sure that others know the frame is deinterlaced
73 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "progressive", 1 );
79 /** Deinterlace filter processing - this should be lazy evaluation here...
82 static mlt_frame
deinterlace_process( mlt_filter
this, mlt_frame frame
)
84 // Push this on to the service stack
85 mlt_frame_push_service( frame
, this );
87 // Push the get_image method on to the stack
88 mlt_frame_push_get_image( frame
, filter_get_image
);
93 /** Constructor for the filter.
96 mlt_filter
filter_deinterlace_init( void *arg
)
98 mlt_filter
this = mlt_filter_new( );
101 this->process
= deinterlace_process
;
102 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "method", arg
);