initial frei0r support
[melted] / 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 if (*format!=mlt_image_yuv422 ){
27 return -1;
28 }
29
30 mlt_frame b_frame = mlt_frame_pop_frame( a_frame );
31 mlt_transition transition = mlt_frame_pop_service( a_frame );
32 mlt_properties properties = MLT_TRANSITION_PROPERTIES( transition );
33 mlt_properties a_props = MLT_FRAME_PROPERTIES( a_frame );
34 mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
35
36 int invert = mlt_properties_get_int( properties, "invert" );
37
38 if ( mlt_properties_get( a_props, "rescale.interp" ) == NULL || !strcmp( mlt_properties_get( a_props, "rescale.interp" ), "none" ) )
39 mlt_properties_set( a_props, "rescale.interp", "nearest" );
40
41 // set consumer_aspect_ratio for a and b frame
42 if ( mlt_properties_get_double( a_props, "aspect_ratio" ) == 0.0 )
43 mlt_properties_set_double( a_props, "aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
44 if ( mlt_properties_get_double( b_props, "aspect_ratio" ) == 0.0 )
45 mlt_properties_set_double( b_props, "aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
46 mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
47
48
49 *width = mlt_properties_get_int( !invert ? a_props : b_props, "width" );
50 *height = mlt_properties_get_int( !invert ? a_props : b_props, "height" );
51
52 uint8_t *images[]={NULL,NULL,NULL};
53
54 mlt_frame_get_image( a_frame, &images[0], format, width, height, 1 );
55 mlt_frame_get_image( b_frame, &images[1], format, width, height, 1 );
56
57 mlt_position in = mlt_transition_get_in( transition );
58 mlt_position out = mlt_transition_get_out( transition );
59
60 // Get the position of the frame
61 char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( transition ), "_unique_id" );
62 mlt_position position = mlt_properties_get_position( MLT_FRAME_PROPERTIES( a_frame ), name );
63
64 float pos=( float )( position - in ) / ( float )( out - in + 1 );
65
66 process_frei0r_item( transition_type , pos , properties, a_frame, images, format, width,height, writable );
67 if (images[2]){
68 *image=images[2];
69 }
70 return 0;
71 }
72
73 mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
74 {
75 char *name = mlt_properties_get( MLT_TRANSITION_PROPERTIES( transition ), "_unique_id" );
76 mlt_properties_set_position( MLT_FRAME_PROPERTIES( a_frame ), name, mlt_frame_get_position( a_frame ) );
77 mlt_frame_push_service( a_frame, transition );
78 mlt_frame_push_frame( a_frame, b_frame );
79 mlt_frame_push_get_image( a_frame, transition_get_image );
80 return a_frame;
81 }
82
83 void transition_close( mlt_transition this ){
84 destruct ( MLT_TRANSITION_PROPERTIES ( this ) );
85 }