]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_white_balance.cpp
Add the new opengl module (opengl branch).
[mlt] / src / modules / opengl / filter_white_balance.cpp
1 /*
2  * filter_white_balance.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/white_balance_effect.h>
26
27 static mlt_frame process( mlt_filter filter, mlt_frame frame )
28 {
29         if ( !mlt_frame_is_test_card( frame ) ) {
30                 Effect* effect = GlslManager::get_effect( filter, frame );
31                 if ( !effect )
32                         effect = GlslManager::add_effect( filter, frame, new WhiteBalanceEffect );
33                 if ( effect ) {
34                         mlt_properties filter_props = MLT_FILTER_PROPERTIES( filter );
35                         int color_int = mlt_properties_get_int( filter_props, "neutral_color" );
36                         RGBTriplet color(
37                                 float((color_int >> 24) & 0xff) / 255.0f,
38                                 float((color_int >> 16) & 0xff) / 255.0f,
39                                 float((color_int >> 8) & 0xff) / 255.0f
40                         );
41                         bool ok = effect->set_vec3( "neutral_color", (float*) &color );
42                         ok |= effect->set_float( "output_color_temperature", mlt_properties_get_double( filter_props, "color_temperature" ) );
43                         assert(ok);
44                 }
45         }
46         return frame;
47 }
48
49 extern "C" {
50
51 mlt_filter filter_white_balance_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
52 {
53         mlt_filter filter = NULL;
54         GlslManager* glsl = GlslManager::get_instance();
55
56         if ( glsl && ( filter = mlt_filter_new() ) ) {
57                 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
58                 mlt_properties_set( properties, "neutral_color", arg? arg : "#7f7f7f" );
59                 mlt_properties_set_double( properties, "color_temperature", 6500.0 );
60                 filter->process = process;
61         }
62         return filter;
63 }
64
65 }