History

avfilter/vf_curves: add commands support

Paul B Mahol committed 5 years ago

Commit d7cb8c51 parent b6327612 files · +63 −15Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_curves.c +59 −15
doc/filters.texi+4−0
@@ -9257,6 +9257,10 @@ Save Gnuplot script of the curves in specified file. · 9256 unmodified lines
92579257 To avoid some filtergraph syntax conflicts, each key points list need to be
92589258 defined using the following syntax: @code{x0/y0 x1/y1 x2/y2 ...}.
92599259
9260+@subsection Commands
9261+
9262+This filter supports same @ref{commands} as options.
9263+
92609264 @subsection Examples
92619265
92629266 @itemize
libavfilter/vf_curves.c+59−15
@@ -69,8 +69,10 @@ typedef struct CurvesContext { · 68 unmodified lines
6969 uint8_t rgba_map[4];
7070 int step;
7171 char *plot_filename;
72+ int saved_plot;
7273 int is_16bit;
7374 int depth;
75+ int parsed_psfile;
7476
7577 int (*filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
7678 } CurvesContext;
@@ -80,20 +82,20 @@ typedef struct ThreadData { · 3 unmodified lines
8082 } ThreadData;
8183
8284 #define OFFSET(x) offsetof(CurvesContext, x)
83−#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
85+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
8486 static const AVOption curves_options[] = {
8587 { "preset", "select a color curves preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=PRESET_NONE}, PRESET_NONE, NB_PRESETS-1, FLAGS, "preset_name" },
86− { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NONE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
87− { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
88− { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
89− { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
90− { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
91− { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
92− { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
93− { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
94− { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
95− { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
96− { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
88+ { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NONE}, 0, 0, FLAGS, "preset_name" },
89+ { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, 0, 0, FLAGS, "preset_name" },
90+ { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, 0, 0, FLAGS, "preset_name" },
91+ { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, 0, 0, FLAGS, "preset_name" },
92+ { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, 0, 0, FLAGS, "preset_name" },
93+ { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, 0, 0, FLAGS, "preset_name" },
94+ { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, 0, 0, FLAGS, "preset_name" },
95+ { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, 0, 0, FLAGS, "preset_name" },
96+ { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, 0, 0, FLAGS, "preset_name" },
97+ { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, 0, 0, FLAGS, "preset_name" },
98+ { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, 0, 0, FLAGS, "preset_name" },
9799 { "master","set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
98100 { "m", "set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
99101 { "red", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
@@ -486,10 +488,11 @@ static av_cold int curves_init(AVFilterContext *ctx) · 386 unmodified lines
486488 }
487489 }
488490
489− if (curves->psfile) {
491+ if (curves->psfile && !curves->parsed_psfile) {
490492 ret = parse_psfile(ctx, curves->psfile);
491493 if (ret < 0)
492494 return ret;
495+ curves->parsed_psfile = 1;
493496 }
494497
495498 if (curves->preset != PRESET_NONE) {
@@ -504,6 +507,7 @@ static av_cold int curves_init(AVFilterContext *ctx) · 8 unmodified lines
504507 SET_COMP_IF_NOT_SET(1, g);
505508 SET_COMP_IF_NOT_SET(2, b);
506509 SET_COMP_IF_NOT_SET(3, master);
510+ curves->preset = PRESET_NONE;
507511 }
508512
509513 return 0;
@@ -664,7 +668,8 @@ static int config_input(AVFilterLink *inlink) · 154 unmodified lines
664668 curves->filter_slice = desc->flags & AV_PIX_FMT_FLAG_PLANAR ? filter_slice_planar : filter_slice_packed;
665669
666670 for (i = 0; i < NB_COMP + 1; i++) {
667− curves->graph[i] = av_mallocz_array(curves->lut_size, sizeof(*curves->graph[0]));
671+ if (!curves->graph[i])
672+ curves->graph[i] = av_mallocz_array(curves->lut_size, sizeof(*curves->graph[0]));
668673 if (!curves->graph[i])
669674 return AVERROR(ENOMEM);
670675 ret = parse_points_str(ctx, comp_points + i, curves->comp_points_str[i], curves->lut_size);
@@ -699,8 +704,10 @@ static int config_input(AVFilterLink *inlink) · 28 unmodified lines
699704 }
700705 }
701706
702− if (curves->plot_filename)
707+ if (curves->plot_filename && !curves->saved_plot) {
703708 dump_curves(curves->plot_filename, curves->graph, comp_points, curves->lut_size);
709+ curves->saved_plot = 1;
710+ }
704711
705712 for (i = 0; i < NB_COMP + 1; i++) {
706713 struct keypoint *point = comp_points[i];
@@ -743,6 +750,42 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 36 unmodified lines
743750 return ff_filter_frame(outlink, out);
744751 }
745752
753+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
754+ char *res, int res_len, int flags)
755+{
756+ CurvesContext *curves = ctx->priv;
757+ int ret;
758+
759+ if (!strcmp(cmd, "plot")) {
760+ curves->saved_plot = 0;
761+ } else if (!strcmp(cmd, "all") || !strcmp(cmd, "preset") || !strcmp(cmd, "psfile")) {
762+ if (!strcmp(cmd, "psfile"))
763+ curves->parsed_psfile = 0;
764+ av_freep(&curves->comp_points_str_all);
765+ av_freep(&curves->comp_points_str[0]);
766+ av_freep(&curves->comp_points_str[1]);
767+ av_freep(&curves->comp_points_str[2]);
768+ av_freep(&curves->comp_points_str[NB_COMP]);
769+ } else if (!strcmp(cmd, "red") || !strcmp(cmd, "r")) {
770+ av_freep(&curves->comp_points_str[0]);
771+ } else if (!strcmp(cmd, "green") || !strcmp(cmd, "g")) {
772+ av_freep(&curves->comp_points_str[1]);
773+ } else if (!strcmp(cmd, "blue") || !strcmp(cmd, "b")) {
774+ av_freep(&curves->comp_points_str[2]);
775+ } else if (!strcmp(cmd, "master") || !strcmp(cmd, "m")) {
776+ av_freep(&curves->comp_points_str[NB_COMP]);
777+ }
778+
779+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
780+ if (ret < 0)
781+ return ret;
782+
783+ ret = curves_init(ctx);
784+ if (ret < 0)
785+ return ret;
786+ return config_input(ctx->inputs[0]);
787+}
788+
746789 static av_cold void curves_uninit(AVFilterContext *ctx)
747790 {
748791 int i;
@@ -781,4 +824,5 @@ AVFilter ff_vf_curves = { · 32 unmodified lines
781824 .outputs = curves_outputs,
782825 .priv_class = &curves_class,
783826 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
827+ .process_command = process_command,
784828 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t