[libcamera-devel] [PATCH v3 7/8] ipa: raspberrypi: Remove #define constants

Naushir Patuck naush at raspberrypi.com
Wed Jul 27 10:55:23 CEST 2022


Replace all #define constant values with equivalent constexpr definitions.
As a drive-by, remove the CAMERA_MODE_NAME_LEN constant as it is unused.

Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/ipa/raspberrypi/controller/alsc_status.h  | 10 ++++-----
 src/ipa/raspberrypi/controller/camera_mode.h  |  2 --
 .../raspberrypi/controller/contrast_status.h  |  4 ++--
 src/ipa/raspberrypi/controller/rpi/agc.cpp    | 22 +++++++++----------
 src/ipa/raspberrypi/controller/rpi/agc.h      |  4 ++--
 src/ipa/raspberrypi/controller/rpi/alsc.cpp   |  4 ++--
 src/ipa/raspberrypi/controller/rpi/alsc.h     | 22 +++++++++----------
 src/ipa/raspberrypi/controller/rpi/awb.cpp    |  8 +++----
 .../raspberrypi/controller/rpi/contrast.cpp   |  6 ++---
 src/ipa/raspberrypi/raspberrypi.cpp           |  2 +-
 10 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/src/ipa/raspberrypi/controller/alsc_status.h b/src/ipa/raspberrypi/controller/alsc_status.h
index 498880daf2d1..e5aa7e37c330 100644
--- a/src/ipa/raspberrypi/controller/alsc_status.h
+++ b/src/ipa/raspberrypi/controller/alsc_status.h
@@ -11,11 +11,11 @@
  * "alsc.status" metadata.
  */
 
-#define ALSC_CELLS_X 16
-#define ALSC_CELLS_Y 12
+constexpr unsigned int AlscCellsX = 16;
+constexpr unsigned int AlscCellsY = 12;
 
 struct AlscStatus {
-	double r[ALSC_CELLS_Y][ALSC_CELLS_X];
-	double g[ALSC_CELLS_Y][ALSC_CELLS_X];
-	double b[ALSC_CELLS_Y][ALSC_CELLS_X];
+	double r[AlscCellsY][AlscCellsX];
+	double g[AlscCellsY][AlscCellsX];
+	double b[AlscCellsY][AlscCellsX];
 };
diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
index 0ac6c07fb7bf..a6ccf8c1c600 100644
--- a/src/ipa/raspberrypi/controller/camera_mode.h
+++ b/src/ipa/raspberrypi/controller/camera_mode.h
@@ -16,8 +16,6 @@
  * including binning, scaling, cropping etc.
  */
 
-#define CAMERA_MODE_NAME_LEN 32
-
 struct CameraMode {
 	/* bit depth of the raw camera output */
 	uint32_t bitdepth;
diff --git a/src/ipa/raspberrypi/controller/contrast_status.h b/src/ipa/raspberrypi/controller/contrast_status.h
index 11d55295963b..ef2a7c680fc2 100644
--- a/src/ipa/raspberrypi/controller/contrast_status.h
+++ b/src/ipa/raspberrypi/controller/contrast_status.h
@@ -11,7 +11,7 @@
  * of contrast stretching based on the AGC histogram.
  */
 
-#define CONTRAST_NUM_POINTS 33
+constexpr unsigned int ContrastNumPoints = 33;
 
 struct ContrastPoint {
 	uint16_t x;
@@ -19,7 +19,7 @@ struct ContrastPoint {
 };
 
 struct ContrastStatus {
-	struct ContrastPoint points[CONTRAST_NUM_POINTS];
+	struct ContrastPoint points[ContrastNumPoints];
 	double brightness;
 	double contrast;
 };
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp
index e9a945e3a630..e0c174b6580d 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp
@@ -28,17 +28,17 @@ LOG_DEFINE_CATEGORY(RPiAgc)
 
 #define NAME "rpi.agc"
 
-#define PIPELINE_BITS 13 /* seems to be a 13-bit pipeline */
+static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */
 
 void AgcMeteringMode::read(boost::property_tree::ptree const &params)
 {
 	int num = 0;
 	for (auto &p : params.get_child("weights")) {
-		if (num == AGC_STATS_SIZE)
+		if (num == AgcStatsSize)
 			LOG(RPiAgc, Fatal) << "AgcConfig: too many weights";
 		weights[num++] = p.second.get_value<double>();
 	}
-	if (num != AGC_STATS_SIZE)
+	if (num != AgcStatsSize)
 		LOG(RPiAgc, Fatal) << "AgcConfig: insufficient weights";
 }
 
@@ -525,11 +525,11 @@ static double computeInitialY(bcm2835_isp_stats *stats, AwbStatus const &awb,
 	 * "average" metering (i.e. all pixels equally important).
 	 */
 	double rSum = 0, gSum = 0, bSum = 0, pixelSum = 0;
-	for (int i = 0; i < AGC_STATS_SIZE; i++) {
+	for (unsigned int i = 0; i < AgcStatsSize; i++) {
 		double counted = regions[i].counted;
-		double rAcc = std::min(regions[i].r_sum * gain, ((1 << PIPELINE_BITS) - 1) * counted);
-		double gAcc = std::min(regions[i].g_sum * gain, ((1 << PIPELINE_BITS) - 1) * counted);
-		double bAcc = std::min(regions[i].b_sum * gain, ((1 << PIPELINE_BITS) - 1) * counted);
+		double rAcc = std::min(regions[i].r_sum * gain, ((1 << PipelineBits) - 1) * counted);
+		double gAcc = std::min(regions[i].g_sum * gain, ((1 << PipelineBits) - 1) * counted);
+		double bAcc = std::min(regions[i].b_sum * gain, ((1 << PipelineBits) - 1) * counted);
 		rSum += rAcc * weights[i];
 		gSum += gAcc * weights[i];
 		bSum += bAcc * weights[i];
@@ -542,7 +542,7 @@ static double computeInitialY(bcm2835_isp_stats *stats, AwbStatus const &awb,
 	double ySum = rSum * awb.gainR * .299 +
 		      gSum * awb.gainG * .587 +
 		      bSum * awb.gainB * .114;
-	return ySum / pixelSum / (1 << PIPELINE_BITS);
+	return ySum / pixelSum / (1 << PipelineBits);
 }
 
 /*
@@ -553,13 +553,13 @@ static double computeInitialY(bcm2835_isp_stats *stats, AwbStatus const &awb,
  * (contrived) cases.
  */
 
-#define EV_GAIN_Y_TARGET_LIMIT 0.9
+static constexpr double EvGainYTargetLimit = 0.9;
 
 static double constraintComputeGain(AgcConstraint &c, Histogram &h, double lux,
 				    double evGain, double &targetY)
 {
 	targetY = c.yTarget.eval(c.yTarget.domain().clip(lux));
-	targetY = std::min(EV_GAIN_Y_TARGET_LIMIT, targetY * evGain);
+	targetY = std::min(EvGainYTargetLimit, targetY * evGain);
 	double iqm = h.interQuantileMean(c.qLo, c.qHi);
 	return (targetY * NUM_HISTOGRAM_BINS) / iqm;
 }
@@ -578,7 +578,7 @@ void Agc::computeGain(bcm2835_isp_stats *statistics, Metadata *imageMetadata,
 	 * that we consider the histogram constraints.
 	 */
 	targetY = config_.yTarget.eval(config_.yTarget.domain().clip(lux.lux));
-	targetY = std::min(EV_GAIN_Y_TARGET_LIMIT, targetY * evGain);
+	targetY = std::min(EvGainYTargetLimit, targetY * evGain);
 
 	/*
 	 * Do this calculation a few times as brightness increase can be
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h
index 48b33a10c73a..f57afa6dc80c 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.h
+++ b/src/ipa/raspberrypi/controller/rpi/agc.h
@@ -22,12 +22,12 @@
  * number (which is 16).
  */
 
-#define AGC_STATS_SIZE 15
+constexpr unsigned int AgcStatsSize = 15;
 
 namespace RPiController {
 
 struct AgcMeteringMode {
-	double weights[AGC_STATS_SIZE];
+	double weights[AgcStatsSize];
 	void read(boost::property_tree::ptree const &params);
 };
 
diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp
index 7df89445711a..03ae33501dc0 100644
--- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp
@@ -23,8 +23,8 @@ LOG_DEFINE_CATEGORY(RPiAlsc)
 
 #define NAME "rpi.alsc"
 
-static const int X = ALSC_CELLS_X;
-static const int Y = ALSC_CELLS_Y;
+static const int X = AlscCellsX;
+static const int Y = AlscCellsY;
 static const int XY = X * Y;
 static const double InsufficientData = -1.0;
 
diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.h b/src/ipa/raspberrypi/controller/rpi/alsc.h
index e17f2fe93379..4e9a715ae0ab 100644
--- a/src/ipa/raspberrypi/controller/rpi/alsc.h
+++ b/src/ipa/raspberrypi/controller/rpi/alsc.h
@@ -19,7 +19,7 @@ namespace RPiController {
 
 struct AlscCalibration {
 	double ct;
-	double table[ALSC_CELLS_X * ALSC_CELLS_Y];
+	double table[AlscCellsX * AlscCellsY];
 };
 
 struct AlscConfig {
@@ -35,7 +35,7 @@ struct AlscConfig {
 	uint16_t minG;
 	double omega;
 	uint32_t nIter;
-	double luminanceLut[ALSC_CELLS_X * ALSC_CELLS_Y];
+	double luminanceLut[AlscCellsX * AlscCellsY];
 	double luminanceStrength;
 	std::vector<AlscCalibration> calibrationsCr;
 	std::vector<AlscCalibration> calibrationsCb;
@@ -61,7 +61,7 @@ private:
 	AlscConfig config_;
 	bool firstTime_;
 	CameraMode cameraMode_;
-	double luminanceTable_[ALSC_CELLS_X * ALSC_CELLS_Y];
+	double luminanceTable_[AlscCellsX * AlscCellsY];
 	std::thread asyncThread_;
 	void asyncFunc(); /* asynchronous thread function */
 	std::mutex mutex_;
@@ -87,8 +87,8 @@ private:
 	int frameCount_;
 	/* counts up to startupFrames for Process function */
 	int frameCount2_;
-	double syncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X];
-	double prevSyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X];
+	double syncResults_[3][AlscCellsY][AlscCellsX];
+	double prevSyncResults_[3][AlscCellsY][AlscCellsX];
 	void waitForAysncThread();
 	/*
 	 * The following are for the asynchronous thread to use, though the main
@@ -98,13 +98,13 @@ private:
 	/* copy out the results from the async thread so that it can be restarted */
 	void fetchAsyncResults();
 	double ct_;
-	bcm2835_isp_stats_region statistics_[ALSC_CELLS_Y * ALSC_CELLS_X];
-	double asyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X];
-	double asyncLambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y];
-	double asyncLambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y];
+	bcm2835_isp_stats_region statistics_[AlscCellsY * AlscCellsX];
+	double asyncResults_[3][AlscCellsY][AlscCellsX];
+	double asyncLambdaR_[AlscCellsX * AlscCellsY];
+	double asyncLambdaB_[AlscCellsX * AlscCellsY];
 	void doAlsc();
-	double lambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y];
-	double lambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y];
+	double lambdaR_[AlscCellsX * AlscCellsY];
+	double lambdaB_[AlscCellsX * AlscCellsY];
 };
 
 } /* namespace RPiController */
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp
index d87a8f358539..f5898fc48eb6 100644
--- a/src/ipa/raspberrypi/controller/rpi/awb.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp
@@ -18,8 +18,8 @@ LOG_DEFINE_CATEGORY(RPiAwb)
 
 #define NAME "rpi.awb"
 
-#define AWB_STATS_SIZE_X DEFAULT_AWB_REGIONS_X
-#define AWB_STATS_SIZE_Y DEFAULT_AWB_REGIONS_Y
+static constexpr unsigned int AwbStatsSizeX = DEFAULT_AWB_REGIONS_X;
+static constexpr unsigned int AwbStatsSizeY = DEFAULT_AWB_REGIONS_Y;
 
 /*
  * todo - the locking in this algorithm needs some tidying up as has been done
@@ -357,7 +357,7 @@ static void generateStats(std::vector<Awb::RGB> &zones,
 			  bcm2835_isp_stats_region *stats, double minPixels,
 			  double minG)
 {
-	for (int i = 0; i < AWB_STATS_SIZE_X * AWB_STATS_SIZE_Y; i++) {
+	for (unsigned int i = 0; i < AwbStatsSizeX * AwbStatsSizeY; i++) {
 		Awb::RGB zone;
 		double counted = stats[i].counted;
 		if (counted >= minPixels) {
@@ -599,7 +599,7 @@ void Awb::awbBayes()
 	 * valid... not entirely sure about this.
 	 */
 	Pwl prior = interpolatePrior();
-	prior *= zones_.size() / (double)(AWB_STATS_SIZE_X * AWB_STATS_SIZE_Y);
+	prior *= zones_.size() / (double)(AwbStatsSizeX * AwbStatsSizeY);
 	prior.map([](double x, double y) {
 		LOG(RPiAwb, Debug) << "(" << x << "," << y << ")";
 	});
diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp
index 04aeb91e4d61..9e60dc5d47e7 100644
--- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp
@@ -70,15 +70,15 @@ static void fillInStatus(ContrastStatus &status, double brightness,
 {
 	status.brightness = brightness;
 	status.contrast = contrast;
-	for (int i = 0; i < CONTRAST_NUM_POINTS - 1; i++) {
+	for (unsigned int i = 0; i < ContrastNumPoints - 1; i++) {
 		int x = i < 16 ? i * 1024
 			       : (i < 24 ? (i - 16) * 2048 + 16384
 					 : (i - 24) * 4096 + 32768);
 		status.points[i].x = x;
 		status.points[i].y = std::min(65535.0, gammaCurve.eval(x));
 	}
-	status.points[CONTRAST_NUM_POINTS - 1].x = 65535;
-	status.points[CONTRAST_NUM_POINTS - 1].y = 65535;
+	status.points[ContrastNumPoints - 1].x = 65535;
+	status.points[ContrastNumPoints - 1].y = 65535;
 }
 
 void Contrast::initialise()
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 951d8c65abfd..9d550354d78e 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -1235,7 +1235,7 @@ void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList
 	struct bcm2835_isp_gamma gamma;
 
 	gamma.enabled = 1;
-	for (int i = 0; i < CONTRAST_NUM_POINTS; i++) {
+	for (unsigned int i = 0; i < ContrastNumPoints; i++) {
 		gamma.x[i] = contrastStatus->points[i].x;
 		gamma.y[i] = contrastStatus->points[i].y;
 	}
-- 
2.25.1



More information about the libcamera-devel mailing list