31#define MAX_DIAMETER 23
76 ctx->command_queue = clCreateCommandQueue(
ctx->ocf.hwctx->context,
77 ctx->ocf.hwctx->device_id,
80 "command queue %d.\n", cle);
83 ctx->global = (
ctx->luma_size_x > 17.0f ||
84 ctx->luma_size_y > 17.0f ||
85 ctx->chroma_size_x > 17.0f ||
86 ctx->chroma_size_y > 17.0f);
88 ctx->kernel = clCreateKernel(
ctx->ocf.program,
89 ctx->global ?
"unsharp_global"
90 :
"unsharp_local", &cle);
97 if (
ctx->command_queue)
98 clReleaseCommandQueue(
ctx->command_queue);
100 clReleaseKernel(
ctx->kernel);
113 float diam_x, diam_y, amount;
114 int err, p, x, y, size_x, size_y;
119 for (p = 0; p <
desc->nb_components; p++)
122 for (p = 0; p <
ctx->nb_planes; p++) {
124 diam_x =
ctx->luma_size_x;
125 diam_y =
ctx->luma_size_y;
126 amount =
ctx->luma_amount;
128 diam_x =
ctx->chroma_size_x;
129 diam_y =
ctx->chroma_size_y;
130 amount =
ctx->chroma_amount;
132 size_x = (int)
ceil(diam_x) | 1;
133 size_y = (int)
ceil(diam_y) | 1;
134 matrix_bytes = size_x * size_y *
sizeof(
float);
143 for (x = 0; x < size_x; x++) {
144 double dx = (
double)(x - size_x / 2) / diam_x;
145 sum +=
ctx->plane[p].blur_x[x] =
exp(-16.0 * (dx * dx));
147 for (x = 0; x < size_x; x++)
148 ctx->plane[p].blur_x[x] /= sum;
151 for (y = 0; y < size_y; y++) {
152 double dy = (
double)(y - size_y / 2) / diam_y;
153 sum +=
ctx->plane[p].blur_y[y] =
exp(-16.0 * (dy * dy));
155 for (y = 0; y < size_y; y++)
156 ctx->plane[p].blur_y[y] /= sum;
158 for (y = 0; y < size_y; y++) {
159 for (x = 0; x < size_x; x++) {
160 val =
ctx->plane[p].blur_x[x] *
ctx->plane[p].blur_y[y];
166 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
168 CL_MEM_COPY_HOST_PTR |
169 CL_MEM_HOST_NO_ACCESS,
170 matrix_bytes,
matrix, &cle);
175 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
177 CL_MEM_COPY_HOST_PTR |
178 CL_MEM_HOST_NO_ACCESS,
179 sizeof(
ctx->plane[p].blur_x),
180 ctx->plane[p].blur_x, &cle);
185 buffer = clCreateBuffer(
ctx->ocf.hwctx->context,
187 CL_MEM_COPY_HOST_PTR |
188 CL_MEM_HOST_NO_ACCESS,
189 sizeof(
ctx->plane[p].blur_y),
190 ctx->plane[p].blur_y, &cle);
198 ctx->plane[p].size_x = size_x;
199 ctx->plane[p].size_y = size_y;
200 ctx->plane[p].amount = amount;
216 size_t global_work[2];
217 size_t local_work[2];
228 if (!
ctx->initialised) {
265 ctx->global ? 0 : 16);
273 p, global_work[0], global_work[1]);
275 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
276 global_work,
ctx->global ?
NULL : local_work,
281 cle = clFinish(
ctx->command_queue);
297 clFinish(
ctx->command_queue);
309 for (
i = 0;
i <
ctx->nb_planes;
i++) {
310 if (
ctx->plane[
i].matrix)
311 clReleaseMemObject(
ctx->plane[
i].matrix);
312 if (
ctx->plane[
i].coef_x)
313 clReleaseMemObject(
ctx->plane[
i].coef_x);
314 if (
ctx->plane[
i].coef_y)
315 clReleaseMemObject(
ctx->plane[
i].coef_y);
319 cle = clReleaseKernel(
ctx->kernel);
320 if (cle != CL_SUCCESS)
322 "kernel: %d.\n", cle);
325 if (
ctx->command_queue) {
326 cle = clReleaseCommandQueue(
ctx->command_queue);
327 if (cle != CL_SUCCESS)
329 "command queue: %d.\n", cle);
335#define OFFSET(x) offsetof(UnsharpOpenCLContext, x)
336#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
338 {
"luma_msize_x",
"Set luma mask horizontal diameter (pixels)",
341 {
"lx",
"Set luma mask horizontal diameter (pixels)",
344 {
"luma_msize_y",
"Set luma mask vertical diameter (pixels)",
347 {
"ly",
"Set luma mask vertical diameter (pixels)",
350 {
"luma_amount",
"Set luma amount (multiplier)",
352 { .dbl = 1.0 }, -10, 10,
FLAGS },
353 {
"la",
"Set luma amount (multiplier)",
355 { .dbl = 1.0 }, -10, 10,
FLAGS },
357 {
"chroma_msize_x",
"Set chroma mask horizontal diameter (pixels after subsampling)",
360 {
"cx",
"Set chroma mask horizontal diameter (pixels after subsampling)",
363 {
"chroma_msize_y",
"Set chroma mask vertical diameter (pixels after subsampling)",
366 {
"cy",
"Set chroma mask vertical diameter (pixels after subsampling)",
369 {
"chroma_amount",
"Set chroma amount (multiplier)",
371 { .dbl = 0.0 }, -10, 10,
FLAGS },
372 {
"ca",
"Set chroma amount (multiplier)",
374 { .dbl = 0.0 }, -10, 10,
FLAGS },
399 .p.name =
"unsharp_opencl",
401 .p.priv_class = &unsharp_opencl_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFFilter ff_vf_unsharp_opencl
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
common internal and external API header
static __device__ float ceil(float a)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
int ff_opencl_filter_load_program(AVFilterContext *avctx, const char **program_source_array, int nb_strings)
Load a new OpenCL program from strings in memory.
int ff_opencl_filter_config_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx, size_t *work_size, AVFrame *frame, int plane, int block_alignment)
Find the work size needed needed for a given plane of an image.
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
const char * ff_source_unsharp_cl
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
#define FF_ARRAY_ELEMS(a)
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
cl_command_queue command_queue
float blur_x[MAX_DIAMETER]
struct UnsharpOpenCLContext::@234236151323151376014240035370306224260322060041 plane[AV_VIDEO_MAX_PLANES]
float blur_y[MAX_DIAMETER]
static AVFormatContext * ctx
static const AVOption unsharp_opencl_options[]
static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
static int unsharp_opencl_init(AVFilterContext *avctx)
static const AVFilterPad unsharp_opencl_inputs[]
static int unsharp_opencl_make_filter_params(AVFilterContext *avctx)
static av_cold void unsharp_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad unsharp_opencl_outputs[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.