From ae16c751c8cef01b686c5368174bad94ad8ed723 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 8 Jan 2012 18:12:43 +0100 Subject: vf_gradfun: use option parser --- libmpcodecs/vf_gradfun.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/libmpcodecs/vf_gradfun.c b/libmpcodecs/vf_gradfun.c index 813b9ecb3f..8e5ff362b6 100644 --- a/libmpcodecs/vf_gradfun.c +++ b/libmpcodecs/vf_gradfun.c @@ -41,7 +41,12 @@ #include "libavutil/avutil.h" #include "ffmpeg_files/x86_cpu.h" +#include "m_option.h" +#include "m_struct.h" + struct vf_priv_s { + float cfg_thresh; + int cfg_radius; int thresh; int radius; uint16_t *buf; @@ -49,6 +54,9 @@ struct vf_priv_s { int width, int thresh, const uint16_t *dithers); void (*blur_line)(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int sstride, int width); +} const vf_priv_dflt = { + .cfg_thresh = 1.2, + .cfg_radius = 16, }; static const uint16_t __attribute__((aligned(16))) pw_7f[8] = {127,127,127,127,127,127,127,127}; @@ -368,20 +376,14 @@ static void uninit(struct vf_instance *vf) static int vf_open(vf_instance_t *vf, char *args) { - float thresh = 1.2; - int radius = 16; - vf->get_image=get_image; vf->put_image=put_image; vf->query_format=query_format; vf->config=config; vf->uninit=uninit; - vf->priv=malloc(sizeof(struct vf_priv_s)); - memset(vf->priv, 0, sizeof(struct vf_priv_s)); - if (args) sscanf(args, "%f:%d", &thresh, &radius); - vf->priv->thresh = (1<<15)/av_clipf(thresh,0.51,255); - vf->priv->radius = av_clip((radius+1)&~1,4,32); + vf->priv->thresh = (1<<15)/av_clipf(vf->priv->cfg_thresh,0.51,255); + vf->priv->radius = av_clip((vf->priv->cfg_radius+1)&~1,4,32); vf->priv->blur_line = blur_line_c; vf->priv->filter_line = filter_line_c; @@ -401,11 +403,26 @@ static int vf_open(vf_instance_t *vf, char *args) return 1; } +#undef ST_OFF +#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) +static const m_option_t vf_opts_fields[] = { + {"strength", ST_OFF(cfg_thresh), CONF_TYPE_FLOAT, M_OPT_RANGE, 0.51, 255, NULL}, + {"radius", ST_OFF(cfg_radius), CONF_TYPE_INT, M_OPT_RANGE, 4, 32, NULL}, + { NULL, NULL, 0, 0, 0, 0, NULL } +}; + +static const m_struct_t vf_opts = { + "gradfun", + sizeof(struct vf_priv_s), + &vf_priv_dflt, + vf_opts_fields +}; + const vf_info_t vf_info_gradfun = { "gradient deband", "gradfun", "Loren Merritt", "", vf_open, - NULL + &vf_opts }; -- cgit v1.2.3 From 278094e233d664356a4fd3d2613e444fcc9a726a Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 8 Jan 2012 18:25:26 +0100 Subject: vf_gradfun: add size parameter, which sets radius according to movie diagonal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a "size" parameter, which scales the filter radius according to movie diagonal, the unit being percent of diagonal. This makes the effect far more predictable across movies of different resolutions. Usage example (with possibly useless values): -vf gradfun=strength=1.2:size=2.3 Based on a patch by Radosław Szkodziński --- libmpcodecs/vf_gradfun.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libmpcodecs/vf_gradfun.c b/libmpcodecs/vf_gradfun.c index 8e5ff362b6..ec1ad80abf 100644 --- a/libmpcodecs/vf_gradfun.c +++ b/libmpcodecs/vf_gradfun.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "config.h" #include "cpudetect.h" @@ -47,6 +48,7 @@ struct vf_priv_s { float cfg_thresh; int cfg_radius; + float cfg_size; int thresh; int radius; uint16_t *buf; @@ -56,7 +58,8 @@ struct vf_priv_s { uint8_t *src, int sstride, int width); } const vf_priv_dflt = { .cfg_thresh = 1.2, - .cfg_radius = 16, + .cfg_radius = -1, + .cfg_size = -1, }; static const uint16_t __attribute__((aligned(16))) pw_7f[8] = {127,127,127,127,127,127,127,127}; @@ -362,6 +365,12 @@ static int config(struct vf_instance *vf, unsigned int flags, unsigned int outfmt) { free(vf->priv->buf); + vf->priv->radius = vf->priv->cfg_radius; + if (vf->priv->cfg_size > -1) { + vf->priv->radius = (vf->priv->cfg_size / 100.0f) + * sqrtf(width * width + height * height); + } + vf->priv->radius = av_clip((vf->priv->radius+1)&~1, 4, 32); vf->priv->buf = av_mallocz((((width+15)&~15)*(vf->priv->radius+1)/2+32)*sizeof(uint16_t)); return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); } @@ -382,8 +391,19 @@ static int vf_open(vf_instance_t *vf, char *args) vf->config=config; vf->uninit=uninit; + bool have_radius = vf->priv->cfg_radius > -1; + bool have_size = vf->priv->cfg_size > -1; + + if (have_radius && have_size) { + mp_msg(MSGT_VFILTER, MSGL_ERR, "scale: gradfun: only one of " + "radius/size parameters allowed at the same time!\n"); + return 0; + } + + if (!have_radius && !have_size) + vf->priv->cfg_radius = 16; + vf->priv->thresh = (1<<15)/av_clipf(vf->priv->cfg_thresh,0.51,255); - vf->priv->radius = av_clip((vf->priv->cfg_radius+1)&~1,4,32); vf->priv->blur_line = blur_line_c; vf->priv->filter_line = filter_line_c; @@ -408,6 +428,7 @@ static int vf_open(vf_instance_t *vf, char *args) static const m_option_t vf_opts_fields[] = { {"strength", ST_OFF(cfg_thresh), CONF_TYPE_FLOAT, M_OPT_RANGE, 0.51, 255, NULL}, {"radius", ST_OFF(cfg_radius), CONF_TYPE_INT, M_OPT_RANGE, 4, 32, NULL}, + {"size", ST_OFF(cfg_size), CONF_TYPE_FLOAT, M_OPT_RANGE, 0.1, 5.0, NULL}, { NULL, NULL, 0, 0, 0, 0, NULL } }; -- cgit v1.2.3 From 7142d2e4c0f26fe74586dd6fc6f3943cb2707801 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 10 Jan 2012 21:18:26 +0100 Subject: vf_gradfun: change default parameters --- libmpcodecs/vf_gradfun.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmpcodecs/vf_gradfun.c b/libmpcodecs/vf_gradfun.c index ec1ad80abf..c74fbfe5fb 100644 --- a/libmpcodecs/vf_gradfun.c +++ b/libmpcodecs/vf_gradfun.c @@ -57,7 +57,7 @@ struct vf_priv_s { void (*blur_line)(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int sstride, int width); } const vf_priv_dflt = { - .cfg_thresh = 1.2, + .cfg_thresh = 1.5, .cfg_radius = -1, .cfg_size = -1, }; @@ -401,7 +401,7 @@ static int vf_open(vf_instance_t *vf, char *args) } if (!have_radius && !have_size) - vf->priv->cfg_radius = 16; + vf->priv->cfg_size = 1.0; vf->priv->thresh = (1<<15)/av_clipf(vf->priv->cfg_thresh,0.51,255); -- cgit v1.2.3