Merge ../mlt
[melted] / src / modules / xine / filter_deinterlace.c
1 /*
2 * filter_deinterlace.c -- deinterlace filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21 #include <framework/mlt_filter.h>
22 #include "deinterlace.h"
23
24 #include <framework/mlt_frame.h>
25
26 #include <string.h>
27 #include <stdlib.h>
28
29 /** Do it :-).
30 */
31
32 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
33 {
34 int error = 0;
35 int deinterlace = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "consumer_deinterlace" );
36
37 // Pop the service off the stack
38 mlt_filter filter = mlt_frame_pop_service( this );
39
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" );
43
44 // Get the input image
45 error = mlt_frame_get_image( this, image, format, width, height, writable );
46
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" ) )
49 {
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" );
54
55 if ( frame_method_str != NULL )
56 method_str = frame_method_str;
57
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;
68
69 // Deinterlace the image
70 deinterlace_yuv( *image, image, *width * 2, *height, method );
71
72 // Make sure that others know the frame is deinterlaced
73 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "progressive", 1 );
74 }
75
76 return error;
77 }
78
79 /** Deinterlace filter processing - this should be lazy evaluation here...
80 */
81
82 static mlt_frame deinterlace_process( mlt_filter this, mlt_frame frame )
83 {
84 // Push this on to the service stack
85 mlt_frame_push_service( frame, this );
86
87 // Push the get_image method on to the stack
88 mlt_frame_push_get_image( frame, filter_get_image );
89
90 return frame;
91 }
92
93 /** Constructor for the filter.
94 */
95
96 mlt_filter filter_deinterlace_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
97 {
98 mlt_filter this = mlt_filter_new( );
99 if ( this != NULL )
100 {
101 this->process = deinterlace_process;
102 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "method", arg );
103 }
104 return this;
105 }
106