FFmpeg
Loading...
Searching...
No Matches
vf_drawvg.c File Reference

drawvg filter, draw vector graphics with cairo. More...

#include <cairo.h>
#include <stdbool.h>
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bswap.h"
#include "libavutil/eval.h"
#include "libavutil/internal.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/sfc64.h"
#include "avfilter.h"
#include "filters.h"
#include "textutils.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  VGSConstant
 Constants for some commands, like setlinejoin. More...
 
struct  VGSParameter
 
struct  VGSCommandSpec
 
struct  VGSParser
 
struct  VGSParserToken
 
struct  VGSArgument
 Command arguments. More...
 
struct  VGSStatement
 Program statements. More...
 
struct  VGSProgram
 
struct  VGSProcedure
 Block assigned to a procedure by a call to the proc command. More...
 
struct  VGSEvalState
 
struct  DrawVGContext
 

Macros

#define USER_VAR_COUNT   20
 Number of user variables that can be created with setvar.
 
#define VAR_COUNT   (VAR_U0 + USER_VAR_COUNT)
 Total number of variables (default- and user-variables).
 
#define MAX_COMMAND_PARAMS   8
 
#define MAX_PROC_ARGS   (MAX_COMMAND_PARAMS - 2)
 
#define VGS_MAX_RECURSION_DEPTH   100
 
#define PARAMS(...)
 
#define L(...)
 
#define R(...)
 
#define NONE   PARAMS({ PARAM_END })
 
#define N   { PARAM_NUMERIC }
 
#define V   { PARAM_VAR_NAME }
 
#define P   { PARAM_SUBPROGRAM }
 
#define C(c)
 
#define WORD_SEPARATOR   " \n\t\r,"
 
#define FAIL(err)
 
#define RANDOM_STATES   4
 Number of different states for the randomg function.
 
#define ASSERT_ARGS(n)
 
#define MAY_PRESERVE(funcname)
 
#define OPT(name, field, help)
 

Typedefs

typedef double cairo_color[4]
 Colors in cairo are defined by 4 values, between 0 and 1.
 

Enumerations

enum  {
  VAR_N , VAR_T , VAR_TS , VAR_W ,
  VAR_H , VAR_DURATION , VAR_CX , VAR_CY ,
  VAR_I , VAR_U0
}
 
enum  VGSCommand {
  CMD_ARC = 1 , CMD_ARC_NEG , CMD_BREAK , CMD_CIRCLE ,
  CMD_CLIP , CMD_CLIP_EO , CMD_CLOSE_PATH , CMD_COLOR_STOP ,
  CMD_CURVE_TO , CMD_DEF_HSLA , CMD_DEF_RGBA , CMD_CURVE_TO_REL ,
  CMD_ELLIPSE , CMD_FILL , CMD_FILL_EO , CMD_GET_METADATA ,
  CMD_HORZ , CMD_HORZ_REL , CMD_IF , CMD_LINEAR_GRAD ,
  CMD_LINE_TO , CMD_LINE_TO_REL , CMD_MOVE_TO , CMD_MOVE_TO_REL ,
  CMD_NEW_PATH , CMD_PRESERVE , CMD_PRINT , CMD_PROC_ASSIGN ,
  CMD_PROC_CALL , CMD_Q_CURVE_TO , CMD_Q_CURVE_TO_REL , CMD_RADIAL_GRAD ,
  CMD_RECT , CMD_REPEAT , CMD_RESET_CLIP , CMD_RESET_DASH ,
  CMD_RESET_MATRIX , CMD_RESTORE , CMD_ROTATE , CMD_ROUNDEDRECT ,
  CMD_SAVE , CMD_SCALE , CMD_SCALEXY , CMD_SET_COLOR ,
  CMD_SET_DASH , CMD_SET_DASH_OFFSET , CMD_SET_HSLA , CMD_SET_LINE_CAP ,
  CMD_SET_LINE_JOIN , CMD_SET_LINE_WIDTH , CMD_SET_RGBA , CMD_SET_VAR ,
  CMD_STROKE , CMD_S_CURVE_TO , CMD_S_CURVE_TO_REL , CMD_TRANSLATE ,
  CMD_T_CURVE_TO , CMD_T_CURVE_TO_REL , CMD_VERT , CMD_VERT_REL
}
 

Functions

static double vgs_fn_pathlen (void *data, double arg)
 Function pathlen(n) for av_expr_eval.
 
static double vgs_fn_randomg (void *data, double arg)
 Function randomg(n) for av_expr_eval.
 
static double vgs_fn_p (void *data, double x0, double y0)
 Function p(x, y) for av_expr_eval.
 
static int vgs_comp_command_spec (const void *cs1, const void *cs2)
 Comparator for VGSCommandDecl, to be used with bsearch(3).
 
static const struct VGSCommandSpecvgs_get_command (const char *name, size_t length)
 Return the specs for the given command, or NULL if the name is not valid.
 
static int vgs_cmd_change_path (enum VGSCommand cmd)
 Return 1 if the command changes the current path in the cairo context.
 
static av_always_inline void color_copy (cairo_color *dest, const cairo_color *src)
 
static av_always_inline void color_reset (cairo_color *const dest)
 
static int vgs_token_is_string (const struct VGSParserToken *token, const char *str)
 Check if token is the value of str.
 
static void vgs_token_span (const struct VGSParser *parser, const struct VGSParserToken *token, size_t *line, size_t *column)
 Compute the line/column numbers of the given token.
 
static av_printf_format (4, 5)
 
static int vgs_parser_next_token (void *log_ctx, struct VGSParser *parser, struct VGSParserToken *token, int advance)
 Return the next token in the source.
 
static void vgs_free (struct VGSProgram *program)
 Release the memory allocated by the program.
 
static int vgs_parse (void *log_ctx, struct VGSParser *parser, struct VGSProgram *program, int subprogram)
 Build a program by parsing a script.
 
static void vgs_statement_free (struct VGSStatement *stm)
 
static int vgs_parse_color (void *log_ctx, struct VGSArgument *arg, const struct VGSParser *parser, const struct VGSParserToken *token)
 
static int vgs_parse_numeric_argument (void *log_ctx, struct VGSParser *parser, struct VGSArgument *arg, int metadata, bool accept_colors)
 Consume the next argument as a numeric value, and store it in arg.
 
static int vgs_parser_can_repeat_cmd (void *log_ctx, struct VGSParser *parser, bool accept_colors)
 Check if the next token is a numeric value (or a color, if accept_colors is true), so the last command must be repeated.
 
static int vgs_is_valid_identifier (const struct VGSParserToken *token)
 
static int vgs_parse_statement (void *log_ctx, struct VGSParser *parser, struct VGSProgram *program, const struct VGSCommandSpec *decl)
 Extract the arguments for a command, and add a new statement to the program.
 
static void vgs_parser_init (struct VGSParser *parser, const char *source)
 
static void vgs_parser_free (struct VGSParser *parser)
 
static int vgs_eval_state_init (struct VGSEvalState *state, const struct VGSProgram *program, void *log_ctx, AVFrame *frame)
 
static void vgs_eval_state_free (struct VGSEvalState *state)
 
static void draw_ellipse (cairo_t *c, double x, double y, double rx, double ry)
 Draw an ellipse.
 
static void draw_quad_curve_to (struct VGSEvalState *state, int relative, double x1, double y1, double x, double y)
 Draw a quadratic bezier from the current point to x, y, The control point is specified by x1, y1.
 
static void draw_cubic_curve_to (struct VGSEvalState *state, int relative, double x1, double y1, double x2, double y2, double x, double y)
 Similar to quad_curve_to, but for cubic curves.
 
static void draw_rounded_rect (cairo_t *c, double x, double y, double width, double height, double radius)
 
static void hsl2rgb (double h, double s, double l, double *pr, double *pg, double *pb)
 
static int vgs_eval (struct VGSEvalState *state, const struct VGSProgram *program, int stack_level)
 Interpreter for VGSProgram.
 
 AVFILTER_DEFINE_CLASS (drawvg)
 
static cairo_format_t cairo_format_from_pix_fmt (DrawVGContext *ctx, enum AVPixelFormat format)
 
static int drawvg_filter_frame (AVFilterLink *inlink, AVFrame *frame)
 
static int drawvg_config_props (AVFilterLink *inlink)
 
static av_cold int drawvg_init (AVFilterContext *ctx)
 
static av_cold void drawvg_uninit (AVFilterContext *ctx)
 

Variables

static const char *const vgs_default_vars []
 
static const char *const vgs_func1_names []
 
static double(*const vgs_func1_impls [])(void *, double)
 
static const char *const vgs_func2_names []
 
static double(*const vgs_func2_impls [])(void *, double, double)
 
static const struct VGSConstant vgs_consts_line_cap []
 
static const struct VGSConstant vgs_consts_line_join []
 
static const struct VGSCommandSpec vgs_commands []
 
static const AVOption drawvg_options []
 
static enum AVPixelFormat drawvg_pix_fmts []
 
static const AVFilterPad drawvg_inputs []
 
const FFFilter ff_vf_drawvg
 

Detailed Description

drawvg filter, draw vector graphics with cairo.

This file contains the parser and the interpreter for VGS, and the AVClass definitions for the drawvg filter.

Definition in file vf_drawvg.c.

Macro Definition Documentation

◆ USER_VAR_COUNT

#define USER_VAR_COUNT   20

Number of user variables that can be created with setvar.

It is possible to allow any number of variables, but this approach simplifies the implementation, and 20 variables is more than enough for the expected use of this filter.

Definition at line 77 of file vf_drawvg.c.

Referenced by main(), vgs_eval(), and vgs_parse_statement().

◆ VAR_COUNT

#define VAR_COUNT   (VAR_U0 + USER_VAR_COUNT)

Total number of variables (default- and user-variables).

Definition at line 80 of file vf_drawvg.c.

Referenced by check_script(), vgs_eval(), vgs_parse_numeric_argument(), vgs_parse_statement(), vgs_parser_can_repeat_cmd(), and vgs_parser_free().

◆ MAX_COMMAND_PARAMS

#define MAX_COMMAND_PARAMS   8

Definition at line 240 of file vf_drawvg.c.

Referenced by vgs_eval(), and vgs_parse_statement().

◆ MAX_PROC_ARGS

#define MAX_PROC_ARGS   (MAX_COMMAND_PARAMS - 2)

Definition at line 246 of file vf_drawvg.c.

Referenced by vgs_eval(), and vgs_parse_statement().

◆ VGS_MAX_RECURSION_DEPTH

#define VGS_MAX_RECURSION_DEPTH   100

Definition at line 248 of file vf_drawvg.c.

Referenced by vgs_eval(), and vgs_parse().

◆ PARAMS

#define PARAMS ( ...)
Value:
(const struct VGSParameter[]){ __VA_ARGS__ }

Definition at line 259 of file vf_drawvg.c.

◆ L

#define L ( ...)
Value:
PARAMS(__VA_ARGS__, { PARAM_END })
#define PARAMS(...)
Definition vf_drawvg.c:259

Definition at line 260 of file vf_drawvg.c.

◆ R

#define R ( ...)
Value:
PARAMS(__VA_ARGS__, { PARAM_MAY_REPEAT })

Definition at line 261 of file vf_drawvg.c.

◆ NONE

#define NONE   PARAMS({ PARAM_END })

Definition at line 262 of file vf_drawvg.c.

Referenced by config_filter(), convert_width2qfactor(), fade_gain(), init(), submit_frame(), and uninit().

◆ N

#define N   { PARAM_NUMERIC }

Definition at line 265 of file vf_drawvg.c.

◆ V

#define V   { PARAM_VAR_NAME }

Definition at line 266 of file vf_drawvg.c.

◆ P

#define P   { PARAM_SUBPROGRAM }

Definition at line 267 of file vf_drawvg.c.

◆ C

#define C ( c)
Value:
{ PARAM_CONSTANT, .constants = c }
static double c[64]

Definition at line 268 of file vf_drawvg.c.

◆ WORD_SEPARATOR

#define WORD_SEPARATOR   " \n\t\r,"

Referenced by vgs_parser_next_token().

◆ FAIL

#define FAIL ( err)
Value:
do { \
vgs_statement_free(&statement); \
return AVERROR(err); \
} while(0)
#define AVERROR(e)
Definition error.h:45

Referenced by vgs_parse_statement().

◆ RANDOM_STATES

#define RANDOM_STATES   4

Number of different states for the randomg function.

Definition at line 1417 of file vf_drawvg.c.

◆ ASSERT_ARGS

#define ASSERT_ARGS ( n)
Value:
av_assert0(statement->args_count == n)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42

Referenced by vgs_eval().

◆ MAY_PRESERVE

#define MAY_PRESERVE ( funcname)
Value:
do { \
if (state->preserve_path) { \
state->preserve_path = 0; \
funcname##_preserve(state->cairo_ctx); \
} else { \
funcname(state->cairo_ctx); \
} \
} while(0)
static struct @346255127015250356166251341105367306144006377143 state

Referenced by vgs_eval().

◆ OPT

#define OPT ( name,
field,
help )
Value:
{ \
name, \
help, \
offsetof(DrawVGContext, field), \
{ .str = NULL }, \
0, 0, \
}
#define NULL
Definition coverity.c:32
static void help(void)
Definition dct.c:457
#define AV_OPT_FLAG_FILTERING_PARAM
A generic parameter which can be set by the user for filtering.
Definition opt.h:380
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
const char * name
Definition qsvenc.c:142

Definition at line 2651 of file vf_drawvg.c.

Typedef Documentation

◆ cairo_color

typedef double cairo_color[4]

Colors in cairo are defined by 4 values, between 0 and 1.

Computed colors (either by #RRGGBB expressions, or by commands like defhsla) are stored in the values that will be sent to Cairo.

Definition at line 418 of file vf_drawvg.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VAR_N 

Frame number.

VAR_T 

Timestamp in seconds.

VAR_TS 

Time in seconds of the first frame.

VAR_W 

Frame width.

VAR_H 

Frame height.

VAR_DURATION 

Frame duration.

VAR_CX 

X coordinate for current point.

VAR_CY 

Y coordinate for current point.

VAR_I 

Loop counter, to use with repeat {}.

VAR_U0 

User variables.

Definition at line 59 of file vf_drawvg.c.

◆ VGSCommand

enum VGSCommand
Enumerator
CMD_ARC 

arc (cx cy radius angle1 angle2)

CMD_ARC_NEG 

arcn (cx cy radius angle1 angle2)

CMD_BREAK 

break

CMD_CIRCLE 

circle (cx cy radius)

CMD_CLIP 

clip

CMD_CLIP_EO 

eoclip

CMD_CLOSE_PATH 

Z, z, closepath.

CMD_COLOR_STOP 

colorstop (offset color)

CMD_CURVE_TO 

C, curveto (x1 y1 x2 y2 x y)

CMD_DEF_HSLA 

defhsla (varname h s l a)

CMD_DEF_RGBA 

defrgba (varname r g b a)

CMD_CURVE_TO_REL 

c, rcurveto (dx1 dy1 dx2 dy2 dx dy)

CMD_ELLIPSE 

ellipse (cx cy rx ry)

CMD_FILL 

fill

CMD_FILL_EO 

eofill

CMD_GET_METADATA 

getmetadata varname key

CMD_HORZ 

H (x)

CMD_HORZ_REL 

h (dx)

CMD_IF 

if (condition) { subprogram }

CMD_LINEAR_GRAD 

lineargrad (x0 y0 x1 y1)

CMD_LINE_TO 

L, lineto (x y)

CMD_LINE_TO_REL 

l, rlineto (dx dy)

CMD_MOVE_TO 

M, moveto (x y)

CMD_MOVE_TO_REL 

m, rmoveto (dx dy)

CMD_NEW_PATH 

newpath

CMD_PRESERVE 

preserve

CMD_PRINT 

print (expr)*

CMD_PROC_ASSIGN 

proc name varnames* { subprogram }

CMD_PROC_CALL 

call name (expr)*

CMD_Q_CURVE_TO 

Q (x1 y1 x y)

CMD_Q_CURVE_TO_REL 

q (dx1 dy1 dx dy)

CMD_RADIAL_GRAD 

radialgrad (cx0 cy0 radius0 cx1 cy1 radius1)

CMD_RECT 

rect (x y width height)

CMD_REPEAT 

repeat (count) { subprogram }

CMD_RESET_CLIP 

resetclip

CMD_RESET_DASH 

resetdash

CMD_RESET_MATRIX 

resetmatrix

CMD_RESTORE 

restore

CMD_ROTATE 

rotate (angle)

CMD_ROUNDEDRECT 

roundedrect (x y width height radius)

CMD_SAVE 

save

CMD_SCALE 

scale (s)

CMD_SCALEXY 

scalexy (sx sy)

CMD_SET_COLOR 

setcolor (color)

CMD_SET_DASH 

setdash (length)

CMD_SET_DASH_OFFSET 

setdashoffset (offset)

CMD_SET_HSLA 

sethsla (h s l a)

CMD_SET_LINE_CAP 

setlinecap (cap)

CMD_SET_LINE_JOIN 

setlinejoin (join)

CMD_SET_LINE_WIDTH 

setlinewidth (width)

CMD_SET_RGBA 

setrgba (r g b a)

CMD_SET_VAR 

setvar (varname value)

CMD_STROKE 

stroke

CMD_S_CURVE_TO 

S (x2 y2 x y)

CMD_S_CURVE_TO_REL 

s (dx2 dy2 dx dy)

CMD_TRANSLATE 

translate (tx ty)

CMD_T_CURVE_TO 

T (x y)

CMD_T_CURVE_TO_REL 

t (dx dy)

CMD_VERT 

V (y)

CMD_VERT_REL 

v (dy)

Definition at line 135 of file vf_drawvg.c.

Function Documentation

◆ vgs_fn_pathlen()

static double vgs_fn_pathlen ( void * data,
double arg )
static

Function pathlen(n) for av_expr_eval.

Compute the length of the current path in the cairo context. If n > 0, it is the maximum number of segments to be added to the length.

Definition at line 1493 of file vf_drawvg.c.

◆ vgs_fn_randomg()

static double vgs_fn_randomg ( void * data,
double arg )
static

Function randomg(n) for av_expr_eval.

Compute a random value between 0 and 1. Similar to random(), but the state is global to the VGS program.

The last 2 bits of the integer representation of the argument are used as the state index. If the state is not initialized, the argument is the seed for that state.

Definition at line 1557 of file vf_drawvg.c.

◆ vgs_fn_p()

static double vgs_fn_p ( void * data,
double x0,
double y0 )
static

Function p(x, y) for av_expr_eval.

Return the pixel color in 0xRRGGBBAA format.

The transformation matrix is applied to the given coordinates.

If the coordinates are outside the frame, return NAN.

Definition at line 1581 of file vf_drawvg.c.

◆ vgs_comp_command_spec()

static int vgs_comp_command_spec ( const void * cs1,
const void * cs2 )
static

Comparator for VGSCommandDecl, to be used with bsearch(3).

Definition at line 352 of file vf_drawvg.c.

Referenced by check_sorted_cmds_array(), and vgs_get_command().

◆ vgs_get_command()

static const struct VGSCommandSpec * vgs_get_command ( const char * name,
size_t length )
static

Return the specs for the given command, or NULL if the name is not valid.

The implementation assumes that vgs_commands is sorted by name.

Definition at line 362 of file vf_drawvg.c.

Referenced by vgs_parse(), and vgs_parser_can_repeat_cmd().

◆ vgs_cmd_change_path()

static int vgs_cmd_change_path ( enum VGSCommand cmd)
static

Return 1 if the command changes the current path in the cairo context.

Definition at line 382 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ color_copy()

static av_always_inline void color_copy ( cairo_color * dest,
const cairo_color * src )
static

Definition at line 420 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ color_reset()

static av_always_inline void color_reset ( cairo_color *const dest)
static

Definition at line 424 of file vf_drawvg.c.

Referenced by vgs_eval(), and vgs_eval_state_init().

◆ vgs_token_is_string()

static int vgs_token_is_string ( const struct VGSParserToken * token,
const char * str )
static

Check if token is the value of str.

Definition at line 485 of file vf_drawvg.c.

Referenced by vgs_parse_numeric_argument(), vgs_parse_statement(), and vgs_parser_can_repeat_cmd().

◆ vgs_token_span()

static void vgs_token_span ( const struct VGSParser * parser,
const struct VGSParserToken * token,
size_t * line,
size_t * column )
static

Compute the line/column numbers of the given token.

Definition at line 491 of file vf_drawvg.c.

Referenced by av_printf_format(), and vgs_parse_numeric_argument().

◆ av_printf_format()

static av_printf_format ( 4 ,
5  )
static

Definition at line 514 of file vf_drawvg.c.

◆ vgs_parser_next_token()

static int vgs_parser_next_token ( void * log_ctx,
struct VGSParser * parser,
struct VGSParserToken * token,
int advance )
static

Return the next token in the source.

Parameters
[out]tokenNext token.
[in]advanceIf true, the cursor is updated after finding a token.
Returns
0 on success, and a negative AVERROR code on failure.

Definition at line 544 of file vf_drawvg.c.

Referenced by vgs_parse(), vgs_parse_numeric_argument(), vgs_parse_statement(), and vgs_parser_can_repeat_cmd().

◆ vgs_free()

static void vgs_free ( struct VGSProgram * program)
static

Release the memory allocated by the program.

Definition at line 731 of file vf_drawvg.c.

Referenced by check_script(), drawvg_uninit(), vgs_parse(), and vgs_statement_free().

◆ vgs_parse()

static int vgs_parse ( void * log_ctx,
struct VGSParser * parser,
struct VGSProgram * program,
int subprogram )
static

Build a program by parsing a script.

subprogram must be true when the function is called to parse the body of a block (like if or proc commands).

Return 0 on success, and a negative AVERROR code on failure.

Definition at line 1330 of file vf_drawvg.c.

Referenced by check_script(), drawvg_init(), and vgs_parse_statement().

◆ vgs_statement_free()

static void vgs_statement_free ( struct VGSStatement * stm)
static

Definition at line 702 of file vf_drawvg.c.

Referenced by vgs_free().

◆ vgs_parse_color()

static int vgs_parse_color ( void * log_ctx,
struct VGSArgument * arg,
const struct VGSParser * parser,
const struct VGSParserToken * token )
static

Definition at line 748 of file vf_drawvg.c.

Referenced by vgs_parse_numeric_argument(), and vgs_parse_statement().

◆ vgs_parse_numeric_argument()

static int vgs_parse_numeric_argument ( void * log_ctx,
struct VGSParser * parser,
struct VGSArgument * arg,
int metadata,
bool accept_colors )
static

Consume the next argument as a numeric value, and store it in arg.

Return 0 on success, and a negative AVERROR code on failure.

Definition at line 777 of file vf_drawvg.c.

Referenced by vgs_parse_statement().

◆ vgs_parser_can_repeat_cmd()

static int vgs_parser_can_repeat_cmd ( void * log_ctx,
struct VGSParser * parser,
bool accept_colors )
static

Check if the next token is a numeric value (or a color, if accept_colors is true), so the last command must be repeated.

Definition at line 890 of file vf_drawvg.c.

Referenced by vgs_parse_statement().

◆ vgs_is_valid_identifier()

static int vgs_is_valid_identifier ( const struct VGSParserToken * token)
static

Definition at line 937 of file vf_drawvg.c.

Referenced by vgs_parse_statement().

◆ vgs_parse_statement()

static int vgs_parse_statement ( void * log_ctx,
struct VGSParser * parser,
struct VGSProgram * program,
const struct VGSCommandSpec * decl )
static

Extract the arguments for a command, and add a new statement to the program.

On success, return 0.

Definition at line 961 of file vf_drawvg.c.

Referenced by vgs_parse().

◆ vgs_parser_init()

static void vgs_parser_init ( struct VGSParser * parser,
const char * source )
static

Definition at line 1298 of file vf_drawvg.c.

Referenced by check_script(), and drawvg_init().

◆ vgs_parser_free()

static void vgs_parser_free ( struct VGSParser * parser)
static

Definition at line 1311 of file vf_drawvg.c.

Referenced by check_script(), and drawvg_init().

◆ vgs_eval_state_init()

static int vgs_eval_state_init ( struct VGSEvalState * state,
const struct VGSProgram * program,
void * log_ctx,
AVFrame * frame )
static

Definition at line 1645 of file vf_drawvg.c.

Referenced by check_script(), and drawvg_filter_frame().

◆ vgs_eval_state_free()

static void vgs_eval_state_free ( struct VGSEvalState * state)
static

Definition at line 1676 of file vf_drawvg.c.

Referenced by check_script(), and drawvg_filter_frame().

◆ draw_ellipse()

static void draw_ellipse ( cairo_t * c,
double x,
double y,
double rx,
double ry )
static

Draw an ellipse.

x/y specifies the center, and rx/ry the radius of the ellipse on the x/y axis.

Cairo does not provide a native way to create an ellipse, but it can be done by scaling the Y axis with the transformation matrix.

Definition at line 1691 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ draw_quad_curve_to()

static void draw_quad_curve_to ( struct VGSEvalState * state,
int relative,
double x1,
double y1,
double x,
double y )
static

Draw a quadratic bezier from the current point to x, y, The control point is specified by x1, y1.

If the control point is NAN, use the reflected point.

cairo only supports cubic cuvers, so control points must be adjusted to simulate the behaviour in SVG.

Definition at line 1713 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ draw_cubic_curve_to()

static void draw_cubic_curve_to ( struct VGSEvalState * state,
int relative,
double x1,
double y1,
double x2,
double y2,
double x,
double y )
static

Similar to quad_curve_to, but for cubic curves.

Definition at line 1762 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ draw_rounded_rect()

static void draw_rounded_rect ( cairo_t * c,
double x,
double y,
double width,
double height,
double radius )
static

Definition at line 1809 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ hsl2rgb()

static void hsl2rgb ( double h,
double s,
double l,
double * pr,
double * pg,
double * pb )
static

Definition at line 1827 of file vf_drawvg.c.

Referenced by vgs_eval().

◆ vgs_eval()

static int vgs_eval ( struct VGSEvalState * state,
const struct VGSProgram * program,
int stack_level )
static

Interpreter for VGSProgram.

Its implementation is a simple switch-based dispatch.

To evaluate blocks (like if or call), it makes a recursive call with the subprogram allocated to the block.

Definition at line 1901 of file vf_drawvg.c.

Referenced by check_script(), drawvg_filter_frame(), and vgs_eval().

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( drawvg )

◆ cairo_format_from_pix_fmt()

static cairo_format_t cairo_format_from_pix_fmt ( DrawVGContext * ctx,
enum AVPixelFormat format )
static

Definition at line 2684 of file vf_drawvg.c.

Referenced by drawvg_config_props().

◆ drawvg_filter_frame()

static int drawvg_filter_frame ( AVFilterLink * inlink,
AVFrame * frame )
static

Definition at line 2708 of file vf_drawvg.c.

◆ drawvg_config_props()

static int drawvg_config_props ( AVFilterLink * inlink)
static

Definition at line 2767 of file vf_drawvg.c.

◆ drawvg_init()

static av_cold int drawvg_init ( AVFilterContext * ctx)
static

Definition at line 2781 of file vf_drawvg.c.

◆ drawvg_uninit()

static av_cold void drawvg_uninit ( AVFilterContext * ctx)
static

Definition at line 2816 of file vf_drawvg.c.

Variable Documentation

◆ vgs_default_vars

const char* const vgs_default_vars[]
static
Initial value:
= {
"n",
"t",
"ts",
"w",
"h",
"duration",
"cx",
"cy",
"i",
NULL,
}

Definition at line 82 of file vf_drawvg.c.

Referenced by vgs_parser_init().

◆ vgs_func1_names

const char* const vgs_func1_names[]
static
Initial value:
= {
"pathlen",
"randomg",
}

Definition at line 97 of file vf_drawvg.c.

Referenced by vgs_parse_numeric_argument().

◆ vgs_func1_impls

double(*const vgs_func1_impls[])(void *, double) ( void * ,
double  )
static
Initial value:
= {
}
static double vgs_fn_randomg(void *, double)
Function randomg(n) for av_expr_eval.
Definition vf_drawvg.c:1557
static double vgs_fn_pathlen(void *, double)
Function pathlen(n) for av_expr_eval.
Definition vf_drawvg.c:1493

Definition at line 106 of file vf_drawvg.c.

Referenced by vgs_parse_numeric_argument().

◆ vgs_func2_names

const char* const vgs_func2_names[]
static
Initial value:
= {
"p",
}

Definition at line 112 of file vf_drawvg.c.

Referenced by vgs_parse_numeric_argument().

◆ vgs_func2_impls

double(*const vgs_func2_impls[])(void *, double, double) ( void * ,
double ,
double  )
static
Initial value:
= {
}
static double vgs_fn_p(void *, double, double)
Function p(x, y) for av_expr_eval.
Definition vf_drawvg.c:1581

Definition at line 119 of file vf_drawvg.c.

Referenced by vgs_parse_numeric_argument().

◆ vgs_consts_line_cap

const struct VGSConstant vgs_consts_line_cap[]
static
Initial value:
= {
{ "butt", CAIRO_LINE_CAP_BUTT },
{ "round", CAIRO_LINE_CAP_ROUND },
{ "square", CAIRO_LINE_CAP_SQUARE },
{ NULL, 0 },
}

Definition at line 204 of file vf_drawvg.c.

◆ vgs_consts_line_join

const struct VGSConstant vgs_consts_line_join[]
static
Initial value:
= {
{ "bevel", CAIRO_LINE_JOIN_BEVEL },
{ "miter", CAIRO_LINE_JOIN_MITER },
{ "round", CAIRO_LINE_JOIN_ROUND },
{ NULL, 0 },
}

Definition at line 211 of file vf_drawvg.c.

◆ vgs_commands

const struct VGSCommandSpec vgs_commands[]
static

Definition at line 273 of file vf_drawvg.c.

Referenced by check_sorted_cmds_array(), and vgs_get_command().

◆ drawvg_options

const AVOption drawvg_options[]
static
Initial value:
= {
OPT("script", script_text, "script source to draw the graphics"),
OPT("s", script_text, "script source to draw the graphics"),
OPT("file", script_file, "file to load the script source"),
{ NULL }
}
#define OPT(name, field, help)
Definition vf_drawvg.c:2651

Definition at line 2663 of file vf_drawvg.c.

◆ drawvg_pix_fmts

enum AVPixelFormat drawvg_pix_fmts[]
static
Initial value:
= {
}
#define AV_PIX_FMT_0RGB32
Definition pixfmt.h:521
#define AV_PIX_FMT_X2RGB10
Definition pixfmt.h:619
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
#define AV_PIX_FMT_RGB565
Definition pixfmt.h:532
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:517

Definition at line 2675 of file vf_drawvg.c.

Referenced by cairo_format_from_pix_fmt().

◆ drawvg_inputs

const AVFilterPad drawvg_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = drawvg_filter_frame,
.config_props = drawvg_config_props,
},
}
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition filters.h:59
static int drawvg_config_props(AVFilterLink *inlink)
Definition vf_drawvg.c:2767
static int drawvg_filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition vf_drawvg.c:2708

Definition at line 2821 of file vf_drawvg.c.

◆ ff_vf_drawvg

const FFFilter ff_vf_drawvg
Initial value:
= {
.p.name = "drawvg",
.p.description = NULL_IF_CONFIG_SMALL("Draw vector graphics on top of video frames."),
.p.priv_class = &drawvg_class,
.priv_size = sizeof(DrawVGContext),
}
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#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:196
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:244
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static const AVFilterPad drawvg_inputs[]
Definition vf_drawvg.c:2821
static enum AVPixelFormat drawvg_pix_fmts[]
Definition vf_drawvg.c:2675
static av_cold int drawvg_init(AVFilterContext *ctx)
Definition vf_drawvg.c:2781
static av_cold void drawvg_uninit(AVFilterContext *ctx)
Definition vf_drawvg.c:2816
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

Definition at line 2831 of file vf_drawvg.c.