[libcamera-devel] ipa: rkisp1: lsc: Fix integer division error
diff mbox series

Message ID 20230302153852.63619-1-jacopo.mondi@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] ipa: rkisp1: lsc: Fix integer division error
Related show

Commit Message

Jacopo Mondi March 2, 2023, 3:38 p.m. UTC
The RkISP1 implementation of the LensShadinCorrection algorithm has been
made adaptive to the scene color temperature in commit 14c869c00fdd ("ipa:
rkisp1: Take into account color temperature during LSC algorithm").

The LSC algorithm interpolates the correction factors using the
table's reference color temperatures. When calculating the interpolation
coefficients, an unintended integer division makes both coefficient
zeros resulting in a completely black image.

Fix this by type casting to double one of the division operands.

Fixes: 14c869c00fdd ("ipa: rkisp1: Take into account color temperature during LSC algorithm")
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/lsc.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.39.0

Comments

Kieran Bingham March 2, 2023, 6:01 p.m. UTC | #1
Quoting Jacopo Mondi via libcamera-devel (2023-03-02 15:38:52)
> The RkISP1 implementation of the LensShadinCorrection algorithm has been
> made adaptive to the scene color temperature in commit 14c869c00fdd ("ipa:
> rkisp1: Take into account color temperature during LSC algorithm").
> 
> The LSC algorithm interpolates the correction factors using the
> table's reference color temperatures. When calculating the interpolation
> coefficients, an unintended integer division makes both coefficient
> zeros resulting in a completely black image.
> 
> Fix this by type casting to double one of the division operands.
> 

This seems reasonable to me.


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Fixes: 14c869c00fdd ("ipa: rkisp1: Take into account color temperature during LSC algorithm")
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  src/ipa/rkisp1/algorithms/lsc.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> index 3a443e776a53..a7ccedb1ed3b 100644
> --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> @@ -216,8 +216,8 @@ void LensShadingCorrection::interpolateTable(rkisp1_cif_isp_lsc_config &config,
>                                              const Components &set1,
>                                              const uint32_t ct)
>  {
> -       double coeff0 = (set1.ct - ct) / (set1.ct - set0.ct);
> -       double coeff1 = (ct - set0.ct) / (set1.ct - set0.ct);
> +       double coeff0 = (set1.ct - ct) / static_cast<double>(set1.ct - set0.ct);
> +       double coeff1 = (ct - set0.ct) / static_cast<double>(set1.ct - set0.ct);
> 
>         for (unsigned int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
>                 for (unsigned int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
> --
> 2.39.0
>
Paul Elder March 3, 2023, 5:57 a.m. UTC | #2
On Thu, Mar 02, 2023 at 04:38:52PM +0100, Jacopo Mondi via libcamera-devel wrote:
> The RkISP1 implementation of the LensShadinCorrection algorithm has been

s/Shadin/Shading/

> made adaptive to the scene color temperature in commit 14c869c00fdd ("ipa:
> rkisp1: Take into account color temperature during LSC algorithm").
> 
> The LSC algorithm interpolates the correction factors using the
> table's reference color temperatures. When calculating the interpolation
> coefficients, an unintended integer division makes both coefficient
> zeros resulting in a completely black image.
> 
> Fix this by type casting to double one of the division operands.
> 
> Fixes: 14c869c00fdd ("ipa: rkisp1: Take into account color temperature during LSC algorithm")
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/ipa/rkisp1/algorithms/lsc.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> index 3a443e776a53..a7ccedb1ed3b 100644
> --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> @@ -216,8 +216,8 @@ void LensShadingCorrection::interpolateTable(rkisp1_cif_isp_lsc_config &config,
>  					     const Components &set1,
>  					     const uint32_t ct)
>  {
> -	double coeff0 = (set1.ct - ct) / (set1.ct - set0.ct);
> -	double coeff1 = (ct - set0.ct) / (set1.ct - set0.ct);
> +	double coeff0 = (set1.ct - ct) / static_cast<double>(set1.ct - set0.ct);
> +	double coeff1 = (ct - set0.ct) / static_cast<double>(set1.ct - set0.ct);
> 
>  	for (unsigned int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
>  		for (unsigned int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
> --
> 2.39.0
>

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
index 3a443e776a53..a7ccedb1ed3b 100644
--- a/src/ipa/rkisp1/algorithms/lsc.cpp
+++ b/src/ipa/rkisp1/algorithms/lsc.cpp
@@ -216,8 +216,8 @@  void LensShadingCorrection::interpolateTable(rkisp1_cif_isp_lsc_config &config,
 					     const Components &set1,
 					     const uint32_t ct)
 {
-	double coeff0 = (set1.ct - ct) / (set1.ct - set0.ct);
-	double coeff1 = (ct - set0.ct) / (set1.ct - set0.ct);
+	double coeff0 = (set1.ct - ct) / static_cast<double>(set1.ct - set0.ct);
+	double coeff1 = (ct - set0.ct) / static_cast<double>(set1.ct - set0.ct);

 	for (unsigned int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
 		for (unsigned int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {