From patchwork Sun Oct 25 16:04:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10239 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A2971C3B5F for ; Sun, 25 Oct 2020 16:04:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6336B61E91; Sun, 25 Oct 2020 17:04:48 +0100 (CET) Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CAC361E01 for ; Sun, 25 Oct 2020 17:04:45 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id CDFE2240003; Sun, 25 Oct 2020 16:04:44 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 25 Oct 2020 17:04:24 +0100 Message-Id: <20201025160434.25664-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201025160434.25664-1-jacopo@jmondi.org> References: <20201025160434.25664-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 04/14] libcamera: controls: Construct from valid values X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add two constructors to the ControlInfo class that allows creating a class instance from the list of the control valid values with an optional default one. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/controls.h | 5 +++++ src/libcamera/controls.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index a556328cd188..3b7f3347761e 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -269,10 +270,13 @@ public: explicit ControlInfo(const ControlValue &min = 0, const ControlValue &max = 0, const ControlValue &def = 0); + explicit ControlInfo(Span values, + const ControlValue &def = {}); const ControlValue &min() const { return min_; } const ControlValue &max() const { return max_; } const ControlValue &def() const { return def_; } + const std::vector &values() const { return values_; } std::string toString() const; @@ -290,6 +294,7 @@ private: ControlValue min_; ControlValue max_; ControlValue def_; + std::vector values_; }; using ControlIdMap = std::unordered_map; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index dca782667d88..aad461121651 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -491,6 +491,28 @@ ControlInfo::ControlInfo(const ControlValue &min, { } +/** + * \brief Construct a ControlInfo from the list of valid values + * \param[in] values The control valid values + * \param[in] def The control default value + * + * Construct a ControlInfo from a list of valid values. The ControlInfo + * minimum and maximum values are set to the first and last members of the + * values list respectively. The default value is set to \a def if provided, or + * to the minimum value otherwise. + */ +ControlInfo::ControlInfo(Span values, + const ControlValue &def) +{ + min_ = values.front(); + max_ = values.back(); + def_ = !def.isNone() ? def : values.front(); + + values_.reserve(values.size()); + for (const ControlValue &value : values) + values_.push_back(value); +} + /** * \fn ControlInfo::min() * \brief Retrieve the minimum value of the control @@ -519,6 +541,17 @@ ControlInfo::ControlInfo(const ControlValue &min, * \return A ControlValue with the default value for the control */ +/** + * \fn ControlInfo::values() + * \brief Retrieve the list of valid values + * + * For controls that support a pre-defined number of values, the enumeration of + * those is reported through a vector of ControlValue instances accessible with + * this method. + * + * \return A vector of ControlValue representing the control valid values + */ + /** * \brief Provide a string representation of the ControlInfo */