[libcamera-devel,1/1] ipa: rkisp1: Take into account color temperature during LSC algorithm
diff mbox series

Message ID 20220906161217.1806662-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 Sept. 6, 2022, 4:12 p.m. UTC
Add coefficients sets in the YAML tuning file to allow using different set
depending of the image color temperature (provided by AWB algorithm).

During processing, LSC algorithm computes coefficients by doing a linear
interpolation between the two closer set.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
---
 src/ipa/rkisp1/algorithms/lsc.cpp | 170 ++++++++++++++++------
 src/ipa/rkisp1/algorithms/lsc.h   |  21 ++-
 src/ipa/rkisp1/data/ov5640.yaml   | 231 ++++++++++++++++++++----------
 3 files changed, 300 insertions(+), 122 deletions(-)

Comments

Jacopo Mondi Sept. 20, 2022, 8:36 p.m. UTC | #1
Hello Florian,

On Tue, Sep 06, 2022 at 06:12:17PM +0200, Florian Sylvestre via libcamera-devel wrote:
> Add coefficients sets in the YAML tuning file to allow using different set
> depending of the image color temperature (provided by AWB algorithm).
>
> During processing, LSC algorithm computes coefficients by doing a linear
> interpolation between the two closer set.
>

As a general question and looking at the implemenation, do we want to
go through copying tables and interpolation every frame ? Shouldn't we
aim instead to re-run it only when the color temperature changes
significnalty enough (with significantly to be defined) ?

Or is there such a mechanism in place already and I've missed it ?

Another thing to consider is that since interpolation might be
expensive, if the color temperature is close enough to one of the
available entries, we might want to use that entry directly. This is
even more relevant when you have sparse temperatures in your set.
In your ov5640 tuning file the available color temperatures are 3000
and 7000. If the current color temperature is 3100 is it worth
interpolating with the 7000-set which is quite distant ? I guess to
answer these question one should actually perform some tuning tests
and verify how the color temperature distance impacts the resulting
tables...

> Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
> ---
>  src/ipa/rkisp1/algorithms/lsc.cpp | 170 ++++++++++++++++------
>  src/ipa/rkisp1/algorithms/lsc.h   |  21 ++-
>  src/ipa/rkisp1/data/ov5640.yaml   | 231 ++++++++++++++++++++----------
>  3 files changed, 300 insertions(+), 122 deletions(-)
>
> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> index da287ac7..f0930e95 100644
> --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> @@ -105,14 +105,39 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
>  	if (xSize_.empty() || ySize_.empty())
>  		return -EINVAL;
>
> -	rData_ = parseTable(tuningData, "r");
> -	grData_ = parseTable(tuningData, "gr");
> -	gbData_ = parseTable(tuningData, "gb");
> -	bData_ = parseTable(tuningData, "b");
> -
> -	if (rData_.empty() || grData_.empty() ||
> -	    gbData_.empty() || bData_.empty())
> +	/* Get all defined sets to apply. */
> +	const YamlObject &yamlSets = tuningData["sets"];
> +	if (!yamlSets.isList()) {
> +		LOG(RkISP1Lsc, Error)
> +			<< "'sets' parameter not found in tuning file";
>  		return -EINVAL;
> +	}
> +
> +	double lastCt = -1;

why a double ?

> +
> +	for (std::size_t i = 0; i < yamlSets.size(); ++i) {
> +		const YamlObject &yamlSet = yamlSets[i];

Would be sweet if we could use utils::enumerate() and make this

	for (const auto &[i, yamlSet] : utils::enumerate(yamlsSets)) {

but YamlObject is not enumerable (yet). Should be easy to add in
facts (ofc not a request for this patch)

> +
> +		sets_.push_back({});
> +		componentsData &set = sets_.back();
> +
> +		set.ct = yamlSet["ct"].get<uint16_t>(0);
> +		if (set.ct <= lastCt) {
> +			LOG(RkISP1Lsc, Error)
> +				<< "Entries in 'sets' must be in increasing ct order";
> +			return -EINVAL;
> +		}
> +		lastCt = set.ct;
> +
> +		set.r = parseTable(yamlSet, "r");
> +		set.gr = parseTable(yamlSet, "gr");
> +		set.gb = parseTable(yamlSet, "gb");
> +		set.b = parseTable(yamlSet, "b");
> +
> +		if (set.r.empty() || set.gr.empty() ||
> +		    set.gb.empty() || set.b.empty())
> +			return -EINVAL;
> +	}
>
>  	initialized_ = true;
>
> @@ -125,56 +150,119 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
>  int LensShadingCorrection::configure(IPAContext &context,
>  				     [[maybe_unused]] const IPACameraSensorInfo &configInfo)
>  {
> -	context.configuration.lsc.enabled = initialized_;
> -	return 0;
> -}
> -
> -/**
> - * \copydoc libcamera::ipa::Algorithm::prepare
> - */
> -void LensShadingCorrection::prepare(IPAContext &context,
> -				    rkisp1_params_cfg *params)
> -{
> -	if (context.frameContext.frameCount > 0)
> -		return;
> -
> -	if (!initialized_)
> -		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;
> +		x_[i] = xSize_[i] * size.width;
> +		y_[i] = ySize_[i] * size.height;
>
>  		/*
> -		 * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> -		 * y_size_tbl items shall be equal to respectively size.width/2 and
> -		 * size.height/2. Enforce it by computing the last tables value to avoid
> -		 * rounding-induced errors.
> -		 */
> +		* To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> +		* y_size_tbl items shall be equal to respectively size.width/2 and
> +		* size.height/2. Enforce it by computing the last tables value to avoid
> +		* 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;
> +			x_[i] = size.width / 2 - totalSize.width;
> +			y_[i] = size.height / 2 - totalSize.height;
>  		}
>
> -		totalSize.width += config.x_size_tbl[i];
> -		totalSize.height += config.y_size_tbl[i];
> +		totalSize.width += x_[i];
> +		totalSize.height += y_[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 / x_[i]);
> +		yGrad_[i] = std::round(32768 / y_[i]);
>  	}
>
> -	std::copy(rData_.begin(), rData_.end(),
> +	context.configuration.lsc.enabled = initialized_;

I would check if initialized_ at the very beginning and exit if not
true

> +	return 0;
> +}
> +
> +void LensShadingCorrection::copyTable(rkisp1_params_cfg *params, const int index)
> +{
> +	componentsData_t &set = sets_[index];
> +
> +	std::copy(set.r.begin(), set.r.end(),
>  		  &params->others.lsc_config.r_data_tbl[0][0]);
> -	std::copy(grData_.begin(), grData_.end(),
> +	std::copy(set.gr.begin(), set.gr.end(),
>  		  &params->others.lsc_config.gr_data_tbl[0][0]);
> -	std::copy(gbData_.begin(), gbData_.end(),
> +	std::copy(set.gb.begin(), set.gb.end(),
>  		  &params->others.lsc_config.gb_data_tbl[0][0]);
> -	std::copy(bData_.begin(), bData_.end(),
> +	std::copy(set.b.begin(), set.b.end(),
>  		  &params->others.lsc_config.b_data_tbl[0][0]);
> +}
> +
> +/*
> + * Interpolate LSC parameters based on color temperature value.
> + */
> +void LensShadingCorrection::interpolateTable(rkisp1_params_cfg *params, const double ct)
> +{
> +	int index = 0;
> +	while (ct > sets_[index + 1].ct)
> +		index++;
> +	double ct0 = sets_[index].ct, ct1 = sets_[index + 1].ct;

That's risky. I know the caller guarantees that we're not dealing with
the first or, most important here, the last vector entry. But
this is an unbounded loop and the caller might get changed without
considering it.

I don't have much better ways to propose, as all the ones I have tried
have anyway some assumptions. In example


	auto set = sets_.begin();
	for (; set != sets_.end() - 1; ++set) {
		if (set->ct < ct)
			break;
	}

	componentsData_t &set0 = *(set - 1);
	componentsData_t &set1 = *set;

Won't work for arrays of a single element.

Anyway, unless something more brilliant can be proposed, I would at
least record that we assume ct is included in the min/max color
temperatures ?

> +
> +	LOG(RkISP1Lsc, Debug)
> +		<< "ct is " << ct << ", interpolating between "
> +		<< ct0 << " and " << ct1;
> +
> +	componentsData_t &set0 = sets_[index];
> +	componentsData_t &set1 = sets_[index + 1];
> +
> +	double coeff0 = (ct1 - ct) / (ct1 - ct0);
> +	double coeff1 = (ct - ct0) / (ct1 - ct0);
> +
> +	for (int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
> +		for (int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
> +			int sample = i * RKISP1_CIF_ISP_LSC_SAMPLES_MAX + j;
> +
> +			params->others.lsc_config.r_data_tbl[i][j] =
> +				set0.r[sample] * coeff0 +
> +				set1.r[sample] * coeff1;
> +
> +			params->others.lsc_config.gr_data_tbl[i][j] =
> +				set0.gr[sample] * coeff0 +
> +				set1.gr[sample] * coeff1;
> +
> +			params->others.lsc_config.gb_data_tbl[i][j] =
> +				set0.gb[sample] * coeff0 +
> +				set1.gb[sample] * coeff1;
> +
> +			params->others.lsc_config.b_data_tbl[i][j] =
> +				set0.b[sample] * coeff0 +
> +				set1.b[sample] * coeff1;
> +		}
> +	}
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::prepare
> + */
> +void LensShadingCorrection::prepare(IPAContext &context,
> +				    rkisp1_params_cfg *params)
> +{
> +	if (!initialized_)
> +		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, x_, sizeof(config.x_size_tbl));
> +	memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
> +
> +	double ct = context.frameContext.awb.temperatureK;

Here it's where I would check how much the color temperature has
changed and make choices (before the memcpys of course)

> +	if (ct <= sets_.front().ct) {
> +		LOG(RkISP1Lsc, Debug) << "using calibration for "
> +				      << sets_.front().ct;
> +		copyTable(params, 0);
> +	} else if (ct >= sets_.back().ct) {
> +		LOG(RkISP1Lsc, Debug) << "using calibration for "
> +				      << sets_.back().ct;
> +		copyTable(params, sets_.size() - 1);
> +	} else {
> +		interpolateTable(params, ct);
> +	}
>
>  	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 f68602c0..9b1adfd7 100644
> --- a/src/ipa/rkisp1/algorithms/lsc.h
> +++ b/src/ipa/rkisp1/algorithms/lsc.h
> @@ -15,6 +15,14 @@ namespace ipa::rkisp1::algorithms {
>
>  class LensShadingCorrection : public Algorithm
>  {
> +	typedef struct componentsData {

No need to typedef, and we usually use capital letter for types.
This can be just

        struct Components {

Nice one, I'm thrilled to test it to see how much it improves the
image quality!

Thanks
  j

> +		uint16_t ct;
> +		std::vector<uint16_t> r;
> +		std::vector<uint16_t> gr;
> +		std::vector<uint16_t> gb;
> +		std::vector<uint16_t> b;
> +	} componentsData_t;
> +
>  public:
>  	LensShadingCorrection();
>  	~LensShadingCorrection() = default;
> @@ -24,15 +32,18 @@ public:
>  	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
>
>  private:
> -	bool initialized_;
> +	void copyTable(rkisp1_params_cfg *params, const int index);
> +	void interpolateTable(rkisp1_params_cfg *params, const double ct);
>
> -	std::vector<uint16_t> rData_;
> -	std::vector<uint16_t> grData_;
> -	std::vector<uint16_t> gbData_;
> -	std::vector<uint16_t> bData_;
> +	bool initialized_;
>
> +	std::vector<componentsData_t> sets_;
>  	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 x_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> +	uint16_t y_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
>  };
>
>  } /* namespace ipa::rkisp1::algorithms */
> diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml
> index 33a672bc..d80c1655 100644
> --- a/src/ipa/rkisp1/data/ov5640.yaml
> +++ b/src/ipa/rkisp1/data/ov5640.yaml
> @@ -20,82 +20,161 @@ algorithms:
>    - LensShadingCorrection:
>        x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
>        y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> -      r:  [
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -          ]
> -      gr: [
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -          ]
> -      gb: [
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -          ]
> -      b:  [
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> -          ]
> +      sets:
> +        - ct: 3000
> +          r:  [
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +              ]
> +          gr: [
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +              ]
> +          gb: [
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +              ]
> +          b:  [
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> +              ]
> +        - ct: 7000
> +          r:  [
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +              ]
> +          gr: [
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +              ]
> +          gb: [
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +              ]
> +          b:  [
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> +              ]
>    - DefectPixelClusterCorrection:
>        fixed-set: false
>        sets:
> --
> 2.34.1
>
Laurent Pinchart Sept. 22, 2022, 11:36 a.m. UTC | #2
On Tue, Sep 20, 2022 at 10:36:50PM +0200, Jacopo Mondi via libcamera-devel wrote:
> Hello Florian,
> 
> On Tue, Sep 06, 2022 at 06:12:17PM +0200, Florian Sylvestre via libcamera-devel wrote:
> > Add coefficients sets in the YAML tuning file to allow using different set
> > depending of the image color temperature (provided by AWB algorithm).
> >
> > During processing, LSC algorithm computes coefficients by doing a linear
> > interpolation between the two closer set.
> 
> As a general question and looking at the implemenation, do we want to
> go through copying tables and interpolation every frame ? Shouldn't we
> aim instead to re-run it only when the color temperature changes
> significnalty enough (with significantly to be defined) ?

That could be useful indeed, although the interpolation is relatively
cheap at this point. Florian, could you share the measurements you made
related to the CPU time consumed by the LSC calculations ?

> Or is there such a mechanism in place already and I've missed it ?
> 
> Another thing to consider is that since interpolation might be
> expensive, if the color temperature is close enough to one of the
> available entries, we might want to use that entry directly. This is
> even more relevant when you have sparse temperatures in your set.
> In your ov5640 tuning file the available color temperatures are 3000
> and 7000. If the current color temperature is 3100 is it worth
> interpolating with the 7000-set which is quite distant ? I guess to
> answer these question one should actually perform some tuning tests
> and verify how the color temperature distance impacts the resulting
> tables...

It's an interesting idea, but I would be cautious with too much early
optimization, the calculation may not be costly. This is especially true
if we implement a hysteresis on the colour temperature.

> > Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
> > ---
> >  src/ipa/rkisp1/algorithms/lsc.cpp | 170 ++++++++++++++++------
> >  src/ipa/rkisp1/algorithms/lsc.h   |  21 ++-
> >  src/ipa/rkisp1/data/ov5640.yaml   | 231 ++++++++++++++++++++----------
> >  3 files changed, 300 insertions(+), 122 deletions(-)
> >
> > diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> > index da287ac7..f0930e95 100644
> > --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> > +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> > @@ -105,14 +105,39 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
> >  	if (xSize_.empty() || ySize_.empty())
> >  		return -EINVAL;
> >
> > -	rData_ = parseTable(tuningData, "r");
> > -	grData_ = parseTable(tuningData, "gr");
> > -	gbData_ = parseTable(tuningData, "gb");
> > -	bData_ = parseTable(tuningData, "b");
> > -
> > -	if (rData_.empty() || grData_.empty() ||
> > -	    gbData_.empty() || bData_.empty())
> > +	/* Get all defined sets to apply. */
> > +	const YamlObject &yamlSets = tuningData["sets"];
> > +	if (!yamlSets.isList()) {
> > +		LOG(RkISP1Lsc, Error)
> > +			<< "'sets' parameter not found in tuning file";
> >  		return -EINVAL;
> > +	}
> > +
> > +	double lastCt = -1;
> 
> why a double ?
> 
> > +
> > +	for (std::size_t i = 0; i < yamlSets.size(); ++i) {
> > +		const YamlObject &yamlSet = yamlSets[i];
> 
> Would be sweet if we could use utils::enumerate() and make this
> 
> 	for (const auto &[i, yamlSet] : utils::enumerate(yamlsSets)) {
> 
> but YamlObject is not enumerable (yet). Should be easy to add in
> facts (ofc not a request for this patch)

YamlObject isn't (by design), but YamlObject::asList() and
YamlObject::asDict() are enumerable.

	const auto &sets = yamlSets.asList();
	for (const auto &[i, yamlSet] : utils::enumerate(sets)) {

You need the intermediate variable until
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2012r2.pdf
gets approved, integrated in a new C++ release, and we move to that C++
version (a.k.a. in a long time).

> > +
> > +		sets_.push_back({});
> > +		componentsData &set = sets_.back();
> > +
> > +		set.ct = yamlSet["ct"].get<uint16_t>(0);
> > +		if (set.ct <= lastCt) {
> > +			LOG(RkISP1Lsc, Error)
> > +				<< "Entries in 'sets' must be in increasing ct order";
> > +			return -EINVAL;
> > +		}
> > +		lastCt = set.ct;

This could also be moved after the loop with

	if (!std::is_sorted(sets_.begin(), sets_.end(),
	    [](const auto &a, const auto &b) { return a.ct < b.ct; })) {
		LOG(RkISP1Lsc, Error)
			<< "Entries in 'sets' must be in increasing ct order";
		return -EINVAL;
	}

(You need to include <algorithm>)

> > +
> > +		set.r = parseTable(yamlSet, "r");
> > +		set.gr = parseTable(yamlSet, "gr");
> > +		set.gb = parseTable(yamlSet, "gb");
> > +		set.b = parseTable(yamlSet, "b");
> > +
> > +		if (set.r.empty() || set.gr.empty() ||
> > +		    set.gb.empty() || set.b.empty())
> > +			return -EINVAL;
> > +	}
> >
> >  	initialized_ = true;
> >
> > @@ -125,56 +150,119 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
> >  int LensShadingCorrection::configure(IPAContext &context,
> >  				     [[maybe_unused]] const IPACameraSensorInfo &configInfo)
> >  {
> > -	context.configuration.lsc.enabled = initialized_;
> > -	return 0;
> > -}
> > -
> > -/**
> > - * \copydoc libcamera::ipa::Algorithm::prepare
> > - */
> > -void LensShadingCorrection::prepare(IPAContext &context,
> > -				    rkisp1_params_cfg *params)
> > -{
> > -	if (context.frameContext.frameCount > 0)
> > -		return;
> > -
> > -	if (!initialized_)
> > -		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;
> > +		x_[i] = xSize_[i] * size.width;
> > +		y_[i] = ySize_[i] * size.height;
> >
> >  		/*
> > -		 * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> > -		 * y_size_tbl items shall be equal to respectively size.width/2 and
> > -		 * size.height/2. Enforce it by computing the last tables value to avoid
> > -		 * rounding-induced errors.
> > -		 */
> > +		* To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> > +		* y_size_tbl items shall be equal to respectively size.width/2 and
> > +		* size.height/2. Enforce it by computing the last tables value to avoid
> > +		* rounding-induced errors.
> > +		*/

Wrong indentation.

> >  		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;
> > +			x_[i] = size.width / 2 - totalSize.width;
> > +			y_[i] = size.height / 2 - totalSize.height;
> >  		}
> >
> > -		totalSize.width += config.x_size_tbl[i];
> > -		totalSize.height += config.y_size_tbl[i];
> > +		totalSize.width += x_[i];
> > +		totalSize.height += y_[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 / x_[i]);
> > +		yGrad_[i] = std::round(32768 / y_[i]);
> >  	}
> >
> > -	std::copy(rData_.begin(), rData_.end(),
> > +	context.configuration.lsc.enabled = initialized_;
> 
> I would check if initialized_ at the very beginning and exit if not
> true
> 
> > +	return 0;

Moving the gradient calculation from prepare() to configure() is a good
change, but it's not even mentioned in the commit message. I'd split
this to its own patch, going first in the series.

> > +}
> > +
> > +void LensShadingCorrection::copyTable(rkisp1_params_cfg *params, const int index)

You can pass rkisp1_cif_isp_lsc_config instead of rkisp1_params_cfg to
this function. I would also make it a reference instead of a pointer as
it can't be null.

I'd also pass a const reference to the set instead of the index.

> > +{
> > +	componentsData_t &set = sets_[index];
> > +
> > +	std::copy(set.r.begin(), set.r.end(),
> >  		  &params->others.lsc_config.r_data_tbl[0][0]);
> > -	std::copy(grData_.begin(), grData_.end(),
> > +	std::copy(set.gr.begin(), set.gr.end(),
> >  		  &params->others.lsc_config.gr_data_tbl[0][0]);
> > -	std::copy(gbData_.begin(), gbData_.end(),
> > +	std::copy(set.gb.begin(), set.gb.end(),
> >  		  &params->others.lsc_config.gb_data_tbl[0][0]);
> > -	std::copy(bData_.begin(), bData_.end(),
> > +	std::copy(set.b.begin(), set.b.end(),
> >  		  &params->others.lsc_config.b_data_tbl[0][0]);
> > +}
> > +
> > +/*
> > + * Interpolate LSC parameters based on color temperature value.
> > + */
> > +void LensShadingCorrection::interpolateTable(rkisp1_params_cfg *params, const double ct)

Same here for params.

> > +{
> > +	int index = 0;
> > +	while (ct > sets_[index + 1].ct)
> > +		index++;
> > +	double ct0 = sets_[index].ct, ct1 = sets_[index + 1].ct;
> 
> That's risky. I know the caller guarantees that we're not dealing with
> the first or, most important here, the last vector entry. But
> this is an unbounded loop and the caller might get changed without
> considering it.
> 
> I don't have much better ways to propose, as all the ones I have tried
> have anyway some assumptions. In example
> 
> 
> 	auto set = sets_.begin();
> 	for (; set != sets_.end() - 1; ++set) {
> 		if (set->ct < ct)
> 			break;
> 	}
> 
> 	componentsData_t &set0 = *(set - 1);
> 	componentsData_t &set1 = *set;
> 
> Won't work for arrays of a single element.
> 
> Anyway, unless something more brilliant can be proposed, I would at
> least record that we assume ct is included in the min/max color
> temperatures ?
> 
> > +
> > +	LOG(RkISP1Lsc, Debug)
> > +		<< "ct is " << ct << ", interpolating between "
> > +		<< ct0 << " and " << ct1;
> > +
> > +	componentsData_t &set0 = sets_[index];
> > +	componentsData_t &set1 = sets_[index + 1];
> > +
> > +	double coeff0 = (ct1 - ct) / (ct1 - ct0);
> > +	double coeff1 = (ct - ct0) / (ct1 - ct0);
> > +
> > +	for (int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
> > +		for (int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
> > +			int sample = i * RKISP1_CIF_ISP_LSC_SAMPLES_MAX + j;

All these variables can be unsigned.

> > +
> > +			params->others.lsc_config.r_data_tbl[i][j] =
> > +				set0.r[sample] * coeff0 +
> > +				set1.r[sample] * coeff1;
> > +
> > +			params->others.lsc_config.gr_data_tbl[i][j] =
> > +				set0.gr[sample] * coeff0 +
> > +				set1.gr[sample] * coeff1;
> > +
> > +			params->others.lsc_config.gb_data_tbl[i][j] =
> > +				set0.gb[sample] * coeff0 +
> > +				set1.gb[sample] * coeff1;
> > +
> > +			params->others.lsc_config.b_data_tbl[i][j] =
> > +				set0.b[sample] * coeff0 +
> > +				set1.b[sample] * coeff1;
> > +		}
> > +	}
> > +}
> > +
> > +/**
> > + * \copydoc libcamera::ipa::Algorithm::prepare
> > + */
> > +void LensShadingCorrection::prepare(IPAContext &context,
> > +				    rkisp1_params_cfg *params)
> > +{
> > +	if (!initialized_)
> > +		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, x_, sizeof(config.x_size_tbl));
> > +	memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
> > +
> > +	double ct = context.frameContext.awb.temperatureK;
> 
> Here it's where I would check how much the color temperature has
> changed and make choices (before the memcpys of course)

As Jacopo mentioned, we shouldn't interpolate if the colour temperate is
very close to one of the tables, so I would have a special case here,
but write

	double ct = context.frameContext.awb.temperatureK;
	ct = std::clamp(ct, sets_.front().ct, sets_.back().ct);

	/*
	 * Possibly Handle hysteresis here, returning if the value
	 * hasn't changed enough.
	 */

	struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;

	/*
	 * Pick the sets to interpolate between, or if the colour temperate is
	 * close enough to one of the sets, use that set without interpolation.
	 */
	...

	if (...)
		copyTable(config, set0);
	else
		interpolateTable(config, set0, set1, ct);

	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, x_, sizeof(config.x_size_tbl));
	memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));

> > +	if (ct <= sets_.front().ct) {
> > +		LOG(RkISP1Lsc, Debug) << "using calibration for "
> > +				      << sets_.front().ct;
> > +		copyTable(params, 0);
> > +	} else if (ct >= sets_.back().ct) {
> > +		LOG(RkISP1Lsc, Debug) << "using calibration for "
> > +				      << sets_.back().ct;
> > +		copyTable(params, sets_.size() - 1);
> > +	} else {
> > +		interpolateTable(params, ct);
> > +	}
> >
> >  	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 f68602c0..9b1adfd7 100644
> > --- a/src/ipa/rkisp1/algorithms/lsc.h
> > +++ b/src/ipa/rkisp1/algorithms/lsc.h
> > @@ -15,6 +15,14 @@ namespace ipa::rkisp1::algorithms {
> >
> >  class LensShadingCorrection : public Algorithm
> >  {
> > +	typedef struct componentsData {
> 
> No need to typedef, and we usually use capital letter for types.
> This can be just
> 
>         struct Components {
> 
> Nice one, I'm thrilled to test it to see how much it improves the
> image quality!
> 
> > +		uint16_t ct;
> > +		std::vector<uint16_t> r;
> > +		std::vector<uint16_t> gr;
> > +		std::vector<uint16_t> gb;
> > +		std::vector<uint16_t> b;
> > +	} componentsData_t;
> > +
> >  public:
> >  	LensShadingCorrection();
> >  	~LensShadingCorrection() = default;
> > @@ -24,15 +32,18 @@ public:
> >  	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
> >
> >  private:
> > -	bool initialized_;
> > +	void copyTable(rkisp1_params_cfg *params, const int index);
> > +	void interpolateTable(rkisp1_params_cfg *params, const double ct);
> >
> > -	std::vector<uint16_t> rData_;
> > -	std::vector<uint16_t> grData_;
> > -	std::vector<uint16_t> gbData_;
> > -	std::vector<uint16_t> bData_;
> > +	bool initialized_;
> >
> > +	std::vector<componentsData_t> sets_;
> >  	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 x_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> > +	uint16_t y_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];

Maybe xSizes_ and ySizes_ ?

> >  };
> >
> >  } /* namespace ipa::rkisp1::algorithms */
> > diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml
> > index 33a672bc..d80c1655 100644
> > --- a/src/ipa/rkisp1/data/ov5640.yaml
> > +++ b/src/ipa/rkisp1/data/ov5640.yaml
> > @@ -20,82 +20,161 @@ algorithms:
> >    - LensShadingCorrection:
> >        x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> >        y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> > -      r:  [
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -          ]
> > -      gr: [
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -          ]
> > -      gb: [
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -          ]
> > -      b:  [
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > -          ]
> > +      sets:
> > +        - ct: 3000
> > +          r:  [
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +              ]
> > +          gr: [
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +              ]
> > +          gb: [
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +              ]
> > +          b:  [
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > +              ]
> > +        - ct: 7000
> > +          r:  [
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +              ]
> > +          gr: [
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +              ]
> > +          gb: [
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +              ]
> > +          b:  [
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > +              ]
> >    - DefectPixelClusterCorrection:
> >        fixed-set: false
> >        sets:
Florian Sylvestre Sept. 26, 2022, 7:35 a.m. UTC | #3
Hello,

On Thu, 22 Sept 2022 at 13:36, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> On Tue, Sep 20, 2022 at 10:36:50PM +0200, Jacopo Mondi via libcamera-devel wrote:
> > Hello Florian,
> >
> > On Tue, Sep 06, 2022 at 06:12:17PM +0200, Florian Sylvestre via libcamera-devel wrote:
> > > Add coefficients sets in the YAML tuning file to allow using different set
> > > depending of the image color temperature (provided by AWB algorithm).
> > >
> > > During processing, LSC algorithm computes coefficients by doing a linear
> > > interpolation between the two closer set.
> >
> > As a general question and looking at the implemenation, do we want to
> > go through copying tables and interpolation every frame ? Shouldn't we
> > aim instead to re-run it only when the color temperature changes
> > significnalty enough (with significantly to be defined) ?
>
> That could be useful indeed, although the interpolation is relatively
> cheap at this point. Florian, could you share the measurements you made
> related to the CPU time consumed by the LSC calculations ?
I have measured the computation time at an average 135us on an Imx8Mp board.

>
> > Or is there such a mechanism in place already and I've missed it ?
> >
> > Another thing to consider is that since interpolation might be
> > expensive, if the color temperature is close enough to one of the
> > available entries, we might want to use that entry directly. This is
> > even more relevant when you have sparse temperatures in your set.
> > In your ov5640 tuning file the available color temperatures are 3000
> > and 7000. If the current color temperature is 3100 is it worth
> > interpolating with the 7000-set which is quite distant ? I guess to
> > answer these question one should actually perform some tuning tests
> > and verify how the color temperature distance impacts the resulting
> > tables...
>
> It's an interesting idea, but I would be cautious with too much early
> optimization, the calculation may not be costly. This is especially true
> if we implement a hysteresis on the colour temperature.
>
> > > Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
> > > ---
> > >  src/ipa/rkisp1/algorithms/lsc.cpp | 170 ++++++++++++++++------
> > >  src/ipa/rkisp1/algorithms/lsc.h   |  21 ++-
> > >  src/ipa/rkisp1/data/ov5640.yaml   | 231 ++++++++++++++++++++----------
> > >  3 files changed, 300 insertions(+), 122 deletions(-)
> > >
> > > diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> > > index da287ac7..f0930e95 100644
> > > --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> > > +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> > > @@ -105,14 +105,39 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
> > >     if (xSize_.empty() || ySize_.empty())
> > >             return -EINVAL;
> > >
> > > -   rData_ = parseTable(tuningData, "r");
> > > -   grData_ = parseTable(tuningData, "gr");
> > > -   gbData_ = parseTable(tuningData, "gb");
> > > -   bData_ = parseTable(tuningData, "b");
> > > -
> > > -   if (rData_.empty() || grData_.empty() ||
> > > -       gbData_.empty() || bData_.empty())
> > > +   /* Get all defined sets to apply. */
> > > +   const YamlObject &yamlSets = tuningData["sets"];
> > > +   if (!yamlSets.isList()) {
> > > +           LOG(RkISP1Lsc, Error)
> > > +                   << "'sets' parameter not found in tuning file";
> > >             return -EINVAL;
> > > +   }
> > > +
> > > +   double lastCt = -1;
> >
> > why a double ?
> >
> > > +
> > > +   for (std::size_t i = 0; i < yamlSets.size(); ++i) {
> > > +           const YamlObject &yamlSet = yamlSets[i];
> >
> > Would be sweet if we could use utils::enumerate() and make this
> >
> >       for (const auto &[i, yamlSet] : utils::enumerate(yamlsSets)) {
> >
> > but YamlObject is not enumerable (yet). Should be easy to add in
> > facts (ofc not a request for this patch)
>
> YamlObject isn't (by design), but YamlObject::asList() and
> YamlObject::asDict() are enumerable.
>
>         const auto &sets = yamlSets.asList();
>         for (const auto &[i, yamlSet] : utils::enumerate(sets)) {
>
> You need the intermediate variable until
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2012r2.pdf
> gets approved, integrated in a new C++ release, and we move to that C++
> version (a.k.a. in a long time).
>
Laurent, so what is your preferred version? The one you suggested?
> > > +
> > > +           sets_.push_back({});
> > > +           componentsData &set = sets_.back();
> > > +
> > > +           set.ct = yamlSet["ct"].get<uint16_t>(0);
> > > +           if (set.ct <= lastCt) {
> > > +                   LOG(RkISP1Lsc, Error)
> > > +                           << "Entries in 'sets' must be in increasing ct order";
> > > +                   return -EINVAL;
> > > +           }
> > > +           lastCt = set.ct;
>
> This could also be moved after the loop with
>
>         if (!std::is_sorted(sets_.begin(), sets_.end(),
>             [](const auto &a, const auto &b) { return a.ct < b.ct; })) {
>                 LOG(RkISP1Lsc, Error)
>                         << "Entries in 'sets' must be in increasing ct order";
>                 return -EINVAL;
>         }
>
> (You need to include <algorithm>)
>
> > > +
> > > +           set.r = parseTable(yamlSet, "r");
> > > +           set.gr = parseTable(yamlSet, "gr");
> > > +           set.gb = parseTable(yamlSet, "gb");
> > > +           set.b = parseTable(yamlSet, "b");
> > > +
> > > +           if (set.r.empty() || set.gr.empty() ||
> > > +               set.gb.empty() || set.b.empty())
> > > +                   return -EINVAL;
> > > +   }
> > >
> > >     initialized_ = true;
> > >
> > > @@ -125,56 +150,119 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
> > >  int LensShadingCorrection::configure(IPAContext &context,
> > >                                  [[maybe_unused]] const IPACameraSensorInfo &configInfo)
> > >  {
> > > -   context.configuration.lsc.enabled = initialized_;
> > > -   return 0;
> > > -}
> > > -
> > > -/**
> > > - * \copydoc libcamera::ipa::Algorithm::prepare
> > > - */
> > > -void LensShadingCorrection::prepare(IPAContext &context,
> > > -                               rkisp1_params_cfg *params)
> > > -{
> > > -   if (context.frameContext.frameCount > 0)
> > > -           return;
> > > -
> > > -   if (!initialized_)
> > > -           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;
> > > +           x_[i] = xSize_[i] * size.width;
> > > +           y_[i] = ySize_[i] * size.height;
> > >
> > >             /*
> > > -            * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> > > -            * y_size_tbl items shall be equal to respectively size.width/2 and
> > > -            * size.height/2. Enforce it by computing the last tables value to avoid
> > > -            * rounding-induced errors.
> > > -            */
> > > +           * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> > > +           * y_size_tbl items shall be equal to respectively size.width/2 and
> > > +           * size.height/2. Enforce it by computing the last tables value to avoid
> > > +           * rounding-induced errors.
> > > +           */
>
> Wrong indentation.
>
> > >             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;
> > > +                   x_[i] = size.width / 2 - totalSize.width;
> > > +                   y_[i] = size.height / 2 - totalSize.height;
> > >             }
> > >
> > > -           totalSize.width += config.x_size_tbl[i];
> > > -           totalSize.height += config.y_size_tbl[i];
> > > +           totalSize.width += x_[i];
> > > +           totalSize.height += y_[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 / x_[i]);
> > > +           yGrad_[i] = std::round(32768 / y_[i]);
> > >     }
> > >
> > > -   std::copy(rData_.begin(), rData_.end(),
> > > +   context.configuration.lsc.enabled = initialized_;
> >
> > I would check if initialized_ at the very beginning and exit if not
> > true
> >
> > > +   return 0;
>
> Moving the gradient calculation from prepare() to configure() is a good
> change, but it's not even mentioned in the commit message. I'd split
> this to its own patch, going first in the series.
>
> > > +}
> > > +
> > > +void LensShadingCorrection::copyTable(rkisp1_params_cfg *params, const int index)
>
> You can pass rkisp1_cif_isp_lsc_config instead of rkisp1_params_cfg to
> this function. I would also make it a reference instead of a pointer as
> it can't be null.
>
> I'd also pass a const reference to the set instead of the index.
>
> > > +{
> > > +   componentsData_t &set = sets_[index];
> > > +
> > > +   std::copy(set.r.begin(), set.r.end(),
> > >               &params->others.lsc_config.r_data_tbl[0][0]);
> > > -   std::copy(grData_.begin(), grData_.end(),
> > > +   std::copy(set.gr.begin(), set.gr.end(),
> > >               &params->others.lsc_config.gr_data_tbl[0][0]);
> > > -   std::copy(gbData_.begin(), gbData_.end(),
> > > +   std::copy(set.gb.begin(), set.gb.end(),
> > >               &params->others.lsc_config.gb_data_tbl[0][0]);
> > > -   std::copy(bData_.begin(), bData_.end(),
> > > +   std::copy(set.b.begin(), set.b.end(),
> > >               &params->others.lsc_config.b_data_tbl[0][0]);
> > > +}
> > > +
> > > +/*
> > > + * Interpolate LSC parameters based on color temperature value.
> > > + */
> > > +void LensShadingCorrection::interpolateTable(rkisp1_params_cfg *params, const double ct)
>
> Same here for params.
>
> > > +{
> > > +   int index = 0;
> > > +   while (ct > sets_[index + 1].ct)
> > > +           index++;
> > > +   double ct0 = sets_[index].ct, ct1 = sets_[index + 1].ct;
> >
> > That's risky. I know the caller guarantees that we're not dealing with
> > the first or, most important here, the last vector entry. But
> > this is an unbounded loop and the caller might get changed without
> > considering it.
> >
> > I don't have much better ways to propose, as all the ones I have tried
> > have anyway some assumptions. In example
> >
> >
> >       auto set = sets_.begin();
> >       for (; set != sets_.end() - 1; ++set) {
> >               if (set->ct < ct)
> >                       break;
> >       }
> >
> >       componentsData_t &set0 = *(set - 1);
> >       componentsData_t &set1 = *set;
> >
> > Won't work for arrays of a single element.
> >
> > Anyway, unless something more brilliant can be proposed, I would at
> > least record that we assume ct is included in the min/max color
> > temperatures ?
> >
> > > +
> > > +   LOG(RkISP1Lsc, Debug)
> > > +           << "ct is " << ct << ", interpolating between "
> > > +           << ct0 << " and " << ct1;
> > > +
> > > +   componentsData_t &set0 = sets_[index];
> > > +   componentsData_t &set1 = sets_[index + 1];
> > > +
> > > +   double coeff0 = (ct1 - ct) / (ct1 - ct0);
> > > +   double coeff1 = (ct - ct0) / (ct1 - ct0);
> > > +
> > > +   for (int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
> > > +           for (int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
> > > +                   int sample = i * RKISP1_CIF_ISP_LSC_SAMPLES_MAX + j;
>
> All these variables can be unsigned.
>
> > > +
> > > +                   params->others.lsc_config.r_data_tbl[i][j] =
> > > +                           set0.r[sample] * coeff0 +
> > > +                           set1.r[sample] * coeff1;
> > > +
> > > +                   params->others.lsc_config.gr_data_tbl[i][j] =
> > > +                           set0.gr[sample] * coeff0 +
> > > +                           set1.gr[sample] * coeff1;
> > > +
> > > +                   params->others.lsc_config.gb_data_tbl[i][j] =
> > > +                           set0.gb[sample] * coeff0 +
> > > +                           set1.gb[sample] * coeff1;
> > > +
> > > +                   params->others.lsc_config.b_data_tbl[i][j] =
> > > +                           set0.b[sample] * coeff0 +
> > > +                           set1.b[sample] * coeff1;
> > > +           }
> > > +   }
> > > +}
> > > +
> > > +/**
> > > + * \copydoc libcamera::ipa::Algorithm::prepare
> > > + */
> > > +void LensShadingCorrection::prepare(IPAContext &context,
> > > +                               rkisp1_params_cfg *params)
> > > +{
> > > +   if (!initialized_)
> > > +           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, x_, sizeof(config.x_size_tbl));
> > > +   memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
> > > +
> > > +   double ct = context.frameContext.awb.temperatureK;
> >
> > Here it's where I would check how much the color temperature has
> > changed and make choices (before the memcpys of course)
>
> As Jacopo mentioned, we shouldn't interpolate if the colour temperate is
> very close to one of the tables, so I would have a special case here,
> but write
Just to be makes it clear before implementing it: this 'close' is it something
that should come from the tuning file? (or hardcoded in the code ? from
somewhere else?)
What should I put as a default value?
>
>         double ct = context.frameContext.awb.temperatureK;
>         ct = std::clamp(ct, sets_.front().ct, sets_.back().ct);
>
>         /*
>          * Possibly Handle hysteresis here, returning if the value
>          * hasn't changed enough.
>          */
>
>         struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;
>
>         /*
>          * Pick the sets to interpolate between, or if the colour temperate is
>          * close enough to one of the sets, use that set without interpolation.
>          */
>         ...
>
>         if (...)
>                 copyTable(config, set0);
>         else
>                 interpolateTable(config, set0, set1, ct);
>
>         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, x_, sizeof(config.x_size_tbl));
>         memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
>
> > > +   if (ct <= sets_.front().ct) {
> > > +           LOG(RkISP1Lsc, Debug) << "using calibration for "
> > > +                                 << sets_.front().ct;
> > > +           copyTable(params, 0);
> > > +   } else if (ct >= sets_.back().ct) {
> > > +           LOG(RkISP1Lsc, Debug) << "using calibration for "
> > > +                                 << sets_.back().ct;
> > > +           copyTable(params, sets_.size() - 1);
> > > +   } else {
> > > +           interpolateTable(params, ct);
> > > +   }
> > >
> > >     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 f68602c0..9b1adfd7 100644
> > > --- a/src/ipa/rkisp1/algorithms/lsc.h
> > > +++ b/src/ipa/rkisp1/algorithms/lsc.h
> > > @@ -15,6 +15,14 @@ namespace ipa::rkisp1::algorithms {
> > >
> > >  class LensShadingCorrection : public Algorithm
> > >  {
> > > +   typedef struct componentsData {
> >
> > No need to typedef, and we usually use capital letter for types.
> > This can be just
> >
> >         struct Components {
> >
> > Nice one, I'm thrilled to test it to see how much it improves the
> > image quality!
> >
> > > +           uint16_t ct;
> > > +           std::vector<uint16_t> r;
> > > +           std::vector<uint16_t> gr;
> > > +           std::vector<uint16_t> gb;
> > > +           std::vector<uint16_t> b;
> > > +   } componentsData_t;
> > > +
> > >  public:
> > >     LensShadingCorrection();
> > >     ~LensShadingCorrection() = default;
> > > @@ -24,15 +32,18 @@ public:
> > >     void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
> > >
> > >  private:
> > > -   bool initialized_;
> > > +   void copyTable(rkisp1_params_cfg *params, const int index);
> > > +   void interpolateTable(rkisp1_params_cfg *params, const double ct);
> > >
> > > -   std::vector<uint16_t> rData_;
> > > -   std::vector<uint16_t> grData_;
> > > -   std::vector<uint16_t> gbData_;
> > > -   std::vector<uint16_t> bData_;
> > > +   bool initialized_;
> > >
> > > +   std::vector<componentsData_t> sets_;
> > >     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 x_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> > > +   uint16_t y_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
>
> Maybe xSizes_ and ySizes_ ?
>
> > >  };
> > >
> > >  } /* namespace ipa::rkisp1::algorithms */
> > > diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml
> > > index 33a672bc..d80c1655 100644
> > > --- a/src/ipa/rkisp1/data/ov5640.yaml
> > > +++ b/src/ipa/rkisp1/data/ov5640.yaml
> > > @@ -20,82 +20,161 @@ algorithms:
> > >    - LensShadingCorrection:
> > >        x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> > >        y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> > > -      r:  [
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -          ]
> > > -      gr: [
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -          ]
> > > -      gb: [
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -          ]
> > > -      b:  [
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > -          ]
> > > +      sets:
> > > +        - ct: 3000
> > > +          r:  [
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +              ]
> > > +          gr: [
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +              ]
> > > +          gb: [
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +              ]
> > > +          b:  [
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > +              ]
> > > +        - ct: 7000
> > > +          r:  [
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +              ]
> > > +          gr: [
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +              ]
> > > +          gb: [
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +              ]
> > > +          b:  [
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > +              ]
> > >    - DefectPixelClusterCorrection:
> > >        fixed-set: false
> > >        sets:
>
> --
> Regards,
>
> Laurent Pinchart
Laurent Pinchart Sept. 26, 2022, 8:07 a.m. UTC | #4
Hi Florian,

On Mon, Sep 26, 2022 at 09:35:17AM +0200, Florian Sylvestre wrote:
> On Thu, 22 Sept 2022 at 13:36, Laurent Pinchart wrote:
> > On Tue, Sep 20, 2022 at 10:36:50PM +0200, Jacopo Mondi wrote:
> > > On Tue, Sep 06, 2022 at 06:12:17PM +0200, Florian Sylvestre via libcamera-devel wrote:
> > > > Add coefficients sets in the YAML tuning file to allow using different set
> > > > depending of the image color temperature (provided by AWB algorithm).
> > > >
> > > > During processing, LSC algorithm computes coefficients by doing a linear
> > > > interpolation between the two closer set.
> > >
> > > As a general question and looking at the implemenation, do we want to
> > > go through copying tables and interpolation every frame ? Shouldn't we
> > > aim instead to re-run it only when the color temperature changes
> > > significnalty enough (with significantly to be defined) ?
> >
> > That could be useful indeed, although the interpolation is relatively
> > cheap at this point. Florian, could you share the measurements you made
> > related to the CPU time consumed by the LSC calculations ?
> 
> I have measured the computation time at an average 135us on an Imx8Mp board.
> 
> > > Or is there such a mechanism in place already and I've missed it ?
> > >
> > > Another thing to consider is that since interpolation might be
> > > expensive, if the color temperature is close enough to one of the
> > > available entries, we might want to use that entry directly. This is
> > > even more relevant when you have sparse temperatures in your set.
> > > In your ov5640 tuning file the available color temperatures are 3000
> > > and 7000. If the current color temperature is 3100 is it worth
> > > interpolating with the 7000-set which is quite distant ? I guess to
> > > answer these question one should actually perform some tuning tests
> > > and verify how the color temperature distance impacts the resulting
> > > tables...
> >
> > It's an interesting idea, but I would be cautious with too much early
> > optimization, the calculation may not be costly. This is especially true
> > if we implement a hysteresis on the colour temperature.
> >
> > > > Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
> > > > ---
> > > >  src/ipa/rkisp1/algorithms/lsc.cpp | 170 ++++++++++++++++------
> > > >  src/ipa/rkisp1/algorithms/lsc.h   |  21 ++-
> > > >  src/ipa/rkisp1/data/ov5640.yaml   | 231 ++++++++++++++++++++----------
> > > >  3 files changed, 300 insertions(+), 122 deletions(-)
> > > >
> > > > diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
> > > > index da287ac7..f0930e95 100644
> > > > --- a/src/ipa/rkisp1/algorithms/lsc.cpp
> > > > +++ b/src/ipa/rkisp1/algorithms/lsc.cpp
> > > > @@ -105,14 +105,39 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
> > > >     if (xSize_.empty() || ySize_.empty())
> > > >             return -EINVAL;
> > > >
> > > > -   rData_ = parseTable(tuningData, "r");
> > > > -   grData_ = parseTable(tuningData, "gr");
> > > > -   gbData_ = parseTable(tuningData, "gb");
> > > > -   bData_ = parseTable(tuningData, "b");
> > > > -
> > > > -   if (rData_.empty() || grData_.empty() ||
> > > > -       gbData_.empty() || bData_.empty())
> > > > +   /* Get all defined sets to apply. */
> > > > +   const YamlObject &yamlSets = tuningData["sets"];
> > > > +   if (!yamlSets.isList()) {
> > > > +           LOG(RkISP1Lsc, Error)
> > > > +                   << "'sets' parameter not found in tuning file";
> > > >             return -EINVAL;
> > > > +   }
> > > > +
> > > > +   double lastCt = -1;
> > >
> > > why a double ?
> > >
> > > > +
> > > > +   for (std::size_t i = 0; i < yamlSets.size(); ++i) {
> > > > +           const YamlObject &yamlSet = yamlSets[i];
> > >
> > > Would be sweet if we could use utils::enumerate() and make this
> > >
> > >       for (const auto &[i, yamlSet] : utils::enumerate(yamlsSets)) {
> > >
> > > but YamlObject is not enumerable (yet). Should be easy to add in
> > > facts (ofc not a request for this patch)
> >
> > YamlObject isn't (by design), but YamlObject::asList() and
> > YamlObject::asDict() are enumerable.
> >
> >         const auto &sets = yamlSets.asList();
> >         for (const auto &[i, yamlSet] : utils::enumerate(sets)) {
> >
> > You need the intermediate variable until
> > https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2012r2.pdf
> > gets approved, integrated in a new C++ release, and we move to that C++
> > version (a.k.a. in a long time).
> 
> Laurent, so what is your preferred version? The one you suggested?

I like utils::enumerate() personally, but if you think it's less
readable here due to the intermediate local variable, I don't mind
either way.

> > > > +
> > > > +           sets_.push_back({});
> > > > +           componentsData &set = sets_.back();
> > > > +
> > > > +           set.ct = yamlSet["ct"].get<uint16_t>(0);
> > > > +           if (set.ct <= lastCt) {
> > > > +                   LOG(RkISP1Lsc, Error)
> > > > +                           << "Entries in 'sets' must be in increasing ct order";
> > > > +                   return -EINVAL;
> > > > +           }
> > > > +           lastCt = set.ct;
> >
> > This could also be moved after the loop with
> >
> >         if (!std::is_sorted(sets_.begin(), sets_.end(),
> >             [](const auto &a, const auto &b) { return a.ct < b.ct; })) {
> >                 LOG(RkISP1Lsc, Error)
> >                         << "Entries in 'sets' must be in increasing ct order";
> >                 return -EINVAL;
> >         }
> >
> > (You need to include <algorithm>)
> >
> > > > +
> > > > +           set.r = parseTable(yamlSet, "r");
> > > > +           set.gr = parseTable(yamlSet, "gr");
> > > > +           set.gb = parseTable(yamlSet, "gb");
> > > > +           set.b = parseTable(yamlSet, "b");
> > > > +
> > > > +           if (set.r.empty() || set.gr.empty() ||
> > > > +               set.gb.empty() || set.b.empty())
> > > > +                   return -EINVAL;
> > > > +   }
> > > >
> > > >     initialized_ = true;
> > > >
> > > > @@ -125,56 +150,119 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
> > > >  int LensShadingCorrection::configure(IPAContext &context,
> > > >                                  [[maybe_unused]] const IPACameraSensorInfo &configInfo)
> > > >  {
> > > > -   context.configuration.lsc.enabled = initialized_;
> > > > -   return 0;
> > > > -}
> > > > -
> > > > -/**
> > > > - * \copydoc libcamera::ipa::Algorithm::prepare
> > > > - */
> > > > -void LensShadingCorrection::prepare(IPAContext &context,
> > > > -                               rkisp1_params_cfg *params)
> > > > -{
> > > > -   if (context.frameContext.frameCount > 0)
> > > > -           return;
> > > > -
> > > > -   if (!initialized_)
> > > > -           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;
> > > > +           x_[i] = xSize_[i] * size.width;
> > > > +           y_[i] = ySize_[i] * size.height;
> > > >
> > > >             /*
> > > > -            * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> > > > -            * y_size_tbl items shall be equal to respectively size.width/2 and
> > > > -            * size.height/2. Enforce it by computing the last tables value to avoid
> > > > -            * rounding-induced errors.
> > > > -            */
> > > > +           * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
> > > > +           * y_size_tbl items shall be equal to respectively size.width/2 and
> > > > +           * size.height/2. Enforce it by computing the last tables value to avoid
> > > > +           * rounding-induced errors.
> > > > +           */
> >
> > Wrong indentation.
> >
> > > >             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;
> > > > +                   x_[i] = size.width / 2 - totalSize.width;
> > > > +                   y_[i] = size.height / 2 - totalSize.height;
> > > >             }
> > > >
> > > > -           totalSize.width += config.x_size_tbl[i];
> > > > -           totalSize.height += config.y_size_tbl[i];
> > > > +           totalSize.width += x_[i];
> > > > +           totalSize.height += y_[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 / x_[i]);
> > > > +           yGrad_[i] = std::round(32768 / y_[i]);
> > > >     }
> > > >
> > > > -   std::copy(rData_.begin(), rData_.end(),
> > > > +   context.configuration.lsc.enabled = initialized_;
> > >
> > > I would check if initialized_ at the very beginning and exit if not
> > > true
> > >
> > > > +   return 0;
> >
> > Moving the gradient calculation from prepare() to configure() is a good
> > change, but it's not even mentioned in the commit message. I'd split
> > this to its own patch, going first in the series.
> >
> > > > +}
> > > > +
> > > > +void LensShadingCorrection::copyTable(rkisp1_params_cfg *params, const int index)
> >
> > You can pass rkisp1_cif_isp_lsc_config instead of rkisp1_params_cfg to
> > this function. I would also make it a reference instead of a pointer as
> > it can't be null.
> >
> > I'd also pass a const reference to the set instead of the index.
> >
> > > > +{
> > > > +   componentsData_t &set = sets_[index];
> > > > +
> > > > +   std::copy(set.r.begin(), set.r.end(),
> > > >               &params->others.lsc_config.r_data_tbl[0][0]);
> > > > -   std::copy(grData_.begin(), grData_.end(),
> > > > +   std::copy(set.gr.begin(), set.gr.end(),
> > > >               &params->others.lsc_config.gr_data_tbl[0][0]);
> > > > -   std::copy(gbData_.begin(), gbData_.end(),
> > > > +   std::copy(set.gb.begin(), set.gb.end(),
> > > >               &params->others.lsc_config.gb_data_tbl[0][0]);
> > > > -   std::copy(bData_.begin(), bData_.end(),
> > > > +   std::copy(set.b.begin(), set.b.end(),
> > > >               &params->others.lsc_config.b_data_tbl[0][0]);
> > > > +}
> > > > +
> > > > +/*
> > > > + * Interpolate LSC parameters based on color temperature value.
> > > > + */
> > > > +void LensShadingCorrection::interpolateTable(rkisp1_params_cfg *params, const double ct)
> >
> > Same here for params.
> >
> > > > +{
> > > > +   int index = 0;
> > > > +   while (ct > sets_[index + 1].ct)
> > > > +           index++;
> > > > +   double ct0 = sets_[index].ct, ct1 = sets_[index + 1].ct;
> > >
> > > That's risky. I know the caller guarantees that we're not dealing with
> > > the first or, most important here, the last vector entry. But
> > > this is an unbounded loop and the caller might get changed without
> > > considering it.
> > >
> > > I don't have much better ways to propose, as all the ones I have tried
> > > have anyway some assumptions. In example
> > >
> > >
> > >       auto set = sets_.begin();
> > >       for (; set != sets_.end() - 1; ++set) {
> > >               if (set->ct < ct)
> > >                       break;
> > >       }
> > >
> > >       componentsData_t &set0 = *(set - 1);
> > >       componentsData_t &set1 = *set;
> > >
> > > Won't work for arrays of a single element.
> > >
> > > Anyway, unless something more brilliant can be proposed, I would at
> > > least record that we assume ct is included in the min/max color
> > > temperatures ?
> > >
> > > > +
> > > > +   LOG(RkISP1Lsc, Debug)
> > > > +           << "ct is " << ct << ", interpolating between "
> > > > +           << ct0 << " and " << ct1;
> > > > +
> > > > +   componentsData_t &set0 = sets_[index];
> > > > +   componentsData_t &set1 = sets_[index + 1];
> > > > +
> > > > +   double coeff0 = (ct1 - ct) / (ct1 - ct0);
> > > > +   double coeff1 = (ct - ct0) / (ct1 - ct0);
> > > > +
> > > > +   for (int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
> > > > +           for (int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
> > > > +                   int sample = i * RKISP1_CIF_ISP_LSC_SAMPLES_MAX + j;
> >
> > All these variables can be unsigned.
> >
> > > > +
> > > > +                   params->others.lsc_config.r_data_tbl[i][j] =
> > > > +                           set0.r[sample] * coeff0 +
> > > > +                           set1.r[sample] * coeff1;
> > > > +
> > > > +                   params->others.lsc_config.gr_data_tbl[i][j] =
> > > > +                           set0.gr[sample] * coeff0 +
> > > > +                           set1.gr[sample] * coeff1;
> > > > +
> > > > +                   params->others.lsc_config.gb_data_tbl[i][j] =
> > > > +                           set0.gb[sample] * coeff0 +
> > > > +                           set1.gb[sample] * coeff1;
> > > > +
> > > > +                   params->others.lsc_config.b_data_tbl[i][j] =
> > > > +                           set0.b[sample] * coeff0 +
> > > > +                           set1.b[sample] * coeff1;
> > > > +           }
> > > > +   }
> > > > +}
> > > > +
> > > > +/**
> > > > + * \copydoc libcamera::ipa::Algorithm::prepare
> > > > + */
> > > > +void LensShadingCorrection::prepare(IPAContext &context,
> > > > +                               rkisp1_params_cfg *params)
> > > > +{
> > > > +   if (!initialized_)
> > > > +           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, x_, sizeof(config.x_size_tbl));
> > > > +   memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
> > > > +
> > > > +   double ct = context.frameContext.awb.temperatureK;
> > >
> > > Here it's where I would check how much the color temperature has
> > > changed and make choices (before the memcpys of course)
> >
> > As Jacopo mentioned, we shouldn't interpolate if the colour temperate is
> > very close to one of the tables, so I would have a special case here,
> > but write
> 
> Just to be makes it clear before implementing it: this 'close' is it something
> that should come from the tuning file? (or hardcoded in the code ? from
> somewhere else?)
> What should I put as a default value?

You can define it as a constant in this file. 1% could be a good value
to start with (a bit randomly).

> >
> >         double ct = context.frameContext.awb.temperatureK;
> >         ct = std::clamp(ct, sets_.front().ct, sets_.back().ct);
> >
> >         /*
> >          * Possibly Handle hysteresis here, returning if the value
> >          * hasn't changed enough.
> >          */
> >
> >         struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config;
> >
> >         /*
> >          * Pick the sets to interpolate between, or if the colour temperate is
> >          * close enough to one of the sets, use that set without interpolation.
> >          */
> >         ...
> >
> >         if (...)
> >                 copyTable(config, set0);
> >         else
> >                 interpolateTable(config, set0, set1, ct);
> >
> >         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, x_, sizeof(config.x_size_tbl));
> >         memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
> >
> > > > +   if (ct <= sets_.front().ct) {
> > > > +           LOG(RkISP1Lsc, Debug) << "using calibration for "
> > > > +                                 << sets_.front().ct;
> > > > +           copyTable(params, 0);
> > > > +   } else if (ct >= sets_.back().ct) {
> > > > +           LOG(RkISP1Lsc, Debug) << "using calibration for "
> > > > +                                 << sets_.back().ct;
> > > > +           copyTable(params, sets_.size() - 1);
> > > > +   } else {
> > > > +           interpolateTable(params, ct);
> > > > +   }
> > > >
> > > >     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 f68602c0..9b1adfd7 100644
> > > > --- a/src/ipa/rkisp1/algorithms/lsc.h
> > > > +++ b/src/ipa/rkisp1/algorithms/lsc.h
> > > > @@ -15,6 +15,14 @@ namespace ipa::rkisp1::algorithms {
> > > >
> > > >  class LensShadingCorrection : public Algorithm
> > > >  {
> > > > +   typedef struct componentsData {
> > >
> > > No need to typedef, and we usually use capital letter for types.
> > > This can be just
> > >
> > >         struct Components {
> > >
> > > Nice one, I'm thrilled to test it to see how much it improves the
> > > image quality!
> > >
> > > > +           uint16_t ct;
> > > > +           std::vector<uint16_t> r;
> > > > +           std::vector<uint16_t> gr;
> > > > +           std::vector<uint16_t> gb;
> > > > +           std::vector<uint16_t> b;
> > > > +   } componentsData_t;
> > > > +
> > > >  public:
> > > >     LensShadingCorrection();
> > > >     ~LensShadingCorrection() = default;
> > > > @@ -24,15 +32,18 @@ public:
> > > >     void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
> > > >
> > > >  private:
> > > > -   bool initialized_;
> > > > +   void copyTable(rkisp1_params_cfg *params, const int index);
> > > > +   void interpolateTable(rkisp1_params_cfg *params, const double ct);
> > > >
> > > > -   std::vector<uint16_t> rData_;
> > > > -   std::vector<uint16_t> grData_;
> > > > -   std::vector<uint16_t> gbData_;
> > > > -   std::vector<uint16_t> bData_;
> > > > +   bool initialized_;
> > > >
> > > > +   std::vector<componentsData_t> sets_;
> > > >     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 x_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> > > > +   uint16_t y_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
> >
> > Maybe xSizes_ and ySizes_ ?
> >
> > > >  };
> > > >
> > > >  } /* namespace ipa::rkisp1::algorithms */
> > > > diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml
> > > > index 33a672bc..d80c1655 100644
> > > > --- a/src/ipa/rkisp1/data/ov5640.yaml
> > > > +++ b/src/ipa/rkisp1/data/ov5640.yaml
> > > > @@ -20,82 +20,161 @@ algorithms:
> > > >    - LensShadingCorrection:
> > > >        x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> > > >        y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
> > > > -      r:  [
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -          ]
> > > > -      gr: [
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -          ]
> > > > -      gb: [
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -          ]
> > > > -      b:  [
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > -          ]
> > > > +      sets:
> > > > +        - ct: 3000
> > > > +          r:  [
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +              ]
> > > > +          gr: [
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +              ]
> > > > +          gb: [
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +              ]
> > > > +          b:  [
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
> > > > +              ]
> > > > +        - ct: 7000
> > > > +          r:  [
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +              ]
> > > > +          gr: [
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +              ]
> > > > +          gb: [
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +              ]
> > > > +          b:  [
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
> > > > +              ]
> > > >    - DefectPixelClusterCorrection:
> > > >        fixed-set: false
> > > >        sets:

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
index da287ac7..f0930e95 100644
--- a/src/ipa/rkisp1/algorithms/lsc.cpp
+++ b/src/ipa/rkisp1/algorithms/lsc.cpp
@@ -105,14 +105,39 @@  int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
 	if (xSize_.empty() || ySize_.empty())
 		return -EINVAL;
 
-	rData_ = parseTable(tuningData, "r");
-	grData_ = parseTable(tuningData, "gr");
-	gbData_ = parseTable(tuningData, "gb");
-	bData_ = parseTable(tuningData, "b");
-
-	if (rData_.empty() || grData_.empty() ||
-	    gbData_.empty() || bData_.empty())
+	/* Get all defined sets to apply. */
+	const YamlObject &yamlSets = tuningData["sets"];
+	if (!yamlSets.isList()) {
+		LOG(RkISP1Lsc, Error)
+			<< "'sets' parameter not found in tuning file";
 		return -EINVAL;
+	}
+
+	double lastCt = -1;
+
+	for (std::size_t i = 0; i < yamlSets.size(); ++i) {
+		const YamlObject &yamlSet = yamlSets[i];
+
+		sets_.push_back({});
+		componentsData &set = sets_.back();
+
+		set.ct = yamlSet["ct"].get<uint16_t>(0);
+		if (set.ct <= lastCt) {
+			LOG(RkISP1Lsc, Error)
+				<< "Entries in 'sets' must be in increasing ct order";
+			return -EINVAL;
+		}
+		lastCt = set.ct;
+
+		set.r = parseTable(yamlSet, "r");
+		set.gr = parseTable(yamlSet, "gr");
+		set.gb = parseTable(yamlSet, "gb");
+		set.b = parseTable(yamlSet, "b");
+
+		if (set.r.empty() || set.gr.empty() ||
+		    set.gb.empty() || set.b.empty())
+			return -EINVAL;
+	}
 
 	initialized_ = true;
 
@@ -125,56 +150,119 @@  int LensShadingCorrection::init([[maybe_unused]] IPAContext &context,
 int LensShadingCorrection::configure(IPAContext &context,
 				     [[maybe_unused]] const IPACameraSensorInfo &configInfo)
 {
-	context.configuration.lsc.enabled = initialized_;
-	return 0;
-}
-
-/**
- * \copydoc libcamera::ipa::Algorithm::prepare
- */
-void LensShadingCorrection::prepare(IPAContext &context,
-				    rkisp1_params_cfg *params)
-{
-	if (context.frameContext.frameCount > 0)
-		return;
-
-	if (!initialized_)
-		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;
+		x_[i] = xSize_[i] * size.width;
+		y_[i] = ySize_[i] * size.height;
 
 		/*
-		 * To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
-		 * y_size_tbl items shall be equal to respectively size.width/2 and
-		 * size.height/2. Enforce it by computing the last tables value to avoid
-		 * rounding-induced errors.
-		 */
+		* To prevent unexpected behavior of the ISP, the sum of x_size_tbl and
+		* y_size_tbl items shall be equal to respectively size.width/2 and
+		* size.height/2. Enforce it by computing the last tables value to avoid
+		* 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;
+			x_[i] = size.width / 2 - totalSize.width;
+			y_[i] = size.height / 2 - totalSize.height;
 		}
 
-		totalSize.width += config.x_size_tbl[i];
-		totalSize.height += config.y_size_tbl[i];
+		totalSize.width += x_[i];
+		totalSize.height += y_[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 / x_[i]);
+		yGrad_[i] = std::round(32768 / y_[i]);
 	}
 
-	std::copy(rData_.begin(), rData_.end(),
+	context.configuration.lsc.enabled = initialized_;
+	return 0;
+}
+
+void LensShadingCorrection::copyTable(rkisp1_params_cfg *params, const int index)
+{
+	componentsData_t &set = sets_[index];
+
+	std::copy(set.r.begin(), set.r.end(),
 		  &params->others.lsc_config.r_data_tbl[0][0]);
-	std::copy(grData_.begin(), grData_.end(),
+	std::copy(set.gr.begin(), set.gr.end(),
 		  &params->others.lsc_config.gr_data_tbl[0][0]);
-	std::copy(gbData_.begin(), gbData_.end(),
+	std::copy(set.gb.begin(), set.gb.end(),
 		  &params->others.lsc_config.gb_data_tbl[0][0]);
-	std::copy(bData_.begin(), bData_.end(),
+	std::copy(set.b.begin(), set.b.end(),
 		  &params->others.lsc_config.b_data_tbl[0][0]);
+}
+
+/*
+ * Interpolate LSC parameters based on color temperature value.
+ */
+void LensShadingCorrection::interpolateTable(rkisp1_params_cfg *params, const double ct)
+{
+	int index = 0;
+	while (ct > sets_[index + 1].ct)
+		index++;
+	double ct0 = sets_[index].ct, ct1 = sets_[index + 1].ct;
+
+	LOG(RkISP1Lsc, Debug)
+		<< "ct is " << ct << ", interpolating between "
+		<< ct0 << " and " << ct1;
+
+	componentsData_t &set0 = sets_[index];
+	componentsData_t &set1 = sets_[index + 1];
+
+	double coeff0 = (ct1 - ct) / (ct1 - ct0);
+	double coeff1 = (ct - ct0) / (ct1 - ct0);
+
+	for (int i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++i) {
+		for (int j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; ++j) {
+			int sample = i * RKISP1_CIF_ISP_LSC_SAMPLES_MAX + j;
+
+			params->others.lsc_config.r_data_tbl[i][j] =
+				set0.r[sample] * coeff0 +
+				set1.r[sample] * coeff1;
+
+			params->others.lsc_config.gr_data_tbl[i][j] =
+				set0.gr[sample] * coeff0 +
+				set1.gr[sample] * coeff1;
+
+			params->others.lsc_config.gb_data_tbl[i][j] =
+				set0.gb[sample] * coeff0 +
+				set1.gb[sample] * coeff1;
+
+			params->others.lsc_config.b_data_tbl[i][j] =
+				set0.b[sample] * coeff0 +
+				set1.b[sample] * coeff1;
+		}
+	}
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void LensShadingCorrection::prepare(IPAContext &context,
+				    rkisp1_params_cfg *params)
+{
+	if (!initialized_)
+		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, x_, sizeof(config.x_size_tbl));
+	memcpy(config.y_size_tbl, y_, sizeof(config.y_size_tbl));
+
+	double ct = context.frameContext.awb.temperatureK;
+	if (ct <= sets_.front().ct) {
+		LOG(RkISP1Lsc, Debug) << "using calibration for "
+				      << sets_.front().ct;
+		copyTable(params, 0);
+	} else if (ct >= sets_.back().ct) {
+		LOG(RkISP1Lsc, Debug) << "using calibration for "
+				      << sets_.back().ct;
+		copyTable(params, sets_.size() - 1);
+	} else {
+		interpolateTable(params, ct);
+	}
 
 	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 f68602c0..9b1adfd7 100644
--- a/src/ipa/rkisp1/algorithms/lsc.h
+++ b/src/ipa/rkisp1/algorithms/lsc.h
@@ -15,6 +15,14 @@  namespace ipa::rkisp1::algorithms {
 
 class LensShadingCorrection : public Algorithm
 {
+	typedef struct componentsData {
+		uint16_t ct;
+		std::vector<uint16_t> r;
+		std::vector<uint16_t> gr;
+		std::vector<uint16_t> gb;
+		std::vector<uint16_t> b;
+	} componentsData_t;
+
 public:
 	LensShadingCorrection();
 	~LensShadingCorrection() = default;
@@ -24,15 +32,18 @@  public:
 	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
 
 private:
-	bool initialized_;
+	void copyTable(rkisp1_params_cfg *params, const int index);
+	void interpolateTable(rkisp1_params_cfg *params, const double ct);
 
-	std::vector<uint16_t> rData_;
-	std::vector<uint16_t> grData_;
-	std::vector<uint16_t> gbData_;
-	std::vector<uint16_t> bData_;
+	bool initialized_;
 
+	std::vector<componentsData_t> sets_;
 	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 x_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
+	uint16_t y_[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
 };
 
 } /* namespace ipa::rkisp1::algorithms */
diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml
index 33a672bc..d80c1655 100644
--- a/src/ipa/rkisp1/data/ov5640.yaml
+++ b/src/ipa/rkisp1/data/ov5640.yaml
@@ -20,82 +20,161 @@  algorithms:
   - LensShadingCorrection:
       x-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
       y-size: [ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625 ]
-      r:  [
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-          ]
-      gr: [
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-          ]
-      gb: [
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-          ]
-      b:  [
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-            1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
-          ]
+      sets:
+        - ct: 3000
+          r:  [
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+              ]
+          gr: [
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+              ]
+          gb: [
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+              ]
+          b:  [
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+                1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
+              ]
+        - ct: 7000
+          r:  [
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+              ]
+          gr: [
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+              ]
+          gb: [
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+              ]
+          b:  [
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+                1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
+              ]
   - DefectPixelClusterCorrection:
       fixed-set: false
       sets: