67 #define OFFSET(x) offsetof(VagueDenoiserContext, x)
68 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
89 0.037828455506995f, -0.023849465019380f, -0.110624404418423f, 0.377402855612654f,
90 0.852698679009403f, 0.377402855612654f, -0.110624404418423f, -0.023849465019380f, 0.037828455506995f
94 -0.064538882628938f, 0.040689417609558f, 0.418092273222212f, -0.788485616405664f,
95 0.418092273222212f, 0.040689417609558f, -0.064538882628938f
99 -0.064538882628938f, -0.040689417609558f, 0.418092273222212f, 0.788485616405664f,
100 0.418092273222212f, -0.040689417609558f, -0.064538882628938f
104 -0.037828455506995f, -0.023849465019380f, 0.110624404418423f, 0.377402855612654f,
105 -0.852698679009403f, 0.377402855612654f, 0.110624404418423f, -0.023849465019380f, -0.037828455506995f
145 int p,
i, nsteps_width, nsteps_height, nsteps_max;
147 s->depth =
desc->comp[0].depth;
148 s->bpc = (
s->depth + 7) / 8;
149 s->nb_planes =
desc->nb_components;
152 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
154 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
161 if (!
s->block || !
s->in || !
s->out || !
s->tmp)
164 s->threshold *= 1 << (
s->depth - 8);
165 s->peak = (1 <<
s->depth) - 1;
167 nsteps_width = ((
s->planes & 2 ||
s->planes & 4) &&
s->nb_planes > 1) ?
s->planewidth[1] :
s->planewidth[0];
168 nsteps_height = ((
s->planes & 2 ||
s->planes & 4) &&
s->nb_planes > 1) ?
s->planeheight[1] :
s->planeheight[0];
170 for (nsteps_max = 1; nsteps_max < 15; nsteps_max++) {
171 if (pow(2, nsteps_max) >= nsteps_width || pow(2, nsteps_max) >= nsteps_height)
175 s->nsteps =
FFMIN(
s->nsteps, nsteps_max - 2);
177 for (p = 0; p < 4; p++) {
178 s->hlowsize[p][0] = (
s->planewidth[p] + 1) >> 1;
179 s->hhighsize[p][0] =
s->planewidth[p] >> 1;
180 s->vlowsize[p][0] = (
s->planeheight[p] + 1) >> 1;
181 s->vhighsize[p][0] =
s->planeheight[p] >> 1;
183 for (
i = 1;
i <
s->nsteps;
i++) {
184 s->hlowsize[p][
i] = (
s->hlowsize[p][
i - 1] + 1) >> 1;
185 s->hhighsize[p][
i] =
s->hlowsize[p][
i - 1] >> 1;
186 s->vlowsize[p][
i] = (
s->vlowsize[p][
i - 1] + 1) >> 1;
187 s->vhighsize[p][
i] =
s->vlowsize[p][
i - 1] >> 1;
194 static inline void copy(
const float *p1,
float *p2,
const int length)
196 memcpy(p2, p1, length *
sizeof(
float));
199 static inline void copyv(
const float *p1,
const int stride1,
float *p2,
const int length)
203 for (
i = 0;
i < length;
i++) {
209 static inline void copyh(
const float *p1,
float *p2,
const int stride2,
const int length)
213 for (
i = 0;
i < length;
i++) {
229 const int originalLast = last;
233 output[--first] = output[
NPAD];
235 output[++last] = output[originalLast];
239 for (
i = 0;
i < nextend;
i++)
240 output[--first] = output[
NPAD + 1 +
i];
245 nextend = idx - last;
246 for (
i = 0;
i < nextend;
i++)
247 output[++last] = output[originalLast - 1 -
i];
267 output[
i] =
a +
b +
c + d + e +
f +
g +
h + k;
279 output[
i + low_size] =
a +
b +
c + d + e +
f +
g;
285 const int low_size = (
size + 1) >> 1;
286 const int high_size =
size >> 1;
287 int left_ext = 1, right_ext,
i;
290 memcpy(
temp +
NPAD, input +
NPAD, low_size *
sizeof(
float));
292 right_ext = (
size % 2 == 0) ? 2 : 1;
295 memset(output, 0, (
NPAD +
NPAD +
size) *
sizeof(
float));
296 findex = (
size + 2) >> 1;
298 for (
i = 9;
i < findex + 11;
i++) {
304 output[2 *
i - 13] +=
a;
305 output[2 *
i - 12] +=
b;
306 output[2 *
i - 11] +=
c;
307 output[2 *
i - 10] += d;
308 output[2 *
i - 9] +=
c;
309 output[2 *
i - 8] +=
b;
310 output[2 *
i - 7] +=
a;
313 memcpy(
temp +
NPAD, input +
NPAD + low_size, high_size *
sizeof(
float));
316 right_ext = (
size % 2 == 0) ? 1 : 2;
319 for (
i = 8;
i < findex + 11;
i++) {
326 output[2 *
i - 13] +=
a;
327 output[2 *
i - 12] +=
b;
328 output[2 *
i - 11] +=
c;
329 output[2 *
i - 10] += d;
330 output[2 *
i - 9] += e;
331 output[2 *
i - 8] += d;
332 output[2 *
i - 7] +=
c;
333 output[2 *
i - 6] +=
b;
334 output[2 *
i - 5] +=
a;
339 const int stride,
const float threshold,
342 const float frac = 1.f - percent * 0.01f;
345 for (y = 0; y <
height; y++) {
346 for (x = 0; x <
width; x++) {
355 const float threshold,
const float percent)
357 const float frac = 1.f - percent * 0.01f;
358 const float shift = threshold * 0.01f * percent;
361 for (y = 0; y <
height; y++) {
362 for (x = 0; x <
width; x++) {
364 if (
temp <= threshold)
374 const int stride,
const float threshold,
377 const float percent01 = percent * 0.01f;
378 const float tr2 = threshold * threshold * percent01;
379 const float frac = 1.f - percent01;
382 for (y = 0; y <
height; y++) {
383 for (x = 0; x <
width; x++) {
385 if (
temp <= threshold) {
389 block[x] *= (tp2 - tr2) / tp2;
397 const int stride,
const float threshold)
401 for (
int y = 0; y <
height; y++) {
402 for (
int x = 0; x <
width; x++) {
410 return threshold * threshold / (
FFMAX(sqrtf(
mean - threshold), FLT_EPSILON));
417 for (p = 0; p <
s->nb_planes; p++) {
418 const int height =
s->planeheight[p];
419 const int width =
s->planewidth[p];
421 const uint16_t *srcp16 = (
const uint16_t *)
in->data[p];
423 uint16_t *dstp16 = (uint16_t *)
out->data[p];
424 float *output =
s->block;
425 int h_low_size0 =
width;
427 int nsteps_transform =
s->nsteps;
428 int nsteps_invert =
s->nsteps;
429 const float *input =
s->block;
431 if (!((1 << p) &
s->planes)) {
433 s->planewidth[p] *
s->bpc,
s->planeheight[p]);
438 for (y = 0; y <
height; y++) {
439 for (x = 0; x <
width; x++)
440 output[x] = srcp8[x];
441 srcp8 +=
in->linesize[p];
445 for (y = 0; y <
height; y++) {
446 for (x = 0; x <
width; x++)
447 output[x] = srcp16[x];
448 srcp16 +=
in->linesize[p] / 2;
453 while (nsteps_transform--) {
454 int low_size = (h_low_size0 + 1) >> 1;
455 float *input =
s->block;
456 for (j = 0; j < v_low_size0; j++) {
463 low_size = (v_low_size0 + 1) >> 1;
465 for (j = 0; j < h_low_size0; j++) {
472 h_low_size0 = (h_low_size0 + 1) >> 1;
473 v_low_size0 = (v_low_size0 + 1) >> 1;
479 for (
int n = 0; n <
s->nsteps; n++) {
483 if (n ==
s->nsteps - 1) {
485 s->thresholding(
s->block,
s->hlowsize[p][n],
s->vlowsize[p][n],
width, threshold,
s->percent);
487 block =
s->block +
s->hlowsize[p][n];
489 s->thresholding(
block,
s->hhighsize[p][n],
s->vlowsize[p][n],
width, threshold,
s->percent);
492 s->thresholding(
block,
s->hlowsize[p][n],
s->vhighsize[p][n],
width, threshold,
s->percent);
493 block =
s->block +
s->hlowsize[p][n] +
s->vlowsize[p][n] *
width;
495 s->thresholding(
block,
s->hhighsize[p][n],
s->vhighsize[p][n],
width, threshold,
s->percent);
499 while (nsteps_invert--) {
500 const int idx =
s->vlowsize[p][nsteps_invert] +
s->vhighsize[p][nsteps_invert];
501 const int idx2 =
s->hlowsize[p][nsteps_invert] +
s->hhighsize[p][nsteps_invert];
502 float * idx3 =
s->block;
503 for (
i = 0;
i < idx2;
i++) {
511 for (
i = 0;
i < idx;
i++) {
520 for (y = 0; y <
height; y++) {
521 for (x = 0; x <
width; x++)
524 dstp8 +=
out->linesize[p];
527 for (y = 0; y <
height; y++) {
528 for (x = 0; x <
width; x++)
529 dstp16[x] =
av_clip(input[x] + 0.5f, 0,
s->peak);
531 dstp16 +=
out->linesize[p] / 2;
614 .
name =
"vaguedenoiser",
617 .priv_class = &vaguedenoiser_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
Macro definitions for various function/variable attributes.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define flags(name, subs,...)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
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.
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static const struct @322 planes[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
typedef void(RENAME(mix_any_func_type))
static int shift(int a, int b)
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void(* thresholding)(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
#define av_malloc_array(a, b)
static float mean(const float *input, int size)
static void hard_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
static const AVOption vaguedenoiser_options[]
static void copy(const float *p1, float *p2, const int length)
static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
static const float analysis_low[9]
static float bayes_threshold(float *block, const int width, const int height, const int stride, const float threshold)
static void symmetric_extension(float *output, const int size, const int left_ext, const int right_ext)
static int query_formats(AVFilterContext *ctx)
AVFILTER_DEFINE_CLASS(vaguedenoiser)
static int config_input(AVFilterLink *inlink)
static void filter(VagueDenoiserContext *s, AVFrame *in, AVFrame *out)
static const float synthesis_low[7]
static void qian_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
static void copyh(const float *p1, float *p2, const int stride2, const int length)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void transform_step(float *input, float *output, const int size, const int low_size, VagueDenoiserContext *s)
static void copyv(const float *p1, const int stride1, float *p2, const int length)
AVFilter ff_vf_vaguedenoiser
static const float analysis_high[7]
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad vaguedenoiser_inputs[]
static const AVFilterPad vaguedenoiser_outputs[]
static const float synthesis_high[9]
static void soft_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.