2 * transition_movit_mix.cpp
3 * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <framework/mlt.h>
25 #include "filter_glsl_manager.h"
26 #include <movit/init.h>
27 #include <movit/effect_chain.h>
28 #include <movit/util.h>
29 #include <movit/mix_effect.h>
30 #include "mlt_movit_input.h"
31 #include "mlt_flip_effect.h"
33 static int get_image( mlt_frame a_frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
37 // Get the b frame from the stack
38 mlt_frame b_frame = (mlt_frame) mlt_frame_pop_frame( a_frame );
40 // Get the transition object
41 mlt_transition transition = (mlt_transition) mlt_frame_pop_service( a_frame );
42 mlt_service service = MLT_TRANSITION_SERVICE( transition );
43 mlt_service_lock( service );
45 // Get the properties of the transition
46 mlt_properties properties = MLT_TRANSITION_PROPERTIES( transition );
48 // Get the transition parameters
49 mlt_position position = mlt_transition_get_position( transition, a_frame );
50 mlt_position length = mlt_transition_get_length( transition );
51 int reverse = mlt_properties_get_int( properties, "reverse" );
52 double mix = mlt_properties_get( properties, "mix" ) ?
53 mlt_properties_anim_get_double( properties, "mix", position, length ) :
54 mlt_transition_get_progress( transition, a_frame );
55 double inverse = 1.0 - mix;
57 // Set the Movit parameters.
58 mlt_properties_set_double( properties, "movit.parms.float.strength_first", reverse ? mix : inverse );
59 mlt_properties_set_double( properties, "movit.parms.float.strength_second", reverse ? inverse : mix );
61 uint8_t *a_image, *b_image;
63 // Get the two images.
64 *format = mlt_image_glsl;
65 error = mlt_frame_get_image( a_frame, &a_image, format, width, height, writable );
66 error = mlt_frame_get_image( b_frame, &b_image, format, width, height, writable );
68 GlslManager::set_effect_input( service, a_frame, (mlt_service) a_image );
69 GlslManager::set_effect_secondary_input( service, a_frame, (mlt_service) b_image, b_frame );
70 GlslManager::set_effect( service, a_frame, new MixEffect() );
71 *image = (uint8_t *) service;
73 mlt_service_unlock( service );
77 static mlt_frame process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
79 mlt_frame_push_service( a_frame, transition );
80 mlt_frame_push_frame( a_frame, b_frame );
81 mlt_frame_push_get_image( a_frame, get_image );
87 mlt_transition transition_movit_mix_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
89 mlt_transition transition = NULL;
90 GlslManager* glsl = GlslManager::get_instance();
91 if ( glsl && ( transition = mlt_transition_new() ) ) {
92 transition->process = process;
93 mlt_properties_set( MLT_TRANSITION_PROPERTIES( transition ), "mix", arg );
95 // Inform apps and framework that this is a video only transition
96 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "_transition_type", 1 );