]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_movit_lift_gamma_gain.cpp
Rename some Movit filter filenames, for consistency.
[mlt] / src / modules / opengl / filter_movit_lift_gamma_gain.cpp
1 /*
2  * filter_lift_gamma_gain.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 "filter_glsl_manager.h"
25 #include <movit/lift_gamma_gain_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( MLT_FILTER_SERVICE( 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                 RGBTriplet triplet(
37                         mlt_properties_anim_get_double( properties, "lift_r", position, length ),
38                         mlt_properties_anim_get_double( properties, "lift_g", position, length ),
39                         mlt_properties_anim_get_double( properties, "lift_b", position, length )
40                 );
41                 bool ok = effect->set_vec3( "lift", (float*) &triplet );
42                 triplet.r = mlt_properties_anim_get_double( properties, "gamma_r", position, length );
43                 triplet.g = mlt_properties_anim_get_double( properties, "gamma_g", position, length );
44                 triplet.b = mlt_properties_anim_get_double( properties, "gamma_b", position, length );
45                 ok |= effect->set_vec3( "gamma", (float*) &triplet );
46                 triplet.r = mlt_properties_anim_get_double( properties, "gain_r", position, length );
47                 triplet.g = mlt_properties_anim_get_double( properties, "gain_g", position, length );
48                 triplet.b = mlt_properties_anim_get_double( properties, "gain_b", position, length );
49                 ok |= effect->set_vec3( "gain", (float*) &triplet );
50                 assert(ok);
51         }
52         GlslManager::get_instance()->unlock_service( frame );
53         *format = mlt_image_glsl;
54         return mlt_frame_get_image( frame, image, format, width, height, writable );
55 }
56
57 static mlt_frame process( mlt_filter filter, mlt_frame frame )
58 {
59         if ( !mlt_frame_is_test_card( frame ) ) {
60                 if ( !GlslManager::get_effect( MLT_FILTER_SERVICE( filter ), frame ) )
61                         GlslManager::add_effect( MLT_FILTER_SERVICE( filter ), frame, new LiftGammaGainEffect );
62         }
63         mlt_frame_push_service( frame, filter );
64         mlt_frame_push_get_image( frame, get_image );
65         return frame;
66 }
67
68 extern "C" {
69
70 mlt_filter filter_lift_gamma_gain_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
71 {
72         mlt_filter filter = NULL;
73         GlslManager* glsl = GlslManager::get_instance();
74
75         if ( glsl && ( filter = mlt_filter_new() ) ) {
76                 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
77                 mlt_properties_set_double( properties, "lift_r", 0.0 );
78                 mlt_properties_set_double( properties, "lift_g", 0.0 );
79                 mlt_properties_set_double( properties, "lift_b", 0.0 );
80                 mlt_properties_set_double( properties, "gamma_r", 1.0 );
81                 mlt_properties_set_double( properties, "gamma_g", 1.0 );
82                 mlt_properties_set_double( properties, "gamma_b", 1.0 );
83                 mlt_properties_set_double( properties, "gain_r", 1.0 );
84                 mlt_properties_set_double( properties, "gain_g", 1.0 );
85                 mlt_properties_set_double( properties, "gain_b", 1.0 );
86                 filter->process = process;
87         }
88         return filter;
89 }
90
91 }