From patchwork Sun Aug 12 20:12:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danil Iashchenko X-Patchwork-Id: 9959 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp2431801jad; Sun, 12 Aug 2018 13:19:50 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxyWaqORA9Gb5bu4qBaIrTnpPFTT5afrRPLVGSq0fB6UacT7qkWo6ryTvwUlKrYuWx5m0ka X-Received: by 2002:adf:8161:: with SMTP id 88-v6mr8796855wrm.22.1534105190239; Sun, 12 Aug 2018 13:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534105190; cv=none; d=google.com; s=arc-20160816; b=AAClSfx0uAmudEleu6deQ0DtjlXuE1h18W3hnDtsBmG/Ofq1fxEa4gH54h6kNDl+Uc 4grjhcmDtg1FM00LIzIAqL+M7x1X1ykec2YLos5VjYL77bvw5BdeeQ0wRC9fIV7OYbnl LmtCCFrmHREc4JFsKxynZ5b+YALx2FG3bnrUwHbEFgEcWKgF7dDs14/IausIWmKxpqum O7QKeXfUZtIVaykxKoyRaekaKVCeMaeD61h2GL06ZD8Jhw6PKw9JDLJWEuFVxRatrl6Y QFqHZ6T+UHm7nGAs43KHTwCSSUNbEw9BnX++azv7YprTZ62zkG66tID3b7aelO9/wxqg LKgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=lkUyCCBRq/O4PuPxuIoxLX+RKd3Y4+2mrgdgo7mOt20=; b=lXQWJVPw6Vhp3i01Mel+wjHHTHygBf9FXnOWwyyKVNkWu+Y4/aqbvG5r64uV3mQQTk kN5cVsUyadz71SuGefmQvSqPjQgfR0P362CLXnRmd8HVai5BanoQi/ioYvLgK/wdYzFN pBbyQn3TjojmUFiQeOzHCwMrLtQjUE29ijKu9QeIlV1YNTt35ROdeb7JUT2jqcYr8S0Z lYpqp2K+Sxk+0A9/wOmEIAj2Uq5CxViFVkj+cHd3vv+xnHGp+XXHVGGN3pbefIxQQ/m2 7P/QgT3DJSg9UMu7y15kQOLI++xcsMRzFQG7ydulQ8D2Yelc27Jthx2V/cxnq4hmFiYh STdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=bd1Gvpct; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b2-v6si5844657wme.49.2018.08.12.13.19.49; Sun, 12 Aug 2018 13:19:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=bd1Gvpct; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B30D068A58B; Sun, 12 Aug 2018 23:19:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0318B689BDF for ; Sun, 12 Aug 2018 23:19:18 +0300 (EEST) Received: by mail-lj1-f181.google.com with SMTP id j19-v6so10973123ljc.7 for ; Sun, 12 Aug 2018 13:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qZeZksgbS263CqwIUGCrVhmrQGkxv8JGDgmdAxFN/Pw=; b=bd1GvpctheITLisaK56rdqRWvgGaHbrd6e/ysXfBXaOikQe7uHRmdOBYYPtYFBoVGe X1GSBqXZRZwqbJ65mG5r8anPtj0JPKijkCRnpHeo5P7dgn4sbpev51zZn1tyHd1j/lt6 NmPaXN8M+A296xKNdlwW27uckUIWsoYRlclPdlRYsFzzb7bir+9kAGxy9awH1dLZlazb pQNcsfW1gp+nuUT7GiVeTF1vAnnQHbXzylvak01hlcFzUsqVuXzm3NgMJWMKLy198cSV 5IU1kPlPn3PTgnJEdmDaQK/dTiEFDpeE38hIwpX770CulRaN8aOA6ABXIrBv88uR5TX1 pZ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qZeZksgbS263CqwIUGCrVhmrQGkxv8JGDgmdAxFN/Pw=; b=YvLIYZfImP0ccfJ6SfBezSdpGXsMrWiPz8ka5xrpKXSBoq/O0eSxRVSMoxWxt307d8 /eU7Xi2IfgX0aoDT6avrHQcIvFLjUcIJ+k3j0JyAb/om0C75hZQVzSJw+Ag7HVkCqhoP kjv6SDs4CJ2Y0ckY5J/eRlYKhr4MDUPDuPR60RGz4WGTWxkKy4lOEn+H9MMstecHYypv rFtckN4R8EFSdZix4NAuFC1G3CQZdvb5+rsqnlDMfAmIAddCCGnY4sEqHiuW5jz+DLRV NxdZpZ70S04xFblQyuf4Q3k8uLfdmfqTTY5UbYgRQcXAVuuLDssROmgjDduau/ALDNjw UsuA== X-Gm-Message-State: AOUpUlGg+2eB9cSSSq1pabFC9p/Nf0419jaHEAsbqdPkqeQ2ZxA3PxVG /LYmk8P+DKYcgHgoiNWVfVukGM4= X-Received: by 2002:a2e:1c4:: with SMTP id f65-v6mr6779534lji.58.1534104817949; Sun, 12 Aug 2018 13:13:37 -0700 (PDT) Received: from dan-acer.lan (campus.ifmo.ru. [194.85.161.2]) by smtp.gmail.com with ESMTPSA id r73-v6sm2718202ljb.16.2018.08.12.13.13.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 13:13:37 -0700 (PDT) From: Danil Iashchenko To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Aug 2018 23:12:08 +0300 Message-Id: <1534104728-22579-1-git-send-email-danyaschenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <4f68350c-5187-7222-cf5c-ad5b0f14cc9b@jkqxz.net> References: <4f68350c-5187-7222-cf5c-ad5b0f14cc9b@jkqxz.net> Subject: [FFmpeg-devel] [PATCH] lavfi: add erosion_opencl, dilation_opencl filters X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Danil Iashchenko MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add erosion_opencl, dilation_opencl filters. Behave like existing erosion and dilation filters. --- Thanks, Fixed! Danil. configure | 2 + libavfilter/Makefile | 4 + libavfilter/allfilters.c | 2 + libavfilter/opencl/neighbor.cl | 87 +++++++++++ libavfilter/opencl_source.h | 1 + libavfilter/vf_neighbor_opencl.c | 319 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 415 insertions(+) create mode 100644 libavfilter/opencl/neighbor.cl create mode 100644 libavfilter/vf_neighbor_opencl.c diff --git a/configure b/configure index 5783407..9ab2e9f 100755 --- a/configure +++ b/configure @@ -3333,10 +3333,12 @@ deinterlace_vaapi_filter_deps="vaapi" delogo_filter_deps="gpl" denoise_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer" deshake_filter_select="pixelutils" +dilation_opencl_filter_deps="opencl" drawtext_filter_deps="libfreetype" drawtext_filter_suggest="libfontconfig libfribidi" elbg_filter_deps="avcodec" eq_filter_deps="gpl" +erosion_opencl_filter_deps="opencl" fftfilt_filter_deps="avcodec" fftfilt_filter_select="rdft" fftdnoiz_filter_deps="avcodec" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 5d4549e..03df93b 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -196,6 +196,8 @@ OBJS-$(CONFIG_DESHAKE_FILTER) += vf_deshake.o OBJS-$(CONFIG_DESPILL_FILTER) += vf_despill.o OBJS-$(CONFIG_DETELECINE_FILTER) += vf_detelecine.o OBJS-$(CONFIG_DILATION_FILTER) += vf_neighbor.o +OBJS-$(CONFIG_DILATION_OPENCL_FILTER) += vf_neighbor_opencl.o opencl.o \ + opencl/neighbor.o OBJS-$(CONFIG_DISPLACE_FILTER) += vf_displace.o framesync.o OBJS-$(CONFIG_DOUBLEWEAVE_FILTER) += vf_weave.o OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o @@ -207,6 +209,8 @@ OBJS-$(CONFIG_ELBG_FILTER) += vf_elbg.o OBJS-$(CONFIG_ENTROPY_FILTER) += vf_entropy.o OBJS-$(CONFIG_EQ_FILTER) += vf_eq.o OBJS-$(CONFIG_EROSION_FILTER) += vf_neighbor.o +OBJS-$(CONFIG_EROSION_OPENCL_FILTER) += vf_neighbor_opencl.o opencl.o \ + opencl/neighbor.o OBJS-$(CONFIG_EXTRACTPLANES_FILTER) += vf_extractplanes.o OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o OBJS-$(CONFIG_FFTDNOIZ_FILTER) += vf_fftdnoiz.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 521bc53..f33129c 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -185,6 +185,7 @@ extern AVFilter ff_vf_deshake; extern AVFilter ff_vf_despill; extern AVFilter ff_vf_detelecine; extern AVFilter ff_vf_dilation; +extern AVFilter ff_vf_dilation_opencl; extern AVFilter ff_vf_displace; extern AVFilter ff_vf_doubleweave; extern AVFilter ff_vf_drawbox; @@ -196,6 +197,7 @@ extern AVFilter ff_vf_elbg; extern AVFilter ff_vf_entropy; extern AVFilter ff_vf_eq; extern AVFilter ff_vf_erosion; +extern AVFilter ff_vf_erosion_opencl; extern AVFilter ff_vf_extractplanes; extern AVFilter ff_vf_fade; extern AVFilter ff_vf_fftdnoiz; diff --git a/libavfilter/opencl/neighbor.cl b/libavfilter/opencl/neighbor.cl new file mode 100644 index 0000000..2235e3e --- /dev/null +++ b/libavfilter/opencl/neighbor.cl @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Danil Iashchenko + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +__kernel void erosion_global(__write_only image2d_t dst, + __read_only image2d_t src, + float threshold, + __constant int *coord) +{ + const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE | + CLK_ADDRESS_CLAMP_TO_EDGE | + CLK_FILTER_NEAREST); + + int2 loc = (int2)(get_global_id(0), get_global_id(1)); + + float4 px = read_imagef(src, sampler, loc); + float limit = px.x - threshold; + if (limit < 0) { + limit = 0; + } + + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + if (coord[(j + 1) * 3 + (i + 1)] == 1) { + float4 cur = read_imagef(src, sampler, loc + (int2)(i, j)); + if (cur.x < px.x) { + px = cur; + } + } + } + } + if (limit > px.x) { + px = (float4)(limit); + } + write_imagef(dst, loc, px); +} + + +__kernel void dilation_global(__write_only image2d_t dst, + __read_only image2d_t src, + float threshold, + __constant int *coord) +{ + const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE | + CLK_ADDRESS_CLAMP_TO_EDGE | + CLK_FILTER_NEAREST); + + int2 loc = (int2)(get_global_id(0), get_global_id(1)); + + float4 px = read_imagef(src, sampler, loc); + float limit = px.x + threshold; + if (limit > 1) { + limit = 1; + } + + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + if (coord[(j + 1) * 3 + (i + 1)] == 1) { + float4 cur = read_imagef(src, sampler, loc + (int2)(i, j)); + if (cur.x > px.x) { + px = cur; + } + } + } + } + if (limit < px.x) { + px = (float4)(limit); + } + write_imagef(dst, loc, px); +} diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h index de4e66e..2f67d89 100644 --- a/libavfilter/opencl_source.h +++ b/libavfilter/opencl_source.h @@ -22,6 +22,7 @@ extern const char *ff_opencl_source_avgblur; extern const char *ff_opencl_source_colorspace_common; extern const char *ff_opencl_source_convolution; +extern const char *ff_opencl_source_neighbor; extern const char *ff_opencl_source_overlay; extern const char *ff_opencl_source_tonemap; extern const char *ff_opencl_source_unsharp; diff --git a/libavfilter/vf_neighbor_opencl.c b/libavfilter/vf_neighbor_opencl.c new file mode 100644 index 0000000..74c3da3 --- /dev/null +++ b/libavfilter/vf_neighbor_opencl.c @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2018 Danil Iashchenko + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/imgutils.h" +#include "libavutil/mem.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/avstring.h" + + +#include "avfilter.h" +#include "internal.h" +#include "opencl.h" +#include "opencl_source.h" +#include "video.h" + +typedef struct NeighborOpenCLContext { + OpenCLFilterContext ocf; + + int initialised; + cl_kernel kernel; + cl_command_queue command_queue; + + char *matrix_str[4]; + + cl_float threshold[4]; + cl_int coordinates; + cl_mem coord; + +} NeighborOpenCLContext; + +static int neighbor_opencl_init(AVFilterContext *avctx) +{ + NeighborOpenCLContext *ctx = avctx->priv; + const char *kernel_name; + cl_int cle; + int err; + + err = ff_opencl_filter_load_program(avctx, &ff_opencl_source_neighbor, 1); + if (err < 0) + goto fail; + + ctx->command_queue = clCreateCommandQueue(ctx->ocf.hwctx->context, + ctx->ocf.hwctx->device_id, + 0, &cle); + CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create OpenCL " + "command queue %d.\n", cle); + + if (!strcmp(avctx->filter->name, "erosion_opencl")){ + kernel_name = "erosion_global"; + } else if (!strcmp(avctx->filter->name, "dilation_opencl")){ + kernel_name = "dilation_global"; + } + ctx->kernel = clCreateKernel(ctx->ocf.program, kernel_name, &cle); + CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create " + "kernel %d.\n", cle); + + ctx->initialised = 1; + return 0; + +fail: + if (ctx->command_queue) + clReleaseCommandQueue(ctx->command_queue); + if (ctx->kernel) + clReleaseKernel(ctx->kernel); + return err; +} + +static int neighbor_opencl_make_filter_params(AVFilterContext *avctx) +{ + NeighborOpenCLContext *ctx = avctx->priv; + cl_int matrix[9]; + cl_mem buffer; + cl_int cle; + int i; + + for (i = 0; i < 4; i++) { + ctx->threshold[i] /= 255.0; + } + + matrix[4] = 0; + for (i = 0; i < 8; i++) { + if (ctx->coordinates & (1 << i)) { + matrix[i > 3 ? i + 1: i] = 1; + } + } + buffer = clCreateBuffer(ctx->ocf.hwctx->context, + CL_MEM_READ_ONLY | + CL_MEM_COPY_HOST_PTR | + CL_MEM_HOST_NO_ACCESS, + 9 * sizeof(cl_int), matrix, &cle); + if (!buffer) { + av_log(avctx, AV_LOG_ERROR, "Failed to create matrix buffer: " + "%d.\n", cle); + return AVERROR(EIO); + } + ctx->coord = buffer; + + return 0; +} + + +static int neighbor_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input) +{ + AVFilterContext *avctx = inlink->dst; + AVFilterLink *outlink = avctx->outputs[0]; + NeighborOpenCLContext *ctx = avctx->priv; + AVFrame *output = NULL; + cl_int cle; + size_t global_work[2]; + cl_mem src, dst; + int err, p; + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {0, 0, 1}; + + av_log(ctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n", + av_get_pix_fmt_name(input->format), + input->width, input->height, input->pts); + + if (!input->hw_frames_ctx) + return AVERROR(EINVAL); + + if (!ctx->initialised) { + err = neighbor_opencl_init(avctx); + if (err < 0) + goto fail; + + err = neighbor_opencl_make_filter_params(avctx); + if (err < 0) + goto fail; + + } + + output = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!output) { + err = AVERROR(ENOMEM); + goto fail; + } + + for (p = 0; p < FF_ARRAY_ELEMS(output->data); p++) { + src = (cl_mem) input->data[p]; + dst = (cl_mem)output->data[p]; + + if (!dst) + break; + + if (ctx->threshold[p] == 0) { + err = ff_opencl_filter_work_size_from_image(avctx, region, output, p, 0); + if (err < 0) + goto fail; + + cle = clEnqueueCopyImage(ctx->command_queue, src, dst, + origin, origin, region, 0, NULL, NULL); + CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to copy plane %d: %d.\n", + p, cle); + } else { + CL_SET_KERNEL_ARG(ctx->kernel, 0, cl_mem, &dst); + CL_SET_KERNEL_ARG(ctx->kernel, 1, cl_mem, &src); + CL_SET_KERNEL_ARG(ctx->kernel, 2, cl_float, &ctx->threshold[p]); + CL_SET_KERNEL_ARG(ctx->kernel, 3, cl_mem, &ctx->coord); + + 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", + p, global_work[0], global_work[1]); + + cle = clEnqueueNDRangeKernel(ctx->command_queue, ctx->kernel, 2, NULL, + global_work, NULL, + 0, NULL, NULL); + CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to enqueue " + "kernel: %d.\n", cle); + } + } + + cle = clFinish(ctx->command_queue); + CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to finish command queue: %d.\n", cle); + + err = av_frame_copy_props(output, input); + if (err < 0) + goto fail; + + av_frame_free(&input); + + av_log(ctx, AV_LOG_DEBUG, "Filter output: %s, %ux%u (%"PRId64").\n", + av_get_pix_fmt_name(output->format), + output->width, output->height, output->pts); + + return ff_filter_frame(outlink, output); + +fail: + clFinish(ctx->command_queue); + av_frame_free(&input); + av_frame_free(&output); + return err; +} + +static av_cold void neighbor_opencl_uninit(AVFilterContext *avctx) +{ + NeighborOpenCLContext *ctx = avctx->priv; + cl_int cle; + + clReleaseMemObject(ctx->coord); + + if (ctx->kernel) { + cle = clReleaseKernel(ctx->kernel); + if (cle != CL_SUCCESS) + av_log(avctx, AV_LOG_ERROR, "Failed to release " + "kernel: %d.\n", cle); + } + + if (ctx->command_queue) { + cle = clReleaseCommandQueue(ctx->command_queue); + if (cle != CL_SUCCESS) + av_log(avctx, AV_LOG_ERROR, "Failed to release " + "command queue: %d.\n", cle); + } + + ff_opencl_filter_uninit(avctx); +} + +static const AVFilterPad neighbor_opencl_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = &neighbor_opencl_filter_frame, + .config_props = &ff_opencl_filter_config_input, + }, + { NULL } +}; + +static const AVFilterPad neighbor_opencl_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = &ff_opencl_filter_config_output, + }, + { NULL } +}; + +#define OFFSET(x) offsetof(NeighborOpenCLContext, x) +#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) + +#if CONFIG_EROSION_OPENCL_FILTER + +static const AVOption erosion_opencl_options[] = { + { "threshold0", "set threshold for 1st plane", OFFSET(threshold[0]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "threshold1", "set threshold for 2nd plane", OFFSET(threshold[1]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "threshold2", "set threshold for 3rd plane", OFFSET(threshold[2]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "threshold3", "set threshold for 4th plane", OFFSET(threshold[3]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "coordinates", "set coordinates", OFFSET(coordinates), AV_OPT_TYPE_INT, {.i64=255}, 0, 255, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(erosion_opencl); + +AVFilter ff_vf_erosion_opencl = { + .name = "erosion_opencl", + .description = NULL_IF_CONFIG_SMALL("Apply erosion effect"), + .priv_size = sizeof(NeighborOpenCLContext), + .priv_class = &erosion_opencl_class, + .init = &ff_opencl_filter_init, + .uninit = &neighbor_opencl_uninit, + .query_formats = &ff_opencl_filter_query_formats, + .inputs = neighbor_opencl_inputs, + .outputs = neighbor_opencl_outputs, + .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, +}; + +#endif /* CONFIG_EROSION_OPENCL_FILTER */ + +#if CONFIG_DILATION_OPENCL_FILTER + +static const AVOption dilation_opencl_options[] = { + { "threshold0", "set threshold for 1st plane", OFFSET(threshold[0]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "threshold1", "set threshold for 2nd plane", OFFSET(threshold[1]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "threshold2", "set threshold for 3rd plane", OFFSET(threshold[2]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "threshold3", "set threshold for 4th plane", OFFSET(threshold[3]), AV_OPT_TYPE_FLOAT, {.dbl=65535.0}, 0.0, 65535, FLAGS }, + { "coordinates", "set coordinates", OFFSET(coordinates), AV_OPT_TYPE_INT, {.i64=255}, 0, 255, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(dilation_opencl); + +AVFilter ff_vf_dilation_opencl = { + .name = "dilation_opencl", + .description = NULL_IF_CONFIG_SMALL("Apply dilation effect"), + .priv_size = sizeof(NeighborOpenCLContext), + .priv_class = &dilation_opencl_class, + .init = &ff_opencl_filter_init, + .uninit = &neighbor_opencl_uninit, + .query_formats = &ff_opencl_filter_query_formats, + .inputs = neighbor_opencl_inputs, + .outputs = neighbor_opencl_outputs, + .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, +}; + +#endif /* CONFIG_DILATION_OPENCL_FILTER */ +