27 #include "libavutil/common.h"
35 for (i = 0; i <
len; i++) {
36 dst[i] = counter1[i] + counter2[i];
43 int counter_size =
sizeof(uint32_t) * (2 * step + 1);
44 uint32_t *temp1_counter, *temp2_counter, **counter;
55 counter =
av_mallocz(
sizeof(uint32_t *) * (2 * step + 1));
60 for (i = 0; i < 2 * step + 1; i++) {
67 for (i = 0; i < 2 * step + 1; i++) {
68 memset(temp1_counter, 0, counter_size);
70 for (z = 0; z < step * 2; z += 2) {
72 memcpy(counter[z], temp1_counter, counter_size);
74 memcpy(counter[z + 1], temp2_counter, counter_size);
77 memcpy(mask, temp1_counter, counter_size);
81 for (i = 0; i < 2 * step + 1; i++) {
92 size_t size_matrix =
sizeof(uint32_t) * (2 * step_x + 1) * (2 * step_y + 1);
93 mask_x =
av_mallocz(
sizeof(uint32_t) * (2 * step_x + 1));
98 mask_y =
av_mallocz(
sizeof(uint32_t) * (2 * step_y + 1));
114 for (j = 0; j < 2 * step_y + 1; j++) {
115 for (i = 0; i < 2 * step_x + 1; i++) {
116 mask_matrix[i + j * (2 * step_x + 1)] = mask_y[j] * mask_x[i];
130 int i,
ret = 0, step_x[2], step_y[2];
132 mask_matrix[0] = unsharp->opencl_ctx.cl_luma_mask;
133 mask_matrix[1] = unsharp->opencl_ctx.cl_chroma_mask;
138 if (!mask_matrix[0] || !mask_matrix[1]) {
142 for (i = 0; i < 2; i++) {
158 const size_t global_work_size = link->
w * link->
h + 2 * ch * cw;
161 opencl_param.
ctx = ctx;
162 opencl_param.
kernel = unsharp->opencl_ctx.kernel_env.kernel;
189 status = clEnqueueNDRangeKernel(unsharp->opencl_ctx.kernel_env.command_queue,
190 unsharp->opencl_ctx.kernel_env.kernel, 1, NULL,
191 &global_work_size, NULL, 0, NULL, NULL);
192 if (status != CL_SUCCESS) {
196 clFinish(unsharp->opencl_ctx.kernel_env.command_queue);
198 unsharp->opencl_ctx.plane_num, unsharp->opencl_ctx.cl_outbuf,
199 unsharp->opencl_ctx.cl_outbuf_size);
211 CL_MEM_READ_ONLY, NULL);
216 CL_MEM_READ_ONLY, NULL);
222 unsharp->opencl_ctx.plane_num =
PLANE_NUM;
223 if (!unsharp->opencl_ctx.kernel_env.kernel) {
251 if ((!unsharp->opencl_ctx.cl_inbuf) || (!unsharp->opencl_ctx.cl_outbuf)) {
252 unsharp->opencl_ctx.in_plane_size[0] = (in->
linesize[0] * in->
height);
253 unsharp->opencl_ctx.in_plane_size[1] = (in->
linesize[1] * ch);
254 unsharp->opencl_ctx.in_plane_size[2] = (in->
linesize[2] * ch);
255 unsharp->opencl_ctx.out_plane_size[0] = (out->
linesize[0] * out->
height);
256 unsharp->opencl_ctx.out_plane_size[1] = (out->
linesize[1] * ch);
257 unsharp->opencl_ctx.out_plane_size[2] = (out->
linesize[2] * ch);
258 unsharp->opencl_ctx.cl_inbuf_size = unsharp->opencl_ctx.in_plane_size[0] +
259 unsharp->opencl_ctx.in_plane_size[1] +
260 unsharp->opencl_ctx.in_plane_size[2];
261 unsharp->opencl_ctx.cl_outbuf_size = unsharp->opencl_ctx.out_plane_size[0] +
262 unsharp->opencl_ctx.out_plane_size[1] +
263 unsharp->opencl_ctx.out_plane_size[2];
264 if (!unsharp->opencl_ctx.cl_inbuf) {
266 unsharp->opencl_ctx.cl_inbuf_size,
267 CL_MEM_READ_ONLY, NULL);
271 if (!unsharp->opencl_ctx.cl_outbuf) {
273 unsharp->opencl_ctx.cl_outbuf_size,
274 CL_MEM_READ_WRITE, NULL);
280 unsharp->opencl_ctx.cl_inbuf_size,
281 0, in->
data, unsharp->opencl_ctx.in_plane_size,
282 unsharp->opencl_ctx.plane_num);
static const uint16_t mask_matrix[]
This structure describes decoded (raw) audio or video data.
void * priv
private data for use by the filter
int h
agreed upon image height
UnsharpFilterParam luma
luma parameters (width, height, amount)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
const char * av_opencl_errstr(cl_int status)
Get OpenCL error string.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int steps_x
horizontal step count
void ff_opencl_unsharp_uninit(AVFilterContext *ctx)
static av_cold int end(AVCodecContext *avctx)
static void add_mask_counter(uint32_t *dst, uint32_t *counter1, uint32_t *counter2, int len)
#define FF_CEIL_RSHIFT(a, b)
int ff_opencl_unsharp_init(AVFilterContext *ctx)
A link between two filters.
int scalebits
bits to shift pixel
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int32_t halfscale
amount to add to pixel
static const uint16_t mask[17]
int w
agreed upon image width
int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void *host_ptr)
Create OpenCL buffer.
int ff_opencl_unsharp_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset, uint8_t **src_data, int *plane_size, int plane_num)
Write image data from memory to OpenCL buffer.
void av_opencl_release_kernel(AVOpenCLKernelEnv *env)
Release kernel object.
static int compute_mask(int step, uint32_t *mask)
int steps_y
vertical step count
int av_opencl_create_kernel(AVOpenCLKernelEnv *env, const char *kernel_name)
Create kernel object in the specified kernel environment.
static int compute_mask_matrix(cl_mem cl_mask_matrix, int step_x, int step_y)
AVFilterLink ** inputs
array of pointers to input links
UnsharpFilterParam chroma
chroma parameters (width, height, amount)
void av_opencl_buffer_release(cl_mem *cl_buf)
Release OpenCL buffer.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_opencl_set_parameter(FFOpenclParam *opencl_param,...)
int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size)
Write OpenCL buffer with data from src_buf.
void av_opencl_uninit(void)
Release OpenCL environment.
#define FF_OPENCL_PARAM_INFO(a)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int av_opencl_init(AVOpenCLExternalEnv *ext_opencl_env)
Initialize the run time OpenCL environment and compile the kernel code registered with av_opencl_regi...
static int generate_mask(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int ff_opencl_apply_unsharp(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num, cl_mem src_cl_buf, size_t cl_buffer_size)
Read image data from OpenCL buffer.