[libcamera-devel,v3,1/2] ipa: rkisp1: Compute LSC algorithm parameter during configure
diff mbox series

Message ID 20221003142357.602633-2-fsylvestre@baylibre.com
State Superseded
Headers show
Series
  • Take into account color temperature during LSC algorithm for rkisp1
Related show

Commit Message

Florian Sylvestre Oct. 3, 2022, 2:23 p.m. UTC
LSC gradient parameters are currently computed during prepare() phase.
Because these parameters can be computed only one time and stay constant for
each frame after, move the computation to the configure() function.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/ipa/rkisp1/algorithms/lsc.cpp | 61 +++++++++++++++++--------------
 src/ipa/rkisp1/algorithms/lsc.h   |  4 ++
 2 files changed, 38 insertions(+), 27 deletions(-)

Comments

Nicolas Dufresne via libcamera-devel Oct. 25, 2022, 1:53 a.m. UTC | #1
On Mon, Oct 03, 2022 at 04:23:56PM +0200, Florian Sylvestre via libcamera-devel wrote:
> LSC gradient parameters are currently computed during prepare() phase.
> Because these parameters can be computed only one time and stay constant for
> each frame after, move the computation to the configure() function.
> 
> Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Looks good to me.

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

> ---
>  src/ipa/rkisp1/algorithms/lsc.cpp | 61 +++++++++++++++++--------------
>  src/ipa/rkisp1/algorithms/lsc.h   |  4 ++
>  2 files changed, 38 insertions(+), 27 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> index 102535bd..ad64aeb4 100644
> --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> @@ -122,27 +122,12 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
>  int LensShadingCorrection::configure(IPAContext &context,
>  				     [[maybe_unused]] const IPACameraSensorInfo &configInfo)
>  {
> -	context.configuration.lsc.enabled = true;
> -	return 0;
> -}
> -
> -/**
> - * \copydoc libcamera::ipa::Algorithm::prepare
> - */
> -void LensShadingCorrection::prepare(IPAContext &context, const uint32_t frame,
> -				    [[maybe_unused]] IPAFrameContext &frameContext,
> -				    rkisp1_params_cfg *params)
> -{
> -	if (frame > 0)
> -		return;
> -
> -	struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;
>  	const Size &size = context.configuration.sensor.size;
>  	Size totalSize{};
>  
>  	for (unsigned int i = 0; i < RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE; ++i) {
> -		config.x_size_tbl[i] = xSize_[i] * size.width;
> -		config.y_size_tbl[i] = ySize_[i] * size.height;
> +		xSizes_[i] = xSize_[i] * size.width;
> +		ySizes_[i] = ySize_[i] * size.height;
>  
>  		/*
>  		 * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> @@ -151,25 +136,47 @@ void LensShadingCorrection::prepare(IPAContext &context, const uint32_t frame,
>  		 * rounding-induced errors.
>  		 */
>  		if (i == RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE - 1) {
> -			config.x_size_tbl[i] = size.width / 2 - totalSize.width;
> -			config.y_size_tbl[i] = size.height / 2 - totalSize.height;
> +			xSizes_[i] = size.width / 2 - totalSize.width;
> +			ySizes_[i] = size.height / 2 - totalSize.height;
>  		}
>  
> -		totalSize.width += config.x_size_tbl[i];
> -		totalSize.height += config.y_size_tbl[i];
> +		totalSize.width += xSizes_[i];
> +		totalSize.height += ySizes_[i];
>  
> -		config.x_grad_tbl[i] = std::round(32768 / config.x_size_tbl[i]);
> -		config.y_grad_tbl[i] = std::round(32768 / config.y_size_tbl[i]);
> +		xGrad_[i] = std::round(32768 / xSizes_[i]);
> +		yGrad_[i] = std::round(32768 / ySizes_[i]);
>  	}
>  
> +	context.configuration.lsc.enabled = true;
> +	return 0;
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::prepare
> + */
> +void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,
> +				    const uint32_t frame,
> +				    [[maybe_unused]] IPAFrameContext &frameContext,
> +				    rkisp1_params_cfg *params)
> +{
> +	if (frame > 0)
> +		return;
> +
> +	struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;
> +
> +	memcpy(config.x_grad_tbl, xGrad_, sizeof(config.x_grad_tbl));
> +	memcpy(config.y_grad_tbl, yGrad_, sizeof(config.y_grad_tbl));
> +	memcpy(config.x_size_tbl, xSizes_, sizeof(config.x_size_tbl));
> +	memcpy(config.y_size_tbl, ySizes_, sizeof(config.y_size_tbl));
> +
>  	std::copy(rData_.begin(), rData_.end(),
> -		  &params->others.lsc_config.r_data_tbl[0][0]);
> +		  &config.r_data_tbl[0][0]);
>  	std::copy(grData_.begin(), grData_.end(),
> -		  &params->others.lsc_config.gr_data_tbl[0][0]);
> +		  &config.gr_data_tbl[0][0]);
>  	std::copy(gbData_.begin(), gbData_.end(),
> -		  &params->others.lsc_config.gb_data_tbl[0][0]);
> +		  &config.gb_data_tbl[0][0]);
>  	std::copy(bData_.begin(), bData_.end(),
> -		  &params->others.lsc_config.b_data_tbl[0][0]);
> +		  &config.b_data_tbl[0][0]);
>  
>  	params->module_en_update |= RKISP1_CIF_ISP_MODULE_LSC;
>  	params->module_ens |= RKISP1_CIF_ISP_MODULE_LSC;
> diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h
> index 6c052669..da81ea53 100644
> --- a/src/ipa/rkisp1/algorithms/lsc.h
> +++ b/src/ipa/rkisp1/algorithms/lsc.h
> @@ -33,6 +33,10 @@ private:
>  
>  	std::vector<double> xSize_;
>  	std::vector<double> ySize_;
> +	uint16_t xGrad_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> +	uint16_t yGrad_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> +	uint16_t xSizes_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> +	uint16_t ySizes_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
>  };
>  
>  } /* namespace ipa::rkisp1::algorithms */
> -- 
> 2.34.1
> 
>

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
index 102535bd..ad64aeb4 100644
--- a/src/ipa/rkisp1/algorithms/lsc.cpp
+++ b/src/ipa/rkisp1/algorithms/lsc.cpp
@@ -122,27 +122,12 @@  int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
 int LensShadingCorrection::configure(IPAContext &context,
 				     [[maybe_unused]] const IPACameraSensorInfo &configInfo)
 {
-	context.configuration.lsc.enabled = true;
-	return 0;
-}
-
-/**
- * \copydoc libcamera::ipa::Algorithm::prepare
- */
-void LensShadingCorrection::prepare(IPAContext &context, const uint32_t frame,
-				    [[maybe_unused]] IPAFrameContext &frameContext,
-				    rkisp1_params_cfg *params)
-{
-	if (frame > 0)
-		return;
-
-	struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;
 	const Size &size = context.configuration.sensor.size;
 	Size totalSize{};
 
 	for (unsigned int i = 0; i < RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE; ++i) {
-		config.x_size_tbl[i] = xSize_[i] * size.width;
-		config.y_size_tbl[i] = ySize_[i] * size.height;
+		xSizes_[i] = xSize_[i] * size.width;
+		ySizes_[i] = ySize_[i] * size.height;
 
 		/*
 		 * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
@@ -151,25 +136,47 @@  void LensShadingCorrection::prepare(IPAContext &context, const uint32_t frame,
 		 * rounding-induced errors.
 		 */
 		if (i == RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE - 1) {
-			config.x_size_tbl[i] = size.width / 2 - totalSize.width;
-			config.y_size_tbl[i] = size.height / 2 - totalSize.height;
+			xSizes_[i] = size.width / 2 - totalSize.width;
+			ySizes_[i] = size.height / 2 - totalSize.height;
 		}
 
-		totalSize.width += config.x_size_tbl[i];
-		totalSize.height += config.y_size_tbl[i];
+		totalSize.width += xSizes_[i];
+		totalSize.height += ySizes_[i];
 
-		config.x_grad_tbl[i] = std::round(32768 / config.x_size_tbl[i]);
-		config.y_grad_tbl[i] = std::round(32768 / config.y_size_tbl[i]);
+		xGrad_[i] = std::round(32768 / xSizes_[i]);
+		yGrad_[i] = std::round(32768 / ySizes_[i]);
 	}
 
+	context.configuration.lsc.enabled = true;
+	return 0;
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,
+				    const uint32_t frame,
+				    [[maybe_unused]] IPAFrameContext &frameContext,
+				    rkisp1_params_cfg *params)
+{
+	if (frame > 0)
+		return;
+
+	struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;
+
+	memcpy(config.x_grad_tbl, xGrad_, sizeof(config.x_grad_tbl));
+	memcpy(config.y_grad_tbl, yGrad_, sizeof(config.y_grad_tbl));
+	memcpy(config.x_size_tbl, xSizes_, sizeof(config.x_size_tbl));
+	memcpy(config.y_size_tbl, ySizes_, sizeof(config.y_size_tbl));
+
 	std::copy(rData_.begin(), rData_.end(),
-		  &params->others.lsc_config.r_data_tbl[0][0]);
+		  &config.r_data_tbl[0][0]);
 	std::copy(grData_.begin(), grData_.end(),
-		  &params->others.lsc_config.gr_data_tbl[0][0]);
+		  &config.gr_data_tbl[0][0]);
 	std::copy(gbData_.begin(), gbData_.end(),
-		  &params->others.lsc_config.gb_data_tbl[0][0]);
+		  &config.gb_data_tbl[0][0]);
 	std::copy(bData_.begin(), bData_.end(),
-		  &params->others.lsc_config.b_data_tbl[0][0]);
+		  &config.b_data_tbl[0][0]);
 
 	params->module_en_update |= RKISP1_CIF_ISP_MODULE_LSC;
 	params->module_ens |= RKISP1_CIF_ISP_MODULE_LSC;
diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h
index 6c052669..da81ea53 100644
--- a/src/ipa/rkisp1/algorithms/lsc.h
+++ b/src/ipa/rkisp1/algorithms/lsc.h
@@ -33,6 +33,10 @@  private:
 
 	std::vector<double> xSize_;
 	std::vector<double> ySize_;
+	uint16_t xGrad_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
+	uint16_t yGrad_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
+	uint16_t xSizes_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
+	uint16_t ySizes_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
 };
 
 } /* namespace ipa::rkisp1::algorithms */