]> git.sesse.net Git - mlt/blob - src/modules/frei0r/transition_frei0r.c
Massive refactoring of image conversion.
[mlt] / src / modules / frei0r / transition_frei0r.c
1 /*
2  * transition_frei0r.c -- frei0r transition
3  * Copyright (c) 2008 Marco Gittler <g.marco@freenet.de>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <framework/mlt.h>
21 #include "frei0r_helper.h"
22 #include <string.h>
23  
24 static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable ){
25         
26         mlt_frame b_frame = mlt_frame_pop_frame( a_frame );
27         mlt_transition transition = mlt_frame_pop_service( a_frame );
28         mlt_properties properties = MLT_TRANSITION_PROPERTIES( transition );
29         mlt_properties a_props = MLT_FRAME_PROPERTIES( a_frame );
30         mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
31
32         int invert = mlt_properties_get_int( properties, "invert" );
33
34         if ( mlt_properties_get( a_props, "rescale.interp" ) == NULL || !strcmp( mlt_properties_get( a_props, "rescale.interp" ), "none" ) )
35                 mlt_properties_set( a_props, "rescale.interp", "nearest" );
36
37         // set consumer_aspect_ratio for a and b frame
38         if ( mlt_properties_get_double( a_props, "aspect_ratio" ) == 0.0 )
39                 mlt_properties_set_double( a_props, "aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
40         if ( mlt_properties_get_double( b_props, "aspect_ratio" ) == 0.0 )
41                 mlt_properties_set_double( b_props, "aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
42         mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
43
44         if ( mlt_properties_get( b_props, "rescale.interp" ) == NULL || !strcmp( mlt_properties_get( b_props, "rescale.interp" ), "none" ) )
45                 mlt_properties_set( b_props, "rescale.interp", "nearest" );
46         
47         uint8_t *images[]={NULL,NULL,NULL};
48
49         *format = mlt_image_rgb24a;
50         mlt_frame_get_image( a_frame, &images[0], format, width, height, 0 );
51         mlt_frame_get_image( b_frame, &images[1], format, width, height, 0 );
52         
53         mlt_position in = mlt_transition_get_in( transition );
54         mlt_position out = mlt_transition_get_out( transition );
55
56         // Get the position of the frame
57         char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( transition ), "_unique_id" );
58         mlt_position position = mlt_properties_get_position( MLT_FRAME_PROPERTIES( a_frame ), name );
59
60         float pos=( float )( position - in ) / ( float )( out - in + 1 );
61         
62         process_frei0r_item( transition_type, pos, properties, !invert ? a_frame : b_frame, images, width, height );
63         
64         *width = mlt_properties_get_int( !invert ? a_props : b_props, "width" );
65         *height = mlt_properties_get_int( !invert ? a_props : b_props, "height" );
66         *image = mlt_properties_get_data( !invert ? a_props : b_props , "image", NULL );
67         return 0;
68 }
69
70 mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
71 {
72         char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( transition ), "_unique_id" );
73         mlt_properties_set_position( MLT_FRAME_PROPERTIES( a_frame ), name, mlt_frame_get_position( a_frame ) );
74         mlt_frame_push_service( a_frame, transition );
75         mlt_frame_push_frame( a_frame, b_frame );
76         mlt_frame_push_get_image( a_frame, transition_get_image );
77         return a_frame;
78 }
79
80 void transition_close( mlt_transition this ){
81         destruct ( MLT_TRANSITION_PROPERTIES ( this ) );
82 }