2 * filter_movit_resample.cpp
3 * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
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.
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.
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.
20 #include <framework/mlt.h>
24 #include "filter_glsl_manager.h"
25 #include <movit/resample_effect.h>
27 static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
30 mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
31 mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame );
32 mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
33 mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) );
35 // Correct width/height if necessary
36 if ( *width == 0 || *height == 0 )
38 *width = profile->width;
39 *height = profile->height;
43 int iheight = *height;
44 double factor = mlt_properties_get_double( filter_properties, "factor" );
45 factor = factor > 0 ? factor : 1.0;
46 int owidth = *width * factor;
47 int oheight = *height * factor;
49 // If meta.media.width/height exist, we want that as minimum information
50 if ( mlt_properties_get_int( properties, "meta.media.width" ) )
52 iwidth = mlt_properties_get_int( properties, "meta.media.width" );
53 iheight = mlt_properties_get_int( properties, "meta.media.height" );
56 mlt_properties_set_int( properties, "rescale_width", *width );
57 mlt_properties_set_int( properties, "rescale_height", *height );
59 // Deinterlace if height is changing to prevent fields mixing on interpolation
60 if ( iheight != oheight )
61 mlt_properties_set_int( properties, "consumer_deinterlace", 1 );
63 // Get the image as requested
64 if ( *format != mlt_image_none )
65 *format = mlt_image_glsl;
66 error = mlt_frame_get_image( frame, image, format, &iwidth, &iheight, writable );
68 GlslManager::get_instance()->lock_service( frame );
69 Effect* effect = GlslManager::get_effect( MLT_FILTER_SERVICE( filter ), frame );
71 bool ok = effect->set_int( "width", owidth );
72 ok |= effect->set_int( "height", oheight );
77 GlslManager::get_instance()->unlock_service( frame );
83 static mlt_frame process( mlt_filter filter, mlt_frame frame )
85 if ( !GlslManager::get_effect( MLT_FILTER_SERVICE( filter ), frame ) )
86 GlslManager::add_effect( MLT_FILTER_SERVICE( filter ), frame, new ResampleEffect );
87 mlt_frame_push_service( frame, filter );
88 mlt_frame_push_get_image( frame, get_image );
93 mlt_filter filter_movit_resample_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
95 mlt_filter filter = NULL;
96 GlslManager* glsl = GlslManager::get_instance();
98 if ( glsl && ( filter = mlt_filter_new() ) ) {
99 filter->process = process;