FFmpeg
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 "internal.h"
#include "vf_nlmeans.h"
#include "vf_nlmeans_init.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  NLMeansContext
 
struct  thread_data
 

Macros

#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 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, float *total_weight, float *sum, ptrdiff_t 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)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption nlmeans_options []
 
static enum AVPixelFormat pix_fmts []
 
static const AVFilterPad nlmeans_inputs []
 
const AVFilter ff_vf_nlmeans
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 63 of file vf_nlmeans.c.

◆ FLAGS

Definition at line 64 of file vf_nlmeans.c.

◆ CHECK_ODD_FIELD

#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)

Definition at line 412 of file vf_nlmeans.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( nlmeans  )

◆ compute_unsafe_ssd_integral_image()

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 @paran r absolute maximum source offsetting
swsource width
shsource height
wwidth to compute
hheight to compute

Definition at line 111 of file vf_nlmeans.c.

Referenced by compute_ssd_integral_image(), and main().

◆ compute_ssd_integral_image()

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 151 of file vf_nlmeans.c.

Referenced by main(), and nlmeans_plane().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 223 of file vf_nlmeans.c.

◆ nlmeans_slice()

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

Definition at line 287 of file vf_nlmeans.c.

Referenced by nlmeans_plane().

◆ weight_averages()

static void weight_averages ( uint8_t *  dst,
ptrdiff_t  dst_linesize,
const uint8_t *  src,
ptrdiff_t  src_linesize,
float total_weight,
float sum,
ptrdiff_t  linesize,
int  w,
int  h 
)
static

Definition at line 323 of file vf_nlmeans.c.

Referenced by nlmeans_plane().

◆ 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 342 of file vf_nlmeans.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 385 of file vf_nlmeans.c.

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 420 of file vf_nlmeans.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 456 of file vf_nlmeans.c.

Variable Documentation

◆ nlmeans_options

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 }
}

Definition at line 65 of file vf_nlmeans.c.

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ nlmeans_inputs

const AVFilterPad nlmeans_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
}

Definition at line 465 of file vf_nlmeans.c.

◆ ff_vf_nlmeans

const 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,
}

Definition at line 474 of file vf_nlmeans.c.

AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
name
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 default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_nlmeans.c:76
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:172
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
nlmeans_inputs
static const AVFilterPad nlmeans_inputs[]
Definition: vf_nlmeans.c:465
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:276
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:36
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
NLMeansContext
Definition: vf_nlmeans.c:41
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
FLAGS
#define FLAGS
Definition: vf_nlmeans.c:64
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_nlmeans.c:456
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_nlmeans.c:223
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:147
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_nlmeans.c:420
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_nlmeans.c:385
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
OFFSET
#define OFFSET(x)
Definition: vf_nlmeans.c:63