#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 },
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;
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);
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",
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_CONVOLUTION_FILTER */
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_PREWITT_FILTER */
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_SOBEL_FILTER */
.inputs = convolution_inputs,
.outputs = convolution_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
+ .process_command = process_command,
};
#endif /* CONFIG_ROBERTS_FILTER */