From d978832d9e987b555be7c0ee8eeda37981924515 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 13 Jun 2024 02:52:15 +0300 Subject: ipa: libipa: pwl: Specialize YamlObject getter Implement a specialization of the YamlObject::Getter structure to support deserializing ipa::Pwl objects from YAML data. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/ipa/libipa/pwl.cpp') diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index cf864fbb..3c639645 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -459,4 +459,39 @@ std::string Pwl::toString() const } /* namespace ipa */ +#ifndef __DOXYGEN__ +/* + * The YAML data shall be a list of numerical values with an even number of + * elements. They are parsed in pairs into x and y points in the piecewise + * linear function, and added in order. x must be monotonically increasing. + */ +template<> +std::optional +YamlObject::Getter::get(const YamlObject &obj) const +{ + if (!obj.size() || obj.size() % 2) + return std::nullopt; + + ipa::Pwl pwl; + + const auto &list = obj.asList(); + + for (auto it = list.begin(); it != list.end(); it++) { + auto x = it->get(); + if (!x) + return std::nullopt; + auto y = (++it)->get(); + if (!y) + return std::nullopt; + + pwl.append(*x, *y); + } + + if (pwl.size() != obj.size() / 2) + return std::nullopt; + + return pwl; +} +#endif /* __DOXYGEN__ */ + } /* namespace libcamera */ -- cgit v1.2.1