FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
vf_nlmeans.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "vf_nlmeans.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  weighted_avg
 
struct  NLMeansContext
 
struct  thread_data
 

Macros

#define WEIGHT_LUT_NBITS   9
 
#define WEIGHT_LUT_SIZE   (1<<WEIGHT_LUT_NBITS)
 
#define OFFSET(x)   offsetof(NLMeansContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define CHECK_ODD_FIELD(field, name)
 

Functions

 AVFILTER_DEFINE_CLASS (nlmeans)
 
static int query_formats (AVFilterContext *ctx)
 
static void compute_safe_ssd_integral_image_c (uint32_t *dst, ptrdiff_t dst_linesize_32, const uint8_t *s1, ptrdiff_t linesize1, const uint8_t *s2, ptrdiff_t linesize2, int w, int h)
 Compute squared difference of the safe area (the zone where s1 and s2 overlap). More...
 
static void compute_unsafe_ssd_integral_image (uint32_t *dst, ptrdiff_t dst_linesize_32, int startx, int starty, const uint8_t *src, ptrdiff_t linesize, int offx, int offy, int r, int sw, int sh, int w, int h)
 Compute squared difference of an unsafe area (the zone nor s1 nor s2 could be readable). More...
 
static void compute_ssd_integral_image (const NLMeansDSPContext *dsp, uint32_t *ii, ptrdiff_t ii_linesize_32, const uint8_t *src, ptrdiff_t linesize, int offx, int offy, int e, int w, int h)
 
static int config_input (AVFilterLink *inlink)
 
static int nlmeans_slice (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static void weight_averages (uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, struct weighted_avg *wa, ptrdiff_t wa_linesize, int w, int h)
 
static int nlmeans_plane (AVFilterContext *ctx, int w, int h, int p, int r, uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
void ff_nlmeans_init (NLMeansDSPContext *dsp)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption nlmeans_options []
 
static const AVFilterPad nlmeans_inputs []
 
static const AVFilterPad nlmeans_outputs []
 
AVFilter ff_vf_nlmeans
 

Macro Definition Documentation

#define WEIGHT_LUT_NBITS   9

Definition at line 46 of file vf_nlmeans.c.

#define WEIGHT_LUT_SIZE   (1<<WEIGHT_LUT_NBITS)

Definition at line 47 of file vf_nlmeans.c.

Referenced by init().

#define OFFSET (   x)    offsetof(NLMeansContext, x)

Definition at line 71 of file vf_nlmeans.c.

Definition at line 72 of file vf_nlmeans.c.

#define CHECK_ODD_FIELD (   field,
  name 
)
Value:
do { \
if (!(s->field & 1)) { \
s->field |= 1; \
av_log(ctx, AV_LOG_WARNING, name " size must be odd, " \
"setting it to %d\n", s->field); \
} \
} while (0)
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define av_log(a,...)
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
if(ret< 0)
Definition: vf_mcdeint.c:279
const char * name
Definition: opengl_enc.c:103

Definition at line 506 of file vf_nlmeans.c.

Referenced by init().

Function Documentation

AVFILTER_DEFINE_CLASS ( nlmeans  )
static int query_formats ( AVFilterContext ctx)
static

Definition at line 84 of file vf_nlmeans.c.

static void compute_safe_ssd_integral_image_c ( uint32_t *  dst,
ptrdiff_t  dst_linesize_32,
const uint8_t s1,
ptrdiff_t  linesize1,
const uint8_t s2,
ptrdiff_t  linesize2,
int  w,
int  h 
)
static

Compute squared difference of the safe area (the zone where s1 and s2 overlap).

It is likely the largest integral zone, so it is interesting to do as little checks as possible; contrary to the unsafe version of this function, we do not need any clipping here.

The line above dst and the column to its left are always readable.

Definition at line 111 of file vf_nlmeans.c.

Referenced by ff_nlmeans_init().

static void compute_unsafe_ssd_integral_image ( uint32_t *  dst,
ptrdiff_t  dst_linesize_32,
int  startx,
int  starty,
const uint8_t src,
ptrdiff_t  linesize,
int  offx,
int  offy,
int  r,
int  sw,
int  sh,
int  w,
int  h 
)
inlinestatic

Compute squared difference of an unsafe area (the zone nor s1 nor s2 could be readable).

On the other hand, the line above dst and the column to its left are always readable.

There is little point in having this function SIMDified as it is likely too complex and only handle small portions of the image.

Parameters
dstintegral image
dst_linesize_32integral image linesize (in 32-bit integers unit)
startxintegral starting x position
startyintegral starting y position
srcsource plane buffer
linesizesource plane linesize
offxsource offsetting in x
offysource offsetting in y r absolute maximum source offsetting
swsource width
shsource height
wwidth to compute
hheight to compute

Definition at line 170 of file vf_nlmeans.c.

Referenced by compute_ssd_integral_image(), and main().

static void compute_ssd_integral_image ( const NLMeansDSPContext dsp,
uint32_t *  ii,
ptrdiff_t  ii_linesize_32,
const uint8_t src,
ptrdiff_t  linesize,
int  offx,
int  offy,
int  e,
int  w,
int  h 
)
static

Definition at line 212 of file vf_nlmeans.c.

Referenced by main(), and nlmeans_plane().

static int config_input ( AVFilterLink inlink)
static

Definition at line 284 of file vf_nlmeans.c.

static int nlmeans_slice ( AVFilterContext ctx,
void arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 347 of file vf_nlmeans.c.

Referenced by nlmeans_plane().

static void weight_averages ( uint8_t dst,
ptrdiff_t  dst_linesize,
const uint8_t src,
ptrdiff_t  src_linesize,
struct weighted_avg wa,
ptrdiff_t  wa_linesize,
int  w,
int  h 
)
static

Definition at line 415 of file vf_nlmeans.c.

Referenced by nlmeans_plane().

static int nlmeans_plane ( AVFilterContext ctx,
int  w,
int  h,
int  p,
int  r,
uint8_t dst,
ptrdiff_t  dst_linesize,
const uint8_t src,
ptrdiff_t  src_linesize 
)
static

Definition at line 435 of file vf_nlmeans.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 478 of file vf_nlmeans.c.

void ff_nlmeans_init ( NLMeansDSPContext dsp)

Definition at line 514 of file vf_nlmeans.c.

Referenced by checkasm_check_nlmeans(), init(), and main().

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 522 of file vf_nlmeans.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 558 of file vf_nlmeans.c.

Variable Documentation

const AVOption nlmeans_options[]
static
Initial value:
= {
{ "s", "denoising strength", OFFSET(sigma), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 1.0, 30.0, FLAGS },
{ "p", "patch size", OFFSET(patch_size), AV_OPT_TYPE_INT, { .i64 = 3*2+1 }, 0, 99, FLAGS },
{ "pc", "patch size for chroma planes", OFFSET(patch_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
{ "r", "research window", OFFSET(research_size), AV_OPT_TYPE_INT, { .i64 = 7*2+1 }, 0, 99, FLAGS },
{ "rc", "research window for chroma planes", OFFSET(research_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: vf_nlmeans.c:71
#define FLAGS
Definition: vf_nlmeans.c:72

Definition at line 73 of file vf_nlmeans.c.

const AVFilterPad nlmeans_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int config_input(AVFilterLink *inlink)
Definition: vf_nlmeans.c:284
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_nlmeans.c:478

Definition at line 565 of file vf_nlmeans.c.

const AVFilterPad nlmeans_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 575 of file vf_nlmeans.c.

AVFilter ff_vf_nlmeans
Initial value:
= {
.name = "nlmeans",
.description = NULL_IF_CONFIG_SMALL("Non-local means denoiser."),
.priv_size = sizeof(NLMeansContext),
.init = init,
.priv_class = &nlmeans_class,
}
static const AVFilterPad nlmeans_outputs[]
Definition: vf_nlmeans.c:575
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
static int query_formats(AVFilterContext *ctx)
Definition: vf_nlmeans.c:84
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
static const AVFilterPad nlmeans_inputs[]
Definition: vf_nlmeans.c:565
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static av_cold int init(AVFilterContext *ctx)
Definition: vf_nlmeans.c:522
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_nlmeans.c:558
#define flags(name, subs,...)
Definition: cbs_av1.c:596

Definition at line 583 of file vf_nlmeans.c.