[libcamera-devel] ipa: raspberrypi: agc: Fix overflow in Y value calculation
diff mbox series

Message ID mailman.54.1677761855.25031.libcamera-devel@lists.libcamera.org
State Accepted
Commit 85541db7bbb5caba1ba0ed5fe85cf5855d024e0b
Headers show
Series
  • [libcamera-devel] ipa: raspberrypi: agc: Fix overflow in Y value calculation
Related show

Commit Message

David Plowman March 2, 2023, 12:57 p.m. UTC
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@raspberrypi.com>
---
 src/ipa/raspberrypi/controller/rpi/agc.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kieran Bingham March 2, 2023, 1:53 p.m. UTC | #1
Quoting David Plowman via libcamera-devel (2023-03-02 12:57:31)

I hope this makes it at least into patchwork:

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Naushir Patuck March 2, 2023, 1:56 p.m. UTC | #2
Hi David,

Thanks for fixing this.


On Thu, 2 Mar 2023 at 12:57, David Plowman via libcamera-devel <
libcamera-devel@lists.libcamera.org> wrote:

> 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@raspberrypi.com>
>

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>

PS: patchwork does seem to have correctly recognised Kieran's tag (
https://patchwork.libcamera.org/patch/18330/)


> ---
>  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
>
>

Patch
diff mbox series

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).