Go to the documentation of this file.
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
138 int p,
i, nsteps_width, nsteps_height, nsteps_max;
140 s->depth =
desc->comp[0].depth;
141 s->bpc = (
s->depth + 7) / 8;
142 s->nb_planes =
desc->nb_components;
145 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
147 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
154 if (!
s->block || !
s->in || !
s->out || !
s->tmp)
157 s->threshold *= 1 << (
s->depth - 8);
158 s->peak = (1 <<
s->depth) - 1;
160 nsteps_width = ((
s->planes & 2 ||
s->planes & 4) &&
s->nb_planes > 1) ?
s->planewidth[1] :
s->planewidth[0];
161 nsteps_height = ((
s->planes & 2 ||
s->planes & 4) &&
s->nb_planes > 1) ?
s->planeheight[1] :
s->planeheight[0];
163 for (nsteps_max = 1; nsteps_max < 15; nsteps_max++) {
164 if (pow(2, nsteps_max) >= nsteps_width || pow(2, nsteps_max) >= nsteps_height)
168 s->nsteps =
FFMIN(
s->nsteps, nsteps_max - 2);
170 for (p = 0; p < 4; p++) {
171 s->hlowsize[p][0] = (
s->planewidth[p] + 1) >> 1;
172 s->hhighsize[p][0] =
s->planewidth[p] >> 1;
173 s->vlowsize[p][0] = (
s->planeheight[p] + 1) >> 1;
174 s->vhighsize[p][0] =
s->planeheight[p] >> 1;
176 for (
i = 1;
i <
s->nsteps;
i++) {
177 s->hlowsize[p][
i] = (
s->hlowsize[p][
i - 1] + 1) >> 1;
178 s->hhighsize[p][
i] =
s->hlowsize[p][
i - 1] >> 1;
179 s->vlowsize[p][
i] = (
s->vlowsize[p][
i - 1] + 1) >> 1;
180 s->vhighsize[p][
i] =
s->vlowsize[p][
i - 1] >> 1;
187 static inline void copy(
const float *p1,
float *p2,
const int length)
189 memcpy(p2, p1, length *
sizeof(
float));
192 static inline void copyv(
const float *p1,
const int stride1,
float *p2,
const int length)
196 for (
i = 0;
i < length;
i++) {
202 static inline void copyh(
const float *p1,
float *p2,
const int stride2,
const int length)
206 for (
i = 0;
i < length;
i++) {
222 const int originalLast = last;
232 for (
i = 0;
i < nextend;
i++)
238 nextend = idx - last;
239 for (
i = 0;
i < nextend;
i++)
278 const int low_size = (
size + 1) >> 1;
279 const int high_size =
size >> 1;
285 right_ext = (
size % 2 == 0) ? 2 : 1;
289 findex = (
size + 2) >> 1;
291 for (
i = 9;
i < findex + 11;
i++) {
309 right_ext = (
size % 2 == 0) ? 1 : 2;
312 for (
i = 8;
i < findex + 11;
i++) {
332 const int stride,
const float threshold,
335 const float frac = 1.f - percent * 0.01f;
338 for (y = 0; y <
height; y++) {
339 for (x = 0; x <
width; x++) {
348 const float threshold,
const float percent)
350 const float frac = 1.f - percent * 0.01f;
351 const float shift = threshold * 0.01f * percent;
354 for (y = 0; y <
height; y++) {
355 for (x = 0; x <
width; x++) {
357 if (
temp <= threshold)
367 const int stride,
const float threshold,
370 const float percent01 = percent * 0.01f;
371 const float tr2 = threshold * threshold * percent01;
372 const float frac = 1.f - percent01;
375 for (y = 0; y <
height; y++) {
376 for (x = 0; x <
width; x++) {
378 if (
temp <= threshold) {
382 block[x] *= (tp2 - tr2) / tp2;
390 const int stride,
const float threshold)
394 for (
int y = 0; y <
height; y++) {
395 for (
int x = 0; x <
width; x++) {
403 return threshold * threshold / (
FFMAX(
sqrtf(
mean - threshold), FLT_EPSILON));
410 for (p = 0; p <
s->nb_planes; p++) {
411 const int height =
s->planeheight[p];
412 const int width =
s->planewidth[p];
413 const uint8_t *srcp8 = in->
data[p];
414 const uint16_t *srcp16 = (
const uint16_t *)in->
data[p];
415 uint8_t *dstp8 =
out->data[p];
416 uint16_t *dstp16 = (uint16_t *)
out->data[p];
418 int h_low_size0 =
width;
420 int nsteps_transform =
s->nsteps;
421 int nsteps_invert =
s->nsteps;
422 const float *
input =
s->block;
424 if (!((1 << p) &
s->planes)) {
426 s->planewidth[p] *
s->bpc,
s->planeheight[p]);
431 for (y = 0; y <
height; y++) {
432 for (x = 0; x <
width; x++)
438 for (y = 0; y <
height; y++) {
439 for (x = 0; x <
width; x++)
446 while (nsteps_transform--) {
447 int low_size = (h_low_size0 + 1) >> 1;
449 for (j = 0; j < v_low_size0; j++) {
456 low_size = (v_low_size0 + 1) >> 1;
458 for (j = 0; j < h_low_size0; j++) {
465 h_low_size0 = (h_low_size0 + 1) >> 1;
466 v_low_size0 = (v_low_size0 + 1) >> 1;
472 for (
int n = 0; n <
s->nsteps; n++) {
476 if (n ==
s->nsteps - 1) {
478 s->thresholding(
s->block,
s->hlowsize[p][n],
s->vlowsize[p][n],
width, threshold,
s->percent);
480 block =
s->block +
s->hlowsize[p][n];
482 s->thresholding(
block,
s->hhighsize[p][n],
s->vlowsize[p][n],
width, threshold,
s->percent);
485 s->thresholding(
block,
s->hlowsize[p][n],
s->vhighsize[p][n],
width, threshold,
s->percent);
486 block =
s->block +
s->hlowsize[p][n] +
s->vlowsize[p][n] *
width;
488 s->thresholding(
block,
s->hhighsize[p][n],
s->vhighsize[p][n],
width, threshold,
s->percent);
492 while (nsteps_invert--) {
493 const int idx =
s->vlowsize[p][nsteps_invert] +
s->vhighsize[p][nsteps_invert];
494 const int idx2 =
s->hlowsize[p][nsteps_invert] +
s->hhighsize[p][nsteps_invert];
495 float * idx3 =
s->block;
496 for (
i = 0;
i < idx2;
i++) {
504 for (
i = 0;
i < idx;
i++) {
513 for (y = 0; y <
height; y++) {
514 for (x = 0; x <
width; x++)
517 dstp8 +=
out->linesize[p];
520 for (y = 0; y <
height; y++) {
521 for (x = 0; x <
width; x++)
524 dstp16 +=
out->linesize[p] / 2;
605 .
name =
"vaguedenoiser",
608 .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.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRAP16
AVPixelFormat
Pixel format.
static const struct @346 planes[]
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
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)
#define FILTER_PIXFMTS_ARRAY(array)
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.
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P16
static const AVFilterPad vaguedenoiser_outputs[]
#define AV_PIX_FMT_YUVA420P10
#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.
#define AV_PIX_FMT_YUVA422P10
static void symmetric_extension(float *output, const int size, const int left_ext, const int right_ext)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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_YUVA420P9
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
static const float analysis_high[7]
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define AV_PIX_FMT_GRAY16
static void qian_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
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
void(* thresholding)(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_GBRAP10
static const float synthesis_low[7]
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GRAY14
static const float synthesis_high[9]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static float bayes_threshold(float *block, const int width, const int height, const int stride, const float threshold)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
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...
static void hard_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
#define AV_PIX_FMT_YUV440P10
static __device__ float sqrtf(float a)
static const AVFilterPad vaguedenoiser_inputs[]
#define AV_PIX_FMT_YUV422P10
@ 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 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)
static int shift(int a, int b)
AVFILTER_DEFINE_CLASS(vaguedenoiser)
const AVFilter ff_vf_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)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
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...
#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_YUVA444P9
static int left_ext(int wavelet_length, int levels, uint64_t sn)
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
static void soft_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
int h
agreed upon image height
#define AV_PIX_FMT_YUVA422P12
static float mean(const float *input, int size)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ 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...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ 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
#define AV_PIX_FMT_GRAY12
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14
static enum AVPixelFormat pix_fmts[]