Go to the documentation of this file.
64 #define OFFSET(x) offsetof(NLMeansContext, x)
65 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
113 int startx,
int starty,
114 const uint8_t *
src, ptrdiff_t linesize,
115 int offx,
int offy,
int r,
int sw,
int sh,
118 for (
int y = starty; y < starty +
h; y++) {
119 uint32_t acc =
dst[y*dst_linesize_32 + startx - 1] -
dst[(y-1)*dst_linesize_32 + startx - 1];
120 const int s1y =
av_clip(y -
r, 0, sh - 1);
121 const int s2y =
av_clip(y - (
r + offy), 0, sh - 1);
123 for (
int x = startx; x < startx +
w; x++) {
124 const int s1x =
av_clip(x -
r, 0, sw - 1);
125 const int s2x =
av_clip(x - (
r + offx), 0, sw - 1);
126 const uint8_t v1 =
src[s1y*linesize + s1x];
127 const uint8_t v2 =
src[s2y*linesize + s2x];
128 const int d = v1 - v2;
130 dst[y*dst_linesize_32 + x] =
dst[(y-1)*dst_linesize_32 + x] + acc;
153 uint32_t *ii, ptrdiff_t ii_linesize_32,
154 const uint8_t *
src, ptrdiff_t linesize,
int offx,
int offy,
158 const int ii_w =
w + e*2;
159 const int ii_h =
h + e*2;
166 const int s2x = e + offx;
167 const int s2y = e + offy;
171 const int startx_safe =
FFMAX(s1x, s2x);
172 const int starty_safe =
FFMAX(s1y, s2y);
173 const int u_endx_safe =
FFMIN(s1x +
w, s2x +
w);
174 const int endy_safe =
FFMIN(s1y +
h, s2y +
h);
177 const int safe_pw = (u_endx_safe - startx_safe) & ~0
xf;
178 const int safe_ph = endy_safe - starty_safe;
181 const int endx_safe = startx_safe + safe_pw;
196 startx_safe, safe_ph);
203 if (safe_pw && safe_ph)
205 src + (starty_safe - s1y) * linesize + (startx_safe - s1x), linesize,
206 src + (starty_safe - s2y) * linesize + (startx_safe - s2x), linesize,
211 endx_safe, starty_safe,
214 ii_w - endx_safe, safe_ph);
221 ii_w, ii_h - endy_safe);
229 const int e =
FFMAX(
s->research_hsize,
s->research_hsize_uv)
230 +
FFMAX(
s->patch_hsize,
s->patch_hsize_uv);
262 s->ii_orig =
av_calloc(
s->ii_h + 1,
s->ii_lz_32 *
sizeof(*
s->ii_orig));
267 s->ii =
s->ii_orig +
s->ii_lz_32 + 1;
273 if (!
s->total_weight || !
s->sum)
291 const uint32_t max_meaningful_diff =
s->max_meaningful_diff;
295 const int slice_start = (process_h * jobnr ) / nb_jobs;
296 const int slice_end = (process_h * (jobnr+1)) / nb_jobs;
301 const int dist_b = 2*
p + 1;
302 const int dist_d = dist_b *
s->ii_lz_32;
303 const int dist_e = dist_d + dist_b;
304 const float *
const weight_lut =
s->weight_lut;
309 float *total_weight =
s->total_weight + y*
s->linesize;
310 float *sum =
s->sum + y*
s->linesize;
311 const uint32_t *
const iia = ii;
312 const uint32_t *
const iib = ii + dist_b;
313 const uint32_t *
const iid = ii + dist_d;
314 const uint32_t *
const iie = ii + dist_e;
316 dsp->compute_weights_line(iia, iib, iid, iie,
src, total_weight, sum,
317 weight_lut, max_meaningful_diff,
326 float *total_weight,
float *sum, ptrdiff_t linesize,
329 for (
int y = 0; y <
h; y++) {
330 for (
int x = 0; x <
w; x++) {
332 total_weight[x] += 1.f;
333 sum[x] += 1.f *
src[x];
338 total_weight += linesize;
344 uint8_t *
dst, ptrdiff_t dst_linesize,
352 const uint32_t *centered_ii =
s->ii + e*
s->ii_lz_32 + e;
354 memset(
s->total_weight, 0,
s->linesize *
h *
sizeof(*
s->total_weight));
355 memset(
s->sum, 0,
s->linesize *
h *
sizeof(*
s->sum));
357 for (
int offy = -
r; offy <=
r; offy++) {
358 for (
int offx = -
r; offx <=
r; offx++) {
363 .startx =
FFMAX(0, -offx),
364 .starty =
FFMAX(0, -offy),
367 .ii_start = centered_ii + offy*
s->ii_lz_32 + offx,
373 offx, offy, e,
w,
h);
381 s->total_weight,
s->sum,
s->linesize,
w,
h);
399 for (
int i = 0;
i <
s->nb_planes;
i++) {
400 const int w =
i ?
s->chroma_w :
inlink->w;
401 const int h =
i ?
s->chroma_h :
inlink->h;
402 const int p =
i ?
s->patch_hsize_uv :
s->patch_hsize;
403 const int r =
i ?
s->research_hsize_uv :
s->research_hsize;
413 #define CHECK_ODD_FIELD(field, name) do { \
414 if (!(s->field & 1)) { \
416 av_log(ctx, AV_LOG_WARNING, name " size must be odd, " \
417 "setting it to %d\n", s->field); \
424 const double h =
s->sigma * 10.;
426 s->pdiff_scale = 1. / (
h *
h);
427 s->max_meaningful_diff =
log(255.) /
s->pdiff_scale;
428 s->weight_lut =
av_calloc(
s->max_meaningful_diff + 1,
sizeof(*
s->weight_lut));
431 for (
int i = 0;
i <
s->max_meaningful_diff;
i++)
432 s->weight_lut[
i] =
exp(-
i *
s->pdiff_scale);
437 if (!
s->research_size_uv)
s->research_size_uv =
s->research_size;
438 if (!
s->patch_size_uv)
s->patch_size_uv =
s->patch_size;
443 s->research_hsize =
s->research_size / 2;
444 s->research_hsize_uv =
s->research_size_uv / 2;
445 s->patch_hsize =
s->patch_size / 2;
446 s->patch_hsize_uv =
s->patch_size_uv / 2;
449 s->research_size,
s->research_size,
s->research_size_uv,
s->research_size_uv,
450 s->patch_size,
s->patch_size,
s->patch_size_uv,
s->patch_size_uv);
484 .priv_class = &nlmeans_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVPixelFormat
Pixel format.
static enum AVPixelFormat pix_fmts[]
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
#define FILTER_PIXFMTS_ARRAY(array)
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)
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 FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
uint32_t max_meaningful_diff
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
#define CHECK_ODD_FIELD(field, name)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
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 const AVFilterPad nlmeans_inputs[]
void(* compute_safe_ssd_integral_image)(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)
A filter pad used for either input or output.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
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).
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
@ 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_CEIL_RSHIFT(a, b)
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(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...
Describe the class of an AVClass context structure.
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...
const AVFilter ff_vf_nlmeans
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)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static av_cold void uninit(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
#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)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define xf(width, name, var, range_min, range_max, subs,...)
@ 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.
void * av_calloc(size_t nmemb, size_t size)
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
static av_unused void ff_nlmeans_init(NLMeansDSPContext *dsp)
static av_cold int init(AVFilterContext *ctx)
int h
agreed upon image height
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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
AVFILTER_DEFINE_CLASS(nlmeans)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static const AVOption nlmeans_options[]
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)
const uint32_t * ii_start