summaryrefslogtreecommitdiff
path: root/libavfilter/vf_convolution.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2020-12-11 18:28:12 +0100
committerPaul B Mahol <onemda@gmail.com>2020-12-11 18:33:48 +0100
commitd76469378d44e17e974499f67248017b750f28bf (patch)
treeec26f7bc37993b1de44472faadf1304aac7ecbe2 /libavfilter/vf_convolution.c
parent7adb747fd760dc756f23d642ee902f6a1389fc97 (diff)
avfilter/vf_convolution: add support for commands
Diffstat (limited to 'libavfilter/vf_convolution.c')
-rw-r--r--libavfilter/vf_convolution.c66
1 files changed, 47 insertions, 19 deletions
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c
index 5909feaad1..3674f5b590 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -31,7 +31,7 @@
#include "video.h"
#define OFFSET(x) offsetof(ConvolutionContext, x)
-#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
static const AVOption convolution_options[] = {
{ "0m", "set matrix for 1st plane", OFFSET(matrix_str[0]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
@@ -644,20 +644,25 @@ static av_cold int init(AVFilterContext *ctx)
float sum = 0;
p = s->matrix_str[i];
- while (s->matrix_length[i] < 49) {
- if (!(arg = av_strtok(p, " ", &saveptr)))
- break;
-
- p = NULL;
- sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
- sum += matrix[s->matrix_length[i]];
- s->matrix_length[i]++;
+ if (p) {
+ s->matrix_length[i] = 0;
+
+ while (s->matrix_length[i] < 49) {
+ if (!(arg = av_strtok(p, " |", &saveptr)))
+ break;
+
+ p = NULL;
+ sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
+ sum += matrix[s->matrix_length[i]];
+ s->matrix_length[i]++;
+ }
+
+ if (!(s->matrix_length[i] & 1)) {
+ av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
+ return AVERROR(EINVAL);
+ }
}
- if (!(s->matrix_length[i] & 1)) {
- av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
- return AVERROR(EINVAL);
- }
if (s->mode[i] == MATRIX_ROW) {
s->filter[i] = filter_row;
s->setup[i] = setup_row;
@@ -668,24 +673,31 @@ static av_cold int init(AVFilterContext *ctx)
s->size[i] = s->matrix_length[i];
} else if (s->matrix_length[i] == 9) {
s->size[i] = 3;
- if (!memcmp(matrix, same3x3, sizeof(same3x3)))
+
+ if (!memcmp(matrix, same3x3, sizeof(same3x3))) {
s->copy[i] = 1;
- else
+ } else {
s->filter[i] = filter_3x3;
+ s->copy[i] = 0;
+ }
s->setup[i] = setup_3x3;
} else if (s->matrix_length[i] == 25) {
s->size[i] = 5;
- if (!memcmp(matrix, same5x5, sizeof(same5x5)))
+ if (!memcmp(matrix, same5x5, sizeof(same5x5))) {
s->copy[i] = 1;
- else
+ } else {
s->filter[i] = filter_5x5;
+ s->copy[i] = 0;
+ }
s->setup[i] = setup_5x5;
} else if (s->matrix_length[i] == 49) {
s->size[i] = 7;
- if (!memcmp(matrix, same7x7, sizeof(same7x7)))
+ if (!memcmp(matrix, same7x7, sizeof(same7x7))) {
s->copy[i] = 1;
- else
+ } else {
s->filter[i] = filter_7x7;
+ s->copy[i] = 0;
+ }
s->setup[i] = setup_7x7;
} else {
return AVERROR(EINVAL);
@@ -737,6 +749,18 @@ static av_cold int init(AVFilterContext *ctx)
return 0;
}
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ int ret;
+
+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+ if (ret < 0)
+ return ret;
+
+ return init(ctx);
+}
+
static const AVFilterPad convolution_inputs[] = {
{
.name = "default",
@@ -767,6 +791,7 @@ AVFilter ff_vf_convolution = {
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_CONVOLUTION_FILTER */
@@ -792,6 +817,7 @@ AVFilter ff_vf_prewitt = {
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_PREWITT_FILTER */
@@ -817,6 +843,7 @@ AVFilter ff_vf_sobel = {
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_SOBEL_FILTER */
@@ -842,6 +869,7 @@ AVFilter ff_vf_roberts = {
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_ROBERTS_FILTER */