FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_edgedetect.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  plane_info
 
struct  EdgeDetectContext
 

Macros

#define PLANE_R   0x4
 
#define PLANE_G   0x1
 
#define PLANE_B   0x2
 
#define PLANE_Y   0x1
 
#define PLANE_U   0x2
 
#define PLANE_V   0x4
 
#define PLANE_A   0x8
 
#define OFFSET(x)   offsetof(EdgeDetectContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define COPY_MAXIMA(ay, ax, by, bx)
 

Enumerations

enum  FilterMode {
  FILTER_8TAP_SMOOTH, FILTER_8TAP_REGULAR, FILTER_8TAP_SHARP, FILTER_BILINEAR,
  N_FILTERS, FILTER_SWITCHABLE = N_FILTERS, MODE_WIRES, MODE_COLORMIX,
  MODE_CANNY, NB_MODE, MODE_NONE, MODE_INTERLEAVE,
  MODE_DEINTERLEAVE, FILTER_NONE = -1, FILTER_TOUT, FILTER_VREP,
  FILTER_BRNG, FILT_NUMB
}
 
enum  { DIRECTION_45UP, DIRECTION_45DOWN, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL }
 

Functions

 AVFILTER_DEFINE_CLASS (edgedetect)
 
static av_cold int init (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_props (AVFilterLink *inlink)
 
static void gaussian_blur (AVFilterContext *ctx, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
 
static int get_rounded_direction (int gx, int gy)
 
static void sobel (int w, int h, uint16_t *dst, int dst_linesize, int8_t *dir, int dir_linesize, const uint8_t *src, int src_linesize)
 
static void non_maximum_suppression (int w, int h, uint8_t *dst, int dst_linesize, const int8_t *dir, int dir_linesize, const uint16_t *src, int src_linesize)
 
static void double_threshold (int low, int high, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
 
static void color_mix (int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption edgedetect_options []
 
static const AVFilterPad edgedetect_inputs []
 
static const AVFilterPad edgedetect_outputs []
 
const AVFilter ff_vf_edgedetect
 

Detailed Description

Edge detection filter

See also
https://en.wikipedia.org/wiki/Canny_edge_detector

Definition in file vf_edgedetect.c.

Macro Definition Documentation

◆ PLANE_R

#define PLANE_R   0x4

Definition at line 36 of file vf_edgedetect.c.

◆ PLANE_G

#define PLANE_G   0x1

Definition at line 37 of file vf_edgedetect.c.

◆ PLANE_B

#define PLANE_B   0x2

Definition at line 38 of file vf_edgedetect.c.

◆ PLANE_Y

#define PLANE_Y   0x1

Definition at line 39 of file vf_edgedetect.c.

◆ PLANE_U

#define PLANE_U   0x2

Definition at line 40 of file vf_edgedetect.c.

◆ PLANE_V

#define PLANE_V   0x4

Definition at line 41 of file vf_edgedetect.c.

◆ PLANE_A

#define PLANE_A   0x8

Definition at line 42 of file vf_edgedetect.c.

◆ OFFSET

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

Definition at line 68 of file vf_edgedetect.c.

◆ FLAGS

Definition at line 69 of file vf_edgedetect.c.

◆ COPY_MAXIMA

#define COPY_MAXIMA (   ay,
  ax,
  by,
  bx 
)
Value:
do { \
if (src[i] > src[(ay)*src_linesize + i+(ax)] && \
src[i] > src[(by)*src_linesize + i+(bx)]) \
dst[i] = av_clip_uint8(src[i]); \
} while (0)

Enumeration Type Documentation

◆ FilterMode

enum FilterMode
Enumerator
FILTER_8TAP_SMOOTH 
FILTER_8TAP_REGULAR 
FILTER_8TAP_SHARP 
FILTER_BILINEAR 
N_FILTERS 
FILTER_SWITCHABLE 
MODE_WIRES 
MODE_COLORMIX 
MODE_CANNY 
NB_MODE 
MODE_NONE 
MODE_INTERLEAVE 
MODE_DEINTERLEAVE 
FILTER_NONE 
FILTER_TOUT 
FILTER_VREP 
FILTER_BRNG 
FILT_NUMB 

Definition at line 44 of file vf_edgedetect.c.

◆ anonymous enum

anonymous enum
Enumerator
DIRECTION_45UP 
DIRECTION_45DOWN 
DIRECTION_HORIZONTAL 
DIRECTION_VERTICAL 

Definition at line 191 of file vf_edgedetect.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( edgedetect  )

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 89 of file vf_edgedetect.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 98 of file vf_edgedetect.c.

◆ config_props()

static int config_props ( AVFilterLink inlink)
static

Definition at line 118 of file vf_edgedetect.c.

◆ gaussian_blur()

static void gaussian_blur ( AVFilterContext ctx,
int  w,
int  h,
uint8_t *  dst,
int  dst_linesize,
const uint8_t *  src,
int  src_linesize 
)
static

Definition at line 142 of file vf_edgedetect.c.

Referenced by filter_frame().

◆ get_rounded_direction()

static int get_rounded_direction ( int  gx,
int  gy 
)
static

Definition at line 198 of file vf_edgedetect.c.

Referenced by sobel().

◆ sobel()

static void sobel ( int  w,
int  h,
uint16_t *  dst,
int  dst_linesize,
int8_t *  dir,
int  dir_linesize,
const uint8_t *  src,
int  src_linesize 
)
static

Definition at line 225 of file vf_edgedetect.c.

Referenced by filter_frame().

◆ non_maximum_suppression()

static void non_maximum_suppression ( int  w,
int  h,
uint8_t *  dst,
int  dst_linesize,
const int8_t *  dir,
int  dir_linesize,
const uint16_t *  src,
int  src_linesize 
)
static

Definition at line 252 of file vf_edgedetect.c.

Referenced by filter_frame().

◆ double_threshold()

static void double_threshold ( int  low,
int  high,
int  w,
int  h,
uint8_t *  dst,
int  dst_linesize,
const uint8_t *  src,
int  src_linesize 
)
static

Definition at line 280 of file vf_edgedetect.c.

Referenced by filter_frame().

◆ color_mix()

static void color_mix ( int  w,
int  h,
uint8_t *  dst,
int  dst_linesize,
const uint8_t *  src,
int  src_linesize 
)
static

Definition at line 312 of file vf_edgedetect.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 326 of file vf_edgedetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 399 of file vf_edgedetect.c.

Variable Documentation

◆ edgedetect_options

const AVOption edgedetect_options[]
static
Initial value:
= {
{ "high", "set high threshold", OFFSET(high), AV_OPT_TYPE_DOUBLE, {.dbl=50/255.}, 0, 1, FLAGS },
{ "low", "set low threshold", OFFSET(low), AV_OPT_TYPE_DOUBLE, {.dbl=20/255.}, 0, 1, FLAGS },
{ "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_WIRES}, 0, NB_MODE-1, FLAGS, "mode" },
{ "wires", "white/gray wires on black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_WIRES}, INT_MIN, INT_MAX, FLAGS, "mode" },
{ "colormix", "mix colors", 0, AV_OPT_TYPE_CONST, {.i64=MODE_COLORMIX}, INT_MIN, INT_MAX, FLAGS, "mode" },
{ "canny", "detect edges on planes", 0, AV_OPT_TYPE_CONST, {.i64=MODE_CANNY}, INT_MIN, INT_MAX, FLAGS, "mode" },
{ "planes", "set planes to filter", OFFSET(filter_planes), AV_OPT_TYPE_FLAGS, {.i64=7}, 1, 0x7, FLAGS, "flags" },
{ "y", "filter luma plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_Y}, 0, 0, FLAGS, "flags" },
{ "u", "filter u plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_U}, 0, 0, FLAGS, "flags" },
{ "v", "filter v plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_V}, 0, 0, FLAGS, "flags" },
{ "r", "filter red plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_R}, 0, 0, FLAGS, "flags" },
{ "g", "filter green plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_G}, 0, 0, FLAGS, "flags" },
{ "b", "filter blue plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_B}, 0, 0, FLAGS, "flags" },
{ NULL }
}

Definition at line 70 of file vf_edgedetect.c.

◆ edgedetect_inputs

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

Definition at line 412 of file vf_edgedetect.c.

◆ edgedetect_outputs

const AVFilterPad edgedetect_outputs[]
static
Initial value:
= {
{
.name = "default",
},
}

Definition at line 421 of file vf_edgedetect.c.

◆ ff_vf_edgedetect

const AVFilter ff_vf_edgedetect
Initial value:
= {
.name = "edgedetect",
.description = NULL_IF_CONFIG_SMALL("Detect and draw edge."),
.priv_size = sizeof(EdgeDetectContext),
.init = init,
.priv_class = &edgedetect_class,
}

Definition at line 428 of file vf_edgedetect.c.

PLANE_B
#define PLANE_B
Definition: vf_edgedetect.c:38
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
MODE_COLORMIX
@ MODE_COLORMIX
Definition: vf_edgedetect.c:46
PLANE_V
#define PLANE_V
Definition: vf_edgedetect.c:41
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
MODE_CANNY
@ MODE_CANNY
Definition: vf_edgedetect.c:47
MODE_WIRES
@ MODE_WIRES
Definition: vf_edgedetect.c:45
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
edgedetect_inputs
static const AVFilterPad edgedetect_inputs[]
Definition: vf_edgedetect.c:412
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_edgedetect.c:89
NULL
#define NULL
Definition: coverity.c:32
PLANE_G
#define PLANE_G
Definition: vf_edgedetect.c:37
src
#define src
Definition: vp8dsp.c:255
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_edgedetect.c:326
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_edgedetect.c:399
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
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:146
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
PLANE_R
#define PLANE_R
Definition: vf_edgedetect.c:36
config_props
static int config_props(AVFilterLink *inlink)
Definition: vf_edgedetect.c:118
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_edgedetect.c:98
PLANE_Y
#define PLANE_Y
Definition: vf_edgedetect.c:39
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
av_clip_uint8
#define av_clip_uint8
Definition: common.h:102
OFFSET
#define OFFSET(x)
Definition: vf_edgedetect.c:68
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FLAGS
#define FLAGS
Definition: vf_edgedetect.c:69
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
PLANE_U
#define PLANE_U
Definition: vf_edgedetect.c:40
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:223
NB_MODE
@ NB_MODE
Definition: vf_edgedetect.c:48
edgedetect_outputs
static const AVFilterPad edgedetect_outputs[]
Definition: vf_edgedetect.c:421
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
EdgeDetectContext
Definition: vf_edgedetect.c:58