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;
170 for (nsteps_max = 1; nsteps_max < 15; nsteps_max++) {
171 if (pow(2, nsteps_max) >= nsteps_width || pow(2, nsteps_max) >= nsteps_height)
177 for (p = 0; p < 4; p++) {
183 for (i = 1; i < s->
nsteps; i++) {
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;
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];
256 for (i =
NPAD; i <
NPAD + low_size; i++) {
258 const float b = input[2 * i - 13] * analysis_low[1];
259 const float c = input[2 * i - 12] * analysis_low[2];
260 const float d = input[2 * i - 11] * analysis_low[3];
261 const float e = input[2 * i - 10] * analysis_low[4];
262 const float f = input[2 * i - 9] * analysis_low[3];
263 const float g = input[2 * i - 8] * analysis_low[2];
264 const float h = input[2 * i - 7] * analysis_low[1];
265 const float k = input[2 * i - 6] * analysis_low[0];
267 output[
i] = a + b + c + d + e + f + g + h + k;
270 for (i =
NPAD; i <
NPAD + low_size; i++) {
272 const float b = input[2 * i - 11] * analysis_high[1];
273 const float c = input[2 * i - 10] * analysis_high[2];
274 const float d = input[2 * i - 9] * analysis_high[3];
275 const float e = input[2 * i - 8] * analysis_high[2];
276 const float f = input[2 * i - 7] * analysis_high[1];
277 const float g = input[2 * i - 6] * analysis_high[0];
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++) {
300 const float b = temp[
i] * synthesis_low[1];
301 const float c = temp[
i] * synthesis_low[2];
302 const float d = temp[
i] * synthesis_low[3];
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++) {
321 const float b = temp[
i] * synthesis_high[1];
322 const float c = temp[
i] * synthesis_high[2];
323 const float d = temp[
i] * synthesis_high[3];
324 const float e = temp[
i] * synthesis_high[4];
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;
342 const float frac = 1.f - percent * 0.01f;
345 for (y = 0; y <
height; y++) {
346 for (x = 0; x <
width; x++) {
347 if (
FFABS(block[x]) <= threshold)
357 const float frac = 1.f - percent * 0.01f;
361 for (y = 0; y <
height; y++) {
362 for (x = 0; x <
width; x++) {
364 if (temp <= threshold)
367 block[x] = (block[x] < 0.f ? -1.f : (block[x] > 0.f ? 1.f : 0.f)) * (temp -
shift);
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) {
388 const float tp2 = temp *
temp;
389 block[x] *= (tp2 - tr2) / tp2;
401 for (
int y = 0; y <
height; y++) {
402 for (
int x = 0; x <
width; x++) {
403 mean += block[x] * block[x];
410 return threshold * threshold / (
FFMAX(sqrtf(mean - threshold), FLT_EPSILON));
421 const uint16_t *srcp16 = (
const uint16_t *)in->
data[p];
423 uint16_t *dstp16 = (uint16_t *)out->
data[p];
425 int h_low_size0 =
width;
427 int nsteps_transform = s->
nsteps;
428 int nsteps_invert = s->
nsteps;
431 if (!((1 << p) & s->
planes)) {
438 for (y = 0; y <
height; y++) {
439 for (x = 0; x <
width; x++)
440 output[x] = srcp8[x];
445 for (y = 0; y <
height; y++) {
446 for (x = 0; x <
width; x++)
447 output[x] = srcp16[x];
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++) {
499 while (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++)
527 for (y = 0; y <
height; y++) {
528 for (x = 0; x <
width; x++)
614 .
name =
"vaguedenoiser",
617 .priv_class = &vaguedenoiser_class,
621 .
inputs = vaguedenoiser_inputs,
622 .
outputs = vaguedenoiser_outputs,
#define AV_PIX_FMT_YUVA422P16
static av_cold int init(AVFilterContext *ctx)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int shift(int a, int b)
#define AV_PIX_FMT_YUV440P10
static void copy(const float *p1, float *p2, const int length)
#define AV_PIX_FMT_YUVA422P9
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA422P10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
int h
agreed upon image height
#define AV_PIX_FMT_GBRP10
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
#define AV_PIX_FMT_YUV420P12
AVFilter ff_vf_vaguedenoiser
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Macro definitions for various function/variable attributes.
#define AV_PIX_FMT_GRAY10
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
#define AV_PIX_FMT_GRAY12
AVFILTER_DEFINE_CLASS(vaguedenoiser)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static void copyv(const float *p1, const int stride1, float *p2, const int length)
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
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
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_PIX_FMT_YUVA420P9
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUVA420P16
A filter pad used for either input or output.
static const float synthesis_low[7]
A link between two filters.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
static void symmetric_extension(float *output, const int size, const int left_ext, const int right_ext)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
void(* thresholding)(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
#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_PIX_FMT_YUVA444P16
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV444P10
static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
static float mean(const float *input, int size)
#define AV_PIX_FMT_GBRAP16
static void qian_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static const AVOption vaguedenoiser_options[]
int w
agreed upon image width
#define AV_PIX_FMT_YUV422P9
uint8_t nb_components
The number of components each pixel has, (1-4)
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GRAY16
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUVA444P12
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static const AVFilterPad vaguedenoiser_outputs[]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_PIX_FMT_YUVA444P10
static const AVFilterPad vaguedenoiser_inputs[]
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
static const AVFilterPad outputs[]
int format
agreed upon media format
static int query_formats(AVFilterContext *ctx)
#define AV_PIX_FMT_YUV420P16
static void transform_step(float *input, float *output, const int size, const int low_size, VagueDenoiserContext *s)
#define AV_PIX_FMT_YUV420P14
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define AV_PIX_FMT_GRAY14
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
#define AV_PIX_FMT_YUV420P10
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
static void hard_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
static void soft_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
const char * name
Filter name.
#define AV_PIX_FMT_YUV440P12
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 AV_PIX_FMT_YUV420P9
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GBRP12
#define flags(name, subs,...)
#define AV_PIX_FMT_YUV422P10
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
planar GBRA 4:4:4:4 32bpp
static const float synthesis_high[9]
#define AV_PIX_FMT_YUVA444P9
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static int config_input(AVFilterLink *inlink)
static void filter(VagueDenoiserContext *s, AVFrame *in, AVFrame *out)
AVFilterContext * dst
dest filter
static float bayes_threshold(float *block, const int width, const int height, const int stride, const float threshold)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static const float analysis_high[7]
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
#define av_malloc_array(a, b)
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.
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 depth
Number of bits in the component.
static void copyh(const float *p1, float *p2, const int stride2, const int length)
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_YUV422P16
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static const float analysis_low[9]
#define AV_PIX_FMT_YUVA422P12
#define AV_CEIL_RSHIFT(a, b)