|
FFmpeg
|
#include <cairo.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 | 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 | C(v, o) ((uint32_t)(av_clipd(v, 0, 1) * 255) << o) |
| #define | OPT(name, field, help) |
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 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_numeric_argument (void *log_ctx, struct VGSParser *parser, struct VGSArgument *arg, int metadata) |
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) |
| Check if the next token is a numeric value, 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) |
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 75 of file vf_drawvg.c.
| #define VAR_COUNT (VAR_U0 + USER_VAR_COUNT) |
Total number of variables (default- and user-variables).
Definition at line 78 of file vf_drawvg.c.
| #define MAX_COMMAND_PARAMS 8 |
Definition at line 237 of file vf_drawvg.c.
| #define MAX_PROC_ARGS (MAX_COMMAND_PARAMS - 2) |
Definition at line 243 of file vf_drawvg.c.
| #define PARAMS | ( | ... | ) | (const struct VGSParameter[]){ __VA_ARGS__ } |
Definition at line 254 of file vf_drawvg.c.
| #define L | ( | ... | ) | PARAMS(__VA_ARGS__, { PARAM_END }) |
Definition at line 255 of file vf_drawvg.c.
| #define R | ( | ... | ) | PARAMS(__VA_ARGS__, { PARAM_MAY_REPEAT }) |
Definition at line 256 of file vf_drawvg.c.
| #define NONE PARAMS({ PARAM_END }) |
Definition at line 257 of file vf_drawvg.c.
| #define N { PARAM_NUMERIC } |
Definition at line 260 of file vf_drawvg.c.
| #define V { PARAM_VAR_NAME } |
Definition at line 261 of file vf_drawvg.c.
| #define P { PARAM_SUBPROGRAM } |
Definition at line 262 of file vf_drawvg.c.
Definition at line 263 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 1334 of file vf_drawvg.c.
| #define ASSERT_ARGS | ( | n | ) | av_assert0(statement->args_count == n) |
| #define MAY_PRESERVE | ( | funcname | ) |
| #define C | ( | v, | |
| o | |||
| ) | ((uint32_t)(av_clipd(v, 0, 1) * 255) << o) |
Definition at line 263 of file vf_drawvg.c.
Definition at line 2517 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 57 of file vf_drawvg.c.
| enum VGSCommand |
Definition at line 133 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 1401 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 1465 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 1489 of file vf_drawvg.c.
|
static |
Comparator for VGSCommandDecl, to be used with bsearch(3).
Definition at line 347 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 357 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 377 of file vf_drawvg.c.
Referenced by vgs_eval().
|
static |
Check if token is the value of str.
Definition at line 463 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 469 of file vf_drawvg.c.
Referenced by av_printf_format(), and vgs_parse_numeric_argument().
|
static |
Definition at line 492 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 522 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 706 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 1260 of file vf_drawvg.c.
Referenced by check_script(), drawvg_init(), and vgs_parse_statement().
|
static |
Definition at line 681 of file vf_drawvg.c.
Referenced by vgs_free().
|
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 726 of file vf_drawvg.c.
Referenced by vgs_parse_statement().
|
static |
Check if the next token is a numeric value, so the last command must be repeated.
Definition at line 830 of file vf_drawvg.c.
Referenced by vgs_parse_statement().
|
static |
Definition at line 868 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 892 of file vf_drawvg.c.
Referenced by vgs_parse().
|
static |
Definition at line 1229 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_init().
|
static |
Definition at line 1241 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_init().
|
static |
Definition at line 1534 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_filter_frame().
|
static |
Definition at line 1560 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 1575 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 1597 of file vf_drawvg.c.
Referenced by vgs_eval().
|
static |
Similar to quad_curve_to, but for cubic curves.
Definition at line 1646 of file vf_drawvg.c.
Referenced by vgs_eval().
|
static |
Definition at line 1693 of file vf_drawvg.c.
Referenced by vgs_eval().
Definition at line 1711 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 1785 of file vf_drawvg.c.
Referenced by check_script(), and drawvg_filter_frame().
| AVFILTER_DEFINE_CLASS | ( | drawvg | ) |
|
static |
Definition at line 2550 of file vf_drawvg.c.
Referenced by drawvg_config_props().
|
static |
Definition at line 2574 of file vf_drawvg.c.
|
static |
Definition at line 2633 of file vf_drawvg.c.
|
static |
Definition at line 2647 of file vf_drawvg.c.
|
static |
Definition at line 2682 of file vf_drawvg.c.
|
static |
Definition at line 80 of file vf_drawvg.c.
Referenced by vgs_parser_init().
|
static |
Definition at line 95 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
Definition at line 104 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
|
static |
Definition at line 110 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
Definition at line 117 of file vf_drawvg.c.
Referenced by vgs_parse_numeric_argument().
|
static |
Definition at line 202 of file vf_drawvg.c.
|
static |
Definition at line 209 of file vf_drawvg.c.
|
static |
Definition at line 268 of file vf_drawvg.c.
Referenced by check_sorted_cmds_array(), and vgs_get_command().
|
static |
|
static |
Definition at line 2541 of file vf_drawvg.c.
Referenced by cairo_format_from_pix_fmt().
|
static |
Definition at line 2687 of file vf_drawvg.c.
| const FFFilter ff_vf_drawvg |
Definition at line 2697 of file vf_drawvg.c.
1.8.17