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 <framework/mlt_filter.h>
22 #include <framework/mlt_log.h>
23 #include "deinterlace.h"
25 #include <framework/mlt_frame.h>
33 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
36 int deinterlace = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "consumer_deinterlace" );
37 int progressive = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "progressive" );
39 // Pop the service off the stack
40 mlt_filter filter = mlt_frame_pop_service( this );
42 // Determine if we need a writable version or not
43 if ( deinterlace && !writable )
44 writable = !progressive;
46 // Get the input image
47 if ( deinterlace && !progressive )
48 *format = mlt_image_yuv422;
49 error = mlt_frame_get_image( this, image, format, width, height, writable );
50 progressive = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "progressive" );
51 mlt_log_debug( MLT_FILTER_SERVICE( filter ), "xine.deinterlace %d prog %d format %s\n",
52 deinterlace, progressive, mlt_image_format_name( *format ) );
54 // Check that we want progressive and we aren't already progressive
55 if ( deinterlace && *format == mlt_image_yuv422 && *image && !progressive )
57 // Determine deinterlace method
58 char *method_str = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "method" );
59 int method = DEINTERLACE_LINEARBLEND;
60 char *frame_method_str = mlt_properties_get( MLT_FRAME_PROPERTIES( this ), "deinterlace_method" );
62 if ( frame_method_str != NULL )
63 method_str = frame_method_str;
65 if ( method_str == NULL )
66 method = DEINTERLACE_LINEARBLEND;
67 else if ( strcmp( method_str, "bob" ) == 0 )
68 method = DEINTERLACE_BOB;
69 else if ( strcmp( method_str, "weave" ) == 0 )
70 method = DEINTERLACE_BOB;
71 else if ( strcmp( method_str, "greedy" ) == 0 )
72 method = DEINTERLACE_GREEDY;
73 else if ( strcmp( method_str, "onefield" ) == 0 )
74 method = DEINTERLACE_ONEFIELD;
76 // Deinterlace the image
77 deinterlace_yuv( *image, image, *width * 2, *height, method );
79 // Make sure that others know the frame is deinterlaced
80 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "progressive", 1 );
86 /** Deinterlace filter processing - this should be lazy evaluation here...
89 static mlt_frame deinterlace_process( mlt_filter this, mlt_frame frame )
91 // Push this on to the service stack
92 mlt_frame_push_service( frame, this );
94 // Push the get_image method on to the stack
95 mlt_frame_push_get_image( frame, filter_get_image );
100 /** Constructor for the filter.
103 mlt_filter filter_deinterlace_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
105 mlt_filter this = mlt_filter_new( );
108 this->process = deinterlace_process;
109 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "method", arg );