From patchwork Fri Oct 23 17:11:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10222 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 C0711BDB13 for ; Fri, 23 Oct 2020 17:11:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 122CB615D2; Fri, 23 Oct 2020 19:11:29 +0200 (CEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A054E615D2 for ; Fri, 23 Oct 2020 19:11:25 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 454F21C0006; Fri, 23 Oct 2020 17:11:25 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Oct 2020 19:11:07 +0200 Message-Id: <20201023171116.24899-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201023171116.24899-1-jacopo@jmondi.org> References: <20201023171116.24899-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/12] 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 --- include/libcamera/controls.h | 5 ++++ src/libcamera/controls.cpp | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 80944efc133a..0ae4fd002726 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -268,10 +268,14 @@ public: explicit ControlInfo(const ControlValue &min = 0, const ControlValue &max = 0, const ControlValue &def = 0); + explicit ControlInfo(const ControlValue *values, unsigned int numValues, + const ControlValue &def); + explicit ControlInfo(const ControlValue *values, unsigned int numValues); 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; @@ -289,6 +293,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..2a2f04a598b6 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -491,6 +491,42 @@ ControlInfo::ControlInfo(const ControlValue &min, { } +/** + * \brief Construct a ControlInfo from the list of values values and a default + * \param[in] values The control valid values + * \param[in] numValues The number or 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 assigned to the first and last members of + * the values list respectively. + */ +ControlInfo::ControlInfo(const ControlValue *values, unsigned int numValues, + const ControlValue &def) + : def_(def) +{ + min_ = values[0]; + max_ = values[numValues - 1]; + + for (unsigned int i = 0; i < numValues; ++i) + values_.push_back(values[i]); +} + +/** + * \brief Construct a ControlInfo from the list of valid values + * \param[in] values The control valid values + * \param[in] numValues The number or valid values + * + * Construct a ControlInfo from a list of valid values. The ControlInfo + * minimum and maximum values are assigned to the first and last members of + * the values list respectively. The ControlInfo default value is set to be + * equal to the minimum one. + */ +ControlInfo::ControlInfo(const ControlValue *values, unsigned int numValues) + : ControlInfo(values, numValues, values[0]) +{ +} + /** * \fn ControlInfo::min() * \brief Retrieve the minimum value of the control @@ -519,6 +555,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 */