From b21cb279d7aba450faa6629adbc500773ab27f58 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 3 Dec 2013 22:30:07 +0100 Subject: vf_unsharp: change options, reroute to vf_lavfi --- DOCS/man/en/vf.rst | 20 ++++------- video/filter/vf_unsharp.c | 87 ++++++++++++++++++++--------------------------- 2 files changed, 43 insertions(+), 64 deletions(-) diff --git a/DOCS/man/en/vf.rst b/DOCS/man/en/vf.rst index 82d4b7500b..323eed8349 100644 --- a/DOCS/man/en/vf.rst +++ b/DOCS/man/en/vf.rst @@ -504,31 +504,23 @@ Available filters are: :0: nearest-neighbor sampling, fast but incorrect :1: linear interpolation (default) -``unsharp[=l|cWxH:amount[:l|cWxH:amount]]`` +``unsharp[=lx:ly:la:cx:cy:ca]`` unsharp mask / gaussian blur - ``l`` - Apply effect on luma component. + ``l`` is for the luma component, ``c`` for the chroma component. ``x``/``y`` + is the filter size. ``a`` is the amount. - ``c`` - Apply effect on chroma components. - - ``x`` + ``lx``, ``ly``, ``cx``, ``cy`` width and height of the matrix, odd sized in both directions (min = - 3x3, max = 13x11 or 11x13, usually something between 3x3 and 7x7) + 3:3, max = 13:11 or 11:13, usually something between 3:3 and 7:7) - ``amount`` + ``la``, ``ca`` Relative amount of sharpness/blur to add to the image (a sane range should be -1.5-1.5). :<0: blur :>0: sharpen - .. note:: - - Deprecated. Use libavfilter's ``unsharp`` filter through ``--vf=lavfi`` - instead. - ``swapuv`` Swap U & V plane. diff --git a/video/filter/vf_unsharp.c b/video/filter/vf_unsharp.c index cd65687780..5a81f8c395 100644 --- a/video/filter/vf_unsharp.c +++ b/video/filter/vf_unsharp.c @@ -27,6 +27,7 @@ #include "config.h" #include "mpvcore/mp_msg.h" #include "mpvcore/cpudetect.h" +#include "mpvcore/m_option.h" #include "video/img_format.h" #include "video/mp_image.h" @@ -34,6 +35,8 @@ #include "video/memcpy_pic.h" #include "libavutil/common.h" +#include "vf_lavfi.h" + //===========================================================================// #define MIN_MATRIX_SIZE 3 @@ -49,6 +52,7 @@ struct vf_priv_s { FilterParam lumaParam; FilterParam chromaParam; unsigned int outfmt; + struct vf_lw_opts *lw_opts; }; @@ -212,32 +216,6 @@ static int query_format( struct vf_instance *vf, unsigned int fmt ) { return 0; } -//===========================================================================// - -static void parse( FilterParam *fp, char* args ) { - - // l7x5:0.8:c3x3:-0.2 - - char *z; - char *pos = args; - char *max = args + strlen(args); - - // parse matrix sizes - fp->msizeX = ( pos && pos+1msizeY = ( z && z+1msizeX; - - // min/max & odd - fp->msizeX = 1 | av_clip(fp->msizeX, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE); - fp->msizeY = 1 | av_clip(fp->msizeY, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE); - - // parse amount - pos = strchr( pos+1, ':' ); - fp->amount = ( pos && pos+1filter = filter; vf->query_format = query_format; vf->uninit = uninit; - vf->priv = malloc( sizeof(struct vf_priv_s) ); - memset( vf->priv, 0, sizeof(struct vf_priv_s) ); - - if( args ) { - char *args2 = strchr( args, 'l' ); - if( args2 ) - parse( &vf->priv->lumaParam, args2 ); - else { - vf->priv->lumaParam.amount = - vf->priv->lumaParam.msizeX = - vf->priv->lumaParam.msizeY = 0; - } - - args2 = strchr( args, 'c' ); - if( args2 ) - parse( &vf->priv->chromaParam, args2 ); - else { - vf->priv->chromaParam.amount = - vf->priv->chromaParam.msizeX = - vf->priv->chromaParam.msizeY = 0; - } - - if( !vf->priv->lumaParam.msizeX && !vf->priv->chromaParam.msizeX ) - return 0; // nothing to do + struct vf_priv_s *p = vf->priv; + + p->lumaParam.msizeX |= 1; + p->lumaParam.msizeY |= 1; + p->chromaParam.msizeX |= 1; + p->chromaParam.msizeY |= 1; + + if (vf_lw_set_graph(vf, p->lw_opts, "unsharp", "%d:%d:%f:%d:%d:%f", + p->lumaParam.msizeX, p->lumaParam.msizeY, p->lumaParam.amount, + p->chromaParam.msizeX, p->chromaParam.msizeY, p->chromaParam.amount) + >= 0) + { + return 1; } // check csp: @@ -284,10 +251,30 @@ static int vf_open( vf_instance_t *vf, char *args ) { return 1; } +// same as MIN_/MAX_MATRIX_SIZE +#define MIN_SIZE 3 +#define MAX_SIZE 63 + +#define OPT_BASE_STRUCT struct vf_priv_s const vf_info_t vf_info_unsharp = { .description = "unsharp mask & gaussian blur", .name = "unsharp", .open = vf_open, + .priv_size = sizeof(struct vf_priv_s), + .priv_defaults = &(const struct vf_priv_s){ + .lumaParam = {5, 5, 1.0}, + .chromaParam = {5, 5, 0.0}, + }, + .options = (const struct m_option[]){ + OPT_INTRANGE("lx", lumaParam.msizeX, 0, MIN_SIZE, MAX_SIZE), + OPT_INTRANGE("ly", lumaParam.msizeY, 0, MIN_SIZE, MAX_SIZE), + OPT_DOUBLE("la", lumaParam.amount, CONF_RANGE, .min = -2, .max = 6), + OPT_INTRANGE("cx", chromaParam.msizeX, 0, MIN_SIZE, MAX_SIZE), + OPT_INTRANGE("cy", chromaParam.msizeY, 0, MIN_SIZE, MAX_SIZE), + OPT_DOUBLE("ca", chromaParam.amount, CONF_RANGE, .min = -2, .max = 6), + OPT_SUBSTRUCT("", lw_opts, vf_lw_conf, 0), + {0} + }, }; //===========================================================================// -- cgit v1.2.3