ipa: simple: awb: Avoid incorrect arithmetic in AWB
The R/G/B sums computed in AWB simple IPA may be zero or perhaps even negative. Let's make sure the sums are always positive, to prevent division by zero or completely nonsense results. Signed-off-by: Milan Zamazal <mzamazal@redhat.com> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Hans de Goede <hansg@kernel.org> Tested-by: Hans de Goede <hansg@kernel.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
committed by
Kieran Bingham
parent
6a48f382e0
commit
6a7fe29a18
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "awb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -72,9 +73,10 @@ void Awb::process(IPAContext &context,
|
||||
const uint64_t nPixels = std::accumulate(
|
||||
histogram.begin(), histogram.end(), 0);
|
||||
const uint64_t offset = blackLevel * nPixels;
|
||||
const uint64_t sumR = stats->sumR_ - offset / 4;
|
||||
const uint64_t sumG = stats->sumG_ - offset / 2;
|
||||
const uint64_t sumB = stats->sumB_ - offset / 4;
|
||||
const uint64_t minValid = 1;
|
||||
const uint64_t sumR = stats->sumR_ > offset / 4 ? stats->sumR_ - offset / 4 : minValid;
|
||||
const uint64_t sumG = stats->sumG_ > offset / 2 ? stats->sumG_ - offset / 2 : minValid;
|
||||
const uint64_t sumB = stats->sumB_ > offset / 4 ? stats->sumB_ - offset / 4 : minValid;
|
||||
|
||||
/*
|
||||
* Calculate red and blue gains for AWB.
|
||||
|
||||
Reference in New Issue
Block a user