[PATCH 2/2] libcamera: Use utils::to_underlying()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Feb 25 17:43:47 CET 2024


Replace manual implementations of the utils::to_underlying() helper with
calls to the function.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/ipa/rpi/controller/rpi/sdn.cpp             |  3 ++-
 src/libcamera/pipeline/rpi/common/rpi_stream.h | 10 +++-------
 src/libcamera/stream.cpp                       |  2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/ipa/rpi/controller/rpi/sdn.cpp b/src/ipa/rpi/controller/rpi/sdn.cpp
index 6743919e6b36..2f777dd725e2 100644
--- a/src/ipa/rpi/controller/rpi/sdn.cpp
+++ b/src/ipa/rpi/controller/rpi/sdn.cpp
@@ -6,6 +6,7 @@
  */
 
 #include <libcamera/base/log.h>
+#include <libcamera/base/utils.h>
 
 #include "../denoise_status.h"
 #include "../noise_status.h"
@@ -60,7 +61,7 @@ void Sdn::prepare(Metadata *imageMetadata)
 	status.noiseConstant = noiseStatus.noiseConstant * deviation_;
 	status.noiseSlope = noiseStatus.noiseSlope * deviation_;
 	status.strength = strength_;
-	status.mode = static_cast<std::underlying_type_t<DenoiseMode>>(mode_);
+	status.mode = utils::to_underlying(mode_);
 	imageMetadata->set("denoise.status", status);
 	LOG(RPiSdn, Debug)
 		<< "programmed constant " << status.noiseConstant
diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h
index fc2bdfe25d4a..48ed41abea01 100644
--- a/src/libcamera/pipeline/rpi/common/rpi_stream.h
+++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h
@@ -14,6 +14,7 @@
 #include <vector>
 
 #include <libcamera/base/flags.h>
+#include <libcamera/base/utils.h>
 
 #include <libcamera/stream.h>
 
@@ -180,19 +181,14 @@ private:
 template<typename E, std::size_t N>
 class Device : public std::array<class Stream, N>
 {
-private:
-	constexpr auto index(E e) const noexcept
-	{
-		return static_cast<std::underlying_type_t<E>>(e);
-	}
 public:
 	Stream &operator[](E e)
 	{
-		return std::array<class Stream, N>::operator[](index(e));
+		return std::array<class Stream, N>::operator[](utils::to_underlying(e));
 	}
 	const Stream &operator[](E e) const
 	{
-		return std::array<class Stream, N>::operator[](index(e));
+		return std::array<class Stream, N>::operator[](utils::to_underlying(e));
 	}
 };
 
diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
index f3e00ead5ac6..540a428eacdd 100644
--- a/src/libcamera/stream.cpp
+++ b/src/libcamera/stream.cpp
@@ -433,7 +433,7 @@ std::ostream &operator<<(std::ostream &out, StreamRole role)
 		"Viewfinder",
 	};
 
-	out << names[static_cast<std::underlying_type_t<StreamRole>>(role)];
+	out << names[utils::to_underlying(role)];
 	return out;
 }
 
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list