From patchwork Thu Jun 13 01:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20273 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 172CCC3293 for ; Thu, 13 Jun 2024 01:40:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91F2065493; Thu, 13 Jun 2024 03:40:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YuJdYE3w"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20BA961A1C for ; Thu, 13 Jun 2024 03:40:06 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D2BABEB; Thu, 13 Jun 2024 03:39:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242792; bh=JRMOX4Cldgs+BbgWKYJ9CEDPYTbUVo4Bnn1TgyrmbL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YuJdYE3w1YJ5FIFoiq2BiQIYqjQk1dAPA67uzWeZw/AU95YuW9954PGb1WlaWlfBG aRnx6dZMIIy2agnllsahlqinYNAz/TuSlWZe7jVA04dUXc7dpu6aQVj32gweZ3EkTU Lgk7Y8uAekHEP2lMQm/bfS8WmoXZMPjLJKIum/ws= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 01/11] libcamera: yaml_parser: Drop std::enable_if_t guards for get() function Date: Thu, 13 Jun 2024 04:39:34 +0300 Message-ID: <20240613013944.23344-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" The YamlObject::get() function template is implemented for a set of basic types through template specializations. The function declaration uses std::enable_if_t<> guards to signal incorrect usage at compilation time. This however prevents the API to be extended with additional specializations in other compilation units. To prepare for new specializations of the function for the ipa::Vector and ipa::Pwl classes types, implemented in their respective compilation units, drop the std::enable_it_t<> guards. Incorrect usage will still be reported as link errors. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- include/libcamera/internal/yaml_parser.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 3ac27e06f69d..81cc0e25ae0f 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -161,22 +161,7 @@ public: std::size_t size() const; -#ifndef __DOXYGEN__ - template || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v> * = nullptr> -#else template -#endif std::optional get() const; template From patchwork Thu Jun 13 01:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20274 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 19284C3237 for ; Thu, 13 Jun 2024 01:40:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E202F6548E; Thu, 13 Jun 2024 03:40:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hm0R90g1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A6F2C6548D for ; Thu, 13 Jun 2024 03:40:07 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DB842D77; Thu, 13 Jun 2024 03:39:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242794; bh=rpXcpQX6Ga5FqCCk4kox9hOvcSZpo6tu6GCqeSqh7nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hm0R90g1qgK/MdAguc3ykL2G65RlPBgD+gWu1y3XBNCh+Zos8KLnLMSUSbDOHpZKR S7gcQcarJSUZcnlVAoK21W9CUFB9ns1vqQb/5ANQpMZ0kVK1A5dUfkeIsxafQExuBK +/QAFFOF9BAO5b2NTsNd+jSc5cA6X6h4P7LBcsCc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 02/11] libcamera: yaml_parser: Delegate YamlObject::get() to helper structure Date: Thu, 13 Jun 2024 04:39:35 +0300 Message-ID: <20240613013944.23344-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" The YamlObject::get() function is a function template that gets fully specialized for various types. This works fine for non-template types, but specializing it for template types (e.g. a std::vector) would require partial template specialization, which C++ allows for classes and variables but not functions. To work around this problem, delegate the implementation to a new YamlObject::Getter structure template, which will support partial specialization. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- include/libcamera/internal/yaml_parser.h | 12 +++- src/libcamera/yaml_parser.cpp | 78 +++++++++++++----------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 81cc0e25ae0f..06a41146ad01 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -162,7 +162,10 @@ public: std::size_t size() const; template - std::optional get() const; + std::optional get() const + { + return Getter{}.get(*this); + } template T get(U &&defaultValue) const @@ -199,6 +202,8 @@ public: private: LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject) + template + friend struct Getter; friend class YamlParserContext; enum class Type { @@ -207,6 +212,11 @@ private: Value, }; + template + struct Getter { + std::optional get(const YamlObject &obj) const; + }; + Type type_; std::string value_; diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index b68a44c15c35..56670ba7a584 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -118,14 +118,15 @@ std::size_t YamlObject::size() const #ifndef __DOXYGEN__ template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; - if (value_ == "true") + if (obj.value_ == "true") return true; - else if (value_ == "false") + else if (obj.value_ == "false") return false; return std::nullopt; @@ -182,14 +183,15 @@ bool parseUnsignedInteger(const std::string &str, unsigned long max, } /* namespace */ template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; long value; - if (!parseSignedInteger(value_, std::numeric_limits::min(), + if (!parseSignedInteger(obj.value_, std::numeric_limits::min(), std::numeric_limits::max(), &value)) return std::nullopt; @@ -197,14 +199,15 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; unsigned long value; - if (!parseUnsignedInteger(value_, std::numeric_limits::max(), + if (!parseUnsignedInteger(obj.value_, std::numeric_limits::max(), &value)) return std::nullopt; @@ -212,14 +215,15 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; long value; - if (!parseSignedInteger(value_, std::numeric_limits::min(), + if (!parseSignedInteger(obj.value_, std::numeric_limits::min(), std::numeric_limits::max(), &value)) return std::nullopt; @@ -227,14 +231,15 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; unsigned long value; - if (!parseUnsignedInteger(value_, std::numeric_limits::max(), + if (!parseUnsignedInteger(obj.value_, std::numeric_limits::max(), &value)) return std::nullopt; @@ -242,14 +247,15 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; long value; - if (!parseSignedInteger(value_, std::numeric_limits::min(), + if (!parseSignedInteger(obj.value_, std::numeric_limits::min(), std::numeric_limits::max(), &value)) return std::nullopt; @@ -257,14 +263,15 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; unsigned long value; - if (!parseUnsignedInteger(value_, std::numeric_limits::max(), + if (!parseUnsignedInteger(obj.value_, std::numeric_limits::max(), &value)) return std::nullopt; @@ -272,18 +279,19 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; - if (value_ == "") + if (obj.value_ == "") return std::nullopt; char *end; errno = 0; - double value = utils::strtod(value_.c_str(), &end); + double value = utils::strtod(obj.value_.c_str(), &end); if ('\0' != *end || errno == ERANGE) return std::nullopt; @@ -292,28 +300,30 @@ std::optional YamlObject::get() const } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::Value) + if (obj.type_ != Type::Value) return std::nullopt; - return value_; + return obj.value_; } template<> -std::optional YamlObject::get() const +std::optional +YamlObject::Getter::get(const YamlObject &obj) const { - if (type_ != Type::List) + if (obj.type_ != Type::List) return std::nullopt; - if (list_.size() != 2) + if (obj.list_.size() != 2) return std::nullopt; - auto width = list_[0].value->get(); + auto width = obj.list_[0].value->get(); if (!width) return std::nullopt; - auto height = list_[1].value->get(); + auto height = obj.list_[1].value->get(); if (!height) return std::nullopt; From patchwork Thu Jun 13 01:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20275 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 8A2DBC3293 for ; Thu, 13 Jun 2024 01:40:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 112F965493; Thu, 13 Jun 2024 03:40:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sxLc39Lo"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E6DB06548C for ; Thu, 13 Jun 2024 03:40:08 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DBD7E39; Thu, 13 Jun 2024 03:39:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242795; bh=vEHaev4LalzGsWPM+nfMRN0TeBcAy0Ra1ZUNuwKQxo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sxLc39LoSC5da49TATx8c+iU3+cdfv5ONSAeoyzeI5BDBL3l222QlxSrFyHTE2uMk ZhUSyMOlWVVA5irChhI2gCywZ5RHIm1/PjdmE9iKkpdba4gMCWr4l0Nvvu494cHwKB bmA0sczb/Wvro8lg/SbpqBBKh7Q5uvYlTPJG4Dm4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 03/11] ipa: libipa: vector: Specialize YamlObject getter Date: Thu, 13 Jun 2024 04:39:36 +0300 Message-ID: <20240613013944.23344-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" Implement a specialization of the YamlObject::Getter structure to support deserializing ipa::Vector objects from YAML data. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/vector.cpp | 17 +++++++++++++++++ src/ipa/libipa/vector.h | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index 5de4ae48b419..4e987d82fa70 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -148,6 +148,23 @@ namespace ipa { * \return True if the two vectors are not equal, false otherwise */ +#ifndef __DOXYGEN__ +bool vectorValidateYaml(const YamlObject &obj, unsigned int size) +{ + if (!obj.isList()) + return false; + + if (obj.size() != size) { + LOG(Vector, Error) + << "Wrong number of values in YAML vector: expected " + << size << ", got " << obj.size(); + return false; + } + + return true; +} +#endif /* __DOXYGEN__ */ + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 7c444363d4bb..4b2fe581ecc2 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -180,6 +180,10 @@ bool operator!=(const Vector &lhs, const Vector &rhs) return !(lhs == rhs); } +#ifndef __DOXYGEN__ +bool vectorValidateYaml(const YamlObject &obj, unsigned int size); +#endif /* __DOXYGEN__ */ + } /* namespace ipa */ #ifndef __DOXYGEN__ @@ -195,6 +199,27 @@ std::ostream &operator<<(std::ostream &out, const ipa::Vector &v) return out; } + +template +struct YamlObject::Getter> { + std::optional> get(const YamlObject &obj) const + { + if (!ipa::vectorValidateYaml(obj, Rows)) + return std::nullopt; + + ipa::Vector vector; + + unsigned int i = 0; + for (const YamlObject &entry : obj.asList()) { + const auto value = entry.get(); + if (!value) + return std::nullopt; + vector[i++] = *value; + } + + return vector; + } +}; #endif /* __DOXYGEN__ */ } /* namespace libcamera */ From patchwork Thu Jun 13 01:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20276 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 DB22DC3237 for ; Thu, 13 Jun 2024 01:40:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 749F26548E; Thu, 13 Jun 2024 03:40:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="et9LEaXA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC2F46548D for ; Thu, 13 Jun 2024 03:40:10 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C8D1BEB; Thu, 13 Jun 2024 03:39:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242796; bh=6+WxV82SCc7NA/PAiPvjRQwCUTImjbjizgdBq9+JBQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=et9LEaXAy9YvB70BWQZFoAZLFyH9GHZiof+UtL6mvBEeCsv/YBG6aD4q9zbgivKW1 HUKy++Gaam6AA0ywEfZGh4GswXGpLX415/NGF0sBzHzV6mz/LZl6v/S0Nwk9RpUtGf FD0As9FfXOtCYyMGlOS9twuJSs0I+Yu+1Nw8/h+A= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 04/11] ipa: libipa: vector: Drop readYaml() function Date: Thu, 13 Jun 2024 04:39:37 +0300 Message-ID: <20240613013944.23344-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" Now that YAML deserialization of Vector instances is supported through YamlObject::get(), remove the Vector::readYaml() function. It turns out not be used. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/vector.cpp | 13 ------------- src/ipa/libipa/vector.h | 23 ----------------------- 2 files changed, 36 deletions(-) diff --git a/src/ipa/libipa/vector.cpp b/src/ipa/libipa/vector.cpp index 4e987d82fa70..b071b261b9c4 100644 --- a/src/ipa/libipa/vector.cpp +++ b/src/ipa/libipa/vector.cpp @@ -40,19 +40,6 @@ namespace ipa { * The size of \a data must be equal to the dimension size Rows of the vector. */ -/** - * \fn Vector::readYaml - * \brief Populate the vector with yaml data - * \param yaml Yaml data to populate the vector with - * - * Any existing data in the vector will be overwritten. The size of the data - * read from \a yaml must be equal to the dimension size Rows of the vector. - * - * The yaml data is expected to be a list with elements of type T. - * - * \return 0 on success, negative error code otherwise - */ - /** * \fn T Vector::operator[](size_t i) const * \brief Index to an element in the vector diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 4b2fe581ecc2..2a2906202ce4 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -39,29 +39,6 @@ public: data_[i] = data[i]; } - int readYaml(const libcamera::YamlObject &yaml) - { - if (yaml.size() != Rows) { - LOG(Vector, Error) - << "Wrong number of values in vector: expected " - << Rows << ", got " << yaml.size(); - return -EINVAL; - } - - unsigned int i = 0; - for (const auto &x : yaml.asList()) { - auto value = x.get(); - if (!value) { - LOG(Vector, Error) << "Failed to read vector value"; - return -EINVAL; - } - - data_[i++] = *value; - } - - return 0; - } - const T &operator[](size_t i) const { ASSERT(i < data_.size()); From patchwork Thu Jun 13 01:39:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20277 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 194F0C32CF for ; Thu, 13 Jun 2024 01:40:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A3B846549D; Thu, 13 Jun 2024 03:40:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Qzdcl1Gi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9AF426548C for ; Thu, 13 Jun 2024 03:40:11 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBD9BE39; Thu, 13 Jun 2024 03:39:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242798; bh=R24D/tLrCwiSeu16WgLpUhETYKZRuAaY2OYR7W3QM7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qzdcl1GiJ6Jt1t1wx9kI+iHVXx2rwgRL9Colmma9gSxHUX3W5cmNSB5Llhy/Nyd1q eHrsVvJ0NrONh4sQNlsKn7qBJVWF5qIUS6waZG507ngfGcQbQbKs6WMLRCS0y50X+U fUvCmFfV8sbYpp2vys+jZFkfZgrCzlOGsqyRNB3E= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 05/11] ipa: libipa: pwl: Suffix \param with direction Date: Thu, 13 Jun 2024 04:39:38 +0300 Message-ID: <20240613013944.23344-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" Suffix the Doxygen \param commands with the direction for all parameters. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 901e42ceb2ce..1ba0108515a1 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -60,14 +60,14 @@ namespace ipa { /** * \fn Pwl::Interval::Interval(double _start, double _end) * \brief Construct an interval - * \param _start Start of the interval - * \param _end End of the interval + * \param[in] _start Start of the interval + * \param[in] _end End of the interval */ /** * \fn Pwl::Interval::contains * \brief Check if a given value falls within the interval - * \param value Value to check + * \param[in] value Value to check * \return True if the value falls within the interval, including its bounds, * or false otherwise */ @@ -75,7 +75,7 @@ namespace ipa { /** * \fn Pwl::Interval::clamp * \brief Clamp a value such that it is within the interval - * \param value Value to clamp + * \param[in] value Value to clamp * \return The clamped value */ @@ -104,7 +104,8 @@ Pwl::Pwl() /** * \brief Construct a piecewise linear function from a list of 2D points - * \param points Vector of points from which to construct the piecewise linear function + * \param[in] points Vector of points from which to construct the piecewise + * linear function * * \a points must be in ascending order of x-value. */ @@ -115,7 +116,7 @@ Pwl::Pwl(const std::vector &points) /** * \brief Populate the piecewise linear function from yaml data - * \param params Yaml data to populate the piecewise linear function with + * \param[in] params Yaml data to populate the piecewise linear function with * * Any existing points in the piecewise linear function *will* be overwritten. * @@ -153,9 +154,9 @@ int Pwl::readYaml(const libcamera::YamlObject ¶ms) /** * \brief Append a point to the end of the piecewise linear function - * \param x x-coordinate of the point to add to the piecewise linear function - * \param y y-coordinate of the point to add to the piecewise linear function - * \param eps Epsilon for the minimum x distance between points (optional) + * \param[in] x x-coordinate of the point to add to the piecewise linear function + * \param[in] y y-coordinate of the point to add to the piecewise linear function + * \param[in] eps Epsilon for the minimum x distance between points (optional) * * The point's x-coordinate must be greater than the x-coordinate of the last * (= greatest) point already in the piecewise linear function. @@ -168,9 +169,9 @@ void Pwl::append(double x, double y, const double eps) /** * \brief Prepend a point to the beginning of the piecewise linear function - * \param x x-coordinate of the point to add to the piecewise linear function - * \param y y-coordinate of the point to add to the piecewise linear function - * \param eps Epsilon for the minimum x distance between points (optional) + * \param[in] x x-coordinate of the point to add to the piecewise linear function + * \param[in] y y-coordinate of the point to add to the piecewise linear function + * \param[in] eps Epsilon for the minimum x distance between points (optional) * * The point's x-coordinate must be less than the x-coordinate of the first * (= smallest) point already in the piecewise linear function. @@ -353,7 +354,7 @@ Pwl Pwl::compose(Pwl const &other, const double eps) const /** * \brief Apply function to (x, y) values at every control point - * \param f Function to be applied + * \param[in] f Function to be applied */ void Pwl::map(std::function f) const { @@ -364,9 +365,9 @@ void Pwl::map(std::function f) const /** * \brief Apply function to (x, y0, y1) values wherever either Pwl has a * control point. - * \param pwl0 First piecewise linear function - * \param pwl1 Second piecewise linear function - * \param f Function to be applied + * \param[in] pwl0 First piecewise linear function + * \param[in] pwl1 Second piecewise linear function + * \param[in] f Function to be applied * * This applies the function \a f to every parameter (x, y0, y1), where x is * the combined list of x-values from \a pwl0 and \a pwl1, y0 is the y-value @@ -395,9 +396,9 @@ void Pwl::map2(Pwl const &pwl0, Pwl const &pwl1, /** * \brief Combine two Pwls - * \param pwl0 First piecewise linear function - * \param pwl1 Second piecewise linear function - * \param f Function to be applied + * \param[in] pwl0 First piecewise linear function + * \param[in] pwl1 Second piecewise linear function + * \param[in] f Function to be applied * \param[in] eps Epsilon for the minimum x distance between points (optional) * * Create a new Pwl where the y values are given by running \a f wherever @@ -418,7 +419,7 @@ Pwl Pwl::combine(Pwl const &pwl0, Pwl const &pwl1, /** * \brief Multiply the piecewise linear function - * \param d Scalar multiplier to multiply the function by + * \param[in] d Scalar multiplier to multiply the function by * \return This function, after it has been multiplied by \a d */ Pwl &Pwl::operator*=(double d) From patchwork Thu Jun 13 01:39:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20278 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 6B677C3293 for ; Thu, 13 Jun 2024 01:40:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7FBC7654A5; Thu, 13 Jun 2024 03:40:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OSzwPOD+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F115665497 for ; Thu, 13 Jun 2024 03:40:12 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 24E03D77; Thu, 13 Jun 2024 03:39:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242799; bh=QfP+IXVNd5SDkUNs2zUuuWEjVVHYBLjTTkKgFe1q5Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OSzwPOD+M2boEMMlzGeHXoogFJmvF1igeacimHjve1cqZ83m+121LSlEqFzb9I67Q M8U6dXH+R7CDUnW5ywuPC5uXpstQ5hsxHN+hn/4NIMOn2rUcTMRcB6cCRe91Yvdlf0 dXxAn4/rZ5IkQ/wDgaKjXZOk8uMcIwUbKTUC+998= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 06/11] ipa: libipa: pwl: Make the empty() function inline Date: Thu, 13 Jun 2024 04:39:39 +0300 Message-ID: <20240613013944.23344-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" The Pwl::empty() function is a one-liner that can be easily optimized by the compiler given the chance. Make it inline. While at it, move the function documentation block to match the class declaration order. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 15 ++++++--------- src/ipa/libipa/pwl.h | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 1ba0108515a1..d8ea92be0a86 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -182,6 +182,12 @@ void Pwl::prepend(double x, double y, const double eps) points_.insert(points_.begin(), Point({ x, y })); } +/** + * \fn Pwl::empty() const + * \brief Check if the piecewise linear function is empty + * \return True if there are no points in the function, false otherwise + */ + /** * \brief Get the domain of the piecewise linear function * \return An interval representing the domain @@ -203,15 +209,6 @@ Pwl::Interval Pwl::range() const return Interval(lo, hi); } -/** - * \brief Check if the piecewise linear function is empty - * \return True if there are no points in the function, false otherwise - */ -bool Pwl::empty() const -{ - return points_.empty(); -} - /** * \brief Evaluate the piecewise linear function * \param[in] x The x value to input into the function diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h index 4cc257f97b19..b4de00cf88f0 100644 --- a/src/ipa/libipa/pwl.h +++ b/src/ipa/libipa/pwl.h @@ -51,7 +51,7 @@ public: void append(double x, double y, double eps = 1e-6); - bool empty() const; + bool empty() const { return points_.empty(); } Interval domain() const; Interval range() const; From patchwork Thu Jun 13 01:39:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20279 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 A2DDAC3237 for ; Thu, 13 Jun 2024 01:40:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5841865493; Thu, 13 Jun 2024 03:40:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QyALSLOf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 385D36548E for ; Thu, 13 Jun 2024 03:40:14 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7242914F6; Thu, 13 Jun 2024 03:40:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242800; bh=+2Ie6SuSVmwT98UJPkmaaxNiaK0n36IBUW/S7guOaR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QyALSLOff8/dTxBUJNkSSFz2nHNH6/kxH5cJtgjzoQWIZdfGk9W9n1ijGXnQku0V4 nxjWJg7dqifnAshxfJ00MQ1kdLWs5YPYJ3e0UKmSzCfaeMTpwgs3J+GCUMKmAF8oK7 7M6+RtNVWTKtta9+yju4BK+59oYyXAvQC48bShMs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 07/11] ipa: libipa: pwl: Add a size() function Date: Thu, 13 Jun 2024 04:39:40 +0300 Message-ID: <20240613013944.23344-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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 a size() function to the Pwl class to return the number of points in the piecewise linear function. This is useful, for instance, to validate that all points added with append() or prepend() have been taken into account. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 6 ++++++ src/ipa/libipa/pwl.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index d8ea92be0a86..8b437dd1a650 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -188,6 +188,12 @@ void Pwl::prepend(double x, double y, const double eps) * \return True if there are no points in the function, false otherwise */ +/** + * \fn Pwl::size() const + * \brief Retrieve the number of points in the piecewise linear function + * \return The number of points in the piecewise linear function + */ + /** * \brief Get the domain of the piecewise linear function * \return An interval representing the domain diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h index b4de00cf88f0..028342314fca 100644 --- a/src/ipa/libipa/pwl.h +++ b/src/ipa/libipa/pwl.h @@ -52,6 +52,8 @@ public: void append(double x, double y, double eps = 1e-6); bool empty() const { return points_.empty(); } + size_t size() const { return points_.size(); } + Interval domain() const; Interval range() const; From patchwork Thu Jun 13 01:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20280 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 80D02C3293 for ; Thu, 13 Jun 2024 01:40:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0305F6549D; Thu, 13 Jun 2024 03:40:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="quBFpeAC"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9110A6549D for ; Thu, 13 Jun 2024 03:40:15 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C4726D77; Thu, 13 Jun 2024 03:40:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242802; bh=sB1nvilvtB2BVEco4UCdHl1jKNcmGdGTbSSCICTpOwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=quBFpeACenKSRA3Mi5VD9sfj3TKprIO6dAj8EP4RT741gBYE8AjehtkTGExFFCj8O DA/R84lPLiOh10nSrp454OqE2p8bkaTnY6tJ18wLTQHjEEudQjlD+OJh8XZK+8awSI tcfv3smnMmqAMhDsDZr2ihi6kJ6LRO8mD+j+PpHk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 08/11] ipa: libipa: pwl: Add a constructor that moves a Point vector Date: Thu, 13 Jun 2024 04:39:41 +0300 Message-ID: <20240613013944.23344-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" The Pwl::Pwl(const std::vector &) constructor is inefficient as it makes a copy of the given points vector. Add a second constructor that takes an rvalue reference to a points vector to provide move semantics. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 11 +++++++++++ src/ipa/libipa/pwl.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 8b437dd1a650..cf864fbb3889 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -114,6 +114,17 @@ Pwl::Pwl(const std::vector &points) { } +/** + * \copydoc Pwl::Pwl(const std::vector &points) + * + * The contents of the \a points vector is moved to the newly constructed Pwl + * instance. + */ +Pwl::Pwl(std::vector &&points) + : points_(std::move(points)) +{ +} + /** * \brief Populate the piecewise linear function from yaml data * \param[in] params Yaml data to populate the piecewise linear function with diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h index 028342314fca..8edb4d33dc71 100644 --- a/src/ipa/libipa/pwl.h +++ b/src/ipa/libipa/pwl.h @@ -47,6 +47,8 @@ public: Pwl(); Pwl(const std::vector &points); + Pwl(std::vector &&points); + int readYaml(const libcamera::YamlObject ¶ms); void append(double x, double y, double eps = 1e-6); From patchwork Thu Jun 13 01:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20281 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 81598C32CF for ; Thu, 13 Jun 2024 01:40:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF4B0654A2; Thu, 13 Jun 2024 03:40:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gKaMeQRi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E22AB6548C for ; Thu, 13 Jun 2024 03:40:16 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 201E1D77; Thu, 13 Jun 2024 03:40:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242803; bh=yota/oSVAMrw0hkf+nFveAese1LIg7FjfDaAk+OTDKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKaMeQRi6R9aNd2v9kg+VDqoqOFqPnsiDh2KgFWG5zDq/jFSVDU3EPJ1lY7CrzjM2 Zh7Qy9tmVi7Yfk2hdr62Wc+Hbj8bPNyrid0YInt4cGZf1K4mwGlZ5RthsuPg8i32Jz fqlqIivZ20fDl5qKNToKOR8n6+13L/Gvp2eBtFqU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 09/11] ipa: libipa: pwl: Specialize YamlObject getter Date: Thu, 13 Jun 2024 04:39:42 +0300 Message-ID: <20240613013944.23344-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" 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(+) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index cf864fbb3889..3c639645fa3d 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 */ From patchwork Thu Jun 13 01:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20282 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 AB459C32D0 for ; Thu, 13 Jun 2024 01:40:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A17A165493; Thu, 13 Jun 2024 03:40:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ucstaAus"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 36C3E6549B for ; Thu, 13 Jun 2024 03:40:18 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77BBCE39; Thu, 13 Jun 2024 03:40:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242804; bh=2MXmYmAqW1FhyNWiain1GT8MZZQ8izk1FG0fwfjn7hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ucstaAusrvwdpCpNxyMjLWtY3gmQxbKGDVjwphBmAUv22tqiova6zmUAy4llR4NYb T0XgsvFtrtFMFQI7AXq1hMGPpfhG4+c6YhEpxV4DcNgAz+j7tCZGlSeR9RaU9zSxF6 7CyC9w5tCN7bMA5qbm+V93IkL6XidfBnomGnvwT0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 10/11] ipa: rpi: controller: Replace Pwl::readYaml() with YamlObject::get() Date: Thu, 13 Jun 2024 04:39:43 +0300 Message-ID: <20240613013944.23344-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" Now that deserializing a Pwl object from YAML data is possible using the YamlObject::get() function, replace all usage of Pwl::readYaml() to prepare for its removal. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: David Plowman Tested-by: Laurent Pinchart --- src/ipa/rpi/controller/rpi/af.cpp | 2 +- src/ipa/rpi/controller/rpi/agc_channel.cpp | 9 +++++---- src/ipa/rpi/controller/rpi/awb.cpp | 3 ++- src/ipa/rpi/controller/rpi/ccm.cpp | 6 +++--- src/ipa/rpi/controller/rpi/contrast.cpp | 4 +++- src/ipa/rpi/controller/rpi/geq.cpp | 6 +++--- src/ipa/rpi/controller/rpi/hdr.cpp | 4 ++-- src/ipa/rpi/controller/rpi/tonemap.cpp | 2 +- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/af.cpp b/src/ipa/rpi/controller/rpi/af.cpp index 304629d6d4e5..5ca76dd98b4b 100644 --- a/src/ipa/rpi/controller/rpi/af.cpp +++ b/src/ipa/rpi/controller/rpi/af.cpp @@ -139,7 +139,7 @@ int Af::CfgParams::read(const libcamera::YamlObject ¶ms) readNumber(skipFrames, params, "skip_frames"); if (params.contains("map")) - map.readYaml(params["map"]); + map = params["map"].get(ipa::Pwl{}); else LOG(RPiAf, Warning) << "No map defined"; diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp index a381dd972215..cf2565a83836 100644 --- a/src/ipa/rpi/controller/rpi/agc_channel.cpp +++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp @@ -130,7 +130,8 @@ int AgcConstraint::read(const libcamera::YamlObject ¶ms) return -EINVAL; qHi = *value; - return yTarget.readYaml(params["y_target"]); + yTarget = params["y_target"].get(ipa::Pwl{}); + return yTarget.empty() ? -EINVAL : 0; } static std::tuple @@ -237,9 +238,9 @@ int AgcConfig::read(const libcamera::YamlObject ¶ms) return ret; } - ret = yTarget.readYaml(params["y_target"]); - if (ret) - return ret; + yTarget = params["y_target"].get(ipa::Pwl{}); + if (yTarget.empty()) + return -EINVAL; speed = params["speed"].get(0.2); startupFrames = params["startup_frames"].get(10); diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index 603953d7d863..003c8fa137f3 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -49,7 +49,8 @@ int AwbPrior::read(const libcamera::YamlObject ¶ms) return -EINVAL; lux = *value; - return prior.readYaml(params["prior"]); + prior = params["prior"].get(ipa::Pwl{}); + return prior.empty() ? -EINVAL : 0; } static int readCtCurve(ipa::Pwl &ctR, ipa::Pwl &ctB, const libcamera::YamlObject ¶ms) diff --git a/src/ipa/rpi/controller/rpi/ccm.cpp b/src/ipa/rpi/controller/rpi/ccm.cpp index 3272a1416ffa..e673964c1856 100644 --- a/src/ipa/rpi/controller/rpi/ccm.cpp +++ b/src/ipa/rpi/controller/rpi/ccm.cpp @@ -71,9 +71,9 @@ int Ccm::read(const libcamera::YamlObject ¶ms) int ret; if (params.contains("saturation")) { - ret = config_.saturation.readYaml(params["saturation"]); - if (ret) - return ret; + config_.saturation = params["saturation"].get(ipa::Pwl{}); + if (config_.saturation.empty()) + return -EINVAL; } for (auto &p : params["ccms"].asList()) { diff --git a/src/ipa/rpi/controller/rpi/contrast.cpp b/src/ipa/rpi/controller/rpi/contrast.cpp index 66871a61ed28..9b37943ae9c9 100644 --- a/src/ipa/rpi/controller/rpi/contrast.cpp +++ b/src/ipa/rpi/controller/rpi/contrast.cpp @@ -53,7 +53,9 @@ int Contrast::read(const libcamera::YamlObject ¶ms) config_.hiHistogram = params["hi_histogram"].get(0.95); config_.hiLevel = params["hi_level"].get(0.95); config_.hiMax = params["hi_max"].get(2000); - return config_.gammaCurve.readYaml(params["gamma_curve"]); + + config_.gammaCurve = params["gamma_curve"].get(ipa::Pwl{}); + return config_.gammaCurve.empty() ? -EINVAL : 0; } void Contrast::setBrightness(double brightness) diff --git a/src/ipa/rpi/controller/rpi/geq.cpp b/src/ipa/rpi/controller/rpi/geq.cpp index c9c38ebff5ba..40e7191ba16a 100644 --- a/src/ipa/rpi/controller/rpi/geq.cpp +++ b/src/ipa/rpi/controller/rpi/geq.cpp @@ -44,9 +44,9 @@ int Geq::read(const libcamera::YamlObject ¶ms) } if (params.contains("strength")) { - int ret = config_.strength.readYaml(params["strength"]); - if (ret) - return ret; + config_.strength = params["strength"].get(ipa::Pwl{}); + if (config_.strength.empty()) + return -EINVAL; } return 0; diff --git a/src/ipa/rpi/controller/rpi/hdr.cpp b/src/ipa/rpi/controller/rpi/hdr.cpp index d533a4ea4e65..f3da8291bf5d 100644 --- a/src/ipa/rpi/controller/rpi/hdr.cpp +++ b/src/ipa/rpi/controller/rpi/hdr.cpp @@ -42,7 +42,7 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod /* Lens shading related parameters. */ if (params.contains("spatial_gain_curve")) { - spatialGainCurve.readYaml(params["spatial_gain_curve"]); + spatialGainCurve = params["spatial_gain_curve"].get(ipa::Pwl{}); } else if (params.contains("spatial_gain")) { double spatialGain = params["spatial_gain"].get(2.0); spatialGainCurve.append(0.0, spatialGain); @@ -66,7 +66,7 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod iirStrength = params["iir_strength"].get(8.0); strength = params["strength"].get(1.5); if (tonemapEnable) - tonemap.readYaml(params["tonemap"]); + tonemap = params["tonemap"].get(ipa::Pwl{}); speed = params["speed"].get(1.0); if (params.contains("hi_quantile_targets")) { hiQuantileTargets = params["hi_quantile_targets"].getList().value(); diff --git a/src/ipa/rpi/controller/rpi/tonemap.cpp b/src/ipa/rpi/controller/rpi/tonemap.cpp index 2dc50dfc8d2d..3422adfe7dee 100644 --- a/src/ipa/rpi/controller/rpi/tonemap.cpp +++ b/src/ipa/rpi/controller/rpi/tonemap.cpp @@ -33,7 +33,7 @@ int Tonemap::read(const libcamera::YamlObject ¶ms) config_.detailSlope = params["detail_slope"].get(0.1); config_.iirStrength = params["iir_strength"].get(1.0); config_.strength = params["strength"].get(1.0); - config_.tonemap.readYaml(params["tone_curve"]); + config_.tonemap = params["tone_curve"].get(ipa::Pwl{}); return 0; } From patchwork Thu Jun 13 01:39:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20283 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 9FBA1C3237 for ; Thu, 13 Jun 2024 01:40:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A3B136549D; Thu, 13 Jun 2024 03:40:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hTz5uDl+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84619654A1 for ; Thu, 13 Jun 2024 03:40:19 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C2EE614F6; Thu, 13 Jun 2024 03:40:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718242805; bh=+wDculNBA42w46q7XROhdckmjwuZrNAg860CH+vBi2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTz5uDl+WDcgJBOePD6ASOArqdNCow6A345psH+yx8XV+oMHpBYNyEtDcN2CpYGCN Se5UbfI1beCwaWF1JK7i9wOUb1fFHIlY/Tbm8cImhNdJo3+0xJKGWpeRL7wHZaCUME 8aCSpc1ijTIwz4/0ouU2uLm3M66u+6d7TBI1DZ7U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , David Plowman , Naushir Patuck Subject: [PATCH 11/11] ipa: libipa: pwl: Drop readYaml() function Date: Thu, 13 Jun 2024 04:39:44 +0300 Message-ID: <20240613013944.23344-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> References: <20240613013944.23344-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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" All users of the Pwl::readYaml() function have been removed. The function is not used, and is deprecated in favour of YamlObject::get(). Drop it. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 38 -------------------------------------- src/ipa/libipa/pwl.h | 2 -- 2 files changed, 40 deletions(-) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 3c639645fa3d..9b213754ec7d 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -125,44 +125,6 @@ Pwl::Pwl(std::vector &&points) { } -/** - * \brief Populate the piecewise linear function from yaml data - * \param[in] params Yaml data to populate the piecewise linear function with - * - * Any existing points in the piecewise linear function *will* be overwritten. - * - * The yaml data is expected to be a list with an even number of numerical - * elements. These will be parsed in pairs into x and y points in the piecewise - * linear function, and added in order. x must be monotonically increasing. - * - * \return 0 on success, negative error code otherwise - */ -int Pwl::readYaml(const libcamera::YamlObject ¶ms) -{ - if (!params.size() || params.size() % 2) - return -EINVAL; - - const auto &list = params.asList(); - - points_.clear(); - - for (auto it = list.begin(); it != list.end(); it++) { - auto x = it->get(); - if (!x) - return -EINVAL; - if (it != list.begin() && *x <= points_.back().x()) - return -EINVAL; - - auto y = (++it)->get(); - if (!y) - return -EINVAL; - - points_.push_back(Point({ *x, *y })); - } - - return 0; -} - /** * \brief Append a point to the end of the piecewise linear function * \param[in] x x-coordinate of the point to add to the piecewise linear function diff --git a/src/ipa/libipa/pwl.h b/src/ipa/libipa/pwl.h index 8edb4d33dc71..b6f93494d807 100644 --- a/src/ipa/libipa/pwl.h +++ b/src/ipa/libipa/pwl.h @@ -49,8 +49,6 @@ public: Pwl(const std::vector &points); Pwl(std::vector &&points); - int readYaml(const libcamera::YamlObject ¶ms); - void append(double x, double y, double eps = 1e-6); bool empty() const { return points_.empty(); }