aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStone Chen <chen.stonechen@gmail.com>2024-02-24 11:08:02 -0500
committerMarton Balint <cus@passwd.hu>2024-02-25 10:49:37 +0100
commitef917950f0298a812bebfed2443626972a7d8f29 (patch)
tree72abca1c41975b11c9a1650cf0842f9c190a9a31
parent9b90d0d36ad1ff6bed5007fa71e6e661d0c20bbd (diff)
downloadffmpeg-ef917950f0298a812bebfed2443626972a7d8f29.tar.gz
avfilter/vf_convolution: add float user_rdiv[4] to allow user options to apply correctly
Previously to support dynamic reconfigurations of the matrix string (e.g. 0m), the rdiv values would always be cleared to 0.f, causing the rdiv to be recalculated based on the new filter. This however had the side effect of always ignoring user specified rdiv values. Instead float user_rdiv[0] is added to ConvolutionContext which will store the user specified rdiv values. Then the original rdiv array will store either the user_rdiv or the automatically calculated 1/sum. This fixes trac ticket #10294, #10867. Signed-off-by: Stone Chen <chen.stonechen@gmail.com> Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r--libavfilter/convolution.h3
-rw-r--r--libavfilter/vf_convolution.c10
2 files changed, 7 insertions, 6 deletions
diff --git a/libavfilter/convolution.h b/libavfilter/convolution.h
index e44bfb5da8..ee7477ef89 100644
--- a/libavfilter/convolution.h
+++ b/libavfilter/convolution.h
@@ -34,13 +34,14 @@ typedef struct ConvolutionContext {
const AVClass *class;
char *matrix_str[4];
- float rdiv[4];
+ float user_rdiv[4];
float bias[4];
int mode[4];
float scale;
float delta;
int planes;
+ float rdiv[4];
int size[4];
int depth;
int max;
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c
index bf67f392f6..88b89289a9 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -40,10 +40,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=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},
+ { "0rdiv", "set rdiv for 1st plane", OFFSET(user_rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
+ { "1rdiv", "set rdiv for 2nd plane", OFFSET(user_rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
+ { "2rdiv", "set rdiv for 3rd plane", OFFSET(user_rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
+ { "3rdiv", "set rdiv for 4th plane", OFFSET(user_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},
@@ -674,7 +674,7 @@ static int param_init(AVFilterContext *ctx)
p = orig = av_strdup(s->matrix_str[i]);
if (p) {
s->matrix_length[i] = 0;
- s->rdiv[i] = 0.f;
+ s->rdiv[i] = s->user_rdiv[i];
sum = 0.f;
while (s->matrix_length[i] < 49) {