[FFmpeg-cvslog] avfilter/vf_gblur: factor out postscale function

Paul B Mahol git at videolan.org
Tue Feb 16 22:14:46 EET 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Feb 13 11:15:22 2021 +0100| [058db59e164dc420239beac054212a1b1933a01d] | committer: Paul B Mahol

avfilter/vf_gblur: factor out postscale function

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=058db59e164dc420239beac054212a1b1933a01d
---

 libavfilter/gblur.h    |  2 ++
 libavfilter/vf_gblur.c | 23 ++++++++++++++---------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/libavfilter/gblur.h b/libavfilter/gblur.h
index 15a8167fe5..dce50671f6 100644
--- a/libavfilter/gblur.h
+++ b/libavfilter/gblur.h
@@ -50,7 +50,9 @@ typedef struct GBlurContext {
     float nuV;
     int nb_planes;
     void (*horiz_slice)(float *buffer, int width, int height, int steps, float nu, float bscale);
+    void (*postscale_slice)(float *buffer, int length, float postscale, float min, float max);
 } GBlurContext;
+
 void ff_gblur_init(GBlurContext *s);
 void ff_gblur_init_x86(GBlurContext *s);
 #endif
diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
index 68a2ed3520..70e2a668b4 100644
--- a/libavfilter/vf_gblur.c
+++ b/libavfilter/vf_gblur.c
@@ -54,6 +54,15 @@ typedef struct ThreadData {
     int width;
 } ThreadData;
 
+static void postscale_c(float *buffer, int length,
+                        float postscale, float min, float max)
+{
+    for (int i = 0; i < length; i++) {
+        buffer[i] *= postscale;
+        buffer[i] = av_clipf(buffer[i], min, max);
+    }
+}
+
 static void horiz_slice_c(float *buffer, int width, int height, int steps,
                           float nu, float bscale)
 {
@@ -154,7 +163,6 @@ static int filter_vertically(AVFilterContext *ctx, void *arg, int jobnr, int nb_
     return 0;
 }
 
-
 static int filter_postscale(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
     GBlurContext *s = ctx->priv;
@@ -164,16 +172,12 @@ static int filter_postscale(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
     const int height = td->height;
     const int width = td->width;
     const int64_t numpixels = width * (int64_t)height;
-    const unsigned slice_start = (numpixels *  jobnr   ) / nb_jobs;
-    const unsigned slice_end   = (numpixels * (jobnr+1)) / nb_jobs;
+    const int slice_start = (numpixels *  jobnr   ) / nb_jobs;
+    const int slice_end   = (numpixels * (jobnr+1)) / nb_jobs;
     const float postscale = s->postscale * s->postscaleV;
-    float *buffer = s->buffer;
-    unsigned i;
+    float *buffer = s->buffer + slice_start;
 
-    for (i = slice_start; i < slice_end; i++) {
-        buffer[i] *= postscale;
-        buffer[i] = av_clipf(buffer[i], min, max);
-    }
+    s->postscale_slice(buffer, slice_end - slice_start, postscale, min, max);
 
     return 0;
 }
@@ -228,6 +232,7 @@ static int query_formats(AVFilterContext *ctx)
 void ff_gblur_init(GBlurContext *s)
 {
     s->horiz_slice = horiz_slice_c;
+    s->postscale_slice = postscale_c;
     if (ARCH_X86_64)
         ff_gblur_init_x86(s);
 }



More information about the ffmpeg-cvslog mailing list