[libcamera-devel,v8,4/4] libcamera: controls: Apply explicit fixed-sized Span type casts
diff mbox series

Message ID 20220610120338.96883-5-Rauch.Christian@gmx.de
State Superseded
Headers show
Series
  • generate and use fixed-sized Span Control types
Related show

Commit Message

Christian Rauch June 10, 2022, 12:03 p.m. UTC
The change of types of some Controls from variable- to fixed-sized requires
explicit casting of FrameDurationLimits, ColourGains and SensorBlackLevels.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
---
 include/libcamera/controls.h                  |  2 +-
 src/ipa/raspberrypi/raspberrypi.cpp           | 19 ++++++++++---------
 .../pipeline/raspberrypi/raspberrypi.cpp      |  2 +-
 src/qcam/dng_writer.cpp                       |  2 +-
 4 files changed, 13 insertions(+), 12 deletions(-)

--
2.34.1

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 192be784..a19f1845 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -168,7 +168,7 @@  public:

 		using V = typename T::value_type;
 		const V *value = reinterpret_cast<const V *>(data().data());
-		return { value, numElements_ };
+		return T{ value, numElements_ };
 	}

 #ifndef __DOXYGEN__
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index f65a0680..203ae613 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -505,18 +505,19 @@  void IPARPi::reportMetadata()

 	AwbStatus *awbStatus = rpiMetadata_.GetLocked<AwbStatus>("awb.status");
 	if (awbStatus) {
-		libcameraMetadata_.set(controls::ColourGains, { static_cast<float>(awbStatus->gain_r),
-								static_cast<float>(awbStatus->gain_b) });
+		libcameraMetadata_.set(controls::ColourGains,
+				       Span<const float, 2>({ static_cast<float>(awbStatus->gain_r),
+							      static_cast<float>(awbStatus->gain_b) }));
 		libcameraMetadata_.set(controls::ColourTemperature, awbStatus->temperature_K);
 	}

 	BlackLevelStatus *blackLevelStatus = rpiMetadata_.GetLocked<BlackLevelStatus>("black_level.status");
 	if (blackLevelStatus)
 		libcameraMetadata_.set(controls::SensorBlackLevels,
-				       { static_cast<int32_t>(blackLevelStatus->black_level_r),
-					 static_cast<int32_t>(blackLevelStatus->black_level_g),
-					 static_cast<int32_t>(blackLevelStatus->black_level_g),
-					 static_cast<int32_t>(blackLevelStatus->black_level_b) });
+				       Span<const int32_t, 4>({ blackLevelStatus->black_level_r,
+								blackLevelStatus->black_level_g,
+								blackLevelStatus->black_level_g,
+								blackLevelStatus->black_level_b }));

 	FocusStatus *focusStatus = rpiMetadata_.GetLocked<FocusStatus>("focus.status");
 	if (focusStatus && focusStatus->num == 12) {
@@ -821,7 +822,7 @@  void IPARPi::queueRequest(const ControlList &controls)
 			if (gains[0] != 0.0f && gains[1] != 0.0f)
 				/* A gain of 0.0f will switch back to auto mode. */
 				libcameraMetadata_.set(controls::ColourGains,
-						       { gains[0], gains[1] });
+						       Span<const float, 2>({ gains[0], gains[1] }));
 			break;
 		}

@@ -1105,8 +1106,8 @@  void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur

 	/* Return the validated limits via metadata. */
 	libcameraMetadata_.set(controls::FrameDurationLimits,
-			       { static_cast<int64_t>(minFrameDuration_.get<std::micro>()),
-				 static_cast<int64_t>(maxFrameDuration_.get<std::micro>()) });
+			       Span<const int64_t, 2>({ static_cast<int64_t>(minFrameDuration_.get<std::micro>()),
+							static_cast<int64_t>(maxFrameDuration_.get<std::micro>()) }));

 	/*
 	 * Calculate the maximum exposure time possible for the AGC to use.
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index a62afdd4..6efe7c3c 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -1706,7 +1706,7 @@  void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &
 	 * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set).
 	 */
 	if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) {
-		libcamera::Span<const float> colourGains =
+		libcamera::Span<const float, 2> colourGains =
 			*controls.get(libcamera::controls::ColourGains);
 		/* The control wants linear gains in the order B, Gb, Gr, R. */
 		ControlList ctrls(sensor_->controls());
diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
index 4b5d8276..23612be0 100644
--- a/src/qcam/dng_writer.cpp
+++ b/src/qcam/dng_writer.cpp
@@ -514,7 +514,7 @@  int DNGWriter::write(const char *filename, const Camera *camera,
 	uint32_t whiteLevel = (1 << info->bitsPerSample) - 1;

 	if (metadata.contains(controls::SensorBlackLevels)) {
-		Span<const int32_t> levels =
+		Span<const int32_t, 4> levels =
 			*metadata.get(controls::SensorBlackLevels);

 		/*