Commit 8bdb1191 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '20b46f8f'

* commit '20b46f8f':
  vf_lut: switch to an AVOptions-based system.

Conflicts:
	doc/filters.texi
	libavfilter/vf_lut.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 94ec709e 20b46f8f
...@@ -3864,12 +3864,7 @@ to an output value, and apply it to input video. ...@@ -3864,12 +3864,7 @@ to an output value, and apply it to input video.
@var{lutyuv} applies a lookup table to a YUV input video, @var{lutrgb} @var{lutyuv} applies a lookup table to a YUV input video, @var{lutrgb}
to an RGB input video. to an RGB input video.
These filters accept in input a ":"-separated list of options, which These filters accept the following options:
specify the expressions used for computing the lookup table for the
corresponding pixel component values.
The @var{lut} filter requires either YUV or RGB pixel formats in
input, and accepts the options:
@table @option @table @option
@item c0 @item c0
set first pixel component expression set first pixel component expression
...@@ -3879,14 +3874,7 @@ set second pixel component expression ...@@ -3879,14 +3874,7 @@ set second pixel component expression
set third pixel component expression set third pixel component expression
@item c3 @item c3
set fourth pixel component expression, corresponds to the alpha component set fourth pixel component expression, corresponds to the alpha component
@end table
The exact component associated to each option depends on the format in
input.
The @var{lutrgb} filter requires RGB pixel formats in input, and
accepts the options:
@table @option
@item r @item r
set red component expression set red component expression
@item g @item g
...@@ -3895,21 +3883,24 @@ set green component expression ...@@ -3895,21 +3883,24 @@ set green component expression
set blue component expression set blue component expression
@item a @item a
alpha component expression alpha component expression
@end table
The @var{lutyuv} filter requires YUV pixel formats in input, and
accepts the options:
@table @option
@item y @item y
set Y/luminance component expression set Y/luminance component expression
@item u @item u
set U/Cb component expression set U/Cb component expression
@item v @item v
set V/Cr component expression set V/Cr component expression
@item a
set alpha component expression
@end table @end table
Each of them specifies the expression to use for computing the lookup table for
the corresponding pixel component values.
The exact component associated to each of the @var{c*} options depends on the
format in input.
The @var{lut} filter requires either YUV or RGB pixel formats in input,
@var{lutrgb} requires RGB pixel formats in input, and @var{lutyuv} requires YUV.
The expressions can contain the following constants and functions: The expressions can contain the following constants and functions:
@table @option @table @option
......
...@@ -672,6 +672,10 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque ...@@ -672,6 +672,10 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
!strcmp(filter->filter->name, "gradfun" ) || !strcmp(filter->filter->name, "gradfun" ) ||
!strcmp(filter->filter->name, "hqdn3d" ) || !strcmp(filter->filter->name, "hqdn3d" ) ||
!strcmp(filter->filter->name, "ocv" ) || !strcmp(filter->filter->name, "ocv" ) ||
!strcmp(filter->filter->name, "lut" ) ||
!strcmp(filter->filter->name, "lutyuv" ) ||
!strcmp(filter->filter->name, "lutrgb" ) ||
!strcmp(filter->filter->name, "negate" ) ||
!strcmp(filter->filter->name, "format") || !strcmp(filter->filter->name, "format") ||
!strcmp(filter->filter->name, "noformat") || !strcmp(filter->filter->name, "noformat") ||
!strcmp(filter->filter->name, "resample") || !strcmp(filter->filter->name, "resample") ||
......
...@@ -80,18 +80,18 @@ typedef struct { ...@@ -80,18 +80,18 @@ typedef struct {
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption options[] = { static const AVOption options[] = {
{"c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"y", "set Y expression", OFFSET(comp_expr_str[Y]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "y", "set Y expression", OFFSET(comp_expr_str[Y]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"u", "set U expression", OFFSET(comp_expr_str[U]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "u", "set U expression", OFFSET(comp_expr_str[U]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"v", "set V expression", OFFSET(comp_expr_str[V]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "v", "set V expression", OFFSET(comp_expr_str[V]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"r", "set R expression", OFFSET(comp_expr_str[R]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "r", "set R expression", OFFSET(comp_expr_str[R]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"g", "set G expression", OFFSET(comp_expr_str[G]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "g", "set G expression", OFFSET(comp_expr_str[G]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"b", "set B expression", OFFSET(comp_expr_str[B]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "b", "set B expression", OFFSET(comp_expr_str[B]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{"a", "set A expression", OFFSET(comp_expr_str[A]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX, FLAGS}, { "a", "set A expression", OFFSET(comp_expr_str[A]), AV_OPT_TYPE_STRING, { .str = "val" }, .flags = FLAGS },
{NULL}, { NULL },
}; };
static av_cold void uninit(AVFilterContext *ctx) static av_cold void uninit(AVFilterContext *ctx)
...@@ -333,11 +333,13 @@ static const AVFilterPad outputs[] = { ...@@ -333,11 +333,13 @@ static const AVFilterPad outputs[] = {
.type = AVMEDIA_TYPE_VIDEO, }, .type = AVMEDIA_TYPE_VIDEO, },
{ .name = NULL} { .name = NULL}
}; };
#define DEFINE_LUT_FILTER(name_, description_) \ #define DEFINE_LUT_FILTER(name_, description_) \
AVFilter avfilter_vf_##name_ = { \ AVFilter avfilter_vf_##name_ = { \
.name = #name_, \ .name = #name_, \
.description = NULL_IF_CONFIG_SMALL(description_), \ .description = NULL_IF_CONFIG_SMALL(description_), \
.priv_size = sizeof(LutContext), \ .priv_size = sizeof(LutContext), \
.priv_class = &name_ ## _class, \
\ \
.init = name_##_init, \ .init = name_##_init, \
.uninit = uninit, \ .uninit = uninit, \
...@@ -345,7 +347,6 @@ static const AVFilterPad outputs[] = { ...@@ -345,7 +347,6 @@ static const AVFilterPad outputs[] = {
\ \
.inputs = inputs, \ .inputs = inputs, \
.outputs = outputs, \ .outputs = outputs, \
.priv_class = &name_##_class, \
} }
#if CONFIG_LUT_FILTER #if CONFIG_LUT_FILTER
...@@ -355,15 +356,6 @@ AVFILTER_DEFINE_CLASS(lut); ...@@ -355,15 +356,6 @@ AVFILTER_DEFINE_CLASS(lut);
static int lut_init(AVFilterContext *ctx, const char *args) static int lut_init(AVFilterContext *ctx, const char *args)
{ {
LutContext *lut = ctx->priv;
int ret;
lut->class = &lut_class;
av_opt_set_defaults(lut);
if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
return ret;
return 0; return 0;
} }
...@@ -378,14 +370,8 @@ AVFILTER_DEFINE_CLASS(lutyuv); ...@@ -378,14 +370,8 @@ AVFILTER_DEFINE_CLASS(lutyuv);
static int lutyuv_init(AVFilterContext *ctx, const char *args) static int lutyuv_init(AVFilterContext *ctx, const char *args)
{ {
LutContext *lut = ctx->priv; LutContext *lut = ctx->priv;
int ret;
lut->class = &lutyuv_class;
lut->is_yuv = 1; lut->is_yuv = 1;
av_opt_set_defaults(lut);
if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
return ret;
return 0; return 0;
} }
...@@ -401,14 +387,8 @@ AVFILTER_DEFINE_CLASS(lutrgb); ...@@ -401,14 +387,8 @@ AVFILTER_DEFINE_CLASS(lutrgb);
static int lutrgb_init(AVFilterContext *ctx, const char *args) static int lutrgb_init(AVFilterContext *ctx, const char *args)
{ {
LutContext *lut = ctx->priv; LutContext *lut = ctx->priv;
int ret;
lut->class = &lutrgb_class;
lut->is_rgb = 1; lut->is_rgb = 1;
av_opt_set_defaults(lut);
if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0)
return ret;
return 0; return 0;
} }
...@@ -418,26 +398,30 @@ DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input vid ...@@ -418,26 +398,30 @@ DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input vid
#if CONFIG_NEGATE_FILTER #if CONFIG_NEGATE_FILTER
#define negate_options options static const AVOption negate_options[] = {
{ "negate_alpha", NULL, OFFSET(negate_alpha), AV_OPT_TYPE_INT, { .i64 = 0 }, .flags = FLAGS },
{ NULL },
};
AVFILTER_DEFINE_CLASS(negate); AVFILTER_DEFINE_CLASS(negate);
static int negate_init(AVFilterContext *ctx, const char *args) static int negate_init(AVFilterContext *ctx, const char *args)
{ {
LutContext *lut = ctx->priv; LutContext *lut = ctx->priv;
char lut_params[64]; int i;
if (args)
sscanf(args, "%d", &lut->negate_alpha);
av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", lut->negate_alpha); av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", lut->negate_alpha);
snprintf(lut_params, sizeof(lut_params), "c0=negval:c1=negval:c2=negval:a=%s", for (i = 0; i < 4; i++) {
lut->negate_alpha ? "negval" : "val"); lut->comp_expr_str[i] = av_strdup((i == 3 && !lut->negate_alpha) ?
"val" : "negval");
lut->class = &negate_class; if (!lut->comp_expr_str[i]) {
av_opt_set_defaults(lut); uninit(ctx);
return AVERROR(ENOMEM);
}
}
return av_set_options_string(lut, lut_params, "=", ":"); return lut_init(ctx, NULL);
} }
DEFINE_LUT_FILTER(negate, "Negate input video."); DEFINE_LUT_FILTER(negate, "Negate input video.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment