summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-10-20 17:05:50 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-10-26 17:51:54 +0100
commit6377817f9f892e6a4601776de523505c14817527 (patch)
treeb7cc158e4289b3421951055591e5f47c07d89699
parent84e79bd8b5347d91309cbd759bbd988b5144fb8d (diff)
libcamera: controls: Construct from valid values
Add a new constructor to the ControlInfo class that allows creating a class instance from the list of the control valid values with an optional default one. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r--include/libcamera/controls.h5
-rw-r--r--src/libcamera/controls.cpp33
2 files changed, 38 insertions, 0 deletions
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index a556328c..3b7f3347 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -12,6 +12,7 @@
#include <stdint.h>
#include <string>
#include <unordered_map>
+#include <vector>
#include <libcamera/geometry.h>
#include <libcamera/span.h>
@@ -269,10 +270,13 @@ public:
explicit ControlInfo(const ControlValue &min = 0,
const ControlValue &max = 0,
const ControlValue &def = 0);
+ explicit ControlInfo(Span<const ControlValue> 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<ControlValue> &values() const { return values_; }
std::string toString() const;
@@ -290,6 +294,7 @@ private:
ControlValue min_;
ControlValue max_;
ControlValue def_;
+ std::vector<ControlValue> values_;
};
using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index dca78266..aad46112 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -492,6 +492,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<const ControlValue> 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
*
@@ -520,6 +542,17 @@ ControlInfo::ControlInfo(const ControlValue &min,
*/
/**
+ * \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
*/
std::string ControlInfo::toString() const