From 964465eb1ae680d5c5db6de35e54bb52bf99d040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Mon, 10 Oct 2011 21:09:30 +0200 Subject: [PATCH] libmodplug: simpler and faster use of eval expr. --- libavformat/libmodplug.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c index fe35992d62..4abba18486 100644 --- a/libavformat/libmodplug.c +++ b/libavformat/libmodplug.c @@ -55,7 +55,7 @@ typedef struct ModPlugContext { int fsize; ///< constant frame size int linesize; ///< line size in bytes char *color_eval; ///< color eval user input expression - int eval_err; ///< 1 if eval failed once, otherwise 0 (used to disable video) + AVExpr *expr; ///< parsed color eval expression } ModPlugContext; static const char *var_names[] = { @@ -167,7 +167,7 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap) AVIOContext *pb = s->pb; ModPlug_Settings settings; ModPlugContext *modplug = s->priv_data; - int sz = avio_size(pb); + int r, sz = avio_size(pb); if (sz < 0) { av_log(s, AV_LOG_WARNING, "Could not determine file size\n"); @@ -178,6 +178,12 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap) "but demuxing is likely to fail due to incomplete buffer\n", sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz); } + + r = av_expr_parse(&modplug->expr, modplug->color_eval, var_names, + NULL, NULL, NULL, NULL, 0, s); + if (r < 0) + return r; + modplug->buf = av_malloc(modplug->max_size); if (!modplug->buf) return AVERROR(ENOMEM); @@ -294,23 +300,14 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt) PRINT_INFO(5, "ts", VAR_TIME); } - if (modplug->color_eval && !modplug->eval_err) { + if (modplug->expr) { int x, y; for (y = 0; y < modplug->h; y++) { for (x = 0; x < modplug->w; x++) { double color; - var_values[VAR_X] = x; var_values[VAR_Y] = y; - if (av_expr_parse_and_eval(&color, modplug->color_eval, - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, s) < 0) { - av_log(s, AV_LOG_ERROR, - "Error while evaluating the expression '%s' with x=%d y=%d\n", - modplug->color_eval, x, y); - modplug->eval_err = 1; - return 0; - } + color = av_expr_eval(modplug->expr, var_values, NULL); pkt->data[y*modplug->linesize + x*3 + 2] |= av_clip((int)color, 0, 0xf)<<4; } }