Commit 5423fe29 authored by Danil Iashchenko's avatar Danil Iashchenko Committed by Mark Thompson

lavfi: add erosion_opencl, dilation_opencl filters

Add erosion_opencl, dilation_opencl filters. Behave like existing erosion and dilation filters.
parent 0f4c3b0b
...@@ -3338,10 +3338,12 @@ deinterlace_vaapi_filter_deps="vaapi" ...@@ -3338,10 +3338,12 @@ deinterlace_vaapi_filter_deps="vaapi"
delogo_filter_deps="gpl" delogo_filter_deps="gpl"
denoise_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer" denoise_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
deshake_filter_select="pixelutils" deshake_filter_select="pixelutils"
dilation_opencl_filter_deps="opencl"
drawtext_filter_deps="libfreetype" drawtext_filter_deps="libfreetype"
drawtext_filter_suggest="libfontconfig libfribidi" drawtext_filter_suggest="libfontconfig libfribidi"
elbg_filter_deps="avcodec" elbg_filter_deps="avcodec"
eq_filter_deps="gpl" eq_filter_deps="gpl"
erosion_opencl_filter_deps="opencl"
fftfilt_filter_deps="avcodec" fftfilt_filter_deps="avcodec"
fftfilt_filter_select="rdft" fftfilt_filter_select="rdft"
fftdnoiz_filter_deps="avcodec" fftdnoiz_filter_deps="avcodec"
......
...@@ -196,6 +196,8 @@ OBJS-$(CONFIG_DESHAKE_FILTER) += vf_deshake.o ...@@ -196,6 +196,8 @@ OBJS-$(CONFIG_DESHAKE_FILTER) += vf_deshake.o
OBJS-$(CONFIG_DESPILL_FILTER) += vf_despill.o OBJS-$(CONFIG_DESPILL_FILTER) += vf_despill.o
OBJS-$(CONFIG_DETELECINE_FILTER) += vf_detelecine.o OBJS-$(CONFIG_DETELECINE_FILTER) += vf_detelecine.o
OBJS-$(CONFIG_DILATION_FILTER) += vf_neighbor.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_DISPLACE_FILTER) += vf_displace.o framesync.o
OBJS-$(CONFIG_DOUBLEWEAVE_FILTER) += vf_weave.o OBJS-$(CONFIG_DOUBLEWEAVE_FILTER) += vf_weave.o
OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o
...@@ -207,6 +209,8 @@ OBJS-$(CONFIG_ELBG_FILTER) += vf_elbg.o ...@@ -207,6 +209,8 @@ OBJS-$(CONFIG_ELBG_FILTER) += vf_elbg.o
OBJS-$(CONFIG_ENTROPY_FILTER) += vf_entropy.o OBJS-$(CONFIG_ENTROPY_FILTER) += vf_entropy.o
OBJS-$(CONFIG_EQ_FILTER) += vf_eq.o OBJS-$(CONFIG_EQ_FILTER) += vf_eq.o
OBJS-$(CONFIG_EROSION_FILTER) += vf_neighbor.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_EXTRACTPLANES_FILTER) += vf_extractplanes.o
OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o
OBJS-$(CONFIG_FFTDNOIZ_FILTER) += vf_fftdnoiz.o OBJS-$(CONFIG_FFTDNOIZ_FILTER) += vf_fftdnoiz.o
......
...@@ -185,6 +185,7 @@ extern AVFilter ff_vf_deshake; ...@@ -185,6 +185,7 @@ extern AVFilter ff_vf_deshake;
extern AVFilter ff_vf_despill; extern AVFilter ff_vf_despill;
extern AVFilter ff_vf_detelecine; extern AVFilter ff_vf_detelecine;
extern AVFilter ff_vf_dilation; extern AVFilter ff_vf_dilation;
extern AVFilter ff_vf_dilation_opencl;
extern AVFilter ff_vf_displace; extern AVFilter ff_vf_displace;
extern AVFilter ff_vf_doubleweave; extern AVFilter ff_vf_doubleweave;
extern AVFilter ff_vf_drawbox; extern AVFilter ff_vf_drawbox;
...@@ -196,6 +197,7 @@ extern AVFilter ff_vf_elbg; ...@@ -196,6 +197,7 @@ extern AVFilter ff_vf_elbg;
extern AVFilter ff_vf_entropy; extern AVFilter ff_vf_entropy;
extern AVFilter ff_vf_eq; extern AVFilter ff_vf_eq;
extern AVFilter ff_vf_erosion; extern AVFilter ff_vf_erosion;
extern AVFilter ff_vf_erosion_opencl;
extern AVFilter ff_vf_extractplanes; extern AVFilter ff_vf_extractplanes;
extern AVFilter ff_vf_fade; extern AVFilter ff_vf_fade;
extern AVFilter ff_vf_fftdnoiz; extern AVFilter ff_vf_fftdnoiz;
......
/*
* 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);
}
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
extern const char *ff_opencl_source_avgblur; extern const char *ff_opencl_source_avgblur;
extern const char *ff_opencl_source_colorspace_common; extern const char *ff_opencl_source_colorspace_common;
extern const char *ff_opencl_source_convolution; 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_overlay;
extern const char *ff_opencl_source_tonemap; extern const char *ff_opencl_source_tonemap;
extern const char *ff_opencl_source_unsharp; extern const char *ff_opencl_source_unsharp;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment