Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
f5edfc9e
Commit
f5edfc9e
authored
Dec 04, 2011
by
Luca Barbato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drawtext: introduce rand(min, max)
Signed-off-by:
Luca Barbato
<
lu_zero@gentoo.org
>
parent
73585620
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
7 deletions
+27
-7
vf_drawtext.c
libavfilter/vf_drawtext.c
+27
-7
No files found.
libavfilter/vf_drawtext.c
View file @
f5edfc9e
...
...
@@ -34,9 +34,11 @@
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/mathematics.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/tree.h"
#include "libavutil/lfg.h"
#include "avfilter.h"
#include "drawutils.h"
...
...
@@ -62,6 +64,22 @@ static const char *var_names[] = {
NULL
};
static
const
char
*
fun2_names
[]
=
{
"rand"
,
};
static
double
drand
(
void
*
opaque
,
double
min
,
double
max
)
{
return
val
=
min
+
(
max
-
min
)
/
UINT_MAX
*
av_lfg_get
(
opaque
);
}
typedef
double
(
*
eval_func2
)(
void
*
,
double
a
,
double
b
);
static
const
eval_func2
fun2
[]
=
{
drand
,
NULL
};
enum
var_name
{
VAR_E
,
VAR_PHI
,
...
...
@@ -119,6 +137,7 @@ typedef struct {
char
*
d_expr
;
AVExpr
*
d_pexpr
;
int
draw
;
///< set to zero to prevent drawing
AVLFG
prng
;
///< random
}
DrawTextContext
;
#define OFFSET(x) offsetof(DrawTextContext, x)
...
...
@@ -559,13 +578,14 @@ static int config_input(AVFilterLink *inlink)
dtext
->
var_values
[
VAR_N
]
=
0
;
dtext
->
var_values
[
VAR_T
]
=
NAN
;
av_lfg_init
(
&
dtext
->
prng
,
av_get_random_seed
());
if
((
ret
=
av_expr_parse
(
&
dtext
->
x_pexpr
,
dtext
->
x_expr
,
var_names
,
NULL
,
NULL
,
NULL
,
NULL
,
0
,
ctx
))
<
0
||
NULL
,
NULL
,
fun2_names
,
fun2
,
0
,
ctx
))
<
0
||
(
ret
=
av_expr_parse
(
&
dtext
->
y_pexpr
,
dtext
->
y_expr
,
var_names
,
NULL
,
NULL
,
NULL
,
NULL
,
0
,
ctx
))
<
0
||
NULL
,
NULL
,
fun2_names
,
fun2
,
0
,
ctx
))
<
0
||
(
ret
=
av_expr_parse
(
&
dtext
->
d_pexpr
,
dtext
->
d_expr
,
var_names
,
NULL
,
NULL
,
NULL
,
NULL
,
0
,
ctx
))
<
0
)
NULL
,
NULL
,
fun2_names
,
fun2
,
0
,
ctx
))
<
0
)
return
AVERROR
(
EINVAL
);
if
((
ret
=
...
...
@@ -792,14 +812,14 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
dtext
->
var_values
[
VAR_T
]
=
inpicref
->
pts
==
AV_NOPTS_VALUE
?
NAN
:
inpicref
->
pts
*
av_q2d
(
inlink
->
time_base
);
dtext
->
var_values
[
VAR_X
]
=
av_expr_eval
(
dtext
->
x_pexpr
,
dtext
->
var_values
,
NULL
);
av_expr_eval
(
dtext
->
x_pexpr
,
dtext
->
var_values
,
&
dtext
->
prng
);
dtext
->
var_values
[
VAR_Y
]
=
av_expr_eval
(
dtext
->
y_pexpr
,
dtext
->
var_values
,
NULL
);
av_expr_eval
(
dtext
->
y_pexpr
,
dtext
->
var_values
,
&
dtext
->
prng
);
dtext
->
var_values
[
VAR_X
]
=
av_expr_eval
(
dtext
->
x_pexpr
,
dtext
->
var_values
,
NULL
);
av_expr_eval
(
dtext
->
x_pexpr
,
dtext
->
var_values
,
&
dtext
->
prng
);
dtext
->
draw
=
fail
?
0
:
av_expr_eval
(
dtext
->
d_pexpr
,
dtext
->
var_values
,
NULL
);
av_expr_eval
(
dtext
->
d_pexpr
,
dtext
->
var_values
,
&
dtext
->
prng
);
normalize_double
(
&
dtext
->
x
,
dtext
->
var_values
[
VAR_X
]);
normalize_double
(
&
dtext
->
y
,
dtext
->
var_values
[
VAR_Y
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment