31 #define MAX_DIAMETER 23 81 "command queue: %d.\n", cle);
93 ctx->
global ?
"unsharp_global" 94 :
"unsharp_local", &cle);
108 clReleaseKernel(ctx->
kernel);
121 float diam_x, diam_y,
amount;
140 size_x = (
int)ceil(diam_x) | 1;
141 size_y = (
int)ceil(diam_y) | 1;
142 matrix_bytes = size_x * size_y *
sizeof(float);
151 for (x = 0; x <
size_x; x++) {
152 double dx = (double)(x - size_x / 2) / diam_x;
155 for (x = 0; x <
size_x; x++)
160 double dy = (double)(y - size_y / 2) / diam_y;
163 for (y = 0; y <
size_y; y++)
167 for (x = 0; x <
size_x; x++) {
169 matrix[y * size_x + x] =
val;
176 CL_MEM_COPY_HOST_PTR |
177 CL_MEM_HOST_NO_ACCESS,
178 matrix_bytes, matrix, &cle);
189 CL_MEM_COPY_HOST_PTR |
190 CL_MEM_HOST_NO_ACCESS,
203 CL_MEM_COPY_HOST_PTR |
204 CL_MEM_HOST_NO_ACCESS,
236 size_t global_work[2];
237 size_t local_work[2];
265 src = (cl_mem) input->
data[p];
266 dst = (cl_mem)output->
data[p];
271 cle = clSetKernelArg(ctx->
kernel, 0,
sizeof(cl_mem), &dst);
272 if (cle != CL_SUCCESS) {
274 "destination image argument: %d.\n", cle);
277 cle = clSetKernelArg(ctx->
kernel, 1,
sizeof(cl_mem), &src);
278 if (cle != CL_SUCCESS) {
280 "source image argument: %d.\n", cle);
284 if (cle != CL_SUCCESS) {
286 "matrix size argument: %d.\n", cle);
290 if (cle != CL_SUCCESS) {
292 "matrix size argument: %d.\n", cle);
296 if (cle != CL_SUCCESS) {
298 "amount argument: %d.\n", cle);
303 if (cle != CL_SUCCESS) {
305 "matrix argument: %d.\n", cle);
310 if (cle != CL_SUCCESS) {
312 "x-coef argument: %d.\n", cle);
316 if (cle != CL_SUCCESS) {
318 "y-coef argument: %d.\n", cle);
333 p, global_work[0], global_work[1]);
338 if (cle != CL_SUCCESS) {
347 if (cle != CL_SUCCESS) {
389 cle = clReleaseKernel(ctx->
kernel);
390 if (cle != CL_SUCCESS)
392 "kernel: %d.\n", cle);
397 if (cle != CL_SUCCESS)
399 "command queue: %d.\n", cle);
405 #define OFFSET(x) offsetof(UnsharpOpenCLContext, x) 406 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) 408 {
"luma_msize_x",
"Set luma mask horizontal diameter (pixels)",
411 {
"lx",
"Set luma mask horizontal diameter (pixels)",
414 {
"luma_msize_y",
"Set luma mask vertical diameter (pixels)",
417 {
"ly",
"Set luma mask vertical diameter (pixels)",
420 {
"luma_amount",
"Set luma amount (multiplier)",
422 { .dbl = 1.0 }, -10, 10, FLAGS },
423 {
"la",
"Set luma amount (multiplier)",
425 { .dbl = 1.0 }, -10, 10, FLAGS },
427 {
"chroma_msize_x",
"Set chroma mask horizontal diameter (pixels after subsampling)",
430 {
"cx",
"Set chroma mask horizontal diameter (pixels after subsampling)",
433 {
"chroma_msize_y",
"Set chroma mask vertical diameter (pixels after subsampling)",
436 {
"cy",
"Set chroma mask vertical diameter (pixels after subsampling)",
439 {
"chroma_amount",
"Set chroma amount (multiplier)",
441 { .dbl = 0.0 }, -10, 10, FLAGS },
442 {
"ca",
"Set chroma amount (multiplier)",
444 { .dbl = 0.0 }, -10, 10, FLAGS },
471 .
name =
"unsharp_opencl",
474 .priv_class = &unsharp_opencl_class,
478 .
inputs = unsharp_opencl_inputs,
479 .
outputs = unsharp_opencl_outputs,
int plane
Which of the 4 planes contains the component.
const char const char void * val
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
AVFilter ff_vf_unsharp_opencl
static av_cold void unsharp_opencl_uninit(AVFilterContext *avctx)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
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_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it...
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
Main libavfilter public API header.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
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.
static int unsharp_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
AVOpenCLDeviceContext * hwctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static av_cold int uninit(AVCodecContext *avctx)
static const AVOption unsharp_opencl_options[]
cl_device_id device_id
The primary device ID of the device.
cl_command_queue command_queue
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
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.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int unsharp_opencl_make_filter_params(AVFilterContext *avctx)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * ff_opencl_source_unsharp
enum AVPixelFormat output_format
int w
agreed upon image width
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
uint8_t nb_components
The number of components each pixel has, (1-4)
float blur_y[MAX_DIAMETER]
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
#define FF_ARRAY_ELEMS(a)
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...
AVFILTER_DEFINE_CLASS(unsharp_opencl)
float blur_x[MAX_DIAMETER]
const char * name
Filter name.
static int unsharp_opencl_init(AVFilterContext *avctx)
AVFilterLink ** outputs
array of pointers to output links
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int query_formats(AVFilterContext *ctx)
common internal and external API header
static const AVFilterPad unsharp_opencl_inputs[]
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
struct UnsharpOpenCLContext::@205 plane[4]
AVFilterContext * dst
dest filter
cl_context context
The OpenCL context which will contain all operations and frames on this device.
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.
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.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.