[v6,11/15] ipa: rkisp1: lsc: Pass sampling positions into samplePolynomial
diff mbox series

Message ID 20260128-sklug-lsc-resampling-v2-dev-v6-11-af7d95f03d22@ideasonboard.com
State Accepted
Headers show
Series
  • Add resampling support for polynomial LSC data
Related show

Commit Message

Stefan Klug Jan. 28, 2026, 4 p.m. UTC
There is no need to recalculate the sampling positions over and over.
Pass them as parameter into the sampling function. The vectors are still
kept inside the loop as this is also a preparatory change for the
upcoming refactoring.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---

Changes in v2:
- Small fixes from review:
  - Replaced move construction by move assignments
  - Replaced some vectors by Spans
- Collected tags
---
 src/ipa/rkisp1/algorithms/lsc.cpp | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
index daf5c9a9b8fddf290a55471c4dce608f1b8ec82a..a70551ab70afec684d9c92bb9769c63d0f4f2653 100644
--- a/src/ipa/rkisp1/algorithms/lsc.cpp
+++ b/src/ipa/rkisp1/algorithms/lsc.cpp
@@ -91,7 +91,9 @@  public:
 
 private:
 	std::vector<double> sizesListToPositions(const std::vector<double> &sizes);
-	std::vector<uint16_t> samplePolynomial(const LscPolynomial &poly);
+	std::vector<uint16_t> samplePolynomial(const LscPolynomial &poly,
+					       Span<const double> xPositions,
+					       Span<const double> yPositions);
 
 	Size sensorSize_;
 	Rectangle cropRectangle_;
@@ -131,10 +133,13 @@  int LscPolynomialLoader::parseLscData(const YamlObject &yamlSets,
 		pgr->setReferenceImageSize(sensorSize_);
 		pgb->setReferenceImageSize(sensorSize_);
 		pb->setReferenceImageSize(sensorSize_);
-		set.r = samplePolynomial(*pr);
-		set.gr = samplePolynomial(*pgr);
-		set.gb = samplePolynomial(*pgb);
-		set.b = samplePolynomial(*pb);
+
+		std::vector<double> xPos = sizesListToPositions(xSizes_);
+		std::vector<double> yPos = sizesListToPositions(ySizes_);
+		set.r = samplePolynomial(*pr, xPos, yPos);
+		set.gr = samplePolynomial(*pgr, xPos, yPos);
+		set.gb = samplePolynomial(*pgb, xPos, yPos);
+		set.b = samplePolynomial(*pb, xPos, yPos);
 	}
 
 	if (lscData.empty()) {
@@ -171,10 +176,10 @@  std::vector<double> LscPolynomialLoader::sizesListToPositions(const std::vector<
 	return positions;
 }
 
-std::vector<uint16_t> LscPolynomialLoader::samplePolynomial(const LscPolynomial &poly)
+std::vector<uint16_t> LscPolynomialLoader::samplePolynomial(const LscPolynomial &poly,
+							    Span<const double> xPositions,
+							    Span<const double> yPositions)
 {
-	constexpr int k = RKISP1_CIF_ISP_LSC_SAMPLES_MAX;
-
 	double m = poly.getM();
 	double x0 = cropRectangle_.x / m;
 	double y0 = cropRectangle_.y / m;
@@ -182,18 +187,12 @@  std::vector<uint16_t> LscPolynomialLoader::samplePolynomial(const LscPolynomial
 	double h = cropRectangle_.height / m;
 	std::vector<uint16_t> samples;
 
-	ASSERT(xSizes_.size() * 2 + 1 == k);
-	ASSERT(ySizes_.size() * 2 + 1 == k);
-
-	samples.reserve(k * k);
-
-	std::vector<double> xPos(sizesListToPositions(xSizes_));
-	std::vector<double> yPos(sizesListToPositions(ySizes_));
+	samples.reserve(xPositions.size() * yPositions.size());
 
-	for (int y = 0; y < k; y++) {
-		for (int x = 0; x < k; x++) {
-			double xp = x0 + xPos[x] * w;
-			double yp = y0 + yPos[y] * h;
+	for (double y : yPositions) {
+		for (double x : xPositions) {
+			double xp = x0 + x * w;
+			double yp = y0 + y * h;
 			/*
 			 * The hardware uses 2.10 fixed point format and limits
 			 * the legal values to [1..3.999]. Scale and clamp the