FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_bm3d.c File Reference
#include <float.h>
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavcodec/avfft.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "framesync.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  ThreadData
 Used for passing data between threads. More...
 
struct  PosCode
 
struct  PosPairCode
 
struct  SliceContext
 
struct  BM3DContext
 

Macros

#define MAX_NB_THREADS   32
 
#define OFFSET(x)   offsetof(BM3DContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define SQR(x)   ((x) * (x))
 

Enumerations

enum  FilterModes { BASIC, FINAL, NB_MODES }
 

Functions

 AVFILTER_DEFINE_CLASS (bm3d)
 
static int query_formats (AVFilterContext *ctx)
 
static int do_search_boundary (int pos, int plane_boundary, int search_range, int search_step)
 
static int search_boundary (int plane_boundary, int search_range, int search_step, int vertical, int y, int x)
 
static int cmp_scores (const void *a, const void *b)
 
static double do_block_ssd (BM3DContext *s, PosCode *pos, const uint8_t *src, int src_stride, int r_y, int r_x)
 
static double do_block_ssd16 (BM3DContext *s, PosCode *pos, const uint8_t *src, int src_stride, int r_y, int r_x)
 
static void do_block_matching_multi (BM3DContext *s, const uint8_t *src, int src_stride, int src_range, const PosCode *search_pos, int search_size, float th_mse, int r_y, int r_x, int plane, int jobnr)
 
static void block_matching_multi (BM3DContext *s, const uint8_t *ref, int ref_linesize, int y, int x, int exclude_cur_pos, int plane, int jobnr)
 
static void block_matching (BM3DContext *s, const uint8_t *ref, int ref_linesize, int j, int i, int plane, int jobnr)
 
static void get_block_row (const uint8_t *srcp, int src_linesize, int y, int x, int block_size, float *dst)
 
static void get_block_row16 (const uint8_t *srcp, int src_linesize, int y, int x, int block_size, float *dst)
 
static void basic_block_filtering (BM3DContext *s, const uint8_t *src, int src_linesize, const uint8_t *ref, int ref_linesize, int y, int x, int plane, int jobnr)
 
static void final_block_filtering (BM3DContext *s, const uint8_t *src, int src_linesize, const uint8_t *ref, int ref_linesize, int y, int x, int plane, int jobnr)
 
static void do_output (BM3DContext *s, uint8_t *dst, int dst_linesize, int plane, int nb_jobs)
 
static void do_output16 (BM3DContext *s, uint8_t *dst, int dst_linesize, int plane, int nb_jobs)
 
static int filter_slice (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int filter_frame (AVFilterContext *ctx, AVFrame **out, AVFrame *in, AVFrame *ref)
 
static int config_input (AVFilterLink *inlink)
 
static int activate (AVFilterContext *ctx)
 
static int process_frame (FFFrameSync *fs)
 
static av_cold int init (AVFilterContext *ctx)
 
static int config_output (AVFilterLink *outlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption bm3d_options []
 
static const AVFilterPad bm3d_outputs []
 
AVFilter ff_vf_bm3d
 

Macro Definition Documentation

◆ MAX_NB_THREADS

#define MAX_NB_THREADS   32
Todo:
  • non-power of 2 DCT
  • opponent color space
  • temporal support

Definition at line 47 of file vf_bm3d.c.

◆ OFFSET

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

Definition at line 130 of file vf_bm3d.c.

◆ FLAGS

Definition at line 131 of file vf_bm3d.c.

◆ SQR

#define SQR (   x)    ((x) * (x))

Definition at line 778 of file vf_bm3d.c.

Enumeration Type Documentation

◆ FilterModes

Enumerator
BASIC 
FINAL 
NB_MODES 

Definition at line 49 of file vf_bm3d.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( bm3d  )

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 164 of file vf_bm3d.c.

◆ do_search_boundary()

static int do_search_boundary ( int  pos,
int  plane_boundary,
int  search_range,
int  search_step 
)
static

Definition at line 198 of file vf_bm3d.c.

Referenced by search_boundary().

◆ search_boundary()

static int search_boundary ( int  plane_boundary,
int  search_range,
int  search_step,
int  vertical,
int  y,
int  x 
)
static

Definition at line 223 of file vf_bm3d.c.

Referenced by block_matching_multi(), and do_search_boundary().

◆ cmp_scores()

static int cmp_scores ( const void *  a,
const void *  b 
)
static

Definition at line 228 of file vf_bm3d.c.

Referenced by do_block_matching_multi().

◆ do_block_ssd()

static double do_block_ssd ( BM3DContext s,
PosCode pos,
const uint8_t src,
int  src_stride,
int  r_y,
int  r_x 
)
static

Definition at line 235 of file vf_bm3d.c.

Referenced by config_input().

◆ do_block_ssd16()

static double do_block_ssd16 ( BM3DContext s,
PosCode pos,
const uint8_t src,
int  src_stride,
int  r_y,
int  r_x 
)
static

Definition at line 256 of file vf_bm3d.c.

Referenced by config_input().

◆ do_block_matching_multi()

static void do_block_matching_multi ( BM3DContext s,
const uint8_t src,
int  src_stride,
int  src_range,
const PosCode search_pos,
int  search_size,
float  th_mse,
int  r_y,
int  r_x,
int  plane,
int  jobnr 
)
static

Definition at line 277 of file vf_bm3d.c.

Referenced by block_matching_multi().

◆ block_matching_multi()

static void block_matching_multi ( BM3DContext s,
const uint8_t ref,
int  ref_linesize,
int  y,
int  x,
int  exclude_cur_pos,
int  plane,
int  jobnr 
)
static

Definition at line 315 of file vf_bm3d.c.

Referenced by block_matching().

◆ block_matching()

static void block_matching ( BM3DContext s,
const uint8_t ref,
int  ref_linesize,
int  j,
int  i,
int  plane,
int  jobnr 
)
static

Definition at line 355 of file vf_bm3d.c.

Referenced by filter_slice().

◆ get_block_row()

static void get_block_row ( const uint8_t srcp,
int  src_linesize,
int  y,
int  x,
int  block_size,
float *  dst 
)
static

Definition at line 372 of file vf_bm3d.c.

Referenced by config_input().

◆ get_block_row16()

static void get_block_row16 ( const uint8_t srcp,
int  src_linesize,
int  y,
int  x,
int  block_size,
float *  dst 
)
static

Definition at line 383 of file vf_bm3d.c.

Referenced by config_input().

◆ basic_block_filtering()

static void basic_block_filtering ( BM3DContext s,
const uint8_t src,
int  src_linesize,
const uint8_t ref,
int  ref_linesize,
int  y,
int  x,
int  plane,
int  jobnr 
)
static

Definition at line 394 of file vf_bm3d.c.

Referenced by init().

◆ final_block_filtering()

static void final_block_filtering ( BM3DContext s,
const uint8_t src,
int  src_linesize,
const uint8_t ref,
int  ref_linesize,
int  y,
int  x,
int  plane,
int  jobnr 
)
static

Definition at line 513 of file vf_bm3d.c.

Referenced by init().

◆ do_output()

static void do_output ( BM3DContext s,
uint8_t dst,
int  dst_linesize,
int  plane,
int  nb_jobs 
)
static

Definition at line 645 of file vf_bm3d.c.

Referenced by config_input().

◆ do_output16()

static void do_output16 ( BM3DContext s,
uint8_t dst,
int  dst_linesize,
int  plane,
int  nb_jobs 
)
static

Definition at line 672 of file vf_bm3d.c.

Referenced by config_input().

◆ filter_slice()

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

Definition at line 700 of file vf_bm3d.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterContext ctx,
AVFrame **  out,
AVFrame in,
AVFrame ref 
)
static

Definition at line 743 of file vf_bm3d.c.

Referenced by activate(), and process_frame().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 780 of file vf_bm3d.c.

Referenced by init().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 854 of file vf_bm3d.c.

◆ process_frame()

static int process_frame ( FFFrameSync fs)
static

Definition at line 888 of file vf_bm3d.c.

Referenced by config_output().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 908 of file vf_bm3d.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 963 of file vf_bm3d.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 1017 of file vf_bm3d.c.

Variable Documentation

◆ bm3d_options

const AVOption bm3d_options[]
static
Initial value:
= {
{ "sigma", "set denoising strength",
OFFSET(sigma), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 99999.9, FLAGS },
{ "block", "set log2(size) of local patch",
OFFSET(block_size), AV_OPT_TYPE_INT, {.i64=4}, 4, 6, FLAGS },
{ "bstep", "set sliding step for processing blocks",
OFFSET(block_step), AV_OPT_TYPE_INT, {.i64=4}, 1, 64, FLAGS },
{ "group", "set maximal number of similar blocks",
OFFSET(group_size), AV_OPT_TYPE_INT, {.i64=1}, 1, 256, FLAGS },
{ "range", "set block matching range",
OFFSET(bm_range), AV_OPT_TYPE_INT, {.i64=9}, 1, INT32_MAX, FLAGS },
{ "mstep", "set step for block matching",
OFFSET(bm_step), AV_OPT_TYPE_INT, {.i64=1}, 1, 64, FLAGS },
{ "thmse", "set threshold of mean square error for block matching",
OFFSET(th_mse), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT32_MAX, FLAGS },
{ "hdthr", "set hard threshold for 3D transfer domain",
OFFSET(hard_threshold), AV_OPT_TYPE_FLOAT, {.dbl=2.7}, 0, INT32_MAX, FLAGS },
{ "estim", "set filtering estimation mode",
OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BASIC}, 0, NB_MODES-1, FLAGS, "mode" },
{ "basic", "basic estimate",
0, AV_OPT_TYPE_CONST, {.i64=BASIC}, 0, 0, FLAGS, "mode" },
{ "final", "final estimate",
0, AV_OPT_TYPE_CONST, {.i64=FINAL}, 0, 0, FLAGS, "mode" },
{ "ref", "have reference stream",
OFFSET(ref), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
{ "planes", "set planes to filter",
OFFSET(planes), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, FLAGS },
{ NULL }
}

Definition at line 132 of file vf_bm3d.c.

◆ bm3d_outputs

const AVFilterPad bm3d_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
{ NULL }
}

Definition at line 1049 of file vf_bm3d.c.

◆ ff_vf_bm3d

AVFilter ff_vf_bm3d
Initial value:
= {
.name = "bm3d",
.description = NULL_IF_CONFIG_SMALL("Block-Matching 3D denoiser."),
.priv_size = sizeof(BM3DContext),
.init = init,
.priv_class = &bm3d_class,
}

Definition at line 1058 of file vf_bm3d.c.

FLAGS
#define FLAGS
Definition: vf_bm3d.c:131
BASIC
@ BASIC
Definition: vf_bm3d.c:50
NB_MODES
@ NB_MODES
Definition: vf_bm3d.c:52
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:106
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
NULL
#define NULL
Definition: coverity.c:32
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_bm3d.c:1017
FINAL
@ FINAL
Definition: vf_bm3d.c:51
OFFSET
#define OFFSET(x)
Definition: vf_bm3d.c:130
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:117
bm3d_outputs
static const AVFilterPad bm3d_outputs[]
Definition: vf_bm3d.c:1049
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_bm3d.c:908
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_bm3d.c:963
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
planes
static const struct @322 planes[]
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_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:134
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
BM3DContext
Definition: vf_bm3d.c:89
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_bm3d.c:164
activate
static int activate(AVFilterContext *ctx)
Definition: vf_bm3d.c:854