Commit 7faa8d8b authored by Mark Thompson's avatar Mark Thompson

lavfi: Add OpenCL unsharp mask filter

Intended to replace existing opencl mode of the unsharp filter.
Supports many more pixel formats and works without immediate upload
and download of frame data.  The options are compatible with the
existing filter.
parent 9204b2de
......@@ -3283,6 +3283,7 @@ tinterlace_filter_deps="gpl"
tinterlace_merge_test_deps="tinterlace_filter"
tinterlace_pad_test_deps="tinterlace_filter"
tonemap_filter_deps="const_nan"
unsharp_opencl_filter_deps="opencl"
uspp_filter_deps="gpl avcodec"
unsharp_filter_suggest="opencl"
vaguedenoiser_filter_deps="gpl"
......
......@@ -331,6 +331,8 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o
OBJS-$(CONFIG_TRIM_FILTER) += trim.o
OBJS-$(CONFIG_UNPREMULTIPLY_FILTER) += vf_premultiply.o framesync.o
OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o
OBJS-$(CONFIG_UNSHARP_OPENCL_FILTER) += vf_unsharp_opencl.o opencl.o \
opencl/unsharp.o
OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o
OBJS-$(CONFIG_VAGUEDENOISER_FILTER) += vf_vaguedenoiser.o
OBJS-$(CONFIG_VECTORSCOPE_FILTER) += vf_vectorscope.o
......
......@@ -339,6 +339,7 @@ static void register_all(void)
REGISTER_FILTER(TRIM, trim, vf);
REGISTER_FILTER(UNPREMULTIPLY, unpremultiply, vf);
REGISTER_FILTER(UNSHARP, unsharp, vf);
REGISTER_FILTER(UNSHARP_OPENCL, unsharp_opencl, vf);
REGISTER_FILTER(USPP, uspp, vf);
REGISTER_FILTER(VAGUEDENOISER, vaguedenoiser, vf);
REGISTER_FILTER(VECTORSCOPE, vectorscope, vf);
......
/*
* 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 unsharp_global(__write_only image2d_t dst,
__read_only image2d_t src,
int size_x,
int size_y,
float amount,
__constant float *coef_matrix)
{
const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
CLK_FILTER_NEAREST);
int2 loc = (int2)(get_global_id(0), get_global_id(1));
int2 centre = (int2)(size_x / 2, size_y / 2);
float4 val = read_imagef(src, sampler, loc);
float4 sum = 0.0f;
int x, y;
for (y = 0; y < size_y; y++) {
for (x = 0; x < size_x; x++) {
int2 pos = loc + (int2)(x, y) - centre;
sum += coef_matrix[y * size_x + x] *
read_imagef(src, sampler, pos);
}
}
write_imagef(dst, loc, val + (val - sum) * amount);
}
__kernel void unsharp_local(__write_only image2d_t dst,
__read_only image2d_t src,
int size_x,
int size_y,
float amount,
__constant float *coef_x,
__constant float *coef_y)
{
const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
CLK_ADDRESS_CLAMP_TO_EDGE |
CLK_FILTER_NEAREST);
int2 block = (int2)(get_group_id(0), get_group_id(1)) * 16;
int2 pos = (int2)(get_local_id(0), get_local_id(1));
__local float4 tmp[32][32];
int rad_x = size_x / 2;
int rad_y = size_y / 2;
int x, y;
for (y = 0; y <= 1; y++) {
for (x = 0; x <= 1; x++) {
tmp[pos.y + 16 * y][pos.x + 16 * x] =
read_imagef(src, sampler, block + pos + (int2)(16 * x - 8, 16 * y - 8));
}
}
barrier(CLK_LOCAL_MEM_FENCE);
float4 val = tmp[pos.y + 8][pos.x + 8];
float4 horiz[2];
for (y = 0; y <= 1; y++) {
horiz[y] = 0.0f;
for (x = 0; x < size_x; x++)
horiz[y] += coef_x[x] * tmp[pos.y + y * 16][pos.x + 8 + x - rad_x];
}
barrier(CLK_LOCAL_MEM_FENCE);
for (y = 0; y <= 1; y++) {
tmp[pos.y + y * 16][pos.x + 8] = horiz[y];
}
barrier(CLK_LOCAL_MEM_FENCE);
float4 sum = 0.0f;
for (y = 0; y < size_y; y++)
sum += coef_y[y] * tmp[pos.y + 8 + y - rad_y][pos.x + 8];
if (block.x + pos.x < get_image_width(dst) &&
block.y + pos.y < get_image_height(dst))
write_imagef(dst, block + pos, val + (val - sum) * amount);
}
......@@ -20,5 +20,6 @@
#define AVFILTER_OPENCL_SOURCE_H
extern const char *ff_opencl_source_overlay;
extern const char *ff_opencl_source_unsharp;
#endif /* AVFILTER_OPENCL_SOURCE_H */
......@@ -31,7 +31,7 @@
#define LIBAVFILTER_VERSION_MAJOR 7
#define LIBAVFILTER_VERSION_MINOR 2
#define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_MICRO 102
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
......
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