65 #define OFFSET(x) offsetof(VagueDenoiserContext, x)
66 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
84 0.037828455506995f, -0.023849465019380f, -0.110624404418423f, 0.377402855612654f,
85 0.852698679009403f, 0.377402855612654f, -0.110624404418423f, -0.023849465019380f, 0.037828455506995f
89 -0.064538882628938f, 0.040689417609558f, 0.418092273222212f, -0.788485616405664f,
90 0.418092273222212f, 0.040689417609558f, -0.064538882628938f
94 -0.064538882628938f, -0.040689417609558f, 0.418092273222212f, 0.788485616405664f,
95 0.418092273222212f, -0.040689417609558f, -0.064538882628938f
99 -0.037828455506995f, -0.023849465019380f, 0.110624404418423f, 0.377402855612654f,
100 -0.852698679009403f, 0.377402855612654f, 0.110624404418423f, -0.023849465019380f, -0.037828455506995f
135 int p, i, nsteps_width, nsteps_height, nsteps_max;
159 for (nsteps_max = 1; nsteps_max < 15; nsteps_max++) {
160 if (pow(2, nsteps_max) >= nsteps_width || pow(2, nsteps_max) >= nsteps_height)
166 for (p = 0; p < 4; p++) {
172 for (i = 1; i < s->
nsteps; i++) {
183 static inline void copy(
const float *p1,
float *p2,
const int length)
185 memcpy(p2, p1, length *
sizeof(
float));
188 static inline void copyv(
const float *p1,
const int stride1,
float *p2,
const int length)
192 for (i = 0; i <
length; i++) {
198 static inline void copyh(
const float *p1,
float *p2,
const int stride2,
const int length)
202 for (i = 0; i <
length; i++) {
218 const int originalLast = last;
222 output[--first] = output[
NPAD];
224 output[++last] = output[originalLast];
228 for (i = 0; i < nextend; i++)
229 output[--first] = output[
NPAD + 1 + i];
234 nextend = idx - last;
235 for (i = 0; i < nextend; i++)
236 output[++last] = output[originalLast - 1 - i];
245 for (i =
NPAD; i <
NPAD + low_size; i++) {
247 const float b = input[2 * i - 13] * analysis_low[1];
248 const float c = input[2 * i - 12] * analysis_low[2];
249 const float d = input[2 * i - 11] * analysis_low[3];
250 const float e = input[2 * i - 10] * analysis_low[4];
251 const float f = input[2 * i - 9] * analysis_low[3];
252 const float g = input[2 * i - 8] * analysis_low[2];
253 const float h = input[2 * i - 7] * analysis_low[1];
254 const float k = input[2 * i - 6] * analysis_low[0];
256 output[i] = a + b + c + d + e + f + g + h + k;
259 for (i =
NPAD; i <
NPAD + low_size; i++) {
261 const float b = input[2 * i - 11] * analysis_high[1];
262 const float c = input[2 * i - 10] * analysis_high[2];
263 const float d = input[2 * i - 9] * analysis_high[3];
264 const float e = input[2 * i - 8] * analysis_high[2];
265 const float f = input[2 * i - 7] * analysis_high[1];
266 const float g = input[2 * i - 6] * analysis_high[0];
268 output[i + low_size] = a + b + c + d + e + f +
g;
274 const int low_size = (size + 1) >> 1;
275 const int high_size = size >> 1;
276 int left_ext = 1, right_ext, i;
279 memcpy(temp +
NPAD, input +
NPAD, low_size *
sizeof(
float));
281 right_ext = (size % 2 == 0) ? 2 : 1;
284 memset(output, 0, (
NPAD +
NPAD + size) *
sizeof(
float));
285 findex = (size + 2) >> 1;
287 for (i = 9; i < findex + 11; i++) {
289 const float b = temp[i] * synthesis_low[1];
290 const float c = temp[i] * synthesis_low[2];
291 const float d = temp[i] * synthesis_low[3];
293 output[2 * i - 13] +=
a;
294 output[2 * i - 12] +=
b;
295 output[2 * i - 11] +=
c;
296 output[2 * i - 10] += d;
297 output[2 * i - 9] +=
c;
298 output[2 * i - 8] +=
b;
299 output[2 * i - 7] +=
a;
302 memcpy(temp +
NPAD, input +
NPAD + low_size, high_size *
sizeof(
float));
305 right_ext = (size % 2 == 0) ? 1 : 2;
308 for (i = 8; i < findex + 11; i++) {
310 const float b = temp[i] * synthesis_high[1];
311 const float c = temp[i] * synthesis_high[2];
312 const float d = temp[i] * synthesis_high[3];
313 const float e = temp[i] * synthesis_high[4];
315 output[2 * i - 13] +=
a;
316 output[2 * i - 12] +=
b;
317 output[2 * i - 11] +=
c;
318 output[2 * i - 10] += d;
319 output[2 * i - 9] += e;
320 output[2 * i - 8] += d;
321 output[2 * i - 7] +=
c;
322 output[2 * i - 6] +=
b;
323 output[2 * i - 5] +=
a;
328 const int stride,
const float threshold,
329 const float percent,
const int unused)
331 const float frac = 1.f - percent * 0.01f;
334 for (y = 0; y <
height; y++) {
335 for (x = 0; x <
width; x++) {
336 if (
FFABS(block[x]) <= threshold)
344 const float threshold,
const float percent,
const int nsteps)
346 const float frac = 1.f - percent * 0.01f;
347 const float shift = threshold * 0.01f * percent;
352 for (l = 0; l < nsteps; l++) {
357 for (y = 0; y <
height; y++) {
358 const int x0 = (y <
h) ? w : 0;
359 for (x = x0; x <
width; x++) {
361 if (temp <= threshold)
364 block[x] = (block[x] < 0.f ? -1.f : (block[x] > 0.f ? 1.f : 0.f)) * (temp -
shift);
371 const int stride,
const float threshold,
372 const float percent,
const int unused)
374 const float percent01 = percent * 0.01f;
375 const float tr2 = threshold * threshold * percent01;
376 const float frac = 1.f - percent01;
379 for (y = 0; y <
height; y++) {
380 for (x = 0; x <
width; x++) {
382 if (temp <= threshold) {
385 const float tp2 = temp *
temp;
386 block[x] *= (tp2 - tr2) / tp2;
401 const uint16_t *srcp16 = (
const uint16_t *)in->
data[p];
403 uint16_t *dstp16 = (uint16_t *)out->
data[p];
404 float *output = s->
block;
405 int h_low_size0 =
width;
407 int nsteps_transform = s->
nsteps;
408 int nsteps_invert = s->
nsteps;
409 const float *input = s->
block;
411 if (!((1 << p) & s->
planes)) {
418 for (y = 0; y <
height; y++) {
419 for (x = 0; x <
width; x++)
420 output[x] = srcp8[x];
425 for (y = 0; y <
height; y++) {
426 for (x = 0; x <
width; x++)
427 output[x] = srcp16[x];
433 while (nsteps_transform--) {
434 int low_size = (h_low_size0 + 1) >> 1;
435 float *input = s->
block;
436 for (j = 0; j < v_low_size0; j++) {
443 low_size = (v_low_size0 + 1) >> 1;
445 for (j = 0; j < h_low_size0; j++) {
452 h_low_size0 = (h_low_size0 + 1) >> 1;
453 v_low_size0 = (v_low_size0 + 1) >> 1;
458 while (nsteps_invert--) {
461 float * idx3 = s->
block;
462 for (i = 0; i < idx2; i++) {
470 for (i = 0; i < idx; i++) {
479 for (y = 0; y <
height; y++) {
480 for (x = 0; x <
width; x++)
481 dstp8[x] = av_clip_uint8(input[x] + 0.5f);
486 for (y = 0; y <
height; y++) {
487 for (x = 0; x <
width; x++)
488 dstp16[x] = av_clip(input[x] + 0.5f, 0, s->
peak);
573 .
name =
"vaguedenoiser",
576 .priv_class = &vaguedenoiser_class,
580 .
inputs = vaguedenoiser_inputs,
581 .
outputs = vaguedenoiser_outputs,
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 qian_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int unused)
static void copy(const float *p1, float *p2, const int length)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUV444P14
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
static void hard_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int unused)
#define AV_PIX_FMT_GBRP10
#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 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.
AVFILTER_DEFINE_CLASS(vaguedenoiser)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static void copyv(const float *p1, const int stride1, float *p2, const int length)
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
A filter pad used for either input or output.
static const float synthesis_low[7]
A link between two filters.
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.
#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_YUV444P10
static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
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...
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 ...
static const AVFilterPad outputs[]
static const AVFilterPad vaguedenoiser_inputs[]
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
int format
agreed upon media format
static int query_formats(AVFilterContext *ctx)
#define AV_PIX_FMT_YUV420P16
static const AVFilterPad inputs[]
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.
void(* thresholding)(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int nsteps)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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){if(!*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));if(!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=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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%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
#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.
const char * name
Filter name.
#define AV_PIX_FMT_YUV440P12
#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 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.
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
static const float synthesis_high[9]
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
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)
static void soft_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent, const int nsteps)
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.
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_CEIL_RSHIFT(a, b)