aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2018-04-28 11:25:43 +0200
committerPaul B Mahol <onemda@gmail.com>2018-04-28 11:25:43 +0200
commit4f484edaa7ca839fa230f9e3aace14acfcceba56 (patch)
tree4ac8eba6e2ddafe4e1e538f98864fa3a0bd8bbb4
parent92a0a6bea9dc3087fa8d232b750db1dd0d70b157 (diff)
downloadffmpeg-4f484edaa7ca839fa230f9e3aace14acfcceba56.tar.gz
avfilter/vf_convolution: make rdiv set to 0 more useful
Use 0 for signaling that rdiv will be calculated from sum of all matrix elements. Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--doc/filters.texi1
-rw-r--r--libavfilter/vf_convolution.c15
2 files changed, 12 insertions, 4 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index 44e0801f9c..e1b0534c95 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6401,6 +6401,7 @@ Matrix is sequence of 9, 25 or 49 signed integers.
@item 2rdiv
@item 3rdiv
Set multiplier for calculated value for each plane.
+If unset or 0, it will be sum of all matrix elements.
@item 0bias
@item 1bias
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c
index ce09e338cc..e9b1f4abe8 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -63,10 +63,10 @@ static const AVOption convolution_options[] = {
{ "1m", "set matrix for 2nd plane", OFFSET(matrix_str[1]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
{ "2m", "set matrix for 3rd plane", OFFSET(matrix_str[2]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
{ "3m", "set matrix for 4th plane", OFFSET(matrix_str[3]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
- { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
- { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
- { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
- { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
+ { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
+ { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
+ { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
+ { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
{ "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
{ "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
{ "2bias", "set bias for 3rd plane", OFFSET(bias[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
@@ -965,6 +965,7 @@ static av_cold int init(AVFilterContext *ctx)
for (i = 0; i < 4; i++) {
int *matrix = (int *)s->matrix[i];
char *p, *arg, *saveptr = NULL;
+ float sum = 0;
p = s->matrix_str[i];
while (s->matrix_length[i] < 49) {
@@ -973,6 +974,7 @@ static av_cold int init(AVFilterContext *ctx)
p = NULL;
sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
+ sum += matrix[s->matrix_length[i]];
s->matrix_length[i]++;
}
@@ -998,6 +1000,11 @@ static av_cold int init(AVFilterContext *ctx)
return AVERROR(EINVAL);
}
+ if (sum == 0)
+ sum = 1;
+ if (s->rdiv[i] == 0)
+ s->rdiv[i] = 1. / sum;
+
if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.))
s->copy[i] = 0;
}