| Message ID | 20261102165032.3921934-1-stefan.klug@ideasonboard.com |
|---|---|
| State | Accepted |
| Headers | show |
| Series |
|
| Related | show |
Quoting Stefan Klug (2026-11-02 16:50:16) > In AgcMeanLuminance::estimateInitialGain() a constant value of 0.001 is > added to yValue. This is there to prevent division by 0 in cases where > yValue is 0. This offset produces a noticeable error in the gain > calculation (Which is especially annoying when doing hand calculations > to check the correct inner workings of the algorithms). > > Fix that by replacing the fixed offset by a max() function. > > Reorder the parameters to the outer min() for better readability. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > --- > src/ipa/libipa/agc_mean_luminance.cpp | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp > index cdfca47a3485..5b0a6e259433 100644 > --- a/src/ipa/libipa/agc_mean_luminance.cpp > +++ b/src/ipa/libipa/agc_mean_luminance.cpp > @@ -527,7 +527,8 @@ double AgcMeanLuminance::estimateInitialGain(const Traits &traits, double yTarge > */ > for (unsigned int i = 0; i < 8; i++) { > double yValue = traits.estimateLuminance(yGain); > - double extra_gain = std::min(10.0, yTarget / (yValue + .001)); > + double extra_gain = std::min(yTarget / std::max(yValue, 0.001), > + 10.0); > > yGain *= extra_gain; > LOG(AgcMeanLuminance, Debug) << "Y value: " << yValue > -- > 2.53.0 >
Hi Stefan On 02/11/2026 16:50, Stefan Klug wrote: > In AgcMeanLuminance::estimateInitialGain() a constant value of 0.001 is > added to yValue. This is there to prevent division by 0 in cases where > yValue is 0. This offset produces a noticeable error in the gain > calculation (Which is especially annoying when doing hand calculations > to check the correct inner workings of the algorithms). > > Fix that by replacing the fixed offset by a max() function. > > Reorder the parameters to the outer min() for better readability. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com> > --- > src/ipa/libipa/agc_mean_luminance.cpp | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp > index cdfca47a3485..5b0a6e259433 100644 > --- a/src/ipa/libipa/agc_mean_luminance.cpp > +++ b/src/ipa/libipa/agc_mean_luminance.cpp > @@ -527,7 +527,8 @@ double AgcMeanLuminance::estimateInitialGain(const Traits &traits, double yTarge > */ > for (unsigned int i = 0; i < 8; i++) { > double yValue = traits.estimateLuminance(yGain); > - double extra_gain = std::min(10.0, yTarget / (yValue + .001)); > + double extra_gain = std::min(yTarget / std::max(yValue, 0.001), > + 10.0); > > yGain *= extra_gain; > LOG(AgcMeanLuminance, Debug) << "Y value: " << yValue
2026. 11. 02. 17:50 keltezéssel, Stefan Klug írta: > In AgcMeanLuminance::estimateInitialGain() a constant value of 0.001 is > added to yValue. This is there to prevent division by 0 in cases where > yValue is 0. This offset produces a noticeable error in the gain > calculation (Which is especially annoying when doing hand calculations > to check the correct inner workings of the algorithms). > > Fix that by replacing the fixed offset by a max() function. > > Reorder the parameters to the outer min() for better readability. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> > --- I think the change is correct, but just as a side note, it has uncovered a fascinating issue on the mali-c55 platform. Due to libstdc++ implementation details, previously, if `yTarget / (yValue + .001)` was a NaN, then the `std::min()` would evaluate to 10. But now that the arguments are swapped, it does evaluate to NaN. > src/ipa/libipa/agc_mean_luminance.cpp | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp > index cdfca47a3485..5b0a6e259433 100644 > --- a/src/ipa/libipa/agc_mean_luminance.cpp > +++ b/src/ipa/libipa/agc_mean_luminance.cpp > @@ -527,7 +527,8 @@ double AgcMeanLuminance::estimateInitialGain(const Traits &traits, double yTarge > */ > for (unsigned int i = 0; i < 8; i++) { > double yValue = traits.estimateLuminance(yGain); > - double extra_gain = std::min(10.0, yTarget / (yValue + .001)); > + double extra_gain = std::min(yTarget / std::max(yValue, 0.001), > + 10.0); > > yGain *= extra_gain; > LOG(AgcMeanLuminance, Debug) << "Y value: " << yValue
diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index cdfca47a3485..5b0a6e259433 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -527,7 +527,8 @@ double AgcMeanLuminance::estimateInitialGain(const Traits &traits, double yTarge */ for (unsigned int i = 0; i < 8; i++) { double yValue = traits.estimateLuminance(yGain); - double extra_gain = std::min(10.0, yTarget / (yValue + .001)); + double extra_gain = std::min(yTarget / std::max(yValue, 0.001), + 10.0); yGain *= extra_gain; LOG(AgcMeanLuminance, Debug) << "Y value: " << yValue
In AgcMeanLuminance::estimateInitialGain() a constant value of 0.001 is added to yValue. This is there to prevent division by 0 in cases where yValue is 0. This offset produces a noticeable error in the gain calculation (Which is especially annoying when doing hand calculations to check the correct inner workings of the algorithms). Fix that by replacing the fixed offset by a max() function. Reorder the parameters to the outer min() for better readability. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> --- src/ipa/libipa/agc_mean_luminance.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)