Commit 4f484eda authored by Paul B Mahol's avatar Paul B Mahol

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: 's avatarPaul B Mahol <onemda@gmail.com>
parent 92a0a6be
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment