Go to the documentation of this file.
63 #define OFFSET(x) offsetof(NLMeansContext, x)
64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
112 int startx,
int starty,
113 const uint8_t *
src, ptrdiff_t linesize,
114 int offx,
int offy,
int r,
int sw,
int sh,
117 for (
int y = starty; y < starty +
h; y++) {
118 uint32_t
acc = dst[y*dst_linesize_32 + startx - 1] - dst[(y-1)*dst_linesize_32 + startx - 1];
119 const int s1y =
av_clip(y -
r, 0, sh - 1);
120 const int s2y =
av_clip(y - (
r + offy), 0, sh - 1);
122 for (
int x = startx; x < startx +
w; x++) {
123 const int s1x =
av_clip(x -
r, 0, sw - 1);
124 const int s2x =
av_clip(x - (
r + offx), 0, sw - 1);
125 const uint8_t v1 =
src[s1y*linesize + s1x];
126 const uint8_t v2 =
src[s2y*linesize + s2x];
127 const int d = v1 - v2;
129 dst[y*dst_linesize_32 + x] = dst[(y-1)*dst_linesize_32 + x] +
acc;
152 uint32_t *ii, ptrdiff_t ii_linesize_32,
153 const uint8_t *
src, ptrdiff_t linesize,
int offx,
int offy,
157 const int ii_w =
w + e*2;
158 const int ii_h =
h + e*2;
165 const int s2x = e + offx;
166 const int s2y = e + offy;
170 const int startx_safe =
FFMAX(s1x, s2x);
171 const int starty_safe =
FFMAX(s1y, s2y);
172 const int u_endx_safe =
FFMIN(s1x +
w, s2x +
w);
173 const int endy_safe =
FFMIN(s1y +
h, s2y +
h);
176 const int safe_pw = (u_endx_safe - startx_safe) & ~0
xf;
177 const int safe_ph = endy_safe - starty_safe;
180 const int endx_safe = startx_safe + safe_pw;
195 startx_safe, safe_ph);
202 if (safe_pw && safe_ph)
204 src + (starty_safe - s1y) * linesize + (startx_safe - s1x), linesize,
205 src + (starty_safe - s2y) * linesize + (startx_safe - s2x), linesize,
210 endx_safe, starty_safe,
213 ii_w - endx_safe, safe_ph);
220 ii_w, ii_h - endy_safe);
228 const int e =
FFMAX(
s->research_hsize,
s->research_hsize_uv)
229 +
FFMAX(
s->patch_hsize,
s->patch_hsize_uv);
261 s->ii_orig =
av_calloc(
s->ii_h + 1,
s->ii_lz_32 *
sizeof(*
s->ii_orig));
266 s->ii =
s->ii_orig +
s->ii_lz_32 + 1;
272 if (!
s->total_weight || !
s->sum)
290 const uint32_t max_meaningful_diff =
s->max_meaningful_diff;
293 const int process_h =
td->endy -
td->starty;
294 const int slice_start = (process_h * jobnr ) / nb_jobs;
295 const int slice_end = (process_h * (jobnr+1)) / nb_jobs;
299 const uint32_t *ii =
td->ii_start + (
starty -
p - 1) *
s->ii_lz_32 -
p - 1;
300 const int dist_b = 2*
p + 1;
301 const int dist_d = dist_b *
s->ii_lz_32;
302 const int dist_e = dist_d + dist_b;
303 const float *
const weight_lut =
s->weight_lut;
308 float *total_weight =
s->total_weight + y*
s->linesize;
309 float *sum =
s->sum + y*
s->linesize;
310 const uint32_t *
const iia = ii;
311 const uint32_t *
const iib = ii + dist_b;
312 const uint32_t *
const iid = ii + dist_d;
313 const uint32_t *
const iie = ii + dist_e;
315 dsp->compute_weights_line(iia, iib, iid, iie,
src, total_weight, sum,
316 weight_lut, max_meaningful_diff,
317 td->startx,
td->endx);
325 float *total_weight,
float *sum, ptrdiff_t linesize,
328 for (
int y = 0; y <
h; y++) {
329 for (
int x = 0; x <
w; x++) {
331 total_weight[x] += 1.f;
332 sum[x] += 1.f *
src[x];
337 total_weight += linesize;
343 uint8_t *dst, ptrdiff_t dst_linesize,
351 const uint32_t *centered_ii =
s->ii + e*
s->ii_lz_32 + e;
353 memset(
s->total_weight, 0,
s->linesize *
h *
sizeof(*
s->total_weight));
354 memset(
s->sum, 0,
s->linesize *
h *
sizeof(*
s->sum));
356 for (
int offy = -
r; offy <=
r; offy++) {
357 for (
int offx = -
r; offx <=
r; offx++) {
362 .startx =
FFMAX(0, -offx),
363 .starty =
FFMAX(0, -offy),
366 .ii_start = centered_ii + offy*
s->ii_lz_32 + offx,
372 offx, offy, e,
w,
h);
380 s->total_weight,
s->sum,
s->linesize,
w,
h);
398 for (
int i = 0;
i <
s->nb_planes;
i++) {
399 const int w =
i ?
s->chroma_w :
inlink->w;
400 const int h =
i ?
s->chroma_h :
inlink->h;
401 const int p =
i ?
s->patch_hsize_uv :
s->patch_hsize;
402 const int r =
i ?
s->research_hsize_uv :
s->research_hsize;
412 #define CHECK_ODD_FIELD(field, name) do { \
413 if (!(s->field & 1)) { \
415 av_log(ctx, AV_LOG_WARNING, name " size must be odd, " \
416 "setting it to %d\n", s->field); \
423 const double h =
s->sigma * 10.;
425 s->pdiff_scale = 1. / (
h *
h);
426 s->max_meaningful_diff =
log(255.) /
s->pdiff_scale;
427 s->weight_lut =
av_calloc(
s->max_meaningful_diff + 1,
sizeof(*
s->weight_lut));
430 for (
int i = 0;
i <
s->max_meaningful_diff;
i++)
431 s->weight_lut[
i] =
exp(-
i *
s->pdiff_scale);
436 if (!
s->research_size_uv)
s->research_size_uv =
s->research_size;
437 if (!
s->patch_size_uv)
s->patch_size_uv =
s->patch_size;
442 s->research_hsize =
s->research_size / 2;
443 s->research_hsize_uv =
s->research_size_uv / 2;
444 s->patch_hsize =
s->patch_size / 2;
445 s->patch_hsize_uv =
s->patch_size_uv / 2;
448 s->research_size,
s->research_size,
s->research_size_uv,
s->research_size_uv,
449 s->patch_size,
s->patch_size,
s->patch_size_uv,
s->patch_size_uv);
483 .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
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)
#define FILTER_PIXFMTS_ARRAY(array)
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.
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 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 int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
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)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
#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_INPUTS(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.
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 av_unused void ff_nlmeans_init(NLMeansDSPContext *dsp)
static av_cold int init(AVFilterContext *ctx)
int h
agreed upon image height
@ 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)
#define FILTER_OUTPUTS(array)
@ 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
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)