On Thu, Sep 01, 2016 at 03:03:18PM +0200, Paul B Mahol wrote: > Hi, > > patch attached.
> doc/filters.texi | 17 ++ > libavfilter/Makefile | 1 > libavfilter/allfilters.c | 1 > libavfilter/vf_gblur.c | 276 > +++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 295 insertions(+) > e14454fae179168294a89bf21ea0d2b1fb0fa41a 0001-avfilter-add-gblur-filter.patch > From dca28955cfa774c0efed615cb5a0434f663731ec Mon Sep 17 00:00:00 2001 > From: Paul B Mahol <one...@gmail.com> > Date: Thu, 1 Sep 2016 01:18:45 +0200 > Subject: [PATCH] avfilter: add gblur filter > > Signed-off-by: Paul B Mahol <one...@gmail.com> > --- > doc/filters.texi | 17 +++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_gblur.c | 276 > +++++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 295 insertions(+) > create mode 100644 libavfilter/vf_gblur.c > > diff --git a/doc/filters.texi b/doc/filters.texi > index 88c6f65..cf43edb 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -8231,6 +8231,23 @@ option may cause flicker since the B-Frames have often > larger QP. Default is > > @end table > > +@section gblur > + > +Apply Gaussian blur filter. > + > +The filter accepts the following options: > + > +@table @option > +@item sigma > +Set sigma, standard deviation of Gaussian blur. Default is @code{0.5}. > + > +@item steps > +Set number of steps for Gaussian approximation. Defauls is @code{4}. > + > +@item planes > +Set which planes to filter. By default all planes are filtered. > +@end table > + > @section geq > > The filter accepts the following options: > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index 81b40ac..0074ca3 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -183,6 +183,7 @@ OBJS-$(CONFIG_FRAMESTEP_FILTER) += > vf_framestep.o > OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o > OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o > OBJS-$(CONFIG_GEQ_FILTER) += vf_geq.o > +OBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o > OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o > OBJS-$(CONFIG_HALDCLUT_FILTER) += vf_lut3d.o dualinput.o > framesync.o > OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index ee6f9cb..0234833 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -200,6 +200,7 @@ void avfilter_register_all(void) > REGISTER_FILTER(FREI0R, frei0r, vf); > REGISTER_FILTER(FSPP, fspp, vf); > REGISTER_FILTER(GEQ, geq, vf); > + REGISTER_FILTER(GBLUR, gblur, vf); > REGISTER_FILTER(GRADFUN, gradfun, vf); > REGISTER_FILTER(HALDCLUT, haldclut, vf); > REGISTER_FILTER(HFLIP, hflip, vf); > diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c > new file mode 100644 > index 0000000..fc316af > --- /dev/null > +++ b/libavfilter/vf_gblur.c > @@ -0,0 +1,276 @@ > +/* > + * Copyright (c) 2011 Pascal Getreuer > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg 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 > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + */ > + > +#include "libavutil/imgutils.h" > +#include "libavutil/opt.h" > +#include "libavutil/pixdesc.h" > +#include "avfilter.h" > +#include "formats.h" > +#include "internal.h" > +#include "video.h" > + > +typedef struct GBlurContext { > + const AVClass *class; > + > + float sigma; > + int steps; > + int planes; > + > + int depth; > + int planewidth[4]; > + int planeheight[4]; > + float *buffer; > + int nb_planes; > +} GBlurContext; > + > +#define OFFSET(x) offsetof(GBlurContext, x) > +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM > + > +static const AVOption gblur_options[] = { > + { "sigma", "set sigma", OFFSET(sigma), AV_OPT_TYPE_FLOAT, > {.dbl=0.5}, 0.0, 1024, FLAGS }, > + { "steps", "set number of steps", OFFSET(steps), AV_OPT_TYPE_INT, > {.i64=4}, 1, 24, FLAGS }, > + { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, > {.i64=0xF}, 0, 0xF, FLAGS }, > + { NULL } > +}; > + > +AVFILTER_DEFINE_CLASS(gblur); > + > +static void gaussianiir2d(float *buffer, int width, int height, > + float sigma, int steps) > +{ > + const int numpixels = width * height; > + float nu, boundaryscale, postscale; > + double lambda, dnu; > + int i, x, y, step; > + float *ptr; > + > + if (sigma <= 0 || steps < 0) > + return; > + > + lambda = (sigma * sigma) / (2.0 * steps); > + dnu = (1.0 + 2.0*lambda - sqrt(1.0 + 4.0 * lambda)) / (2.0 * lambda); > + postscale = pow(dnu / lambda, 2*steps); > + boundaryscale = 1.0 / (1.0 - dnu); > + nu = (float)dnu; > + > + /* Filter horizontally along each row */ > + for (y = 0; y < height; y++) { > + for (step = 0; step < steps; step++) { > + ptr = buffer + width*y; > + ptr[0] *= boundaryscale; > + > + /* Filter rightwards */ > + for (x = 1; x < width; x++) > + ptr[x] += nu*ptr[x - 1]; > + > + ptr[x = width - 1] *= boundaryscale; > + > + /* Filter leftwards */ > + for (; x > 0; x--) > + ptr[x - 1] += nu*ptr[x]; > + } > + } > + > + /* Filter vertically along each column */ > + for (x = 0; x < width; x++) { > + for (step = 0; step < steps; step++) { > + ptr = buffer + x; > + ptr[0] *= boundaryscale; > + > + /* Filter downwards */ > + for (i = width; i < numpixels; i += width) > + ptr[i] += nu*ptr[i - width]; > + > + ptr[i = numpixels - width] *= boundaryscale; > + > + /* Filter upwards */ > + for (; i > 0; i -= width) > + ptr[i - width] += nu*ptr[i]; > + } > + } This is a bit hard on the CPU cache, doing multiple colums at once likely is faster also this can be done much faster with SIMD [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No great genius has ever existed without some touch of madness. -- Aristotle
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel