]> git.sesse.net Git - mlt/blob - src/modules/plus/filter_affine.c
2e76c51c31b539dd86def97634f91071f0c0e81a
[mlt] / src / modules / plus / filter_affine.c
1 /*
2  * filter_affine.c -- affine 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_affine.h"
22
23 #include <framework/mlt.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <math.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         // Get the filter
35         mlt_filter filter = mlt_frame_pop_service( this );
36
37         // Get the properties
38         mlt_properties properties = mlt_filter_properties( filter );
39
40         // Get the image
41         int error = mlt_frame_get_image( this, image, format, width, height, 0 );
42
43         // Only process if we have no error and a valid colour space
44         if ( error == 0 && *format == mlt_image_yuv422 )
45         {
46                 mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
47                 mlt_transition transition = mlt_properties_get_data( properties, "transition", NULL );
48                 mlt_frame a_frame = NULL;
49
50                 if ( producer == NULL )
51                 {
52                         char *background = mlt_properties_get( properties, "background" );
53                         producer = mlt_factory_producer( "fezzik", background );
54                         mlt_properties_set_data( properties, "producer", producer, 0, (mlt_destructor)mlt_producer_close, NULL );
55                 }
56
57                 if ( transition == NULL )
58                 {
59                         transition = mlt_factory_transition( "affine", NULL );
60                         mlt_properties_set_data( properties, "transition", transition, 0, (mlt_destructor)mlt_transition_close, NULL );
61                 }
62
63                 if ( producer != NULL && transition != NULL )
64                 {
65                         char *name = mlt_properties_get( properties, "_unique_id" );
66                         mlt_position position = mlt_properties_get_position( mlt_frame_properties( this ), name );
67                         mlt_properties frame_properties = mlt_frame_properties( this );
68                         mlt_producer_seek( producer, position );
69                         mlt_frame_set_position( this, position );
70                         mlt_properties_pass( mlt_producer_properties( producer ), properties, "producer." );
71                         mlt_properties_pass( mlt_transition_properties( transition ), properties, "transition." );
72                         mlt_service_get_frame( mlt_producer_service( producer ), &a_frame, 0 );
73                         mlt_properties_set( mlt_frame_properties( a_frame ), "rescale.interp", "nearest" );
74                         mlt_properties_set( mlt_frame_properties( a_frame ), "distort", "true" );
75                         mlt_properties_set_double( mlt_frame_properties( a_frame ), "consumer_aspect_ratio", 
76                                                                            mlt_properties_get_double( frame_properties, "consumer_aspect_ratio" ) );
77                         mlt_transition_process( transition, a_frame, this );
78                         mlt_frame_get_image( a_frame, image, format, width, height, writable );
79                         mlt_properties_set_data( frame_properties, "affine_frame", a_frame, 0, (mlt_destructor)mlt_frame_close, NULL );
80                         mlt_properties_set_data( frame_properties, "image", *image, *width * *height * 2, NULL, NULL );
81                 }
82         }
83
84         return error;
85 }
86
87 /** Filter processing.
88 */
89
90 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
91 {
92         // Get the properties of the frame
93         mlt_properties properties = mlt_frame_properties( frame );
94
95         // Get a unique name to store the frame position
96         char *name = mlt_properties_get( mlt_filter_properties( this ), "_unique_id" );
97
98         // Assign the current position to the name
99         mlt_properties_set_position( properties, name, mlt_frame_get_position( frame ) );
100
101         // Push the frame filter
102         mlt_frame_push_service( frame, this );
103         mlt_frame_push_get_image( frame, filter_get_image );
104
105         return frame;
106 }
107
108 /** Constructor for the filter.
109 */
110
111 mlt_filter filter_affine_init( char *arg )
112 {
113         mlt_filter this = mlt_filter_new( );
114         if ( this != NULL )
115         {
116                 this->process = filter_process;
117                 mlt_properties_set( mlt_filter_properties( this ), "background", "colour:black" );
118                 mlt_properties_set( mlt_filter_properties( this ), "transition.rotate_x", "10" );
119         }
120         return this;
121 }
122
123