]> git.sesse.net Git - mlt/blob - src/modules/opengl/filter_movit_resample.cpp
Hide the movit.parms properties from serialization.
[mlt] / src / modules / opengl / filter_movit_resample.cpp
1 /*
2  * filter_movit_resample.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/resample_effect.h>
26 #include "optional_effect.h"
27
28 using namespace movit;
29
30 static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
31 {
32         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
33         mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame );
34         mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
35         mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) );
36
37         // Correct width/height if necessary
38         if ( *width == 0 || *height == 0 )
39         {
40                 *width = profile->width;
41                 *height = profile->height;
42         }
43
44         int iwidth = *width;
45         int iheight = *height;
46         double factor = mlt_properties_get_double( filter_properties, "factor" );
47         factor = factor > 0 ? factor : 1.0;
48         int owidth = *width * factor;
49         int oheight = *height * factor;
50
51         // If meta.media.width/height exist, we want that as minimum information
52         if ( mlt_properties_get_int( properties, "meta.media.width" ) )
53         {
54                 iwidth = mlt_properties_get_int( properties, "meta.media.width" );
55                 iheight = mlt_properties_get_int( properties, "meta.media.height" );
56         }
57
58         mlt_properties_set_int( properties, "rescale_width", *width );
59         mlt_properties_set_int( properties, "rescale_height", *height );
60
61         // Deinterlace if height is changing to prevent fields mixing on interpolation
62         if ( iheight != oheight )
63                 mlt_properties_set_int( properties, "consumer_deinterlace", 1 );
64
65         GlslManager::get_instance()->lock_service( frame );
66         mlt_properties_set_int( filter_properties, "_movit.parms.int.width", owidth );
67         mlt_properties_set_int( filter_properties, "_movit.parms.int.height", oheight );
68
69         bool disable = ( iwidth == owidth && iheight == oheight );
70         mlt_properties_set_int( filter_properties, "_movit.parms.int.disable", disable );
71
72         *width = owidth;
73         *height = oheight;
74
75         GlslManager::get_instance()->unlock_service( frame );
76
77         // Get the image as requested
78         if ( *format != mlt_image_none )
79                 *format = mlt_image_glsl;
80         int error = mlt_frame_get_image( frame, image, format, &iwidth, &iheight, writable );
81         GlslManager::set_effect_input( MLT_FILTER_SERVICE( filter ), frame, (mlt_service) *image );
82         Effect *effect = GlslManager::set_effect( MLT_FILTER_SERVICE( filter ), frame, new OptionalEffect<ResampleEffect> );
83         // This needs to be something else than 0x0 at chain finalization time.
84         bool ok = effect->set_int("width", owidth);
85         ok |= effect->set_int("height", oheight);
86         assert( ok );
87         *image = (uint8_t *) MLT_FILTER_SERVICE( filter );
88         return error;
89 }
90
91 static mlt_frame process( mlt_filter filter, mlt_frame frame )
92 {
93         mlt_frame_push_service( frame, filter );
94         mlt_frame_push_get_image( frame, get_image );
95         return frame;
96 }
97
98 extern "C"
99 mlt_filter filter_movit_resample_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
100 {
101         mlt_filter filter = NULL;
102         GlslManager* glsl = GlslManager::get_instance();
103
104         if ( glsl && ( filter = mlt_filter_new() ) ) {
105                 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
106                 glsl->add_ref( properties );
107                 filter->process = process;
108         }
109         return filter;
110 }