FFmpeg
Data Structures | Macros | Functions | Variables
vf_unsharp.c File Reference
#include "avfilter.h"
#include "filters.h"
#include "video.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"

Go to the source code of this file.

Data Structures

struct  UnsharpFilterParam
 
struct  UnsharpContext
 
struct  TheadData
 

Macros

#define MIN_MATRIX_SIZE   3
 
#define MAX_MATRIX_SIZE   63
 
#define DEF_UNSHARP_SLICE_FUNC(name, nbits)
 
#define MAX_SCALEBITS   25
 
#define SET_FILTER_PARAM(name_, short_)
 
#define OFFSET(x)   offsetof(UnsharpContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define MIN_SIZE   3
 
#define MAX_SIZE   23
 

Functions

static int apply_unsharp (AVFilterContext *ctx, AVFrame *in, AVFrame *out)
 
static int set_filter_param (AVFilterContext *ctx, const char *name, const char *short_name, UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
 
static av_cold int init (AVFilterContext *ctx)
 
static int init_filter_param (AVFilterContext *ctx, UnsharpFilterParam *fp, const char *effect_type, int width)
 
static int config_input (AVFilterLink *inlink)
 
static void free_filter_param (UnsharpFilterParam *fp, int nb_threads)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *link, AVFrame *in)
 
 AVFILTER_DEFINE_CLASS (unsharp)
 

Variables

static enum AVPixelFormat pix_fmts []
 
static const AVOption unsharp_options []
 
static const AVFilterPad avfilter_vf_unsharp_inputs []
 
const AVFilter ff_vf_unsharp
 

Detailed Description

blur / sharpen filter, ported to FFmpeg from MPlayer libmpcodecs/unsharp.c.

This code is based on:

An Efficient algorithm for Gaussian blur using finite-state machines Frederick M. Waltz and John W. V. Miller

SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII Originally published Boston, Nov 98

http://www.engin.umd.umich.edu/~jwvm/ece581/21_GBlur.pdf

Definition in file vf_unsharp.c.

Macro Definition Documentation

◆ MIN_MATRIX_SIZE

#define MIN_MATRIX_SIZE   3

Definition at line 48 of file vf_unsharp.c.

◆ MAX_MATRIX_SIZE

#define MAX_MATRIX_SIZE   63

Definition at line 49 of file vf_unsharp.c.

◆ DEF_UNSHARP_SLICE_FUNC

#define DEF_UNSHARP_SLICE_FUNC (   name,
  nbits 
)

Definition at line 90 of file vf_unsharp.c.

◆ MAX_SCALEBITS

#define MAX_SCALEBITS   25

Definition at line 204 of file vf_unsharp.c.

◆ SET_FILTER_PARAM

#define SET_FILTER_PARAM (   name_,
  short_ 
)
Value:
ret = set_filter_param(ctx, #name_, #short_, &s->name_, \
s->short_##msize_x, s->short_##msize_y, s->short_##amount); \
if (ret < 0) \
return ret; \

◆ OFFSET

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

Definition at line 360 of file vf_unsharp.c.

◆ FLAGS

Definition at line 361 of file vf_unsharp.c.

◆ MIN_SIZE

#define MIN_SIZE   3

Definition at line 362 of file vf_unsharp.c.

◆ MAX_SIZE

#define MAX_SIZE   23

Definition at line 363 of file vf_unsharp.c.

Function Documentation

◆ apply_unsharp()

static int apply_unsharp ( AVFilterContext ctx,
AVFrame in,
AVFrame out 
)
static

Definition at line 175 of file vf_unsharp.c.

Referenced by filter_frame().

◆ set_filter_param()

static int set_filter_param ( AVFilterContext ctx,
const char *  name,
const char *  short_name,
UnsharpFilterParam fp,
int  msize_x,
int  msize_y,
float  amount 
)
static

Definition at line 206 of file vf_unsharp.c.

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 227 of file vf_unsharp.c.

◆ init_filter_param()

static int init_filter_param ( AVFilterContext ctx,
UnsharpFilterParam fp,
const char *  effect_type,
int  width 
)
static

Definition at line 259 of file vf_unsharp.c.

Referenced by config_input().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 288 of file vf_unsharp.c.

◆ free_filter_param()

static void free_filter_param ( UnsharpFilterParam fp,
int  nb_threads 
)
static

Definition at line 316 of file vf_unsharp.c.

Referenced by uninit().

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 328 of file vf_unsharp.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 336 of file vf_unsharp.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( unsharp  )

Variable Documentation

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ unsharp_options

const AVOption unsharp_options[]
static
Initial value:
= {
{ "luma_msize_x", "set luma matrix horizontal size", OFFSET(lmsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "lx", "set luma matrix horizontal size", OFFSET(lmsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "luma_msize_y", "set luma matrix vertical size", OFFSET(lmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "ly", "set luma matrix vertical size", OFFSET(lmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "luma_amount", "set luma effect strength", OFFSET(lamount), AV_OPT_TYPE_FLOAT, { .dbl = 1 }, -2, 5, FLAGS },
{ "la", "set luma effect strength", OFFSET(lamount), AV_OPT_TYPE_FLOAT, { .dbl = 1 }, -2, 5, FLAGS },
{ "chroma_msize_x", "set chroma matrix horizontal size", OFFSET(cmsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "cx", "set chroma matrix horizontal size", OFFSET(cmsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "chroma_msize_y", "set chroma matrix vertical size", OFFSET(cmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "cy", "set chroma matrix vertical size", OFFSET(cmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "chroma_amount", "set chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "ca", "set chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "alpha_msize_x", "set alpha matrix horizontal size", OFFSET(amsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "ax", "set alpha matrix horizontal size", OFFSET(amsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "alpha_msize_y", "set alpha matrix vertical size", OFFSET(amsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "ay", "set alpha matrix vertical size", OFFSET(amsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "alpha_amount", "set alpha effect strength", OFFSET(aamount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "aa", "set alpha effect strength", OFFSET(aamount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ NULL }
}

Definition at line 364 of file vf_unsharp.c.

◆ avfilter_vf_unsharp_inputs

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

Definition at line 388 of file vf_unsharp.c.

◆ ff_vf_unsharp

const AVFilter ff_vf_unsharp
Initial value:
= {
.name = "unsharp",
.description = NULL_IF_CONFIG_SMALL("Sharpen or blur the input video."),
.priv_size = sizeof(UnsharpContext),
.priv_class = &unsharp_class,
.init = init,
}

Definition at line 397 of file vf_unsharp.c.

AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:531
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:523
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:530
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:525
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:487
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:526
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_unsharp.c:328
MIN_SIZE
#define MIN_SIZE
Definition: vf_unsharp.c:362
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_unsharp.c:336
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:522
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_unsharp.c:288
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:532
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:485
set_filter_param
static int set_filter_param(AVFilterContext *ctx, const char *name, const char *short_name, UnsharpFilterParam *fp, int msize_x, int msize_y, float amount)
Definition: vf_unsharp.c:206
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_unsharp.c:227
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:490
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:499
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:37
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:86
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:500
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:529
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:484
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:498
ctx
AVFormatContext * ctx
Definition: movenc.c:49
MAX_SIZE
#define MAX_SIZE
Definition: vf_unsharp.c:363
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:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
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:87
UnsharpContext
Definition: vf_unsharp.c:63
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:85
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:489
OFFSET
#define OFFSET(x)
Definition: vf_unsharp.c:360
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:488
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:94
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:492
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:494
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:527
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:182
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_unsharp.c:245
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:107
FLAGS
#define FLAGS
Definition: vf_unsharp.c:361
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:486
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:524
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:491
avfilter_vf_unsharp_inputs
static const AVFilterPad avfilter_vf_unsharp_inputs[]
Definition: vf_unsharp.c:388
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:528
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
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:78
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:152
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:77
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:80
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:79
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:493
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173