diff mbox

[FFmpeg-devel] vf_avgblur_opencl: Don't run kernel on pixels outside the image

Message ID daf764de-c840-8e9d-4abf-81c38d5b9644@jkqxz.net
State Accepted
Commit 213839edffbf3982570e4e06ca713f8547dd336a
Headers show

Commit Message

Mark Thompson March 24, 2018, 2:06 p.m. UTC
The output frame size is larger than the image containing a subsampled
plane - use the actual size of the image being written rather than the
dimensions of the intended output frame.
---
 libavfilter/vf_avgblur_opencl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Dylan Fernando March 25, 2018, 12:41 p.m. UTC | #1
On Sun, Mar 25, 2018 at 1:06 AM, Mark Thompson <sw@jkqxz.net> wrote:

> The output frame size is larger than the image containing a subsampled
> plane - use the actual size of the image being written rather than the
> dimensions of the intended output frame.
> ---
>  libavfilter/vf_avgblur_opencl.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_avgblur_opencl.c
> b/libavfilter/vf_avgblur_opencl.c
> index 5ee66c0ba2..3a5b4a28ca 100644
> --- a/libavfilter/vf_avgblur_opencl.c
> +++ b/libavfilter/vf_avgblur_opencl.c
> @@ -170,8 +170,10 @@ static int avgblur_opencl_filter_frame(AVFilterLink
> *inlink, AVFrame *input)
>              goto fail;
>          }
>
> -        global_work[0] = output->width;
> -        global_work[1] = output->height;
> +        err = ff_opencl_filter_work_size_from_image(avctx, global_work,
> +                                                    intermediate, p, 0);
> +        if (err < 0)
> +            goto fail;
>
>          av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
>                 "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
> @@ -206,8 +208,10 @@ static int avgblur_opencl_filter_frame(AVFilterLink
> *inlink, AVFrame *input)
>              goto fail;
>          }
>
> -        global_work[0] = output->width;
> -        global_work[1] = output->height;
> +        err = ff_opencl_filter_work_size_from_image(avctx, global_work,
> +                                                    output, p, 0);
> +        if (err < 0)
> +            goto fail;
>
>          av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
>                 "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
> --
> 2.16.1
>
Thanks. I tried the patch, it works correctly.

Following is a patch attempting to fix the err issue. It returns -1 if any
clSetKernelArg() fails. Is this good, or should I be using a different
return value for this error?

- Dylan
diff mbox

Patch

diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_opencl.c
index 5ee66c0ba2..3a5b4a28ca 100644
--- a/libavfilter/vf_avgblur_opencl.c
+++ b/libavfilter/vf_avgblur_opencl.c
@@ -170,8 +170,10 @@  static int avgblur_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
             goto fail;
         }
 
-        global_work[0] = output->width;
-        global_work[1] = output->height;
+        err = ff_opencl_filter_work_size_from_image(avctx, global_work,
+                                                    intermediate, p, 0);
+        if (err < 0)
+            goto fail;
 
         av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
                "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
@@ -206,8 +208,10 @@  static int avgblur_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
             goto fail;
         }
 
-        global_work[0] = output->width;
-        global_work[1] = output->height;
+        err = ff_opencl_filter_work_size_from_image(avctx, global_work,
+                                                    output, p, 0);
+        if (err < 0)
+            goto fail;
 
         av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
                "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",