[libcamera-devel,v2,5/5] ipa: rkisp1: add support of Black Level Correction default values
diff mbox series

Message ID 20220616080744.548995-6-fsylvestre@baylibre.com
State Superseded
Headers show
Series
  • Add tuning file support for rkisp1 blc algo
Related show

Commit Message

Florian Sylvestre June 16, 2022, 8:07 a.m. UTC
Get default values for Black Level Correction algorithm form Yaml
tuning file.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
---
 src/ipa/rkisp1/algorithms/blc.cpp | 71 +++++++++++++++++++++++++------
 src/ipa/rkisp1/algorithms/blc.h   |  8 ++++
 2 files changed, 66 insertions(+), 13 deletions(-)

Comments

Laurent Pinchart June 16, 2022, 9:39 a.m. UTC | #1
Hi Florian,

Thank you for the patch.

On Thu, Jun 16, 2022 at 10:07:44AM +0200, Florian Sylvestre via libcamera-devel wrote:
> Get default values for Black Level Correction algorithm form Yaml

s/form Yaml/from the YAML/

> tuning file.
> 
> Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
> ---
>  src/ipa/rkisp1/algorithms/blc.cpp | 71 +++++++++++++++++++++++++------
>  src/ipa/rkisp1/algorithms/blc.h   |  8 ++++
>  2 files changed, 66 insertions(+), 13 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp
> index 0c5948ff..d11160d3 100644
> --- a/src/ipa/rkisp1/algorithms/blc.cpp
> +++ b/src/ipa/rkisp1/algorithms/blc.cpp
> @@ -7,6 +7,10 @@
>  
>  #include "blc.h"
>  
> +#include <libcamera/base/log.h>
> +
> +#include "libcamera/internal/yaml_parser.h"
> +
>  /**
>   * \file blc.h
>   */
> @@ -29,6 +33,45 @@ namespace ipa::rkisp1::algorithms {
>   * isn't currently supported.
>   */
>  
> +LOG_DEFINE_CATEGORY(RkISP1Blc)
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::init
> + */
> +int BlackLevelCorrection::init(IPAContext &,

We use [[maybe_unused]] instead of omitting the parameter name, as it's
more standard.

> +			       const YamlObject *params)
> +{
> +	tuningParameters_ = false;

This should be initialized in the constructor.

> +
> +	/* Parse property "BlackLevelCorrection". */
> +	if (!params->contains("BlackLevelCorrection")) {
> +		LOG(RkISP1Blc, Debug) << "No tuning parameters found for BlackLevelCorrection";
> +		return 0;
> +	}
> +
> +	const YamlObject &blcObject = (*params)["BlackLevelCorrection"];
> +
> +	if (!blcObject.isDictionary()) {
> +		LOG(RkISP1Blc, Error) << "'BlackLevelCorrection' in tuning file is not a dictionnary";
> +		return -EINVAL;
> +	}
> +
> +	blackLevelRed_ = blcObject["R"].get<int16_t>(256);
> +	blackLevelGreenR_ = blcObject["Gr"].get<int16_t>(256);
> +	blackLevelGreenB_ = blcObject["Gb"].get<int16_t>(256);
> +	blackLevelBlue_ = blcObject["B"].get<int16_t>(256);
> +
> +	tuningParameters_ = true;
> +
> +	LOG(RkISP1Blc, Debug)
> +		<< " Read black levels red " << blackLevelRed_
> +		<< " green (red) " << blackLevelGreenR_
> +		<< " green (blue) " << blackLevelGreenB_
> +		<< " blue " << blackLevelBlue_;

		<< ", green (red) " << blackLevelGreenR_
		<< ", green (blue) " << blackLevelGreenB_
		<< ", blue " << blackLevelBlue_;

will be more readable in the log.

> +
> +	return 0;
> +}
> +
>  /**
>   * \copydoc libcamera::ipa::Algorithm::prepare
>   */
> @@ -37,19 +80,21 @@ void BlackLevelCorrection::prepare(IPAContext &context,
>  {
>  	if (context.frameContext.frameCount > 0)
>  		return;
> -	/*
> -	 * Substract fixed values taken from imx219 tuning file.
> -	 * \todo Use a configuration file for it ?
> -	 */
> -	params->others.bls_config.enable_auto = 0;
> -	params->others.bls_config.fixed_val.r = 256;
> -	params->others.bls_config.fixed_val.gr = 256;
> -	params->others.bls_config.fixed_val.gb = 256;
> -	params->others.bls_config.fixed_val.b = 256;
> -
> -	params->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS;
> -	params->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;
> -	params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_BLS;
> +
> +	if (tuningParameters_) {

	if (!tuningParameters_)
		return;

will save you an indentation level below.

> +		/*
> +		* Substract fixed values taken from imx219 tuning file.

Wrong indentation.

But the comment isn't right anymore :-) You can thus drop it.

> +		*/
> +		params->others.bls_config.enable_auto = 0;
> +		params->others.bls_config.fixed_val.r = blackLevelRed_;
> +		params->others.bls_config.fixed_val.gr = blackLevelGreenR_;
> +		params->others.bls_config.fixed_val.gb = blackLevelGreenB_;
> +		params->others.bls_config.fixed_val.b = blackLevelBlue_;
> +
> +		params->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS;
> +		params->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;
> +		params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_BLS;
> +	}
>  }
>  
>  } /* namespace ipa::rkisp1::algorithms */
> diff --git a/src/ipa/rkisp1/algorithms/blc.h b/src/ipa/rkisp1/algorithms/blc.h
> index 69874d8f..ed2e8ed9 100644
> --- a/src/ipa/rkisp1/algorithms/blc.h
> +++ b/src/ipa/rkisp1/algorithms/blc.h
> @@ -23,7 +23,15 @@ public:
>  	BlackLevelCorrection() = default;
>  	~BlackLevelCorrection() = default;
>  
> +	int init(IPAContext &context, const YamlObject *params) override;
>  	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
> +
> +private:
> +	bool tuningParameters_;
> +	int16_t blackLevelRed_;
> +	int16_t blackLevelGreenR_;
> +	int16_t blackLevelGreenB_;
> +	int16_t blackLevelBlue_;
>  };
>  
>  } /* namespace ipa::rkisp1::algorithms */

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp
index 0c5948ff..d11160d3 100644
--- a/src/ipa/rkisp1/algorithms/blc.cpp
+++ b/src/ipa/rkisp1/algorithms/blc.cpp
@@ -7,6 +7,10 @@ 
 
 #include "blc.h"
 
+#include <libcamera/base/log.h>
+
+#include "libcamera/internal/yaml_parser.h"
+
 /**
  * \file blc.h
  */
@@ -29,6 +33,45 @@  namespace ipa::rkisp1::algorithms {
  * isn't currently supported.
  */
 
+LOG_DEFINE_CATEGORY(RkISP1Blc)
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::init
+ */
+int BlackLevelCorrection::init(IPAContext &,
+			       const YamlObject *params)
+{
+	tuningParameters_ = false;
+
+	/* Parse property "BlackLevelCorrection". */
+	if (!params->contains("BlackLevelCorrection")) {
+		LOG(RkISP1Blc, Debug) << "No tuning parameters found for BlackLevelCorrection";
+		return 0;
+	}
+
+	const YamlObject &blcObject = (*params)["BlackLevelCorrection"];
+
+	if (!blcObject.isDictionary()) {
+		LOG(RkISP1Blc, Error) << "'BlackLevelCorrection' in tuning file is not a dictionnary";
+		return -EINVAL;
+	}
+
+	blackLevelRed_ = blcObject["R"].get<int16_t>(256);
+	blackLevelGreenR_ = blcObject["Gr"].get<int16_t>(256);
+	blackLevelGreenB_ = blcObject["Gb"].get<int16_t>(256);
+	blackLevelBlue_ = blcObject["B"].get<int16_t>(256);
+
+	tuningParameters_ = true;
+
+	LOG(RkISP1Blc, Debug)
+		<< " Read black levels red " << blackLevelRed_
+		<< " green (red) " << blackLevelGreenR_
+		<< " green (blue) " << blackLevelGreenB_
+		<< " blue " << blackLevelBlue_;
+
+	return 0;
+}
+
 /**
  * \copydoc libcamera::ipa::Algorithm::prepare
  */
@@ -37,19 +80,21 @@  void BlackLevelCorrection::prepare(IPAContext &context,
 {
 	if (context.frameContext.frameCount > 0)
 		return;
-	/*
-	 * Substract fixed values taken from imx219 tuning file.
-	 * \todo Use a configuration file for it ?
-	 */
-	params->others.bls_config.enable_auto = 0;
-	params->others.bls_config.fixed_val.r = 256;
-	params->others.bls_config.fixed_val.gr = 256;
-	params->others.bls_config.fixed_val.gb = 256;
-	params->others.bls_config.fixed_val.b = 256;
-
-	params->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS;
-	params->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;
-	params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_BLS;
+
+	if (tuningParameters_) {
+		/*
+		* Substract fixed values taken from imx219 tuning file.
+		*/
+		params->others.bls_config.enable_auto = 0;
+		params->others.bls_config.fixed_val.r = blackLevelRed_;
+		params->others.bls_config.fixed_val.gr = blackLevelGreenR_;
+		params->others.bls_config.fixed_val.gb = blackLevelGreenB_;
+		params->others.bls_config.fixed_val.b = blackLevelBlue_;
+
+		params->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS;
+		params->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;
+		params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_BLS;
+	}
 }
 
 } /* namespace ipa::rkisp1::algorithms */
diff --git a/src/ipa/rkisp1/algorithms/blc.h b/src/ipa/rkisp1/algorithms/blc.h
index 69874d8f..ed2e8ed9 100644
--- a/src/ipa/rkisp1/algorithms/blc.h
+++ b/src/ipa/rkisp1/algorithms/blc.h
@@ -23,7 +23,15 @@  public:
 	BlackLevelCorrection() = default;
 	~BlackLevelCorrection() = default;
 
+	int init(IPAContext &context, const YamlObject *params) override;
 	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
+
+private:
+	bool tuningParameters_;
+	int16_t blackLevelRed_;
+	int16_t blackLevelGreenR_;
+	int16_t blackLevelGreenB_;
+	int16_t blackLevelBlue_;
 };
 
 } /* namespace ipa::rkisp1::algorithms */