[PATCH] ipa: raspberrypi: agc: Fix overflow in Y value calculation

David Plowman david.plowman at raspberrypi.com
Thu Mar 2 13:57:31 CET 2023


The maxVal variable in the computeInitialY function needs to be a
uint64_t, otherwise the subsequent multiplications in the function
can overflow on relatively high resolution images (when the counts in
the regions go over 16 bits).

Signed-off-by: David Plowman <david.plowman at raspberrypi.com>
---
 src/ipa/raspberrypi/controller/rpi/agc.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp
index ea0c82b5..4ea0dd41 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp
@@ -584,7 +584,7 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata)
 static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
 			      double weights[], double gain)
 {
-	constexpr unsigned int maxVal = 1 << Statistics::NormalisationFactorPow2;
+	constexpr uint64_t maxVal = 1 << Statistics::NormalisationFactorPow2;
 	/*
 	 * Note how the calculation below means that equal weights give you
 	 * "average" metering (i.e. all pixels equally important).
-- 
2.30.2



More information about the libcamera-devel mailing list