Use 0 for signaling that rdiv will be calculated from sum of all matrix elements.
Unified · Split
| @@ -6401,6 +6401,7 @@ Matrix is sequence of 9, 25 or 49 signed integers. · 6400 unmodified lines | ||
| 6401 | 6401 | @item 2rdiv |
| 6402 | 6402 | @item 3rdiv |
| 6403 | 6403 | Set multiplier for calculated value for each plane. |
| 6404 | +If unset or 0, it will be sum of all matrix elements. | |
| 6404 | 6405 | |
| 6405 | 6406 | @item 0bias |
| 6406 | 6407 | @item 1bias |
| @@ -63,10 +63,10 @@ static const AVOption convolution_options[] = { · 62 unmodified lines | ||
| 63 | 63 | { "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 }, |
| 64 | 64 | { "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 }, |
| 65 | 65 | { "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 }, |
| 66 | − { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS}, | |
| 67 | − { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS}, | |
| 68 | − { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS}, | |
| 69 | − { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS}, | |
| 66 | + { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS}, | |
| 67 | + { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS}, | |
| 68 | + { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS}, | |
| 69 | + { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS}, | |
| 70 | 70 | { "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS}, |
| 71 | 71 | { "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS}, |
| 72 | 72 | { "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) · 892 unmodified lines | ||
| 965 | 965 | for (i = 0; i < 4; i++) { |
| 966 | 966 | int *matrix = (int *)s->matrix[i]; |
| 967 | 967 | char *p, *arg, *saveptr = NULL; |
| 968 | + float sum = 0; | |
| 968 | 969 | |
| 969 | 970 | p = s->matrix_str[i]; |
| 970 | 971 | while (s->matrix_length[i] < 49) { |
| @@ -973,6 +974,7 @@ static av_cold int init(AVFilterContext *ctx) · 2 unmodified lines | ||
| 973 | 974 | |
| 974 | 975 | p = NULL; |
| 975 | 976 | sscanf(arg, "%d", &matrix[s->matrix_length[i]]); |
| 977 | + sum += matrix[s->matrix_length[i]]; | |
| 976 | 978 | s->matrix_length[i]++; |
| 977 | 979 | } |
| 978 | 980 | |
| @@ -998,6 +1000,11 @@ static av_cold int init(AVFilterContext *ctx) · 19 unmodified lines | ||
| 998 | 1000 | return AVERROR(EINVAL); |
| 999 | 1001 | } |
| 1000 | 1002 | |
| 1003 | + if (sum == 0) | |
| 1004 | + sum = 1; | |
| 1005 | + if (s->rdiv[i] == 0) | |
| 1006 | + s->rdiv[i] = 1. / sum; | |
| 1007 | + | |
| 1001 | 1008 | if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.)) |
| 1002 | 1009 | s->copy[i] = 0; |
| 1003 | 1010 | } |