From 6d3965cf0137fcc6e87fd1cbd3833719a4ac5dbe Mon Sep 17 00:00:00 2001 From: Christian Rauch Date: Mon, 5 Aug 2024 19:10:35 +0200 Subject: [PATCH] clarify the value range and meaning of the extracted ControlId extent --- src/CameraNode.cpp | 2 +- src/type_extent.cpp | 10 ++++++++-- src/type_extent.hpp | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/CameraNode.cpp b/src/CameraNode.cpp index 0ce9f287..8f83933a 100644 --- a/src/CameraNode.cpp +++ b/src/CameraNode.cpp @@ -451,7 +451,7 @@ CameraNode::declareParameters() } // format type description - const bool scalar = (extent == 0) || (extent == 1); + const bool scalar = (extent == 0); const bool dynamic = (extent == libcamera::dynamic_extent); const std::string cv_type_descr = scalar ? "scalar" : "array[" + (dynamic ? std::string() : std::to_string(extent)) + "]"; diff --git a/src/type_extent.cpp b/src/type_extent.cpp index d67f28b0..b189cda4 100644 --- a/src/type_extent.cpp +++ b/src/type_extent.cpp @@ -19,6 +19,7 @@ template::value, bo std::size_t get_extent(const libcamera::Control &) { + // return an extent of 0 for non-span types return 0; } @@ -26,7 +27,12 @@ template::value, boo std::size_t get_extent(const libcamera::Control &) { - return libcamera::Control::type::extent; + // return the span extent, excluding 0 + // This assumes that libcamera does not define control types + // with a fixed size span that does not hold any elements + constexpr std::size_t extent = libcamera::Control::type::extent; + static_assert(extent != 0); + return extent; } #define IF(T) \ @@ -35,7 +41,7 @@ get_extent(const libcamera::Control &) std::size_t -get_extent(const libcamera::ControlId *id) +get_extent(const libcamera::ControlId *const id) { #if LIBCAMERA_VER_GE(0, 1, 0) IF(AeEnable) diff --git a/src/type_extent.hpp b/src/type_extent.hpp index 40b1efda..ca9b9d19 100644 --- a/src/type_extent.hpp +++ b/src/type_extent.hpp @@ -6,5 +6,11 @@ namespace libcamera class ControlId; } +/** + * @brief get the extent of a libcamera::ControlId + * @param id + * @return the extent of the control: 0 if the control is not a span, + * otherwise [1 ... libcamera::dynamic_extent] + */ std::size_t -get_extent(const libcamera::ControlId *id); +get_extent(const libcamera::ControlId *const id);