Go to the documentation of this file.
66 #define OFFSET(x) offsetof(VagueDenoiserContext, x)
67 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
85 0.037828455506995f, -0.023849465019380f, -0.110624404418423f, 0.377402855612654f,
86 0.852698679009403f, 0.377402855612654f, -0.110624404418423f, -0.023849465019380f, 0.037828455506995f
90 -0.064538882628938f, 0.040689417609558f, 0.418092273222212f, -0.788485616405664f,
91 0.418092273222212f, 0.040689417609558f, -0.064538882628938f
95 -0.064538882628938f, -0.040689417609558f, 0.418092273222212f, 0.788485616405664f,
96 0.418092273222212f, -0.040689417609558f, -0.064538882628938f
100 -0.037828455506995f, -0.023849465019380f, 0.110624404418423f, 0.377402855612654f,
101 -0.852698679009403f, 0.377402855612654f, 0.110624404418423f, -0.023849465019380f, -0.037828455506995f
136 int p,
i, nsteps_width, nsteps_height, nsteps_max;
138 s->depth =
desc->comp[0].depth;
139 s->bpc = (
s->depth + 7) / 8;
140 s->nb_planes =
desc->nb_components;
143 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
145 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
152 if (!
s->block || !
s->in || !
s->out || !
s->tmp)
155 s->threshold *= 1 << (
s->depth - 8);
156 s->peak = (1 <<
s->depth) - 1;
158 nsteps_width = ((
s->planes & 2 ||
s->planes & 4) &&
s->nb_planes > 1) ?
s->planewidth[1] :
s->planewidth[0];
159 nsteps_height = ((
s->planes & 2 ||
s->planes & 4) &&
s->nb_planes > 1) ?
s->planeheight[1] :
s->planeheight[0];
161 for (nsteps_max = 1; nsteps_max < 15; nsteps_max++) {
162 if (pow(2, nsteps_max) >= nsteps_width || pow(2, nsteps_max) >= nsteps_height)
166 s->nsteps =
FFMIN(
s->nsteps, nsteps_max - 2);
168 for (p = 0; p < 4; p++) {
169 s->hlowsize[p][0] = (
s->planewidth[p] + 1) >> 1;
170 s->hhighsize[p][0] =
s->planewidth[p] >> 1;
171 s->vlowsize[p][0] = (
s->planeheight[p] + 1) >> 1;
172 s->vhighsize[p][0] =
s->planeheight[p] >> 1;
174 for (
i = 1;
i <
s->nsteps;
i++) {
175 s->hlowsize[p][
i] = (
s->hlowsize[p][
i - 1] + 1) >> 1;
176 s->hhighsize[p][
i] =
s->hlowsize[p][
i - 1] >> 1;
177 s->vlowsize[p][
i] = (
s->vlowsize[p][
i - 1] + 1) >> 1;
178 s->vhighsize[p][
i] =
s->vlowsize[p][
i - 1] >> 1;
185 static inline void copy(
const float *p1,
float *p2,
const int length)
187 memcpy(p2, p1,
length *
sizeof(
float));
190 static inline void copyv(
const float *p1,
const int stride1,
float *p2,
const int length)
200 static inline void copyh(
const float *p1,
float *p2,
const int stride2,
const int length)
220 const int originalLast = last;
230 for (
i = 0;
i < nextend;
i++)
236 nextend = idx - last;
237 for (
i = 0;
i < nextend;
i++)
276 const int low_size = (
size + 1) >> 1;
277 const int high_size =
size >> 1;
278 int left_ext = 1, right_ext,
i;
283 right_ext = (
size % 2 == 0) ? 2 : 1;
287 findex = (
size + 2) >> 1;
289 for (
i = 9;
i < findex + 11;
i++) {
307 right_ext = (
size % 2 == 0) ? 1 : 2;
310 for (
i = 8;
i < findex + 11;
i++) {
330 const int stride,
const float threshold,
331 const float percent,
const int unused)
333 const float frac = 1.f - percent * 0.01f;
336 for (y = 0; y <
height; y++) {
337 for (x = 0; x <
width; x++) {
346 const float threshold,
const float percent,
const int nsteps)
348 const float frac = 1.f - percent * 0.01f;
349 const float shift = threshold * 0.01f * percent;
354 for (l = 0; l < nsteps; l++) {
359 for (y = 0; y <
height; y++) {
360 const int x0 = (y <
h) ?
w : 0;
361 for (x = x0; x <
width; x++) {
363 if (
temp <= threshold)
373 const int stride,
const float threshold,
374 const float percent,
const int unused)
376 const float percent01 = percent * 0.01f;
377 const float tr2 = threshold * threshold * percent01;
378 const float frac = 1.f - percent01;
381 for (y = 0; y <
height; y++) {
382 for (x = 0; x <
width; x++) {
384 if (
temp <= threshold) {
388 block[x] *= (tp2 - tr2) / tp2;
399 for (p = 0; p <
s->nb_planes; p++) {
400 const int height =
s->planeheight[p];
401 const int width =
s->planewidth[p];
403 const uint16_t *srcp16 = (
const uint16_t *)
in->data[p];
405 uint16_t *dstp16 = (uint16_t *)
out->data[p];
407 int h_low_size0 =
width;
409 int nsteps_transform =
s->nsteps;
410 int nsteps_invert =
s->nsteps;
411 const float *
input =
s->block;
413 if (!((1 << p) &
s->planes)) {
415 s->planewidth[p] *
s->bpc,
s->planeheight[p]);
420 for (y = 0; y <
height; y++) {
421 for (x = 0; x <
width; x++)
423 srcp8 +=
in->linesize[p];
427 for (y = 0; y <
height; y++) {
428 for (x = 0; x <
width; x++)
430 srcp16 +=
in->linesize[p] / 2;
435 while (nsteps_transform--) {
436 int low_size = (h_low_size0 + 1) >> 1;
438 for (j = 0; j < v_low_size0; j++) {
445 low_size = (v_low_size0 + 1) >> 1;
447 for (j = 0; j < h_low_size0; j++) {
454 h_low_size0 = (h_low_size0 + 1) >> 1;
455 v_low_size0 = (v_low_size0 + 1) >> 1;
460 while (nsteps_invert--) {
461 const int idx =
s->vlowsize[p][nsteps_invert] +
s->vhighsize[p][nsteps_invert];
462 const int idx2 =
s->hlowsize[p][nsteps_invert] +
s->hhighsize[p][nsteps_invert];
463 float * idx3 =
s->block;
464 for (
i = 0;
i < idx2;
i++) {
472 for (
i = 0;
i < idx;
i++) {
481 for (y = 0; y <
height; y++) {
482 for (x = 0; x <
width; x++)
483 dstp8[x] = av_clip_uint8(
input[x] + 0.5
f);
485 dstp8 +=
out->linesize[p];
488 for (y = 0; y <
height; y++) {
489 for (x = 0; x <
width; x++)
490 dstp16[x] = av_clip(
input[x] + 0.5
f, 0,
s->peak);
492 dstp16 +=
out->linesize[p] / 2;
575 .
name =
"vaguedenoiser",
578 .priv_class = &vaguedenoiser_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVPixelFormat
Pixel format.
static void transform_step(float *input, float *output, const int size, const int low_size, VagueDenoiserContext *s)
static void filter(VagueDenoiserContext *s, AVFrame *in, AVFrame *out)
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
static int query_formats(AVFilterContext *ctx)
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)
static void copyv(const float *p1, const int stride1, float *p2, const int length)
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
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.
static const AVFilterPad vaguedenoiser_outputs[]
#define AV_PIX_FMT_YUV420P10
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
static void copyh(const float *p1, float *p2, const int stride2, const int length)
A link between two filters.
static void symmetric_extension(float *output, const int size, const int left_ext, const int right_ext)
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.
#define AV_PIX_FMT_GBRP14
static const float analysis_high[7]
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P9
static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
#define AV_PIX_FMT_GRAY16
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
static const float synthesis_low[7]
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
void(* thresholding)(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int nsteps)
static const float synthesis_high[9]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void soft_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int nsteps)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void qian_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int unused)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ 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_YUV440P10
static const AVFilterPad vaguedenoiser_inputs[]
#define AV_PIX_FMT_YUV422P10
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
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static const struct @314 planes[]
static av_cold int init(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void copy(const float *p1, float *p2, const int length)
AVFILTER_DEFINE_CLASS(vaguedenoiser)
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
static av_cold void uninit(AVFilterContext *ctx)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int config_input(AVFilterLink *inlink)
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
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
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
#define i(width, name, range_min, range_max)
int w
agreed upon image width
#define av_malloc_array(a, b)
#define AV_PIX_FMT_GBRP12
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
#define AV_PIX_FMT_YUV444P9
static const AVOption vaguedenoiser_options[]
static const float analysis_low[9]
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
int h
agreed upon image height
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int shift(int a, int b)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static void hard_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int unused)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define flags(name, subs,...)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
The exact code depends on how similar the blocks are and how related they are to the block
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV444P14
AVFilter ff_vf_vaguedenoiser
#define AV_PIX_FMT_YUV420P14