Go to the documentation of this file.
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];
161 matrix[y * size_x + x] =
val;
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];
225 if (!
input->hw_frames_ctx)
228 if (!
ctx->initialised) {
246 dst = (cl_mem)
output->data[p];
265 ctx->global ? 0 : 16);
274 p, global_work[0], global_work[1]);
276 cle = clEnqueueNDRangeKernel(
ctx->command_queue,
ctx->kernel, 2,
NULL,
277 global_work,
ctx->global ?
NULL : local_work,
282 cle = clFinish(
ctx->command_queue);
298 clFinish(
ctx->command_queue);
310 for (
i = 0;
i <
ctx->nb_planes;
i++) {
311 if (
ctx->plane[
i].matrix)
312 clReleaseMemObject(
ctx->plane[
i].matrix);
313 if (
ctx->plane[
i].coef_x)
314 clReleaseMemObject(
ctx->plane[
i].coef_x);
315 if (
ctx->plane[
i].coef_y)
316 clReleaseMemObject(
ctx->plane[
i].coef_y);
320 cle = clReleaseKernel(
ctx->kernel);
321 if (cle != CL_SUCCESS)
323 "kernel: %d.\n", cle);
326 if (
ctx->command_queue) {
327 cle = clReleaseCommandQueue(
ctx->command_queue);
328 if (cle != CL_SUCCESS)
330 "command queue: %d.\n", cle);
336 #define OFFSET(x) offsetof(UnsharpOpenCLContext, x)
337 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
339 {
"luma_msize_x",
"Set luma mask horizontal diameter (pixels)",
342 {
"lx",
"Set luma mask horizontal diameter (pixels)",
345 {
"luma_msize_y",
"Set luma mask vertical diameter (pixels)",
348 {
"ly",
"Set luma mask vertical diameter (pixels)",
351 {
"luma_amount",
"Set luma amount (multiplier)",
353 { .dbl = 1.0 }, -10, 10,
FLAGS },
354 {
"la",
"Set luma amount (multiplier)",
356 { .dbl = 1.0 }, -10, 10,
FLAGS },
358 {
"chroma_msize_x",
"Set chroma mask horizontal diameter (pixels after subsampling)",
361 {
"cx",
"Set chroma mask horizontal diameter (pixels after subsampling)",
364 {
"chroma_msize_y",
"Set chroma mask vertical diameter (pixels after subsampling)",
367 {
"cy",
"Set chroma mask vertical diameter (pixels after subsampling)",
370 {
"chroma_amount",
"Set chroma amount (multiplier)",
372 { .dbl = 0.0 }, -10, 10,
FLAGS },
373 {
"ca",
"Set chroma amount (multiplier)",
375 { .dbl = 0.0 }, -10, 10,
FLAGS },
402 .
name =
"unsharp_opencl",
405 .priv_class = &unsharp_opencl_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static av_cold int init(AVCodecContext *avctx)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg)
set argument to specific Kernel.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
cl_command_queue command_queue
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
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.
AVFilter ff_vf_unsharp_opencl
const char * name
Filter name.
A link between two filters.
static const AVOption unsharp_opencl_options[]
float blur_x[MAX_DIAMETER]
static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
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.
void * priv
private data for use by the filter
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const AVFilterPad unsharp_opencl_outputs[]
static int unsharp_opencl_make_filter_params(AVFilterContext *avctx)
static const AVFilterPad outputs[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
float blur_y[MAX_DIAMETER]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
static int unsharp_opencl_init(AVFilterContext *avctx)
AVFILTER_DEFINE_CLASS(unsharp_opencl)
const char const char void * val
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
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.
#define i(width, name, range_min, range_max)
int w
agreed upon image width
struct UnsharpOpenCLContext::@245 plane[4]
const char * name
Pad name.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
#define FF_ARRAY_ELEMS(a)
int h
agreed upon image height
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
static av_cold void unsharp_opencl_uninit(AVFilterContext *avctx)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int query_formats(AVFilterContext *ctx)
const char * ff_opencl_source_unsharp
#define CL_FAIL_ON_ERROR(errcode,...)
A helper macro to handle OpenCL errors.
static av_cold int uninit(AVCodecContext *avctx)
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
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.
static const AVFilterPad unsharp_opencl_inputs[]
AVFilterLink ** outputs
array of pointers to output links