]> git.sesse.net Git - mlt/blob - src/modules/xine/filter_deinterlace.c
Massive refactoring of image conversion.
[mlt] / 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 <framework/mlt_log.h>
23 #include "deinterlace.h"
24
25 #include <framework/mlt_frame.h>
26
27 #include <string.h>
28 #include <stdlib.h>
29
30 /** Do it :-).
31 */
32
33 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
34 {
35         int error = 0;
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" );
38         
39         // Pop the service off the stack
40         mlt_filter filter = mlt_frame_pop_service( this );
41
42         // Determine if we need a writable version or not
43         if ( deinterlace && !writable )
44                  writable = !progressive;
45
46         // Get the input image
47         if ( deinterlace && !progressive )
48                 *format = mlt_image_yuv422;
49         mlt_log_debug( MLT_FILTER_SERVICE( filter ), "xine.deinterlace %d prog %d format %s\n",
50                 deinterlace, progressive, mlt_image_format_name( *format ) );
51         error = mlt_frame_get_image( this, image, format, width, height, writable );
52         progressive = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "progressive" );
53
54         // Check that we want progressive and we aren't already progressive
55         if ( deinterlace && *format == mlt_image_yuv422 && *image && !progressive )
56         {
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" );
61                 
62                 if ( frame_method_str != NULL )
63                         method_str = frame_method_str;
64                 
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;
75                         
76                 // Deinterlace the image
77                 deinterlace_yuv( *image, image, *width * 2, *height, method );
78                 
79                 // Make sure that others know the frame is deinterlaced
80                 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "progressive", 1 );
81         }
82
83         return error;
84 }
85
86 /** Deinterlace filter processing - this should be lazy evaluation here...
87 */
88
89 static mlt_frame deinterlace_process( mlt_filter this, mlt_frame frame )
90 {
91         // Push this on to the service stack
92         mlt_frame_push_service( frame, this );
93
94         // Push the get_image method on to the stack
95         mlt_frame_push_get_image( frame, filter_get_image );
96         
97         return frame;
98 }
99
100 /** Constructor for the filter.
101 */
102
103 mlt_filter filter_deinterlace_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
104 {
105         mlt_filter this = mlt_filter_new( );
106         if ( this != NULL )
107         {
108                 this->process = deinterlace_process;
109                 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "method", arg );
110         }
111         return this;
112 }
113