|
FFmpeg
|
#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. More... | |
| #define | VAR_COUNT (VAR_U0 + USER_VAR_COUNT) |
| Total number of variables (default- and user-variables). More... | |
| #define | MAX_COMMAND_PARAMS 8 |
| #define | MAX_PROC_ARGS (MAX_COMMAND_PARAMS - 2) |
| #define | VGS_MAX_RECURSION_DEPTH 100 |
| #define | PARAMS(...) (const struct VGSParameter[]){ __VA_ARGS__ } |
| #define | L(...) PARAMS(__VA_ARGS__, { PARAM_END }) |
| #define | R(...) PARAMS(__VA_ARGS__, { PARAM_MAY_REPEAT }) |
| #define | NONE PARAMS({ PARAM_END }) |
| #define | N { PARAM_NUMERIC } |
| #define | V { PARAM_VAR_NAME } |
| #define | P { PARAM_SUBPROGRAM } |
| #define | C(c) { PARAM_CONSTANT, .constants = c } |
| #define | WORD_SEPARATOR " \n\t\r," |
| #define | FAIL(err) |
| #define | RANDOM_STATES 4 |
Number of different states for the randomg function. More... | |
| #define | ASSERT_ARGS(n) av_assert0(statement->args_count == 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. More... | |
Functions | |
| static double | vgs_fn_pathlen (void *data, double arg) |
Function pathlen(n) for av_expr_eval. More... | |
| static double | vgs_fn_randomg (void *data, double arg) |
Function randomg(n) for av_expr_eval. More... | |
| static double | vgs_fn_p (void *data, double x0, double y0) |
Function p(x, y) for av_expr_eval. More... | |
| static int | vgs_comp_command_spec (const void *cs1, const void *cs2) |
Comparator for VGSCommandDecl, to be used with bsearch(3). More... | |
| static const struct VGSCommandSpec * | vgs_get_command (const char *name, size_t length) |
Return the specs for the given command, or NULL if the name is not valid. More... | |
| static int | vgs_cmd_change_path (enum VGSCommand cmd) |
Return 1 if the command changes the current path in the cairo context. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| static void | vgs_free (struct VGSProgram *program) |
| Release the memory allocated by the program. More... | |
| static int | vgs_parse (void *log_ctx, struct VGSParser *parser, struct VGSProgram *program, int subprogram) |
| Build a program by parsing a script. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| 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 |
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.
| #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.
| #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.
| #define MAX_COMMAND_PARAMS 8 |
Definition at line 240 of file vf_drawvg.c.
| #define MAX_PROC_ARGS (MAX_COMMAND_PARAMS - 2) |
Definition at line 246 of file vf_drawvg.c.
| #define VGS_MAX_RECURSION_DEPTH 100 |
Definition at line 248 of file vf_drawvg.c.
| #define PARAMS | ( | ... | ) | (const struct VGSParameter[]){ __VA_ARGS__ } |
Definition at line 259 of file vf_drawvg.c.
| #define L | ( | ... | ) | PARAMS(__VA_ARGS__, { PARAM_END }) |
Definition at line 260 of file vf_drawvg.c.
| #define R | ( | ... | ) | PARAMS(__VA_ARGS__, { PARAM_MAY_REPEAT }) |
Definition at line 261 of file vf_drawvg.c.
| #define NONE PARAMS({ PARAM_END }) |
Definition at line 262 of file vf_drawvg.c.
| #define N { PARAM_NUMERIC } |
Definition at line 265 of file vf_drawvg.c.
| #define V { PARAM_VAR_NAME } |
Definition at line 266 of file vf_drawvg.c.
| #define P { PARAM_SUBPROGRAM } |
Definition at line 267 of file vf_drawvg.c.
Definition at line 268 of file vf_drawvg.c.
| #define WORD_SEPARATOR " \n\t\r," |
| #define FAIL | ( | err | ) |
| #define RANDOM_STATES 4 |
Number of different states for the randomg function.
Definition at line 1417 of file vf_drawvg.c.
| #define ASSERT_ARGS | ( | n | ) | av_assert0(statement->args_count == n) |
| #define MAY_PRESERVE | ( | funcname | ) |
Definition at line 2651 of file vf_drawvg.c.
| 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.
| 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 |
| VAR_U0 | User variables. |
Definition at line 59 of file vf_drawvg.c.
| enum VGSCommand |
Definition at line 135 of file vf_drawvg.c.
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.
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.
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.
|
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().
|
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().
|
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().
|
static |
Definition at line 420 of file vf_drawvg.c.
Referenced by vgs_eval().
|
static |
Definition at line 424 of file vf_drawvg.c.
Referenced by vgs_eval(), and vgs_eval_state_init().
|
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().
|
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().
|
static |
Definition at line 514 of file vf_drawvg.c.
|
static |
Return the next token in the source.
| [out] | token | Next token. |
| [in] | advance | If true, the cursor is updated after finding a token. |
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().
|
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().
|
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().
|
static |
Definition at line 702 of file vf_drawvg.c.
Referenced by vgs_free().
|
static |
Definition at line 748 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument(), and vgs_parse_statement().
|
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().
|
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().
|
static |
Definition at line 937 of file vf_drawvg.c.
Referenced by vgs_parse_statement().
|
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().
|
static |
Definition at line 1298 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_init().
|
static |
Definition at line 1311 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_init().
|
static |
Definition at line 1645 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_filter_frame().
|
static |
Definition at line 1676 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_filter_frame().
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().
|
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().
|
static |
Similar to quad_curve_to, but for cubic curves.
Definition at line 1762 of file vf_drawvg.c.
Referenced by vgs_eval().
|
static |
Definition at line 1809 of file vf_drawvg.c.
Referenced by vgs_eval().
Definition at line 1827 of file vf_drawvg.c.
Referenced by vgs_eval().
|
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(), and drawvg_filter_frame().
| AVFILTER_DEFINE_CLASS | ( | drawvg | ) |
|
static |
Definition at line 2684 of file vf_drawvg.c.
Referenced by drawvg_config_props().
|
static |
Definition at line 2708 of file vf_drawvg.c.
|
static |
Definition at line 2767 of file vf_drawvg.c.
|
static |
Definition at line 2781 of file vf_drawvg.c.
|
static |
Definition at line 2816 of file vf_drawvg.c.
|
static |
Definition at line 82 of file vf_drawvg.c.
Referenced by vgs_parser_init().
|
static |
Definition at line 97 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
Definition at line 106 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
|
static |
Definition at line 112 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
Definition at line 119 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
|
static |
Definition at line 204 of file vf_drawvg.c.
|
static |
Definition at line 211 of file vf_drawvg.c.
|
static |
Definition at line 273 of file vf_drawvg.c.
Referenced by check_sorted_cmds_array(), and vgs_get_command().
|
static |
|
static |
Definition at line 2675 of file vf_drawvg.c.
Referenced by cairo_format_from_pix_fmt().
|
static |
Definition at line 2821 of file vf_drawvg.c.
| const FFFilter ff_vf_drawvg |
Definition at line 2831 of file vf_drawvg.c.
1.8.17