composite aspect ratio fix (again ;-)), added fill compositing test case, filter...
[melted] / src / modules / core / filter_luma.c
1 /*
2 * filter_luma.c -- luma 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 "filter_luma.h"
22
23 #include <framework/mlt_factory.h>
24 #include <framework/mlt_frame.h>
25 #include <framework/mlt_producer.h>
26 #include <framework/mlt_transition.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 /** Do it :-).
33 */
34
35 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
36 {
37 int error = 0;
38 mlt_filter filter = mlt_frame_pop_service( this );
39 mlt_properties properties = mlt_filter_properties( filter );
40 mlt_transition luma = mlt_properties_get_data( properties, "luma", NULL );
41 mlt_frame b_frame = mlt_properties_get_data( properties, "frame", NULL );
42 int out = 24;
43
44 if ( luma == NULL )
45 {
46 char *resource = mlt_properties_get( properties, "resource" );
47 luma = mlt_factory_transition( "luma", resource );
48 if ( luma != NULL )
49 {
50 mlt_properties luma_properties = mlt_transition_properties( luma );
51 mlt_properties_set_int( luma_properties, "in", 0 );
52 mlt_properties_set_int( luma_properties, "out", out );
53 mlt_properties_set_int( luma_properties, "reverse", 1 );
54 mlt_properties_pass( luma_properties, properties, "luma." );
55 mlt_properties_set_data( properties, "luma", luma, 0, ( mlt_destructor )mlt_transition_close, NULL );
56 out = mlt_properties_get_int( luma_properties, "out" );
57 }
58 }
59
60 if ( b_frame == NULL )
61 {
62 b_frame = mlt_frame_init( );
63 mlt_properties_set_data( properties, "frame", b_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
64 }
65
66 if ( luma != NULL &&
67 ( mlt_properties_get( properties, "blur" ) != NULL ||
68 mlt_frame_get_position( this ) % ( out + 1 ) != out ) )
69 mlt_transition_process( luma, this, b_frame );
70
71 error = mlt_frame_get_image( this, image, format, width, height, 1 );
72
73 if ( error == 0 )
74 {
75 mlt_properties a_props = mlt_frame_properties( this );
76 int size = 0;
77 uint8_t *src = mlt_properties_get_data( a_props, "image", &size );
78 uint8_t *dst = mlt_pool_alloc( size );
79
80 if ( dst != NULL )
81 {
82 mlt_properties b_props = mlt_frame_properties( b_frame );
83 memcpy( dst, src, size );
84 mlt_properties_set_data( b_props, "image", dst, size, mlt_pool_release, NULL );
85 mlt_properties_set_int( b_props, "width", *width );
86 mlt_properties_set_int( b_props, "height", *height );
87 }
88 }
89
90 return error;
91 }
92
93 /** Filter processing.
94 */
95
96 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
97 {
98 // Push the filter on to the stack
99 mlt_frame_push_service( frame, this );
100
101 // Push the get_image on to the stack
102 mlt_frame_push_get_image( frame, filter_get_image );
103
104 return frame;
105 }
106
107 /** Constructor for the filter.
108 */
109
110 mlt_filter filter_luma_init( void *arg )
111 {
112 mlt_filter this = mlt_filter_new( );
113 if ( this != NULL )
114 {
115 mlt_properties properties = mlt_filter_properties( this );
116 this->process = filter_process;
117 if ( arg != NULL )
118 mlt_properties_set( properties, "resource", arg );
119 }
120 return this;
121 }
122