2 * filter_deconvolution_sharpen.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/deconvolution_sharpen_effect.h>
27 using namespace movit;
29 static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
31 mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame );
32 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
33 GlslManager::get_instance()->lock_service( frame );
34 mlt_position position = mlt_filter_get_position( filter, frame );
35 mlt_position length = mlt_filter_get_length2( filter, frame );
36 int matrix_size = mlt_properties_anim_get_int( properties, "matrix_size", position, length );
37 mlt_properties_set_int( properties, "_movit.parms.int.matrix_size", matrix_size );
38 mlt_properties_set_double( properties, "_movit.parms.float.circle_radius",
39 mlt_properties_anim_get_double( properties, "circle_radius", position, length ) );
40 mlt_properties_set_double( properties, "_movit.parms.float.gaussian_radius",
41 mlt_properties_anim_get_double( properties, "gaussian_radius", position, length ) );
42 mlt_properties_set_double( properties, "_movit.parms.float.correlation",
43 mlt_properties_anim_get_double( properties, "correlation", position, length ) );
44 mlt_properties_set_double( properties, "_movit.parms.float.noise",
45 mlt_properties_anim_get_double( properties, "noise", position, length ) );
47 // DeconvolutionSharpenEffect compiles the matrix size into the shader,
48 // so we need to regenerate the chain if this changes.
49 char fingerprint[256];
50 snprintf( fingerprint, sizeof( fingerprint ), "s=%d", matrix_size );
51 mlt_properties_set( properties, "_movit fingerprint", fingerprint );
53 GlslManager::get_instance()->unlock_service( frame );
54 *format = mlt_image_glsl;
55 int error = mlt_frame_get_image( frame, image, format, width, height, writable );
56 GlslManager::set_effect_input( MLT_FILTER_SERVICE( filter ), frame, (mlt_service) *image );
57 GlslManager::set_effect( MLT_FILTER_SERVICE( filter ), frame, new DeconvolutionSharpenEffect );
58 *image = (uint8_t *) MLT_FILTER_SERVICE( filter );
62 static mlt_frame process( mlt_filter filter, mlt_frame frame )
64 mlt_frame_push_service( frame, filter );
65 mlt_frame_push_get_image( frame, get_image );
71 mlt_filter filter_deconvolution_sharpen_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
73 mlt_filter filter = NULL;
74 GlslManager* glsl = GlslManager::get_instance();
76 if ( glsl && ( filter = mlt_filter_new() ) ) {
77 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
78 glsl->add_ref( properties );
79 mlt_properties_set_int( properties, "matrix_size", 5 );
80 mlt_properties_set_double( properties, "circle_radius", 2.0 );
81 mlt_properties_set_double( properties, "gaussian_radius", 0.0 );
82 mlt_properties_set_double( properties, "correlation", 0.95 );
83 mlt_properties_set_double( properties, "noise", 0.01 );
84 filter->process = process;