Skip to content

Commit

Permalink
Add MLT movit.sharpen filter using Movit DeconvolutionSharpenEffect.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Jan 19, 2013
1 parent d5b1a86 commit b3dfa2a
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/modules/opengl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CPPOBJS += movit/padding_effect.o
# Movit MLT services
CPPOBJS += filter_movit_blur.o
CPPOBJS += filter_movit_convert.o
CPPOBJS += filter_deconvolution_sharpen.o
CPPOBJS += filter_movit_mirror.o
CPPOBJS += filter_movit_resample.o
CPPOBJS += filter_movit_resize.o
Expand Down
7 changes: 5 additions & 2 deletions src/modules/opengl/factory.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
* factory.c -- the factory method interfaces
* Copyright (C) 2006 Visual Media
* Author: Charles Yates <charles.yates@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -28,6 +27,7 @@ extern mlt_consumer consumer_xgl_init( mlt_profile profile, mlt_service_type typ
extern mlt_filter filter_glsl_manager_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
extern mlt_filter filter_movit_blur_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
extern mlt_filter filter_movit_convert_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
extern mlt_filter filter_deconvolution_sharpen_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
extern mlt_filter filter_movit_mirror_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
extern mlt_filter filter_movit_resample_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
extern mlt_filter filter_movit_resize_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
Expand All @@ -52,4 +52,7 @@ MLT_REPOSITORY
MLT_REGISTER( filter_type, "movit.mirror", filter_movit_mirror_init );
MLT_REGISTER( filter_type, "movit.resample", filter_movit_resample_init );
MLT_REGISTER( filter_type, "movit.resize", filter_movit_resize_init );
MLT_REGISTER( filter_type, "movit.sharpen", filter_deconvolution_sharpen_init );

MLT_REGISTER_METADATA( filter_type, "movit.sharpen", metadata, "filter_deconvolution_sharpen.yml" );
}
62 changes: 62 additions & 0 deletions src/modules/opengl/filter_deconvolution_sharpen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* filter_deconvolution_sharpen.cpp
* Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <framework/mlt.h>
#include <string.h>
#include <assert.h>

#include "glsl_manager.h"
#include "movit/init.h"
#include "movit/deconvolution_sharpen_effect.h"

static mlt_frame process( mlt_filter filter, mlt_frame frame )
{
Effect* effect = GlslManager::add_effect( filter, frame, new DeconvolutionSharpenEffect() );
if ( effect ) {
mlt_properties filter_props = MLT_FILTER_PROPERTIES( filter );
bool ok = effect->set_int( "matrix_size", mlt_properties_get_int( filter_props, "matrix_size" ) );
ok |= effect->set_float( "circle_radius", mlt_properties_get_double( filter_props, "circle_radius" ) );
ok |= effect->set_float( "gaussian_radius", mlt_properties_get_double( filter_props, "gaussian_radius" ) );
ok |= effect->set_float( "correlation", mlt_properties_get_double( filter_props, "correlation" ) );
ok |= effect->set_float( "noise", mlt_properties_get_double( filter_props, "noise" ) );
assert(ok);
}
return frame;
}

extern "C" {

mlt_filter filter_deconvolution_sharpen_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
{
mlt_filter filter = NULL;
GlslManager* glsl = GlslManager::get_instance();

if ( glsl && ( filter = mlt_filter_new() ) ) {
mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
mlt_properties_set_int( properties, "matrix_size", 5 );
mlt_properties_set_double( properties, "circle_radius", 2.0 );
mlt_properties_set_double( properties, "gaussian_radius", 0.0 );
mlt_properties_set_double( properties, "correlation", 0.95 );
mlt_properties_set_double( properties, "noise", 0.01 );
filter->process = process;
}
return filter;
}

}
53 changes: 53 additions & 0 deletions src/modules/opengl/filter_deconvolution_sharpen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
schema_version: 0.1
type: filter
identifier: movit.sharpen
title: Deconvolution Sharpen (GLSL)
version: 1
copyright: Dan Dennedy
creator: Steinar H. Gunderson
license: GPLv2
language: en
tags:
- Video
description: >
Deconvolution Sharpen is a filter that sharpens by way of deconvolution
(i.e., trying to reverse the blur kernel, as opposed to just boosting high
frequencies), more specifically by FIR Wiener filters. It is the same
algorithm as used by the (now largely abandoned) Refocus plug-in for GIMP,
and I suspect the same as in Photoshop's “Smart Sharpen” filter.
The effect gives generally better results than unsharp masking, but can be very
GPU intensive, and requires a fair bit of tweaking to get good results without
ringing and/or excessive noise. It should be mentioned that for the larger
parameters:
- identifier: matrix_size
title: Matrix Size
type: integer
minimum: 0
maximum: 10
default: 5

- identifier: circle_radius
title: Circle Radius
type: float
minimum: 0
default: 2

- identifier: gaussian_radius
title: Gaussian Radius
type: float
minimum: 0
default: 0

- identifier: correlation
title: Correlation
type: float
minimum: 0
default: 0.95

- identifier: noise
title: Noise Level
type: float
minimum: 0
default: 0.01

0 comments on commit b3dfa2a

Please sign in to comment.