From 7d04327e7158d42ff62bc8b607d2832bb0b73d08 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 3 Dec 2013 22:24:49 +0100 Subject: vf_gradfun: reroute to vf_lavfi Also update the manpage. We changed defaults and added a suboption quite some time ago, and we forgot to update the manpage at all. --- DOCS/man/en/vf.rst | 12 ++++++------ video/filter/vf_gradfun.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/DOCS/man/en/vf.rst b/DOCS/man/en/vf.rst index 3823bcf4c4..e202a21575 100644 --- a/DOCS/man/en/vf.rst +++ b/DOCS/man/en/vf.rst @@ -830,24 +830,24 @@ Available filters are: Deprecated. Use libavfilter's ``stereo3d`` filter through ``--vf=lavfi`` instead. -``gradfun[=strength[:radius]]`` +``gradfun[=strength[:radius|:size=]]`` Fix the banding artifacts that are sometimes introduced into nearly flat regions by truncation to 8bit color depth. Interpolates the gradients that should go where the bands are, and dithers them. ```` Maximum amount by which the filter will change any one pixel. Also the - threshold for detecting nearly flat regions (default: 1.2). + threshold for detecting nearly flat regions (default: 1.5). ```` Neighborhood to fit the gradient to. Larger radius makes for smoother gradients, but also prevents the filter from modifying pixels near - detailed regions (default: 16). + detailed regions (default: disabled). - .. note:: + ```` + size of the filter in percent of the image diagonal size. This is + used to calculate the final radius size (default: 1). - Deprecated. Use libavfilter's ``gradfun`` filter through ``--vf=lavfi`` - instead. ``dlopen=dll[:a0[:a1[:a2[:a3]]]]`` Loads an external library to filter the image. The library interface diff --git a/video/filter/vf_gradfun.c b/video/filter/vf_gradfun.c index f7b39fa999..28916e7871 100644 --- a/video/filter/vf_gradfun.c +++ b/video/filter/vf_gradfun.c @@ -45,6 +45,8 @@ #include "mpvcore/m_option.h" +#include "vf_lavfi.h" + struct vf_priv_s { float cfg_thresh; int cfg_radius; @@ -56,6 +58,7 @@ 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); + struct vf_lw_opts *lw_opts; } const vf_priv_dflt = { .cfg_thresh = 1.5, .cfg_radius = -1, @@ -353,6 +356,18 @@ static void uninit(struct vf_instance *vf) av_free(vf->priv->buf); } +static void lavfi_recreate(struct vf_instance *vf) +{ + struct vf_priv_s *p = vf_lw_old_priv(vf); + int w = vf->fmt_in.params.w; + int h = vf->fmt_in.params.h; + p->radius = p->cfg_radius; + if (p->cfg_size > -1) + p->radius = (p->cfg_size / 100.0f) * sqrtf(w * w + h * h); + p->radius = av_clip((p->radius+1)&~1, 4, 32); + vf_lw_update_graph(vf, "gradfun", "%f:%d", p->cfg_thresh, p->radius); +} + static int vf_open(vf_instance_t *vf, char *args) { vf->filter=filter; @@ -372,6 +387,13 @@ static int vf_open(vf_instance_t *vf, char *args) if (!have_radius && !have_size) vf->priv->cfg_size = 1.0; + if (vf_lw_set_graph(vf, vf->priv->lw_opts, "gradfun", "%f:4", + vf->priv->cfg_thresh) >= 0) + { + vf_lw_set_recreate_cb(vf, lavfi_recreate); + return 1; + } + vf->priv->thresh = (1<<15)/av_clipf(vf->priv->cfg_thresh,0.51,255); vf->priv->blur_line = blur_line_c; @@ -397,6 +419,7 @@ static const m_option_t vf_opts_fields[] = { OPT_FLOATRANGE("strength", cfg_thresh, 0, 0.51, 255), OPT_INTRANGE("radius", cfg_radius, 0, 4, 32), OPT_FLOATRANGE("size", cfg_size, 0, 0.1, 5.0), + OPT_SUBSTRUCT("", lw_opts, vf_lw_conf, 0), {0} }; -- cgit v1.2.3