mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-03-28 12:32:17 +02:00
libmodplug: simpler and faster use of eval expr.
This commit is contained in:
parent
d377deaaa3
commit
964465eb1a
@ -55,7 +55,7 @@ typedef struct ModPlugContext {
|
|||||||
int fsize; ///< constant frame size
|
int fsize; ///< constant frame size
|
||||||
int linesize; ///< line size in bytes
|
int linesize; ///< line size in bytes
|
||||||
char *color_eval; ///< color eval user input expression
|
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;
|
} ModPlugContext;
|
||||||
|
|
||||||
static const char *var_names[] = {
|
static const char *var_names[] = {
|
||||||
@ -167,7 +167,7 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|||||||
AVIOContext *pb = s->pb;
|
AVIOContext *pb = s->pb;
|
||||||
ModPlug_Settings settings;
|
ModPlug_Settings settings;
|
||||||
ModPlugContext *modplug = s->priv_data;
|
ModPlugContext *modplug = s->priv_data;
|
||||||
int sz = avio_size(pb);
|
int r, sz = avio_size(pb);
|
||||||
|
|
||||||
if (sz < 0) {
|
if (sz < 0) {
|
||||||
av_log(s, AV_LOG_WARNING, "Could not determine file size\n");
|
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",
|
"but demuxing is likely to fail due to incomplete buffer\n",
|
||||||
sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz);
|
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);
|
modplug->buf = av_malloc(modplug->max_size);
|
||||||
if (!modplug->buf)
|
if (!modplug->buf)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -294,23 +300,14 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
PRINT_INFO(5, "ts", VAR_TIME);
|
PRINT_INFO(5, "ts", VAR_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modplug->color_eval && !modplug->eval_err) {
|
if (modplug->expr) {
|
||||||
int x, y;
|
int x, y;
|
||||||
for (y = 0; y < modplug->h; y++) {
|
for (y = 0; y < modplug->h; y++) {
|
||||||
for (x = 0; x < modplug->w; x++) {
|
for (x = 0; x < modplug->w; x++) {
|
||||||
double color;
|
double color;
|
||||||
|
|
||||||
var_values[VAR_X] = x;
|
var_values[VAR_X] = x;
|
||||||
var_values[VAR_Y] = y;
|
var_values[VAR_Y] = y;
|
||||||
if (av_expr_parse_and_eval(&color, modplug->color_eval,
|
color = av_expr_eval(modplug->expr, var_values, NULL);
|
||||||
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;
|
|
||||||
}
|
|
||||||
pkt->data[y*modplug->linesize + x*3 + 2] |= av_clip((int)color, 0, 0xf)<<4;
|
pkt->data[y*modplug->linesize + x*3 + 2] |= av_clip((int)color, 0, 0xf)<<4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user