[FFmpeg-devel] vf_unsharp_opencl: Do not apply kernel to locations outside images

Submitted by Mark Thompson on March 9, 2018, 12:47 a.m.

Details

Message ID 8c4b71d6-2830-e38b-ac84-1c85c7d562fc@jkqxz.net
State New
Headers show

Commit Message

Mark Thompson March 9, 2018, 12:47 a.m.
---
(Oops.)


 libavfilter/vf_unsharp_opencl.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

Comments

Jun Zhao March 9, 2018, 1:49 a.m.
On 2018/3/9 8:47, Mark Thompson wrote:
> ---
> (Oops.)
>
>
>  libavfilter/vf_unsharp_opencl.c | 24 ++++++++++++++++++++----
>  1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_unsharp_opencl.c b/libavfilter/vf_unsharp_opencl.c
> index 6a453c014b..3ee1b5b4ae 100644
> --- a/libavfilter/vf_unsharp_opencl.c
> +++ b/libavfilter/vf_unsharp_opencl.c
> @@ -236,6 +236,7 @@ static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
>      size_t global_work[2];
>      size_t local_work[2];
>      cl_mem src, dst;
> +    size_t plane_width, plane_height;
>      int err, p;
>  
>      av_log(ctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n",
> @@ -268,6 +269,21 @@ static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
>          if (!dst)
>              break;
>  
> +        cle = clGetImageInfo(src, CL_IMAGE_WIDTH,
> +                             sizeof(plane_width), &plane_width, NULL);
> +        if (cle != CL_SUCCESS) {
> +            av_log(avctx, AV_LOG_ERROR, "Failed to get plane %d "
> +                   "width: %d.\n", p, cle);
> +            goto fail;
> +        }
> +        cle = clGetImageInfo(src, CL_IMAGE_HEIGHT,
> +                             sizeof(plane_height), &plane_height, NULL);
> +        if (cle != CL_SUCCESS) {
> +            av_log(avctx, AV_LOG_ERROR, "Failed to get plane %d "
> +                   "height: %d.\n", p, cle);
> +            goto fail;
> +        }
> +
>          cle = clSetKernelArg(ctx->kernel, 0, sizeof(cl_mem), &dst);
>          if (cle != CL_SUCCESS) {
>              av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
> @@ -321,11 +337,11 @@ static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
>          }
>  
>          if (ctx->global) {
> -            global_work[0] = output->width;
> -            global_work[1] = output->height;
> +            global_work[0] = plane_width;
> +            global_work[1] = plane_height;
>          } else {
> -            global_work[0] = FFALIGN(output->width,  16);
> -            global_work[1] = FFALIGN(output->height, 16);
> +            global_work[0] = FFALIGN(plane_width,  16);
> +            global_work[1] = FFALIGN(plane_height, 16);
>              local_work[0]  = 16;
>              local_work[1]  = 16;
>          }
LGTM, maybe add some commit message more better :)

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_unsharp_opencl.c b/libavfilter/vf_unsharp_opencl.c
index 6a453c014b..3ee1b5b4ae 100644
--- a/libavfilter/vf_unsharp_opencl.c
+++ b/libavfilter/vf_unsharp_opencl.c
@@ -236,6 +236,7 @@  static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
     size_t global_work[2];
     size_t local_work[2];
     cl_mem src, dst;
+    size_t plane_width, plane_height;
     int err, p;
 
     av_log(ctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n",
@@ -268,6 +269,21 @@  static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
         if (!dst)
             break;
 
+        cle = clGetImageInfo(src, CL_IMAGE_WIDTH,
+                             sizeof(plane_width), &plane_width, NULL);
+        if (cle != CL_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to get plane %d "
+                   "width: %d.\n", p, cle);
+            goto fail;
+        }
+        cle = clGetImageInfo(src, CL_IMAGE_HEIGHT,
+                             sizeof(plane_height), &plane_height, NULL);
+        if (cle != CL_SUCCESS) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to get plane %d "
+                   "height: %d.\n", p, cle);
+            goto fail;
+        }
+
         cle = clSetKernelArg(ctx->kernel, 0, sizeof(cl_mem), &dst);
         if (cle != CL_SUCCESS) {
             av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
@@ -321,11 +337,11 @@  static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
         }
 
         if (ctx->global) {
-            global_work[0] = output->width;
-            global_work[1] = output->height;
+            global_work[0] = plane_width;
+            global_work[1] = plane_height;
         } else {
-            global_work[0] = FFALIGN(output->width,  16);
-            global_work[1] = FFALIGN(output->height, 16);
+            global_work[0] = FFALIGN(plane_width,  16);
+            global_work[1] = FFALIGN(plane_height, 16);
             local_work[0]  = 16;
             local_work[1]  = 16;
         }