]> git.sesse.net Git - mlt/blob - src/modules/opengl/transition_movit_mix.cpp
Hide the movit.parms properties from serialization.
[mlt] / src / modules / opengl / transition_movit_mix.cpp
1 /*
2  * transition_movit_mix.cpp
3  * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
4  *
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.
9  *
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.
14  *
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.
18  */
19
20
21 #include <framework/mlt.h>
22 #include <string.h>
23 #include <assert.h>
24
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"
32
33 using namespace movit;
34
35 static int get_image( mlt_frame a_frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
36 {
37         int error;
38
39         // Get the b frame from the stack
40         mlt_frame b_frame = (mlt_frame) mlt_frame_pop_frame( a_frame );
41
42         // Get the transition object
43         mlt_transition transition = (mlt_transition) mlt_frame_pop_service( a_frame );
44         mlt_service service = MLT_TRANSITION_SERVICE( transition );
45         mlt_service_lock( service );
46
47         // Get the properties of the transition
48         mlt_properties properties = MLT_TRANSITION_PROPERTIES( transition );
49
50         // Get the transition parameters
51         mlt_position position = mlt_transition_get_position( transition, a_frame );
52         mlt_position length = mlt_transition_get_length( transition );
53         int reverse = mlt_properties_get_int( properties, "reverse" );
54         const char* mix_str = mlt_properties_get( properties, "mix" );
55         double mix = ( mix_str && strlen( mix_str ) > 0 ) ?
56                 mlt_properties_anim_get_double( properties, "mix", position, length ) :
57                 mlt_transition_get_progress( transition, a_frame );
58         double inverse = 1.0 - mix;
59
60         // Set the Movit parameters.
61         mlt_properties_set_double( properties, "_movit.parms.float.strength_first", reverse ? mix : inverse );
62         mlt_properties_set_double( properties, "_movit.parms.float.strength_second", reverse ? inverse : mix );
63
64         uint8_t *a_image, *b_image;
65
66         // Get the two images.
67         *format = mlt_image_glsl;
68         error = mlt_frame_get_image( a_frame, &a_image, format, width, height, writable );
69         error = mlt_frame_get_image( b_frame, &b_image, format, width, height, writable );
70
71         GlslManager::set_effect_input( service, a_frame, (mlt_service) a_image );
72         GlslManager::set_effect_secondary_input( service, a_frame, (mlt_service) b_image, b_frame );
73         GlslManager::set_effect( service, a_frame, new MixEffect() );
74         *image = (uint8_t *) service;
75
76         mlt_service_unlock( service );
77         return error;
78 }
79
80 static mlt_frame process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame )
81 {
82         mlt_frame_push_service( a_frame, transition );
83         mlt_frame_push_frame( a_frame, b_frame );
84         mlt_frame_push_get_image( a_frame, get_image );
85
86         return a_frame;
87 }
88
89 extern "C"
90 mlt_transition transition_movit_mix_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
91 {
92         mlt_transition transition = NULL;
93         GlslManager* glsl = GlslManager::get_instance();
94         if ( glsl && ( transition = mlt_transition_new() ) ) {
95                 transition->process = process;
96                 mlt_properties_set( MLT_TRANSITION_PROPERTIES( transition ), "mix", arg );
97                 
98                 // Inform apps and framework that this is a video only transition
99                 mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( transition ), "_transition_type", 1 );
100         }
101         return transition;
102 }