]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_movit_glow.cpp
Add property animation to the other movit services.
[mlt] / src / modules / opengl / filter_movit_glow.cpp
1 /*
2  * filter_movit_glow.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 #include <framework/mlt.h>
21 #include <string.h>
22 #include <assert.h>
23
24 #include "glsl_manager.h"
25 #include <movit/glow_effect.h>
26
27 static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
28 {
29         mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame );
30         mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
31         GlslManager::get_instance()->lock_service( frame );
32         Effect* effect = GlslManager::get_effect( filter, frame );
33         if ( effect ) {
34                 mlt_position position = mlt_filter_get_position( filter, frame );
35                 mlt_position length = mlt_filter_get_length2( filter, frame );
36                 bool ok = effect->set_float( "radius",
37                         mlt_properties_anim_get_double( properties, "radius", position, length ) );
38                 ok |= effect->set_float( "blurred_mix_amount",
39                         mlt_properties_anim_get_double( properties, "blur_mix", position, length ) );
40                 ok |= effect->set_float( "highlight_cutoff",
41                         mlt_properties_anim_get_double( properties, "highlight_cutoff", position, length ) );
42                 assert(ok);
43         }
44         GlslManager::get_instance()->unlock_service( frame );
45         *format = mlt_image_glsl;
46         return mlt_frame_get_image( frame, image, format, width, height, writable );
47 }
48
49 static mlt_frame process( mlt_filter filter, mlt_frame frame )
50 {
51         if ( !mlt_frame_is_test_card( frame ) ) {
52                 if ( !GlslManager::get_effect( filter, frame ) )
53                         GlslManager::add_effect( filter, frame, new GlowEffect() );
54         }
55         mlt_frame_push_service( frame, filter );
56         mlt_frame_push_get_image( frame, get_image );
57         return frame;
58 }
59
60 extern "C" {
61
62 mlt_filter filter_movit_glow_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
63 {
64         mlt_filter filter = NULL;
65         GlslManager* glsl = GlslManager::get_instance();
66
67         if ( glsl && ( filter = mlt_filter_new() ) ) {
68                 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
69                 mlt_properties_set_double( properties, "radius", 20.0 );
70                 mlt_properties_set_double( properties, "blur_mix", 1.0 );
71                 mlt_properties_set_double( properties, "highlight_cutoff", 0.2 );
72                 filter->process = process;
73         }
74         return filter;
75 }
76
77 }