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
9257To avoid some filtergraph syntax conflicts, each key points list need to be9257To avoid some filtergraph syntax conflicts, each key points list need to be
9258defined using the following syntax: @code{x0/y0 x1/y1 x2/y2 ...}.9258defined using the following syntax: @code{x0/y0 x1/y1 x2/y2 ...}.
9259 9259
9260@subsection Commands
9261
9262This filter supports same @ref{commands} as options.
9263
9260@subsection Examples9264@subsection Examples
9261 9265
9262@itemize9266@itemize
libavfilter/vf_curves.c+59−15
@@ -69,8 +69,10 @@ typedef struct CurvesContext { · 68 unmodified lines
69 uint8_t rgba_map[4];69 uint8_t rgba_map[4];
70 int step;70 int step;
71 char *plot_filename;71 char *plot_filename;
72 int saved_plot;
72 int is_16bit;73 int is_16bit;
73 int depth;74 int depth;
75 int parsed_psfile;
74 76
75 int (*filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);77 int (*filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
76} CurvesContext;78} CurvesContext;
@@ -80,20 +82,20 @@ typedef struct ThreadData { · 3 unmodified lines
80} ThreadData;82} ThreadData;
81 83
82#define OFFSET(x) offsetof(CurvesContext, x)84#define OFFSET(x) offsetof(CurvesContext, x)
83#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM85#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
84static const AVOption curves_options[] = {86static const AVOption curves_options[] = {
85 { "preset", "select a color curves preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=PRESET_NONE}, PRESET_NONE, NB_PRESETS-1, FLAGS, "preset_name" },87 { "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" },88 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NONE}, 0, 0, FLAGS, "preset_name" },
87 { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },89 { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, 0, 0, FLAGS, "preset_name" },
88 { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, INT_MIN, INT_MAX, FLAGS, "preset_name" },90 { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, 0, 0, FLAGS, "preset_name" },
89 { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },91 { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, 0, 0, FLAGS, "preset_name" },
90 { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },92 { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, 0, 0, FLAGS, "preset_name" },
91 { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },93 { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, 0, 0, FLAGS, "preset_name" },
92 { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },94 { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, 0, 0, FLAGS, "preset_name" },
93 { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },95 { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, 0, 0, FLAGS, "preset_name" },
94 { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },96 { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, 0, 0, FLAGS, "preset_name" },
95 { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },97 { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, 0, 0, FLAGS, "preset_name" },
96 { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },98 { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, 0, 0, FLAGS, "preset_name" },
97 { "master","set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },99 { "master","set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
98 { "m", "set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },100 { "m", "set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
99 { "red", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },101 { "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
486 }488 }
487 }489 }
488 490
489 if (curves->psfile) {491 if (curves->psfile && !curves->parsed_psfile) {
490 ret = parse_psfile(ctx, curves->psfile);492 ret = parse_psfile(ctx, curves->psfile);
491 if (ret < 0)493 if (ret < 0)
492 return ret;494 return ret;
495 curves->parsed_psfile = 1;
493 }496 }
494 497
495 if (curves->preset != PRESET_NONE) {498 if (curves->preset != PRESET_NONE) {
@@ -504,6 +507,7 @@ static av_cold int curves_init(AVFilterContext *ctx) · 8 unmodified lines
504 SET_COMP_IF_NOT_SET(1, g);507 SET_COMP_IF_NOT_SET(1, g);
505 SET_COMP_IF_NOT_SET(2, b);508 SET_COMP_IF_NOT_SET(2, b);
506 SET_COMP_IF_NOT_SET(3, master);509 SET_COMP_IF_NOT_SET(3, master);
510 curves->preset = PRESET_NONE;
507 }511 }
508 512
509 return 0;513 return 0;
@@ -664,7 +668,8 @@ static int config_input(AVFilterLink *inlink) · 154 unmodified lines
664 curves->filter_slice = desc->flags & AV_PIX_FMT_FLAG_PLANAR ? filter_slice_planar : filter_slice_packed;668 curves->filter_slice = desc->flags & AV_PIX_FMT_FLAG_PLANAR ? filter_slice_planar : filter_slice_packed;
665 669
666 for (i = 0; i < NB_COMP + 1; i++) {670 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]));
668 if (!curves->graph[i])673 if (!curves->graph[i])
669 return AVERROR(ENOMEM);674 return AVERROR(ENOMEM);
670 ret = parse_points_str(ctx, comp_points + i, curves->comp_points_str[i], curves->lut_size);675 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
699 }704 }
700 }705 }
701 706
702 if (curves->plot_filename)707 if (curves->plot_filename && !curves->saved_plot) {
703 dump_curves(curves->plot_filename, curves->graph, comp_points, curves->lut_size);708 dump_curves(curves->plot_filename, curves->graph, comp_points, curves->lut_size);
709 curves->saved_plot = 1;
710 }
704 711
705 for (i = 0; i < NB_COMP + 1; i++) {712 for (i = 0; i < NB_COMP + 1; i++) {
706 struct keypoint *point = comp_points[i];713 struct keypoint *point = comp_points[i];
@@ -743,6 +750,42 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 36 unmodified lines
743 return ff_filter_frame(outlink, out);750 return ff_filter_frame(outlink, out);
744}751}
745 752
753static 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
746static av_cold void curves_uninit(AVFilterContext *ctx)789static av_cold void curves_uninit(AVFilterContext *ctx)
747{790{
748 int i;791 int i;
@@ -781,4 +824,5 @@ AVFilter ff_vf_curves = { · 32 unmodified lines
781 .outputs = curves_outputs,824 .outputs = curves_outputs,
782 .priv_class = &curves_class,825 .priv_class = &curves_class,
783 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,826 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
827 .process_command = process_command,
784};828};

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