On 1/29/23, Michael Koch <[email protected]> wrote:
> Hello,
>
> if I understood the documentation correctly, the normalize filter maps
> the darkest input pixel to blackpt and the brightest input pixel to
> whitept:
> darkest pixel --> blackpt
> brightest pixel --> whitept
>
> However I need a slightly different mapping:
> A black input pixel shall remain black, and the brightest input pixel
> shall become white.
> black --> blackpt
> brightest pixel --> whitept
>
> With other words: Just multiply all pixels by a suitable constant. Don't
> add or subtract anything.
> Is this possible?
>
> Known workaround: Make sure that the input frame contains a black pixel,
> by inserting one in a corner.
Try attached patch.
>
> Michael
> _______________________________________________
> ffmpeg-user mailing list
> [email protected]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [email protected] with subject "unsubscribe".
>
diff --git a/libavfilter/vf_normalize.c b/libavfilter/vf_normalize.c
index 43ed3c67b3..91499bd009 100644
--- a/libavfilter/vf_normalize.c
+++ b/libavfilter/vf_normalize.c
@@ -101,7 +101,9 @@ typedef struct NormalizeContext {
uint8_t whitept[4];
int smoothing;
float independence;
+ float independence2;
float strength;
+ float strength2;
uint8_t co[4]; // Offsets to R,G,B,A bytes respectively in each pixel
int depth;
@@ -132,6 +134,8 @@ static const AVOption normalize_options[] = {
{ "smoothing", "amount of temporal smoothing of the input range, to reduce flicker", OFFSET(smoothing), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX/8, FLAGS },
{ "independence", "proportion of independent to linked channel normalization", OFFSET(independence), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 1.0, FLAGSR },
{ "strength", "strength of filter, from no effect to full normalization", OFFSET(strength), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 1.0, FLAGSR },
+ { "independence2", "proportion of independent to linked channel normalization, for brightest input", OFFSET(independence2), AV_OPT_TYPE_FLOAT, {.dbl=-1.0}, -1.0, 1.0, FLAGSR },
+ { "strength2", "strength of filter, from no effect to full normalization, for brightest input", OFFSET(strength2), AV_OPT_TYPE_FLOAT, {.dbl=-1.0}, -1.0, 1.0, FLAGSR },
{ NULL }
};
@@ -335,22 +339,30 @@ static void normalize(NormalizeContext *s, AVFrame *in, AVFrame *out)
// Now, process each channel to determine the input and output range and
// build the lookup tables.
for (c = 0; c < 3; c++) {
+ float strength[2], independence[2];
int in_val;
+
+ strength[0] = s->strength;
+ strength[1] = s->strength2 >= 0.f ? s->strength2 : s->strength;
+
+ independence[0] = s->independence;
+ independence[1] = s->independence2 >= 0.f ? s->independence2 : s->independence;
+
// Adjust the input range for this channel [min.smoothed,max.smoothed]
// by mixing in the correct proportion of the linked normalization
// input range [rgb_min_smoothed,rgb_max_smoothed].
- min[c].smoothed = (min[c].smoothed * s->independence)
- + (rgb_min_smoothed * (1.0f - s->independence));
- max[c].smoothed = (max[c].smoothed * s->independence)
- + (rgb_max_smoothed * (1.0f - s->independence));
+ min[c].smoothed = (min[c].smoothed * independence[0])
+ + (rgb_min_smoothed * (1.0f - independence[0]));
+ max[c].smoothed = (max[c].smoothed * independence[1])
+ + (rgb_max_smoothed * (1.0f - independence[1]));
// Calculate the output range [min.out,max.out] as a ratio of the full-
// strength output range [blackpt,whitept] and the original input range
// [min.in,max.in], based on the user-specified filter strength.
- min[c].out = (s->sblackpt[c] * s->strength)
- + (min[c].in * (1.0f - s->strength));
- max[c].out = (s->swhitept[c] * s->strength)
- + (max[c].in * (1.0f - s->strength));
+ min[c].out = (s->sblackpt[c] * strength[0])
+ + (min[c].in * (1.0f - strength[0]));
+ max[c].out = (s->swhitept[c] * strength[1])
+ + (max[c].in * (1.0f - strength[1]));
// Now, build a lookup table which linearly maps the adjusted input range
// [min.smoothed,max.smoothed] to the output range [min.out,max.out].
_______________________________________________
ffmpeg-user mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".