aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2011-12-05 00:56:21 +0100
committerLuca Barbato <lu_zero@gentoo.org>2011-12-07 12:11:14 +0100
commitf5edfc9e92d1340cd50385081e563da226940e4e (patch)
tree83b3a465433a83e86420ae59b1efc2a621031bce /libavfilter
parent73585620b8a1d170133c8e41e557d4ec5f648888 (diff)
downloadffmpeg-f5edfc9e92d1340cd50385081e563da226940e4e.tar.gz
drawtext: introduce rand(min, max)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_drawtext.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index cd4386a483..87c8d8f8ac 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -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]);