[v5,5/7] ipa: simple: awb: Use correct type in std::accumulate
diff mbox series

Message ID 20250929201924.45019-6-mzamazal@redhat.com
State New
Headers show
Series
  • Fix stats related problems in software ISP
Related show

Commit Message

Milan Zamazal Sept. 29, 2025, 8:19 p.m. UTC
The result type of the std::accumulate() call is uint64_t; let's use the
same type for the initial value (rather than the default int) to prevent
summing up the values in a different integer type.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 src/ipa/simple/algorithms/awb.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Hans de Goede Sept. 29, 2025, 9:01 p.m. UTC | #1
Hi,

On 29-Sep-25 10:19 PM, Milan Zamazal wrote:
> The result type of the std::accumulate() call is uint64_t; let's use the
> same type for the initial value (rather than the default int) to prevent
> summing up the values in a different integer type.
> 
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hansg@kernel.org>

Regards,

Hans



> ---
>  src/ipa/simple/algorithms/awb.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp
> index b1eb7d310..fb21396ef 100644
> --- a/src/ipa/simple/algorithms/awb.cpp
> +++ b/src/ipa/simple/algorithms/awb.cpp
> @@ -68,7 +68,7 @@ void Awb::process(IPAContext &context,
>  	 * rather than from the sensor range.
>  	 */
>  	const uint64_t nPixels = std::accumulate(
> -		histogram.begin(), histogram.end(), 0);
> +		histogram.begin(), histogram.end(), uint64_t(0));
>  	const uint64_t offset = blackLevel * nPixels;
>  	const uint64_t minValid = 1;
>  	const uint64_t sumR = stats->sumR_ > offset / 4 ? stats->sumR_ - offset / 4 : minValid;
Barnabás Pőcze Sept. 30, 2025, 8:36 a.m. UTC | #2
2025. 09. 29. 22:19 keltezéssel, Milan Zamazal írta:
> The result type of the std::accumulate() call is uint64_t; let's use the
> same type for the initial value (rather than the default int) to prevent
> summing up the values in a different integer type.
> 
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
> ---

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


>   src/ipa/simple/algorithms/awb.cpp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp
> index b1eb7d310..fb21396ef 100644
> --- a/src/ipa/simple/algorithms/awb.cpp
> +++ b/src/ipa/simple/algorithms/awb.cpp
> @@ -68,7 +68,7 @@ void Awb::process(IPAContext &context,
>   	 * rather than from the sensor range.
>   	 */
>   	const uint64_t nPixels = std::accumulate(
> -		histogram.begin(), histogram.end(), 0);
> +		histogram.begin(), histogram.end(), uint64_t(0));
>   	const uint64_t offset = blackLevel * nPixels;
>   	const uint64_t minValid = 1;
>   	const uint64_t sumR = stats->sumR_ > offset / 4 ? stats->sumR_ - offset / 4 : minValid;
> --
> 2.51.0
>

Patch
diff mbox series

diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp
index b1eb7d310..fb21396ef 100644
--- a/src/ipa/simple/algorithms/awb.cpp
+++ b/src/ipa/simple/algorithms/awb.cpp
@@ -68,7 +68,7 @@  void Awb::process(IPAContext &context,
 	 * rather than from the sensor range.
 	 */
 	const uint64_t nPixels = std::accumulate(
-		histogram.begin(), histogram.end(), 0);
+		histogram.begin(), histogram.end(), uint64_t(0));
 	const uint64_t offset = blackLevel * nPixels;
 	const uint64_t minValid = 1;
 	const uint64_t sumR = stats->sumR_ > offset / 4 ? stats->sumR_ - offset / 4 : minValid;