2 * filter_affine.c -- affine filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <framework/mlt_filter.h>
22 #include <framework/mlt.h>
31 static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
34 mlt_filter filter = mlt_frame_pop_service( this );
37 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
41 *format = mlt_image_rgb24a;
42 //mlt_frame_get_image( this, image, format, width, height, 0 );
44 // Only process if we have no error and a valid colour space
47 mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
48 mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
49 mlt_transition transition = mlt_properties_get_data( properties, "transition", NULL );
50 mlt_frame a_frame = NULL;
51 mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) );
53 if ( producer == NULL )
55 char *background = mlt_properties_get( properties, "background" );
56 producer = mlt_factory_producer( profile, NULL, background );
57 mlt_properties_set_data( properties, "producer", producer, 0, (mlt_destructor)mlt_producer_close, NULL );
60 if ( transition == NULL )
62 transition = mlt_factory_transition( profile, "affine", NULL );
63 mlt_properties_set_data( properties, "transition", transition, 0, (mlt_destructor)mlt_transition_close, NULL );
65 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "b_alpha", 1 );
68 if ( producer != NULL && transition != NULL )
70 mlt_position position = mlt_filter_get_position( filter, this );
71 mlt_properties frame_properties = MLT_FRAME_PROPERTIES( this );
72 mlt_position in = mlt_filter_get_in( filter );
73 mlt_position out = mlt_filter_get_out( filter );
74 double consumer_ar = mlt_profile_sar( profile );
75 mlt_transition_set_in_and_out( transition, in, out );
77 mlt_properties_set_position( MLT_PRODUCER_PROPERTIES( producer ), "length", out - in + 1 );
78 mlt_producer_set_in_and_out( producer, in, out );
80 mlt_producer_seek( producer, in + position );
81 mlt_frame_set_position( this, position );
82 mlt_properties_pass( MLT_PRODUCER_PROPERTIES( producer ), properties, "producer." );
83 mlt_properties_pass( MLT_TRANSITION_PROPERTIES( transition ), properties, "transition." );
84 mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &a_frame, 0 );
85 mlt_frame_set_position( a_frame, in + position );
86 // mlt_properties_set_int( MLT_FRAME_PROPERTIES( a_frame ), "distort", 1 );
88 // Special case - aspect_ratio = 0
89 if ( mlt_frame_get_aspect_ratio( this ) == 0 )
90 mlt_frame_set_aspect_ratio( this, consumer_ar );
91 if ( mlt_frame_get_aspect_ratio( a_frame ) == 0 )
92 mlt_frame_set_aspect_ratio( a_frame, consumer_ar );
94 // Add the affine transition onto the frame stack
95 mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
96 mlt_transition_process( transition, a_frame, this );
98 if ( mlt_properties_get_int( properties, "use_normalised" ) )
100 // Use the normalised width & height
101 mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) );
102 *width = profile->width;
103 *height = profile->height;
106 mlt_frame_get_image( a_frame, image, format, width, height, writable );
107 mlt_properties_set_data( frame_properties, "affine_frame", a_frame, 0, (mlt_destructor)mlt_frame_close, NULL );
108 mlt_frame_set_image( this, *image, *width * *height * 4, NULL );
109 mlt_frame_set_alpha( this, mlt_frame_get_alpha_mask( a_frame ), *width * *height, NULL );
113 mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
120 /** Filter processing.
123 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
125 // Push the frame filter
126 mlt_frame_push_service( frame, this );
127 mlt_frame_push_get_image( frame, filter_get_image );
132 /** Constructor for the filter.
135 mlt_filter filter_affine_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
137 mlt_filter this = mlt_filter_new( );
140 this->process = filter_process;
141 mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "background", arg ? arg : "colour:0" );