From ab67fdd210e30ad3806f10cb5f6d4e325059f8de Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Mon, 16 Sep 2024 01:50:43 +0200 Subject: libcamera: controls: Add array information to ControlId Add to ControlId information on whether or not it is an array control, and the size of the control if it is an array control. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- include/libcamera/controls.h | 17 ++++++++++++++++- src/libcamera/controls.cpp | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 96a774cc..25f67ed9 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -46,50 +46,60 @@ struct control_type { template<> struct control_type { static constexpr ControlType value = ControlTypeNone; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeBool; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeByte; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeInteger32; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeInteger64; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeFloat; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeString; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeRectangle; + static constexpr std::size_t size = 0; }; template<> struct control_type { static constexpr ControlType value = ControlTypeSize; + static constexpr std::size_t size = 0; }; template struct control_type> : public control_type> { + static constexpr std::size_t size = N; }; } /* namespace details */ @@ -215,11 +225,14 @@ class ControlId { public: ControlId(unsigned int id, const std::string &name, ControlType type, + std::size_t size = 0, const std::map &enumStrMap = {}); unsigned int id() const { return id_; } const std::string &name() const { return name_; } ControlType type() const { return type_; } + bool isArray() const { return size_ > 0; } + std::size_t size() const { return size_; } const std::map &enumerators() const { return reverseMap_; } private: @@ -228,6 +241,7 @@ private: unsigned int id_; std::string name_; ControlType type_; + std::size_t size_; std::map enumStrMap_; std::map reverseMap_; }; @@ -259,7 +273,8 @@ public: using type = T; Control(unsigned int id, const char *name, const std::map &enumStrMap = {}) - : ControlId(id, name, details::control_type>::value, enumStrMap) + : ControlId(id, name, details::control_type>::value, + details::control_type>::size, enumStrMap) { } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index a46c431a..ea439730 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -389,11 +389,12 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen * \param[in] id The control numerical ID * \param[in] name The control name * \param[in] type The control data type + * \param[in] size The size of the array control, or 0 if scalar control * \param[in] enumStrMap The map from enum names to values (optional) */ ControlId::ControlId(unsigned int id, const std::string &name, ControlType type, - const std::map &enumStrMap) - : id_(id), name_(name), type_(type), enumStrMap_(enumStrMap) + std::size_t size, const std::map &enumStrMap) + : id_(id), name_(name), type_(type), size_(size), enumStrMap_(enumStrMap) { for (const auto &pair : enumStrMap_) reverseMap_[pair.second] = pair.first; @@ -417,6 +418,19 @@ ControlId::ControlId(unsigned int id, const std::string &name, ControlType type, * \return The control data type */ +/** + * \fn bool ControlId::isArray() const + * \brief Determine if the control is an array control + * \return True if the control is an array control, false otherwise + */ + +/** + * \fn std::size_t ControlId::size() const + * \brief Retrieve the size of the control if it is an array control + * \return The size of the array control, size_t::max for dynamic extent, or 0 + * for non-array + */ + /** * \fn const std::map &ControlId::enumerators() const * \brief Retrieve the map of enum values to enum names -- cgit v1.2.1