]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_gblur.c
avfilter/af_afreqshift: add fltp sample format support
[ffmpeg] / libavfilter / vf_gblur.c
index b91a8c074a2d5b1a721d167cdf4b906fe708105e..2e587f6a0af1652e891c4646443a39fc4b44f5ca 100644 (file)
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "formats.h"
+#include "gblur.h"
 #include "internal.h"
 #include "video.h"
 
-typedef struct GBlurContext {
-    const AVClass *class;
-
-    float sigma;
-    float sigmaV;
-    int steps;
-    int planes;
-
-    int depth;
-    int planewidth[4];
-    int planeheight[4];
-    float *buffer;
-    float boundaryscale;
-    float boundaryscaleV;
-    float postscale;
-    float postscaleV;
-    float nu;
-    float nuV;
-    int nb_planes;
-} GBlurContext;
-
 #define OFFSET(x) offsetof(GBlurContext, x)
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
 static const AVOption gblur_options[] = {
     { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0.0, 1024, FLAGS },
@@ -72,39 +52,44 @@ typedef struct ThreadData {
     int width;
 } ThreadData;
 
-static int filter_horizontally(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+static void horiz_slice_c(float *buffer, int width, int height, int steps,
+                          float nu, float bscale)
 {
-    GBlurContext *s = ctx->priv;
-    ThreadData *td = arg;
-    const int height = td->height;
-    const int width = td->width;
-    const int slice_start = (height *  jobnr   ) / nb_jobs;
-    const int slice_end   = (height * (jobnr+1)) / nb_jobs;
-    const float boundaryscale = s->boundaryscale;
-    const int steps = s->steps;
-    const float nu = s->nu;
-    float *buffer = s->buffer;
-    int y, x, step;
+    int step, x, y;
     float *ptr;
-
-    /* Filter horizontally along each row */
-    for (y = slice_start; y < slice_end; y++) {
+    for (y = 0; y < height; y++) {
         for (step = 0; step < steps; step++) {
             ptr = buffer + width * y;
-            ptr[0] *= boundaryscale;
+            ptr[0] *= bscale;
 
             /* Filter rightwards */
             for (x = 1; x < width; x++)
                 ptr[x] += nu * ptr[x - 1];
-
-            ptr[x = width - 1] *= boundaryscale;
+            ptr[x = width - 1] *= bscale;
 
             /* Filter leftwards */
             for (; x > 0; x--)
                 ptr[x - 1] += nu * ptr[x];
         }
     }
+}
+
+static int filter_horizontally(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+{
+    GBlurContext *s = ctx->priv;
+    ThreadData *td = arg;
+    const int height = td->height;
+    const int width = td->width;
+    const int slice_start = (height *  jobnr   ) / nb_jobs;
+    const int slice_end   = (height * (jobnr+1)) / nb_jobs;
+    const float boundaryscale = s->boundaryscale;
+    const int steps = s->steps;
+    const float nu = s->nu;
+    float *buffer = s->buffer;
 
+    s->horiz_slice(buffer + width * slice_start, width, slice_end - slice_start,
+                   steps, nu, boundaryscale);
+    emms_c();
     return 0;
 }
 
@@ -172,6 +157,7 @@ static int filter_postscale(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
 {
     GBlurContext *s = ctx->priv;
     ThreadData *td = arg;
+    const float max = (1 << s->depth) - 1;
     const int height = td->height;
     const int width = td->width;
     const int64_t numpixels = width * (int64_t)height;
@@ -181,8 +167,10 @@ static int filter_postscale(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
     float *buffer = s->buffer;
     unsigned i;
 
-    for (i = slice_start; i < slice_end; i++)
+    for (i = slice_start; i < slice_end; i++) {
         buffer[i] *= postscale;
+        buffer[i] = av_clipf(buffer[i], 0.f, max);
+    }
 
     return 0;
 }
@@ -220,6 +208,7 @@ static int query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
         AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
         AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
+        AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
         AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
         AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
         AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
@@ -231,6 +220,13 @@ static int query_formats(AVFilterContext *ctx)
     return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
 }
 
+void ff_gblur_init(GBlurContext *s)
+{
+    s->horiz_slice = horiz_slice_c;
+    if (ARCH_X86_64)
+        ff_gblur_init_x86(s);
+}
+
 static int config_input(AVFilterLink *inlink)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
@@ -244,13 +240,14 @@ static int config_input(AVFilterLink *inlink)
 
     s->nb_planes = av_pix_fmt_count_planes(inlink->format);
 
-    s->buffer = av_malloc_array(inlink->w, inlink->h * sizeof(*s->buffer));
+    s->buffer = av_malloc_array(FFALIGN(inlink->w, 16), FFALIGN(inlink->h, 16) * sizeof(*s->buffer));
     if (!s->buffer)
         return AVERROR(ENOMEM);
 
     if (s->sigmaV < 0) {
         s->sigmaV = s->sigma;
     }
+    ff_gblur_init(s);
 
     return 0;
 }
@@ -386,4 +383,5 @@ AVFilter ff_vf_gblur = {
     .inputs        = gblur_inputs,
     .outputs       = gblur_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+    .process_command = ff_filter_process_command,
 };