[FFmpeg-cvslog] avfilter/vf_gblur: add float format support

Paul B Mahol git at videolan.org
Fri Feb 12 22:10:46 EET 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Feb 12 21:07:29 2021 +0100| [34922dffcae2eb3d0aa1f98a1a7e022c7edb0e6e] | committer: Paul B Mahol

avfilter/vf_gblur: add float format support

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

 libavfilter/gblur.h    |  1 +
 libavfilter/vf_gblur.c | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavfilter/gblur.h b/libavfilter/gblur.h
index 87129801de..15a8167fe5 100644
--- a/libavfilter/gblur.h
+++ b/libavfilter/gblur.h
@@ -37,6 +37,7 @@ typedef struct GBlurContext {
     int steps;
     int planes;
 
+    int flt;
     int depth;
     int planewidth[4];
     int planeheight[4];
diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
index 2e587f6a0a..68a2ed3520 100644
--- a/libavfilter/vf_gblur.c
+++ b/libavfilter/vf_gblur.c
@@ -25,6 +25,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <float.h>
+
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
@@ -157,7 +159,8 @@ 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 float max = s->flt ?  FLT_MAX : (1 << s->depth) - 1;
+    const float min = s->flt ? -FLT_MAX : 0.f;
     const int height = td->height;
     const int width = td->width;
     const int64_t numpixels = width * (int64_t)height;
@@ -169,7 +172,7 @@ static int filter_postscale(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
 
     for (i = slice_start; i < slice_end; i++) {
         buffer[i] *= postscale;
-        buffer[i] = av_clipf(buffer[i], 0.f, max);
+        buffer[i] = av_clipf(buffer[i], min, max);
     }
 
     return 0;
@@ -214,6 +217,8 @@ static int query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
         AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
+        AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
+        AV_PIX_FMT_GRAYF32,
         AV_PIX_FMT_NONE
     };
 
@@ -233,6 +238,7 @@ static int config_input(AVFilterLink *inlink)
     GBlurContext *s = inlink->dst->priv;
 
     s->depth = desc->comp[0].depth;
+    s->flt = !!(desc->flags & AV_PIX_FMT_FLAG_FLOAT);
     s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
     s->planewidth[0] = s->planewidth[3] = inlink->w;
     s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
@@ -303,7 +309,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
             continue;
         }
 
-        if (s->depth == 8) {
+        if (s->flt) {
+            av_image_copy_plane((uint8_t *)bptr, width * sizeof(float),
+                                in->data[plane], in->linesize[plane],
+                                width * sizeof(float), height);
+        } else if (s->depth == 8) {
             for (y = 0; y < height; y++) {
                 for (x = 0; x < width; x++) {
                     bptr[x] = src[x];
@@ -324,7 +334,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         gaussianiir2d(ctx, plane);
 
         bptr = s->buffer;
-        if (s->depth == 8) {
+        if (s->flt) {
+            av_image_copy_plane(out->data[plane], out->linesize[plane],
+                                (uint8_t *)bptr, width * sizeof(float),
+                                width * sizeof(float), height);
+        } else if (s->depth == 8) {
             for (y = 0; y < height; y++) {
                 for (x = 0; x < width; x++) {
                     dst[x] = bptr[x];



More information about the ffmpeg-cvslog mailing list