From patchwork Tue May 24 22:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16027 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 8A0B8BD161 for ; Tue, 24 May 2022 22:58:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1756C65670; Wed, 25 May 2022 00:58:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433109; bh=c+sScQK4fT7hxRiMXqN58bPZT5GyrKJgbTvVGkrF0lI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=TOw6v4PTnvFZDpvDMyZ4pPa+zMoBb/vQfnj7W0/nVYuzBrwz+X5+hXmbpZkxH44k/ 9uOEdiOLirz7mfYSwTV20d3qwLl9zcn0yNlZYKuYs0i5vXfuryJnYe+KGYnM4GBn1Q eIbWE3w7p5jrkyQoCiR42wynosZyqC9sHG5DfRTnd37FETyu2Ya1gWJDiJgZHh5Yes JVTbzQQbfB2I/v66DtshQoYW6f7LMGjqJFyOWh4+rYvMUgpNce8a/eLDji3njl0AOf KDjLdjCNnVgAU590ngvCQA3LzqMpGOXiTvitWp/vSH+rqdg2F7TF4OUcRFjfpuGuDK QusKWQ4aTwgEw== 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 ED3C360416 for ; Wed, 25 May 2022 00:58:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Q+/WmQua"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6CEEAA58; Wed, 25 May 2022 00:58:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433104; bh=c+sScQK4fT7hxRiMXqN58bPZT5GyrKJgbTvVGkrF0lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q+/WmQuafk/xWtnEjVIIKrqgq7RGQqR3uWfSruTsigpU3q25HLysEyV7fGuSbtCty 0VfHg0JBPnITMLjkhl5DJq3uopY4aMorGnuZ3HEj3Tsd2Ntwuo2A29amecqBvVHLlS y8K2DA8thXbBTPwUsIdQHRdzc5d/okibD+IyibMk= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:05 +0300 Message-Id: <20220524225816.6830-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 01/12] libcamera: yaml_object: Turn Type into an enum class 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Turn the Type enum into an enum class to force qualifying 'List' and 'Dictionary' in the YamlObject namespace scope. This will help avoiding ambiguities when adding iterator support. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 8 +++--- src/libcamera/yaml_parser.cpp | 32 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 3a4f3052fb65..e002fcf59278 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -28,15 +28,15 @@ public: bool isValue() const { - return type_ == Value; + return type_ == Type::Value; } bool isList() const { - return type_ == List; + return type_ == Type::List; } bool isDictionary() const { - return type_ == Dictionary; + return type_ == Type::Dictionary; } #ifndef __DOXYGEN__ @@ -65,7 +65,7 @@ private: friend class YamlParserContext; - enum Type { + enum class Type { Dictionary, List, Value, diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 92fedaebebfd..4b5ea427bf45 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -47,7 +47,7 @@ void setOk(bool *ok, bool result) */ YamlObject::YamlObject() - : type_(Value) + : type_(Type::Value) { } @@ -99,7 +99,7 @@ bool YamlObject::get(const bool &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "true") { @@ -118,7 +118,7 @@ int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "") @@ -141,7 +141,7 @@ uint32_t YamlObject::get(const uint32_t &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "") @@ -175,7 +175,7 @@ double YamlObject::get(const double &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; if (value_ == "") @@ -198,7 +198,7 @@ std::string YamlObject::get(const std::string &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != Value) + if (type_ != Type::Value) return defaultValue; setOk(ok, true); @@ -210,7 +210,7 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const { setOk(ok, false); - if (type_ != List) + if (type_ != Type::List) return defaultValue; if (list_.size() != 2) @@ -248,7 +248,7 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const */ std::size_t YamlObject::size() const { - if (type_ != List) + if (type_ != Type::List) return 0; return list_.size(); @@ -266,7 +266,7 @@ std::size_t YamlObject::size() const */ const YamlObject &YamlObject::operator[](std::size_t index) const { - if (type_ != List || index >= size()) + if (type_ != Type::List || index >= size()) return empty; return *list_[index]; @@ -326,7 +326,7 @@ std::vector YamlObject::memberNames() const */ const YamlObject &YamlObject::operator[](const std::string &key) const { - if (type_ != Dictionary || !contains(key)) + if (type_ != Type::Dictionary || !contains(key)) return empty; auto iter = dictionary_.find(key); @@ -510,7 +510,7 @@ int YamlParserContext::parseDictionaryOrList(YamlObject::Type type, const std::function &parseItem) { yaml_event_type_t endEventType = YAML_SEQUENCE_END_EVENT; - if (type == YamlObject::Dictionary) + if (type == YamlObject::Type::Dictionary) endEventType = YAML_MAPPING_END_EVENT; /* @@ -554,22 +554,22 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even switch (event->type) { case YAML_SCALAR_EVENT: - yamlObject.type_ = YamlObject::Value; + yamlObject.type_ = YamlObject::Type::Value; readValue(yamlObject.value_, std::move(event)); return 0; case YAML_SEQUENCE_START_EVENT: { - yamlObject.type_ = YamlObject::List; + yamlObject.type_ = YamlObject::Type::List; auto &list = yamlObject.list_; auto handler = [this, &list](EventPtr evt) { list.emplace_back(new YamlObject()); return parseNextYamlObject(*list.back(), std::move(evt)); }; - return parseDictionaryOrList(YamlObject::List, handler); + return parseDictionaryOrList(YamlObject::Type::List, handler); } case YAML_MAPPING_START_EVENT: { - yamlObject.type_ = YamlObject::Dictionary; + yamlObject.type_ = YamlObject::Type::Dictionary; auto &dictionary = yamlObject.dictionary_; auto handler = [this, &dictionary](EventPtr evtKey) { /* Parse key */ @@ -592,7 +592,7 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even auto elem = dictionary.emplace(key, std::make_unique()); return parseNextYamlObject(*elem.first->second.get(), std::move(evtValue)); }; - return parseDictionaryOrList(YamlObject::Dictionary, handler); + return parseDictionaryOrList(YamlObject::Type::Dictionary, handler); } default: From patchwork Tue May 24 22:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16028 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 60E71C3256 for ; Tue, 24 May 2022 22:58:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49B1965673; Wed, 25 May 2022 00:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433110; bh=6snE1bRh0/Y/freE7UR3RHw585z+/5KDONypF6MBOh0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=e9i8A1bQxgjIUeSuUj/CmMVhXnlhAe1jba7W0mn0R5PAYvQjDBSC42AWhOAsosjLq puIgYlh1iIiHbOqoy/8Tc9zDOrrZwPsmtUvHj3+1Vdn3v722z49cRVXqnefZVjUFdV S5C2TIh8FWlBXM0EsZEnPqIQYPxD1hKzW81FogcDWt3lCdY2wJWiI8qMTS9gO8Xs1V iIWdYqscWb7LWdHso21TplK0Mb4cEVWqEFW2sEXZ7tIqZ4xSYydQ9ackBlZNoc8HV/ WLXP05Ehy1nS6RuaEIwEQ+SmjSI2l+4SL9I+vg7iCx3X3pEVtEU7OYXbqY3ffxGvFi eZCguK/iHPYNg== 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 7919D60416 for ; Wed, 25 May 2022 00:58:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="b81PIlm6"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED87CA5E; Wed, 25 May 2022 00:58:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433105; bh=6snE1bRh0/Y/freE7UR3RHw585z+/5KDONypF6MBOh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b81PIlm6uxTR5CUNGqnCdhSxrLpWcnKrDZhY4WvoVDESwisKH0jeMUa59brEcjuJr yfL+yIHp0AY6FjQjqKqrTw2DQy/h2DH9MI5r3Da0Q3sNxBs6RMb3wc6SfX6WnrjwgL 8g5U8aBcazNN/7/1dDx5qx0x/n1uxHH6WhP+S4+M= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:06 +0300 Message-Id: <20220524225816.6830-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 02/12] libcamera: yaml_parser: Extend YamlObject::size() to dictionaries 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Dictionaries have a size too, extend the size() function to support them. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 3 +- src/libcamera/yaml_parser.cpp | 42 +++++++++++++----------- test/yaml-parser.cpp | 5 +++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index e002fcf59278..b4f852b1ce54 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -39,6 +39,8 @@ public: return type_ == Type::Dictionary; } + std::size_t size() const; + #ifndef __DOXYGEN__ template YamlObject::get( * const T &defaultValue, bool *ok) const @@ -235,25 +258,6 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const #endif /* __DOXYGEN__ */ -/** - * \fn YamlObject::size() - * \brief Retrieve the number of elements in a list YamlObject - * - * This function retrieves the size of the YamlObject, defined as the number of - * child elements it contains. Only YamlObject instances of List type have a - * size, calling this function on other types of instances is invalid and - * results in undefined behaviour. - * - * \return The size of the YamlObject - */ -std::size_t YamlObject::size() const -{ - if (type_ != Type::List) - return 0; - - return list_.size(); -} - /** * \fn YamlObject::operator[](std::size_t index) const * \brief Retrieve the element from list YamlObject by index diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 652adf53d0cc..585b545b71c5 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -421,6 +421,11 @@ protected: return TestFail; } + if (dictObj.size() != 3) { + cerr << "Dictionary object parse with wrong size" << std::endl; + return TestFail; + } + auto memeberNames = dictObj.memberNames(); sort(memeberNames.begin(), memeberNames.end()); From patchwork Tue May 24 22:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16029 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 6320DBD161 for ; Tue, 24 May 2022 22:58:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5ECC86566A; Wed, 25 May 2022 00:58:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433111; bh=10oF107TACaNIAQeC1VCMPhoUoGbMZCRPS66kKBs1zc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=nCzhQ911Dint6m8U5nl2pNTBNXkGp7MyvibccOSxKwq2LxJEoSX8zE3KZD7cZYDQ8 w1cPeh7uiwRK2Wxb3zb1ithmyc3sGyuCDdgrpLnUy88uIrYz7CPcrM4uVCcCa6Oy4/ CsHTQ98alXsxQYXwSqh2/owjriB1nm3vCoGDuCrZJ4NrfsVU5ShEvfoOckhCZip/H9 4nXhHVAwjFQsuMkxMln2kXTE1EKW0vWse/W0FA/op4oL6rVYj48UY0jbBgEZGGvfeG tcYsKqlVPdUqL4RZLJ0umHIzNbL1iT3cafIpOsoeY/fFN9ucBQ5GFFHKuOYHbYHNYI 1MxjcbB43u82g== 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 2B63665665 for ; Wed, 25 May 2022 00:58:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fBRaqBHd"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 84B81E50; Wed, 25 May 2022 00:58:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433105; bh=10oF107TACaNIAQeC1VCMPhoUoGbMZCRPS66kKBs1zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fBRaqBHdODDN8xwP5CcPcnKRPj+5snIijFmuP4mXLv2Qd29CfZWNRjlAOJYmFTT1T /CAr7SHMPPsJ6Hp7YjRWrxxu2WbRmzCy2x8V40cqj2o6OHWPgsQEjw6+UTDs8SzTHs jWKpJug40KgicFqQayjMPZcGN5yRUAXk88Y7C21g= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:07 +0300 Message-Id: <20220524225816.6830-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 03/12] libcamera: yaml_parser: Switch from FILE to File 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" THe FILE object isn't very user-friendly as it requires manual close. Replace it with File to provide RAII-style resource management in the YamlParser API. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 4 +-- src/android/camera_hal_config.cpp | 16 +++++----- src/libcamera/yaml_parser.cpp | 39 +++++++++++++++++------- test/yaml-parser.cpp | 17 +++++------ 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index b4f852b1ce54..be5f0914703f 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include @@ -18,6 +17,7 @@ namespace libcamera { +class File; class YamlParserContext; class YamlObject @@ -82,7 +82,7 @@ private: class YamlParser final { public: - static std::unique_ptr parse(std::FILE *fh); + static std::unique_ptr parse(File &file); }; } /* namespace libcamera */ diff --git a/src/android/camera_hal_config.cpp b/src/android/camera_hal_config.cpp index 28072cb86285..42f3e3aeed04 100644 --- a/src/android/camera_hal_config.cpp +++ b/src/android/camera_hal_config.cpp @@ -12,6 +12,7 @@ #include +#include #include #include @@ -27,7 +28,7 @@ class CameraHalConfig::Private : public Extensible::Private public: Private(); - int parseConfigFile(FILE *fh, std::map *cameras); + int parseConfigFile(File &file, std::map *cameras); private: int parseCameraConfigData(const std::string &cameraId, const YamlObject &); @@ -41,7 +42,7 @@ CameraHalConfig::Private::Private() { } -int CameraHalConfig::Private::parseConfigFile(FILE *fh, +int CameraHalConfig::Private::parseConfigFile(File &file, std::map *cameras) { /* @@ -65,7 +66,7 @@ int CameraHalConfig::Private::parseConfigFile(FILE *fh, cameras_ = cameras; - std::unique_ptr root = YamlParser::parse(fh); + std::unique_ptr root = YamlParser::parse(file); if (!root) return -EINVAL; @@ -169,9 +170,9 @@ int CameraHalConfig::parseConfigurationFile() return -ENOENT; } - FILE *fh = fopen(filePath.c_str(), "r"); - if (!fh) { - int ret = -errno; + File file(filePath); + if (!file.open(File::OpenModeFlag::ReadOnly)) { + int ret = file.error(); LOG(HALConfig, Error) << "Failed to open configuration file " << filePath << ": " << strerror(-ret); return ret; @@ -179,8 +180,7 @@ int CameraHalConfig::parseConfigurationFile() exists_ = true; - int ret = _d()->parseConfigFile(fh, &cameras_); - fclose(fh); + int ret = _d()->parseConfigFile(file, &cameras_); if (ret) return -EINVAL; diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 5b872dbb0a2d..85f6694f5fde 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -345,7 +346,7 @@ public: YamlParserContext(); ~YamlParserContext(); - int init(std::FILE *fh); + int init(File &file); int parseContent(YamlObject &yamlObject); private: @@ -358,6 +359,9 @@ private: }; using EventPtr = std::unique_ptr; + static int yamlRead(void *data, unsigned char *buffer, size_t size, + size_t *sizeRead); + EventPtr nextEvent(); void readValue(std::string &value, EventPtr event); @@ -399,13 +403,13 @@ YamlParserContext::~YamlParserContext() * \param[in] fh The YAML file to parse * * Prior to parsing the YAML content, the YamlParserContext must be initialized - * with an opened FILE to create an internal parser. The FILE needs to stay - * valid during the process. + * with a file to create an internal parser. The file needs to stay valid until + * parsing completes. * * \return 0 on success or a negative error code otherwise * \retval -EINVAL The parser has failed to initialize */ -int YamlParserContext::init(std::FILE *fh) +int YamlParserContext::init(File &file) { /* yaml_parser_initialize returns 1 when it succeededs */ if (!yaml_parser_initialize(&parser_)) { @@ -413,11 +417,25 @@ int YamlParserContext::init(std::FILE *fh) return -EINVAL; } parserValid_ = true; - yaml_parser_set_input_file(&parser_, fh); + yaml_parser_set_input(&parser_, &YamlParserContext::yamlRead, &file); return 0; } +int YamlParserContext::yamlRead(void *data, unsigned char *buffer, size_t size, + size_t *sizeRead) +{ + File *file = static_cast(data); + + Span buf{ buffer, size }; + ssize_t ret = file->read(buf); + if (ret < 0) + return 0; + + *sizeRead = ret; + return 1; +} + /** * \fn YamlParserContext::nextEvent() * \brief Get the next event @@ -655,21 +673,20 @@ int YamlParserContext::parseNextYamlObject(YamlObject &yamlObject, EventPtr even */ /** - * \fn YamlParser::parse() * \brief Parse a YAML file as a YamlObject - * \param[in] fh The YAML file to parse + * \param[in] file The YAML file to parse * - * The YamlParser::parse() function takes an open FILE, parses its contents, and + * The YamlParser::parse() function takes a file, parses its contents, and * returns a pointer to a YamlObject corresponding to the root node of the YAML - * document. The caller is responsible for closing the file. + * document. * * \return Pointer to result YamlObject on success or nullptr otherwise */ -std::unique_ptr YamlParser::parse(std::FILE *fh) +std::unique_ptr YamlParser::parse(File &file) { YamlParserContext context; - if (context.init(fh)) + if (context.init(file)) return nullptr; std::unique_ptr root(new YamlObject()); diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 585b545b71c5..959a657478fa 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include "test.h" @@ -69,29 +70,27 @@ protected: int run() { /* Test invalid YAML file */ - FILE *fh = fopen(invalidYamlFile_.c_str(), "r"); - if (!fh) { + File file{ invalidYamlFile_ }; + if (!file.open(File::OpenModeFlag::ReadOnly)) { cerr << "Fail to open invalid YAML file" << std::endl; return TestFail; } - std::unique_ptr root = YamlParser::parse(fh); - fclose(fh); - + std::unique_ptr root = YamlParser::parse(file); if (root) { cerr << "Invalid YAML file parse successfully" << std::endl; return TestFail; } /* Test YAML file */ - fh = fopen(testYamlFile_.c_str(), "r"); - if (!fh) { + file.close(); + file.setFileName(testYamlFile_); + if (!file.open(File::OpenModeFlag::ReadOnly)) { cerr << "Fail to open test YAML file" << std::endl; return TestFail; } - root = YamlParser::parse(fh); - fclose(fh); + root = YamlParser::parse(file); if (!root) { cerr << "Fail to parse test YAML file: " << std::endl; From patchwork Tue May 24 22:58:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16030 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 637BAC3256 for ; Tue, 24 May 2022 22:58:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13BBB6566D; Wed, 25 May 2022 00:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433112; bh=DRsGWBWMLH4h9Mk+gTUka3k+HceDdjisBlEHmLN1iX0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=0hPOfgsVBBYK6E2gipdpQQfjfV++kmo9mP0sDr9B+wmdbKDCu4AA6zn0POjYTAFRe izwdaQ64C8PtfSx98d76vC7PgPPXaAJztcpEuolr1SEpqyui2HfKHHDQervhw867qG Eb511JYcK97h+6zDur5JsR6mmgiKNxNMFw1QBklckMKyzRYE5ZT3FClzRr3joxy1ja nNypCj00KfnTkuCbss/RMgkYkjBITOtfNazinxEWBtiDP/7bVuI4fU2zxDTXy8tfxF M55JpM3FLWWWe2Uj4DglQbX2iIQ5HxZmnifn0qGgpdIF4bs4zIfMwbn71xkAPBrcQU fBjRsFy7L8VmA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DE95F65668 for ; Wed, 25 May 2022 00:58:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pSOQkHnk"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 52A349DA; Wed, 25 May 2022 00:58:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433106; bh=DRsGWBWMLH4h9Mk+gTUka3k+HceDdjisBlEHmLN1iX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pSOQkHnkMKs5lwttEiOBQOT48ZBeItkDoklXMsHfb0vp1hL3XVDFMwzA52nMRQj9X mVp41rqShCpvu5r8NCSFOMdzCdJiIUS43H1uzDtB1YFR/rxQOmurr51Oskphn8qhR5 MZO5q6z30LQspyNsUDHMlB8f5p3OTx4AE/Bi1ujE= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:08 +0300 Message-Id: <20220524225816.6830-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 04/12] test: yaml-parser: Use write() instead of fwrite() 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There's no point in wrapping a fd into a FILE to then only call fwrite() and fclose(). Use write() and close() directly. Signed-off-by: Laurent Pinchart --- test/yaml-parser.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 959a657478fa..944b564bbe22 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -48,10 +48,11 @@ protected: if (fd == -1) return false; - FILE *fh = fdopen(fd, "w"); - fputs(content.c_str(), fh); + int ret = write(fd, content.c_str(), content.size()); + close(fd); - fclose(fh); + if (ret != static_cast(content.size())) + return false; return true; } From patchwork Tue May 24 22:58:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16031 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 45472C326D for ; Tue, 24 May 2022 22:58:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 980706567F; Wed, 25 May 2022 00:58:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433112; bh=Vc024EDhS8mSSRGZH4WuAv7kzOTtH8qkRDZUS9RWDqg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RIIE4A4qAF15dQvX246C7vVfazpA6DDgPZyZLotu0l2sdywPU1mv8q1nIQ4Wq+f/d AU3kiZBzDqq2LP7rl2gODkEBBTn5n82xZs1FEUpIs6GIER3ezqgVyX/Q/gzaduLkSy yiGv/NGgYkyrQchXn9RPB93XCAmNDMJlXNf0y1+Gh4Ejhpfssb0gxRPjRXw3gzmztP ttV4Q/q/NkrIn4wmpxE3hhXaxocIdxTAe6yKNZLiiBuGNs2nEPA4iaP6T/eycA/cF6 FDCWF3JT7d3glI2J4u6dJ3oKkNnVTHrQz/Peg+yCBhCx5mNfX1JjsXVr5+Pz7/uC/e jiuQ46IIaMNCg== 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 874E160416 for ; Wed, 25 May 2022 00:58:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OPKL63MZ"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E3EA9102E; Wed, 25 May 2022 00:58:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433107; bh=Vc024EDhS8mSSRGZH4WuAv7kzOTtH8qkRDZUS9RWDqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OPKL63MZ1MU2kY5RfoDkpALaOGEaR0d6pU8Xzj3vKIEzgoRYXn7G87tS4EDhw5XzN JXhQ0UBiEYyduIitT74MFW0KCe6ui8oBCwvFAQFsxJns3MO4Fnu2KgSkMamgqdqGPS jhg9dQ6Q/kFS4iHDaIYLePx9iHvZWwCgStAVl1fA= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:09 +0300 Message-Id: <20220524225816.6830-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 05/12] libcamera: yaml_parser: Add iterator API 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow using range-based for loops over YamlObject instances by implementing iterators. New YamlObject::DictAdapter and YamlObject::ListAdapter adapter classes are introduced to provide different iterators depending on the object type. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 115 ++++++++++++++++++++++- src/libcamera/yaml_parser.cpp | 37 ++++++++ 2 files changed, 150 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index be5f0914703f..22ed87efdf8f 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -22,7 +23,114 @@ class YamlParserContext; class YamlObject { +private: + using DictContainer = std::map>; + using ListContainer = std::vector>; + public: +#ifndef __DOXYGEN__ + template + class Iterator + { + public: + using difference_type = std::ptrdiff_t; + using iterator_category = std::bidirectional_iterator_tag; + + Iterator(typename Container::const_iterator it) + : it_(it) + { + } + + Derived &operator++() + { + ++it_; + return *static_cast(this); + } + + Derived operator++(int) + { + Derived it = *static_cast(this); + it_++; + return it; + } + + friend bool operator==(const Iterator &a, const Iterator &b) + { + return a.it_ == b.it_; + } + + friend bool operator!=(const Iterator &a, const Iterator &b) + { + return a.it_ != b.it_; + } + + protected: + typename Container::const_iterator it_; + }; + + template + class Adapter + { + public: + Adapter(const Container &container) + : container_(container) + { + } + + Iterator begin() const + { + return Iterator{ container_.begin() }; + } + + Iterator end() const + { + return Iterator{ container_.end() }; + } + + protected: + const Container &container_; + }; + + class ListIterator : public Iterator + { + public: + using value_type = const YamlObject &; + using pointer = const YamlObject *; + using reference = value_type; + + value_type operator*() const + { + return *it_->get(); + } + + pointer operator->() const + { + return it_->get(); + } + }; + + class DictIterator : public Iterator + { + public: + using value_type = std::pair; + using pointer = value_type *; + using reference = value_type &; + + value_type operator*() const + { + return { it_->first, *it_->second.get() }; + } + }; + + class DictAdapter : public Adapter + { + }; + + class ListAdapter : public Adapter + { + }; +#endif /* __DOXYGEN__ */ + YamlObject(); ~YamlObject(); @@ -55,6 +163,9 @@ public: #endif T get(const T &defaultValue, bool *ok = nullptr) const; + DictAdapter asDict() const { return DictAdapter{ dictionary_ }; } + ListAdapter asList() const { return ListAdapter{ list_ }; } + const YamlObject &operator[](std::size_t index) const; bool contains(const std::string &key) const; @@ -75,8 +186,8 @@ private: Type type_; std::string value_; - std::vector> list_; - std::map> dictionary_; + ListContainer list_; + DictContainer dictionary_; }; class YamlParser final diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 85f6694f5fde..a156df36e222 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -259,6 +259,43 @@ Size YamlObject::get(const Size &defaultValue, bool *ok) const #endif /* __DOXYGEN__ */ +/** + * \fn YamlObject::asDict() const + * \brief Wrap a dictionary YamlObject in an adapter that exposes iterators + * + * The YamlObject class doesn't directly implement iterators, as the iterator + * type depends on whether the object is a Dictionary or List. This function + * wraps a YamlObject of Dictionary type into an adapter that exposes + * iterators, as well as begin() and end() functions, allowing usage of + * range-based for loops with YamlObject. + * + * The iterator's value_type is a + * std::pair. + * + * If the YamlObject is not of Dictionary type, the returned adapter operates + * as an empty container. + * + * \return An adapter of unspecified type compatible with range-based for loops + */ + +/** + * \fn YamlObject::asList() const + * \brief Wrap a list YamlObject in an adapter that exposes iterators + * + * The YamlObject class doesn't directly implement iterators, as the iterator + * type depends on whether the object is a Dictionary or List. This function + * wraps a YamlObject of List type into an adapter that exposes iterators, as + * well as begin() and end() functions, allowing usage of range-based for loops + * with YamlObject. + * + * The iterator's value_type is a const YamlObject &. + * + * If the YamlObject is not of List type, the returned adapter operates as an + * empty container. + * + * \return An adapter of unspecified type compatible with range-based for loops + */ + /** * \fn YamlObject::operator[](std::size_t index) const * \brief Retrieve the element from list YamlObject by index From patchwork Tue May 24 22:58:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16032 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 14737BD161 for ; Tue, 24 May 2022 22:58:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AAE3665672; Wed, 25 May 2022 00:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433113; bh=yuzPcW09xN5jnjxLp9B1c60Gpp/d/NIaVzr7xlwAIT8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UYhFUdKiQGGXeEeO7xXKBeuyldzDPCpMrCYccGH0ArCPwV7SXtAVK/1ppsu1O2QcR B4fjjKsvRAYqG59UiWOT/9d+2a56VFAU21g5NMN0J4SXrzQa+N0ouPvpiS96wtdV9q //vi5AGi7pZ5CB+0jnshCnMZkVicpCBMhNP7K6QS9luKIpNVzPBEMSCglfjXMgK4ym 2tWfzmY3jqOHVYQ75zm7j5x3zVa346F+xu3mNCWmC9xlqcwVz3J/Q2y4zobpBGjqjt N2yGGAgearMx86VdvfhMtvVQRrtZGgrd9ipQWLKUVUnZLuHM7xUYQFfXgKfyuoXnyh OJbHr+BUyDFyQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27C9B65663 for ; Wed, 25 May 2022 00:58:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jSk9RUyF"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 865DB1224; Wed, 25 May 2022 00:58:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433107; bh=yuzPcW09xN5jnjxLp9B1c60Gpp/d/NIaVzr7xlwAIT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSk9RUyFQNjozcwhesKnzxVaETbxx5h6iNdlcSw3cpVQDdTwD1kNS0LSHxSlh93gv 4x99X2f5kw6YcnYOeN+ogihohA0Km/O/OF1sm+JR2Ti5396Avwv6t3p+0geskbPF6L oVtcSqj54YiicMOCWY4g/NyvkRg+LKkdY/wHFMOc= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:10 +0300 Message-Id: <20220524225816.6830-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 06/12] test: yaml_parser: Extend tests to cover the iterator API 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test iteration over lists and dictionaries to test the YamlObject iterator API. Signed-off-by: Laurent Pinchart --- test/yaml-parser.cpp | 88 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 944b564bbe22..7ad9936bb82b 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -5,6 +5,7 @@ * yaml-parser.cpp - YAML parser operations tests */ +#include #include #include #include @@ -372,15 +373,39 @@ protected: return TestFail; } - if (listObj.size() > 2) { + static constexpr std::array listValues{ + "James", + "Mary", + }; + + if (listObj.size() != listValues.size()) { cerr << "List object parse with wrong size" << std::endl; return TestFail; } - if (listObj[0].get("") != "James" || - listObj[1].get("") != "Mary") { - cerr << "List object parse as wrong value" << std::endl; - return TestFail; + unsigned int i = 0; + for (auto &elem : listObj.asList()) { + if (i >= listValues.size()) { + std::cerr << "Too many elements in list during iteration" + << std::endl; + return TestFail; + } + + std::string value = listValues[i]; + + if (&elem != &listObj[i]) { + std::cerr << "List element " << i << " has wrong address" + << std::endl; + return TestFail; + } + + if (elem.get("") != value) { + std::cerr << "List element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + i++; } /* Test dictionary object */ @@ -421,19 +446,51 @@ protected: return TestFail; } - if (dictObj.size() != 3) { - cerr << "Dictionary object parse with wrong size" << std::endl; + static constexpr std::array, 3> dictValues{ { + { "a", 1 }, + { "b", 2 }, + { "c", 3 }, + } }; + + if (dictObj.size() != dictValues.size()) { + cerr << "Dictionary object has wrong size" << std::endl; return TestFail; } + i = 0; + for (const auto &[key, elem] : dictObj.asDict()) { + if (i >= dictValues.size()) { + std::cerr << "Too many elements in dictionary during iteration" + << std::endl; + return TestFail; + } + + const std::pair &value = dictValues[i]; + + if (key != value.first) { + std::cerr << "Dictionary key " << i << " has wrong value" + << std::endl; + return TestFail; + } + + if (&elem != &dictObj[key]) { + std::cerr << "Dictionary element " << i << " has wrong address" + << std::endl; + return TestFail; + } + + if (elem.get(0) != value.second) { + std::cerr << "Dictionary element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + i++; + } + auto memeberNames = dictObj.memberNames(); sort(memeberNames.begin(), memeberNames.end()); - if (memeberNames.size() != 3) { - cerr << "Dictionary object fail to extra member names" << std::endl; - return TestFail; - } - if (memeberNames[0] != "a" || memeberNames[1] != "b" || memeberNames[2] != "c") { @@ -441,13 +498,6 @@ protected: return TestFail; } - if (dictObj["a"].get(0) != 1 || - dictObj["b"].get(0) != 2 || - dictObj["c"].get(0) != 3) { - cerr << "Dictionary object fail to parse member value" << std::endl; - return TestFail; - } - /* Test leveled objects */ auto &level1Obj = (*root)["level1"]; From patchwork Tue May 24 22:58:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16033 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 9FF3CC326E for ; Tue, 24 May 2022 22:58:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0173165676; Wed, 25 May 2022 00:58:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433115; bh=+B+P8nN4wN36md/i6eEoSbd3s0PvS4G8/FkDKBz6VlY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dk7DwgOWbPExkI7ELOZ6iBVG1QN0wHnzG+Y8/HlHPrw6FmRugEVcVC+3rv3lRHoSs dWH4w7eKTbppKr0a36Sb0C2aV34/uV/3lvDg4Myl7Sp8qiRlayvvxaxiso1bKJslo/ TvZ3UaYITqb/2Wwu+VSmizPO88JRvoozG2jlPbTqP8qq+o75dB5IQsxLp0xrhAME6w ybTAMxwAGYmHXakc3KI0XXfMLof72SBFRQAb9qEgvTAIwuFHcIWhCKFEe+ra5fNIvX 7J80FqF8IFK/5axt5hcFD2RN1lrqcpbAALev60KVSyA4HvIRlvAza9dhXrTv0p+g9s y9yqHWK2heOLw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B89ED65663 for ; Wed, 25 May 2022 00:58:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kBBEXskE"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 23F8F1245; Wed, 25 May 2022 00:58:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433108; bh=+B+P8nN4wN36md/i6eEoSbd3s0PvS4G8/FkDKBz6VlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kBBEXskE0Rm8jZCqMjP0Pkv7kCf2mYMXib+fMHJ9pqoqcjhMxwdcE0rQ+jBliMHcg cpscLQu1So22Ji57H+RZDU7XIr1DlRBtfJkzZ1Mv348J0CM00zFyVKuBBROIkDEn4P j0nw0eeM+WqKcJlB22L1QJvFyfPPSgSKCa9KdYcU= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:11 +0300 Message-Id: <20220524225816.6830-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 07/12] android: Use the YamlObject iterator API 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace usage of YamlObject::memberNames() with the more efficient iterator API. Signed-off-by: Laurent Pinchart --- src/android/camera_hal_config.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/android/camera_hal_config.cpp b/src/android/camera_hal_config.cpp index 42f3e3aeed04..723860db2371 100644 --- a/src/android/camera_hal_config.cpp +++ b/src/android/camera_hal_config.cpp @@ -82,10 +82,8 @@ int CameraHalConfig::Private::parseConfigFile(File &file, if (!yamlObjectCameras.isDictionary()) return -EINVAL; - std::vector cameraIds = yamlObjectCameras.memberNames(); - for (const std::string &cameraId : cameraIds) { - if (parseCameraConfigData(cameraId, - yamlObjectCameras[cameraId])) + for (const auto &[cameraId, configData] : yamlObjectCameras.asDict()) { + if (parseCameraConfigData(cameraId, configData)) return -EINVAL; } From patchwork Tue May 24 22:58:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16034 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 37F81C3256 for ; Tue, 24 May 2022 22:58:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA88D6567B; Wed, 25 May 2022 00:58:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433116; bh=2nQl4KS4/oBh2PeoCRVpWrYuo4qMue8+OMbQmS8DqUY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=u/cMl7QobJv9BkB+wA2ly7gAnxzblotbpgocw3FccHz41q1yDkcbnpgencl6OQd+x 2xX3C88EZvhVezUnB/Zh6n+MCmXS4TdokZvYZoTdTMstJkOvQtU4q4JHEN0gQH4Aqq t/bCryYGlMB2O3yBVsJcUvoxjAPEZisH+iiCTTp6SK8lO3Bmwy3p5F4k+FFooq58P0 ryUSlYMXr0+5ZHjpd6Fw1EAX4yyE0SIGtVm4JqAZ0U9j2n8+0uJenULUsHGxf0JNNA R5Jtwm0YbXOwKnmxuzQ0e5o/Oj0hz/d69pcToJ1qJvuf4n+PHfNn6QFMZHdouRkLZE CGL+WcVIwDngw== 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 4BD6465672 for ; Wed, 25 May 2022 00:58:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZOQXJBmT"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BDA001051; Wed, 25 May 2022 00:58:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433109; bh=2nQl4KS4/oBh2PeoCRVpWrYuo4qMue8+OMbQmS8DqUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOQXJBmTMP5EPdgLZtgoJUi60qSDkLy4YK8DDXi758AQgW1/heiEyQuwBlPW00SM2 SmCdhdC0m/2R0z2f2U/EUSKPz8Hx/UVQKWHQbkILEiNl1i4IRv8ZmZmJP794kyAT7K cJGwki2pHSeQrD/Bgqx6G8OdTvUg5TkLe1J4uC8M= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:12 +0300 Message-Id: <20220524225816.6830-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 08/12] libcamera: yaml_parser: Remove memberNames() function 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that YamlObject supports iteration, the memberNames() function isn't useful anymore as it can be implemented using utils::map_keys() if really needed. Drop it. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 1 - src/libcamera/yaml_parser.cpp | 22 ---------------------- test/yaml-parser.cpp | 10 ---------- 3 files changed, 33 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 22ed87efdf8f..79537ff2ea7c 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -170,7 +170,6 @@ public: bool contains(const std::string &key) const; const YamlObject &operator[](const std::string &key) const; - std::vector memberNames() const; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index a156df36e222..65b9a9097375 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -333,28 +333,6 @@ bool YamlObject::contains(const std::string &key) const return true; } -/** - * \fn YamlObject::memberNames() - * \brief Retrieve all member names of the dictionary - * - * This function retrieve member names of a YamlObject. Only YamlObject - * instances of Dictionary type associate elements with names, calling this - * function on other types of instances is invalid and results in undefined - * behaviour. - * - * \todo Replace this function with an iterator-based API - * - * \return A vector of string as the member names - */ -std::vector YamlObject::memberNames() const -{ - std::vector memberNames; - for (auto &[key, _] : dictionary_) - memberNames.push_back(key); - - return memberNames; -} - /** * \fn YamlObject::operator[](const std::string &key) const * \brief Retrieve a member by name from the dictionary diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 7ad9936bb82b..3662e7144dfd 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -488,16 +488,6 @@ protected: i++; } - auto memeberNames = dictObj.memberNames(); - sort(memeberNames.begin(), memeberNames.end()); - - if (memeberNames[0] != "a" || - memeberNames[1] != "b" || - memeberNames[2] != "c") { - cerr << "Dictionary object fail to parse member names" << std::endl; - return TestFail; - } - /* Test leveled objects */ auto &level1Obj = (*root)["level1"]; From patchwork Tue May 24 22:58:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16035 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 47EE3C326D for ; Tue, 24 May 2022 22:58:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4B6F65680; Wed, 25 May 2022 00:58:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433118; bh=q5bcKpUKf2VCUYBU6wO/nSr1MvL3jZOliCxcDfokEEo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=zLGkl0oqi3TYWg7sq3CHYyreJasoWefk55gnHvVZPl9eGSodlgID+8B5pkOs0Zz3q l6bJYGt5AobNYwEp9NY2RTG7peOghESyRJWhfIyPGCkJvmGs12EftWRvA1A52zE6b+ zDX9p8op5DPMG7g9ExW1qPuA9DmJhEVBeWmAAWOqiM34e7kbGU6it4/eou/DtYqI0X Nt9/R6tqfwWo9dJbKqGfCRQdgngODP4cDTNvWM5huN9bwytf7bm4BkMeLpwqzH1xBC Vg4osPIuvoYK9U7UmjQ5fY4VszChac4oK3j5/KwvpG4Rv7fe6usGtf9T5LZk3mynNX vinjf8ZMCb8bQ== 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 D8B1565663 for ; Wed, 25 May 2022 00:58:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ijFG2eam"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4730D1287; Wed, 25 May 2022 00:58:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433109; bh=q5bcKpUKf2VCUYBU6wO/nSr1MvL3jZOliCxcDfokEEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ijFG2eamASjaq2uNB1q/vWEkPwjqmnoLdrAQtFsOYF12dvzkFQS/TF5wt54oJBtAh EmZw8GsnOv4nQJA3t00caBtqcGPKUghKSaQ4jVLt5Ox5s6RY3iTbJVL22X4Y7crSBo 4A2Rbfm/uxIMU1YvzRhcG421MwpfkWkr7/a3o56k= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:13 +0300 Message-Id: <20220524225816.6830-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 09/12] libcamera: yaml_parser: Fix range checks for 32-bit integers 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The strtol() and strtoul() functions return long integers, which may be larger than 32-bit integers. Add manual range checks. Signed-off-by: Laurent Pinchart --- src/libcamera/yaml_parser.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 65b9a9097375..f0b5eb96449b 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -151,9 +152,11 @@ int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const char *end; errno = 0; - int32_t value = std::strtol(value_.c_str(), &end, 10); + long value = std::strtol(value_.c_str(), &end, 10); - if ('\0' != *end || errno == ERANGE) + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) return defaultValue; setOk(ok, true); @@ -185,9 +188,11 @@ uint32_t YamlObject::get(const uint32_t &defaultValue, bool *ok) const char *end; errno = 0; - uint32_t value = std::strtoul(value_.c_str(), &end, 10); + unsigned long value = std::strtoul(value_.c_str(), &end, 10); - if ('\0' != *end || errno == ERANGE) + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) return defaultValue; setOk(ok, true); From patchwork Tue May 24 22:58:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16036 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 C93C0C326F for ; Tue, 24 May 2022 22:58:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A09496566D; Wed, 25 May 2022 00:58:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433119; bh=jAs5MXsa9CbCjWdFhEKz7i6feQcOFMCR3aVzCVIcSWU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QlsAxkiboHb5WORUtCCSF8LjEBsCaCZiNYOVbNKlRhjXtlwsYPIvS9aGNJOb/r0bV 0MlfES6S73zHF1qNOdi/nr0UThPzpSQH++Z0Q/cPu/G7ow72HndEpAXr0ip9Eu4WPu Bd96kfRitgiB51zsYefDZQQoq31+Qu4OpT6VHgICCuUoyV5vjhwEFVCwP3KyZW/NfK UrHhirinf1NwxOUqjBCBjcaAbiPQAB48R/wwJ8kuXvvQa/J9HdAqY88vPrXEcaOQ9/ yjtB25/SW9GhoulgO0Tw+D9vFtRRGVcRNY/uenAtKSWJJYVZi9yvbypRDZBbrOOLWo ubXwzcYv9nw1A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E27265674 for ; Wed, 25 May 2022 00:58:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RzEepIhT"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D5693A58; Wed, 25 May 2022 00:58:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433110; bh=jAs5MXsa9CbCjWdFhEKz7i6feQcOFMCR3aVzCVIcSWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RzEepIhTrERlSZEgQKAdZ9xFpfiwOgbw3RrhUEhV97v6Xv8SXfNIoteAwIxLqK1rz GNRoU9bluIksVy756vkTEGUzaw1KDFB/O826sg5WRbucPm9vxRZEIwLGKY57CiOYtU Z7p/xGs3ykNbUOOFj/9FmaQ+ie8HsMaVYSuEYJtE= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:14 +0300 Message-Id: <20220524225816.6830-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 10/12] libcamera: yaml_parser: Add get() specializations for 16-bit integers 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Extend the YamlObject::get() function template to support 16-bit integers. Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 2 + src/libcamera/yaml_parser.cpp | 61 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 79537ff2ea7c..dd543a138af5 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -154,6 +154,8 @@ public: typename std::enable_if_t< std::is_same::value || std::is_same::value || + std::is_same::value || + std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index f0b5eb96449b..57e8b52965e8 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -138,6 +138,67 @@ bool YamlObject::get(const bool &defaultValue, bool *ok) const return defaultValue; } +template<> +int16_t YamlObject::get(const int16_t &defaultValue, bool *ok) const +{ + setOk(ok, false); + + if (type_ != Type::Value) + return defaultValue; + + if (value_ == "") + return defaultValue; + + char *end; + + errno = 0; + int16_t value = std::strtol(value_.c_str(), &end, 10); + + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) + return defaultValue; + + setOk(ok, true); + return value; +} + +template<> +uint16_t YamlObject::get(const uint16_t &defaultValue, bool *ok) const +{ + setOk(ok, false); + + if (type_ != Type::Value) + return defaultValue; + + if (value_ == "") + return defaultValue; + + /* + * libyaml parses all scalar values as strings. When a string has + * leading spaces before a minus sign, for example " -10", strtoul + * skips leading spaces, accepts the leading minus sign, and the + * calculated digits are negated as if by unary minus. Rule it out in + * case the user gets a large number when the value is negative. + */ + std::size_t found = value_.find_first_not_of(" \t"); + if (found != std::string::npos && value_[found] == '-') + return defaultValue; + + char *end; + + errno = 0; + uint16_t value = std::strtoul(value_.c_str(), &end, 10); + + if ('\0' != *end || errno == ERANGE || + value < std::numeric_limits::min() || + value > std::numeric_limits::max()) + return defaultValue; + + setOk(ok, true); + return value; +} + template<> int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const { From patchwork Tue May 24 22:58:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16037 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 BC7C4C3270 for ; Tue, 24 May 2022 22:58:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C59865673; Wed, 25 May 2022 00:58:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433120; bh=Glf9pjjGnzIfbfULE+Zq+A8HaL9XSI9VV/ERWec7nYo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tS96R0zcrU+6quhbBKE3fBJ0XkTPPQWl7Tkr60vD303h92D1ZSIQe36LfcheCEOuA FzZuuweDCNr5tHR2tncytersfMISMEbjmXfT66H6FAmaH4bl45wFRUSRYTTNSG5iFK x+1GZlfs9J2ZHievib3qPQCuv4g/GqkIAKaoEoZ26EOebNAfogSVCnmydw/6I7ly5I cOqoRSTqrPX0R4DADioqlXhk6bVQ+jrypxlgjnx+IsrGoxHJomFu35oVENxwvojeWS rpI3hAoJXLr2/WSz9tSbRVBcC/8LFsVz+OVe/JX0M22PTGkV07yD5Z3GXt7KWy5Bw8 xnwkVYkBZELog== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3465665675 for ; Wed, 25 May 2022 00:58:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TBbmiWmX"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8F1C49DA; Wed, 25 May 2022 00:58:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433110; bh=Glf9pjjGnzIfbfULE+Zq+A8HaL9XSI9VV/ERWec7nYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TBbmiWmX1zUXtXdEKT+Weh04bSWxs5RaRe/BWkJm4vyg/FSbVb9VYAO3I2fr7jYG9 77S4W3Z01vrIQfMiy28EnfLhOdIgKNr+m5j7CFtJ77ASWWTP22XCmzOSoA2vWnIP9w 4x6o1JxI31dHomHuAMvCZaN3IyMesG8MhGrzCtsY= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:15 +0300 Message-Id: <20220524225816.6830-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 11/12] ipa: raspberrypi: Replace tabs with spaces in tuning data files 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Tuning data files mostly use spaces for indentation, with occasional stray tabs. Use spaces consistently. This allows parsing the tuning files with libyaml, preparing to replace the dependency on boost. Signed-off-by: Laurent Pinchart --- src/ipa/raspberrypi/data/imx219.json | 8 ++++---- src/ipa/raspberrypi/data/imx219_noir.json | 10 +++++----- src/ipa/raspberrypi/data/imx290.json | 18 +++++++++--------- src/ipa/raspberrypi/data/imx477.json | 8 ++++---- src/ipa/raspberrypi/data/imx477_noir.json | 10 +++++----- src/ipa/raspberrypi/data/ov5647.json | 10 +++++----- src/ipa/raspberrypi/data/ov5647_noir.json | 12 ++++++------ src/ipa/raspberrypi/data/se327m12.json | 6 +++--- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/ipa/raspberrypi/data/imx219.json b/src/ipa/raspberrypi/data/imx219.json index de59d9363be4..4e24c5d57da1 100644 --- a/src/ipa/raspberrypi/data/imx219.json +++ b/src/ipa/raspberrypi/data/imx219.json @@ -189,10 +189,10 @@ ] } ], - "shadows": - [ - { - "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": + "shadows": + [ + { + "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": [ 0, 0.17, 1000, 0.17 ] diff --git a/src/ipa/raspberrypi/data/imx219_noir.json b/src/ipa/raspberrypi/data/imx219_noir.json index 9a3f03ec86f4..1835ec3df63b 100644 --- a/src/ipa/raspberrypi/data/imx219_noir.json +++ b/src/ipa/raspberrypi/data/imx219_noir.json @@ -31,7 +31,7 @@ }, "rpi.awb": { - "bayes": 0 + "bayes": 0 }, "rpi.agc": { @@ -121,10 +121,10 @@ ] } ], - "shadows": - [ - { - "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": + "shadows": + [ + { + "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": [ 0, 0.17, 1000, 0.17 ] diff --git a/src/ipa/raspberrypi/data/imx290.json b/src/ipa/raspberrypi/data/imx290.json index 20b45c1684c2..1363bab71340 100644 --- a/src/ipa/raspberrypi/data/imx290.json +++ b/src/ipa/raspberrypi/data/imx290.json @@ -29,11 +29,11 @@ }, "rpi.awb": { - "bayes": 0 + "bayes": 0 }, "rpi.agc": { - "speed": 0.2, + "speed": 0.2, "metering_modes": { "matrix": @@ -150,14 +150,14 @@ "rpi.ccm": { "ccms": - [ + [ { - "ct": 3900, "ccm": - [ - 1.54659, -0.17707, -0.36953, -0.51471, 1.72733, -0.21262, 0.06667, -0.92279, 1.85612 - ] - } - ] + "ct": 3900, "ccm": + [ + 1.54659, -0.17707, -0.36953, -0.51471, 1.72733, -0.21262, 0.06667, -0.92279, 1.85612 + ] + } + ] }, "rpi.focus": { diff --git a/src/ipa/raspberrypi/data/imx477.json b/src/ipa/raspberrypi/data/imx477.json index d07febd283ed..0f389661c246 100644 --- a/src/ipa/raspberrypi/data/imx477.json +++ b/src/ipa/raspberrypi/data/imx477.json @@ -189,10 +189,10 @@ ] } ], - "shadows": - [ - { - "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": + "shadows": + [ + { + "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": [ 0, 0.17, 1000, 0.17 ] diff --git a/src/ipa/raspberrypi/data/imx477_noir.json b/src/ipa/raspberrypi/data/imx477_noir.json index 7d4fc7dab9fd..a379d780d966 100644 --- a/src/ipa/raspberrypi/data/imx477_noir.json +++ b/src/ipa/raspberrypi/data/imx477_noir.json @@ -31,7 +31,7 @@ }, "rpi.awb": { - "bayes": 0 + "bayes": 0 }, "rpi.agc": { @@ -121,10 +121,10 @@ ] } ], - "shadows": - [ - { - "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": + "shadows": + [ + { + "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": [ 0, 0.17, 1000, 0.17 ] diff --git a/src/ipa/raspberrypi/data/ov5647.json b/src/ipa/raspberrypi/data/ov5647.json index 24bc06fb6114..e65f9385d970 100644 --- a/src/ipa/raspberrypi/data/ov5647.json +++ b/src/ipa/raspberrypi/data/ov5647.json @@ -189,10 +189,10 @@ ] } ], - "shadows": - [ - { - "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": + "shadows": + [ + { + "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": [ 0, 0.17, 1000, 0.17 ] @@ -203,7 +203,7 @@ [ 0, 0.16, 1000, 0.165, 10000, 0.17 ], - "base_ev": 1.25 + "base_ev": 1.25 }, "rpi.alsc": { diff --git a/src/ipa/raspberrypi/data/ov5647_noir.json b/src/ipa/raspberrypi/data/ov5647_noir.json index 1c628ed13f19..dad73a5e8cd9 100644 --- a/src/ipa/raspberrypi/data/ov5647_noir.json +++ b/src/ipa/raspberrypi/data/ov5647_noir.json @@ -31,7 +31,7 @@ }, "rpi.awb": { - "bayes": 0 + "bayes": 0 }, "rpi.agc": { @@ -121,10 +121,10 @@ ] } ], - "shadows": - [ - { - "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": + "shadows": + [ + { + "bound": "LOWER", "q_lo": 0.0, "q_hi": 0.5, "y_target": [ 0, 0.17, 1000, 0.17 ] @@ -135,7 +135,7 @@ [ 0, 0.16, 1000, 0.165, 10000, 0.17 ], - "base_ev": 1.25 + "base_ev": 1.25 }, "rpi.alsc": { diff --git a/src/ipa/raspberrypi/data/se327m12.json b/src/ipa/raspberrypi/data/se327m12.json index 94af2239f700..5b1ac2ce3bf8 100644 --- a/src/ipa/raspberrypi/data/se327m12.json +++ b/src/ipa/raspberrypi/data/se327m12.json @@ -334,8 +334,8 @@ }, "rpi.sharpen": { - "threshold": 2.0, - "strength": 0.5, - "limit": 0.5 + "threshold": 2.0, + "strength": 0.5, + "limit": 0.5 } } From patchwork Tue May 24 22:58:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16038 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 89BC9C3271 for ; Tue, 24 May 2022 22:58:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C32A65682; Wed, 25 May 2022 00:58:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433121; bh=BXwVDLqZukHi73ClXR+i2KffARet0962NKFFXGZ6VxM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jORCRQk0QxEf8A9HtO3YVdB+yjrFob9CdYDBTasCmSjCxqitnFjaz6XY+MM2r9t+X 6rj+9SEzMCjNzpwaBGFAO6xl6uT5aUH2TwTlKLhnQtN+nYh+3jQwtqTCnf0pvRcurb PVgnT+I7jb94++cmOJkG07LjpMI2Nosd1Vh5fj5In+YkUpzQFeabuQqUJV43oEKZ8Q wTR8NthZMiIszppo24/QR3mqI6+GBdhqy22p+PyMtVdzZlGT9mGSlt0d7WXo4Porrb fO8tjWY3CK2gAy3vdHFkcHMZaoRDKGFnR/9RiBRUUMCVVB3TDd//UhrTnleDyxTwkW BDXiTI1kz1pNg== 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 6AFDA6567E for ; Wed, 25 May 2022 00:58:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QWZ6BPvF"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B7F28E50; Wed, 25 May 2022 00:58:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433112; bh=BXwVDLqZukHi73ClXR+i2KffARet0962NKFFXGZ6VxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWZ6BPvFTX3xgLN5TQIgtLHSEkbqRkJwmk9JmSYu86iuXFh8m3dEC66n/qCaggDf6 /hoTyrE7AxLKZ+I7DQOFeC+LqM32aiphil5Pp275AFlbseJZK+aH5wHepFzakDK3Ej pVCtwatHPQEDH/y/1EMjcXsCStTwdGlAIVXGloyU= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:16 +0300 Message-Id: <20220524225816.6830-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 12/12] ipa: raspberrypi: Use YamlParser to replace dependency on boost 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Raspberry Pi IPA module depends on boost only to parse the JSON tuning data files. As libcamera depends on libyaml, use the YamlParser class to parse those files and drop the dependency on boost. Signed-off-by: Laurent Pinchart --- README.rst | 6 -- src/ipa/raspberrypi/controller/algorithm.cpp | 2 +- src/ipa/raspberrypi/controller/algorithm.hpp | 6 +- src/ipa/raspberrypi/controller/controller.cpp | 27 ++++-- src/ipa/raspberrypi/controller/pwl.cpp | 12 ++- src/ipa/raspberrypi/controller/pwl.hpp | 5 +- src/ipa/raspberrypi/controller/rpi/agc.cpp | 94 +++++++++---------- src/ipa/raspberrypi/controller/rpi/agc.hpp | 10 +- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 94 +++++++++---------- src/ipa/raspberrypi/controller/rpi/alsc.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/awb.cpp | 89 +++++++++--------- src/ipa/raspberrypi/controller/rpi/awb.hpp | 8 +- .../controller/rpi/black_level.cpp | 12 +-- .../controller/rpi/black_level.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/ccm.cpp | 28 +++--- src/ipa/raspberrypi/controller/rpi/ccm.hpp | 4 +- .../raspberrypi/controller/rpi/contrast.cpp | 18 ++-- .../raspberrypi/controller/rpi/contrast.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/dpc.cpp | 4 +- src/ipa/raspberrypi/controller/rpi/dpc.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/geq.cpp | 10 +- src/ipa/raspberrypi/controller/rpi/geq.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/lux.cpp | 12 +-- src/ipa/raspberrypi/controller/rpi/lux.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/noise.cpp | 6 +- src/ipa/raspberrypi/controller/rpi/noise.hpp | 2 +- src/ipa/raspberrypi/controller/rpi/sdn.cpp | 6 +- src/ipa/raspberrypi/controller/rpi/sdn.hpp | 2 +- .../raspberrypi/controller/rpi/sharpen.cpp | 8 +- .../raspberrypi/controller/rpi/sharpen.hpp | 2 +- src/ipa/raspberrypi/meson.build | 1 - src/ipa/raspberrypi/raspberrypi.cpp | 1 + 32 files changed, 241 insertions(+), 240 deletions(-) diff --git a/README.rst b/README.rst index f81d6e2e7867..8d9145f58d64 100644 --- a/README.rst +++ b/README.rst @@ -71,12 +71,6 @@ for improved debugging: [optional] information, and libunwind is not needed if both libdw and the glibc backtrace() function are available. -for the Raspberry Pi IPA: [optional] - libboost-dev - - Support for Raspberry Pi can be disabled through the meson - 'pipelines' option to avoid this dependency. - for device hotplug enumeration: [optional] libudev-dev diff --git a/src/ipa/raspberrypi/controller/algorithm.cpp b/src/ipa/raspberrypi/controller/algorithm.cpp index 43ad0a2be222..4fd36fc1be5b 100644 --- a/src/ipa/raspberrypi/controller/algorithm.cpp +++ b/src/ipa/raspberrypi/controller/algorithm.cpp @@ -9,7 +9,7 @@ using namespace RPiController; -void Algorithm::Read([[maybe_unused]] boost::property_tree::ptree const ¶ms) +void Algorithm::Read([[maybe_unused]] const libcamera::YamlObject ¶ms) { } diff --git a/src/ipa/raspberrypi/controller/algorithm.hpp b/src/ipa/raspberrypi/controller/algorithm.hpp index 5123c87bab34..87bfca8d2045 100644 --- a/src/ipa/raspberrypi/controller/algorithm.hpp +++ b/src/ipa/raspberrypi/controller/algorithm.hpp @@ -13,10 +13,10 @@ #include #include +#include "libcamera/internal/yaml_parser.h" + #include "controller.hpp" -#include - namespace RPiController { // This defines the basic interface for all control algorithms. @@ -33,7 +33,7 @@ public: virtual bool IsPaused() const { return paused_; } virtual void Pause() { paused_ = true; } virtual void Resume() { paused_ = false; } - virtual void Read(boost::property_tree::ptree const ¶ms); + virtual void Read(const libcamera::YamlObject ¶ms); virtual void Initialise(); virtual void SwitchMode(CameraMode const &camera_mode, Metadata *metadata); virtual void Prepare(Metadata *image_metadata); diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp index d3433ad2e7e8..67d650ef0c1b 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -5,14 +5,16 @@ * controller.cpp - ISP controller */ +#include + +#include #include +#include "libcamera/internal/yaml_parser.h" + #include "algorithm.hpp" #include "controller.hpp" -#include -#include - using namespace RPiController; using namespace libcamera; @@ -32,16 +34,23 @@ Controller::~Controller() {} void Controller::Read(char const *filename) { - boost::property_tree::ptree root; - boost::property_tree::read_json(filename, root); - for (auto const &key_and_value : root) { - Algorithm *algo = CreateAlgorithm(key_and_value.first.c_str()); + File file(filename); + if (!file.open(File::OpenModeFlag::ReadOnly)) { + LOG(RPiController, Warning) + << "Failed to open tuning file '" << filename << "'"; + return; + } + + std::unique_ptr root = YamlParser::parse(file); + + for (auto const &[key, value] : root->asDict()) { + Algorithm *algo = CreateAlgorithm(key.c_str()); if (algo) { - algo->Read(key_and_value.second); + algo->Read(value); algorithms_.push_back(AlgorithmPtr(algo)); } else LOG(RPiController, Warning) - << "No algorithm found for \"" << key_and_value.first << "\""; + << "No algorithm found for \"" << key << "\""; } } diff --git a/src/ipa/raspberrypi/controller/pwl.cpp b/src/ipa/raspberrypi/controller/pwl.cpp index 130c820b559f..9c7bc94dd484 100644 --- a/src/ipa/raspberrypi/controller/pwl.cpp +++ b/src/ipa/raspberrypi/controller/pwl.cpp @@ -12,13 +12,15 @@ using namespace RPiController; -void Pwl::Read(boost::property_tree::ptree const ¶ms) +void Pwl::Read(const libcamera::YamlObject ¶ms) { - for (auto it = params.begin(); it != params.end(); it++) { - double x = it->second.get_value(); - assert(it == params.begin() || x > points_.back().x); + const auto &list = params.asList(); + + for (auto it = list.begin(); it != list.end(); it++) { + double x = it->get(0.0); + assert(it == list.begin() || x > points_.back().x); it++; - double y = it->second.get_value(); + double y = it->get(0.0); points_.push_back(Point(x, y)); } assert(points_.size() >= 2); diff --git a/src/ipa/raspberrypi/controller/pwl.hpp b/src/ipa/raspberrypi/controller/pwl.hpp index 484672f64095..70df4ba0daea 100644 --- a/src/ipa/raspberrypi/controller/pwl.hpp +++ b/src/ipa/raspberrypi/controller/pwl.hpp @@ -6,10 +6,11 @@ */ #pragma once +#include #include #include -#include +#include "libcamera/internal/yaml_parser.h" namespace RPiController { @@ -55,7 +56,7 @@ public: }; Pwl() {} Pwl(std::vector const &points) : points_(points) {} - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); void Append(double x, double y, const double eps = 1e-6); void Prepend(double x, double y, const double eps = 1e-6); Interval Domain() const; diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index f6a9cb0a2cd8..c82f29600be7 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -30,13 +30,13 @@ LOG_DEFINE_CATEGORY(RPiAgc) #define PIPELINE_BITS 13 // seems to be a 13-bit pipeline -void AgcMeteringMode::Read(boost::property_tree::ptree const ¶ms) +void AgcMeteringMode::Read(const libcamera::YamlObject ¶ms) { int num = 0; - for (auto &p : params.get_child("weights")) { + for (const auto &p : params["weights"].asList()) { if (num == AGC_STATS_SIZE) throw std::runtime_error("AgcConfig: too many weights"); - weights[num++] = p.second.get_value(); + weights[num++] = p.get(0.0); } if (num != AGC_STATS_SIZE) throw std::runtime_error("AgcConfig: insufficient weights"); @@ -44,39 +44,39 @@ void AgcMeteringMode::Read(boost::property_tree::ptree const ¶ms) static std::string read_metering_modes(std::map &metering_modes, - boost::property_tree::ptree const ¶ms) + const libcamera::YamlObject ¶ms) { std::string first; - for (auto &p : params) { + for (const auto &[key, value] : params.asDict()) { AgcMeteringMode metering_mode; - metering_mode.Read(p.second); - metering_modes[p.first] = std::move(metering_mode); + metering_mode.Read(value); + metering_modes[key] = std::move(metering_mode); if (first.empty()) - first = p.first; + first = key; } return first; } static int read_list(std::vector &list, - boost::property_tree::ptree const ¶ms) + const libcamera::YamlObject ¶ms) { - for (auto &p : params) - list.push_back(p.second.get_value()); + for (const auto &p : params.asList()) + list.push_back(p.get(0.0)); return list.size(); } static int read_list(std::vector &list, - boost::property_tree::ptree const ¶ms) + const libcamera::YamlObject ¶ms) { - for (auto &p : params) - list.push_back(p.second.get_value() * 1us); + for (const auto &p : params.asList()) + list.push_back(p.get(0.0) * 1us); return list.size(); } -void AgcExposureMode::Read(boost::property_tree::ptree const ¶ms) +void AgcExposureMode::Read(const libcamera::YamlObject ¶ms) { - int num_shutters = read_list(shutter, params.get_child("shutter")); - int num_ags = read_list(gain, params.get_child("gain")); + int num_shutters = read_list(shutter, params["shutter"]); + int num_ags = read_list(gain, params["gain"]); if (num_shutters < 2 || num_ags < 2) throw std::runtime_error( "AgcConfig: must have at least two entries in exposure profile"); @@ -87,40 +87,40 @@ void AgcExposureMode::Read(boost::property_tree::ptree const ¶ms) static std::string read_exposure_modes(std::map &exposure_modes, - boost::property_tree::ptree const ¶ms) + const libcamera::YamlObject ¶ms) { std::string first; - for (auto &p : params) { + for (const auto &[key, value] : params.asDict()) { AgcExposureMode exposure_mode; - exposure_mode.Read(p.second); - exposure_modes[p.first] = std::move(exposure_mode); + exposure_mode.Read(value); + exposure_modes[key] = std::move(exposure_mode); if (first.empty()) - first = p.first; + first = key; } return first; } -void AgcConstraint::Read(boost::property_tree::ptree const ¶ms) +void AgcConstraint::Read(const libcamera::YamlObject ¶ms) { - std::string bound_string = params.get("bound", ""); + std::string bound_string = params["bound"].get(""); transform(bound_string.begin(), bound_string.end(), bound_string.begin(), ::toupper); if (bound_string != "UPPER" && bound_string != "LOWER") throw std::runtime_error( "AGC constraint type should be UPPER or LOWER"); bound = bound_string == "UPPER" ? Bound::UPPER : Bound::LOWER; - q_lo = params.get("q_lo"); - q_hi = params.get("q_hi"); - Y_target.Read(params.get_child("y_target")); + q_lo = params["q_lo"].get(0.0); + q_hi = params["q_hi"].get(0.0); + Y_target.Read(params["y_target"]); } static AgcConstraintMode -read_constraint_mode(boost::property_tree::ptree const ¶ms) +read_constraint_mode(const libcamera::YamlObject ¶ms) { AgcConstraintMode mode; - for (auto &p : params) { + for (const auto &p : params.asList()) { AgcConstraint constraint; - constraint.Read(p.second); + constraint.Read(p); mode.push_back(std::move(constraint)); } return mode; @@ -128,36 +128,36 @@ read_constraint_mode(boost::property_tree::ptree const ¶ms) static std::string read_constraint_modes( std::map &constraint_modes, - boost::property_tree::ptree const ¶ms) + const libcamera::YamlObject ¶ms) { std::string first; - for (auto &p : params) { - constraint_modes[p.first] = read_constraint_mode(p.second); + for (const auto &[key, value] : params.asDict()) { + constraint_modes[key] = read_constraint_mode(value); if (first.empty()) - first = p.first; + first = key; } return first; } -void AgcConfig::Read(boost::property_tree::ptree const ¶ms) +void AgcConfig::Read(const libcamera::YamlObject ¶ms) { LOG(RPiAgc, Debug) << "AgcConfig"; default_metering_mode = read_metering_modes( - metering_modes, params.get_child("metering_modes")); + metering_modes, params["metering_modes"]); default_exposure_mode = read_exposure_modes( - exposure_modes, params.get_child("exposure_modes")); + exposure_modes, params["exposure_modes"]); default_constraint_mode = read_constraint_modes( - constraint_modes, params.get_child("constraint_modes")); - Y_target.Read(params.get_child("y_target")); - speed = params.get("speed", 0.2); - startup_frames = params.get("startup_frames", 10); - convergence_frames = params.get("convergence_frames", 6); + constraint_modes, params["constraint_modes"]); + Y_target.Read(params["y_target"]); + speed = params["speed"].get(0.2); + startup_frames = params["startup_frames"].get(10); + convergence_frames = params["convergence_frames"].get(6); fast_reduce_threshold = - params.get("fast_reduce_threshold", 0.4); - base_ev = params.get("base_ev", 1.0); + params["fast_reduce_threshold"].get(0.4); + base_ev = params["base_ev"].get(1.0); // Start with quite a low value as ramping up is easier than ramping down. - default_exposure_time = params.get("default_exposure_time", 1000) * 1us; - default_analogue_gain = params.get("default_analogue_gain", 1.0); + default_exposure_time = params["default_exposure_time"].get(1000) * 1us; + default_analogue_gain = params["default_analogue_gain"].get(1.0); } Agc::ExposureValues::ExposureValues() @@ -186,7 +186,7 @@ char const *Agc::Name() const return NAME; } -void Agc::Read(boost::property_tree::ptree const ¶ms) +void Agc::Read(const libcamera::YamlObject ¶ms) { LOG(RPiAgc, Debug) << "Agc"; config_.Read(params); diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp index c100d3128c90..7794ba744efc 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp @@ -26,13 +26,13 @@ namespace RPiController { struct AgcMeteringMode { double weights[AGC_STATS_SIZE]; - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); }; struct AgcExposureMode { std::vector shutter; std::vector gain; - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); }; struct AgcConstraint { @@ -41,13 +41,13 @@ struct AgcConstraint { double q_lo; double q_hi; Pwl Y_target; - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); }; typedef std::vector AgcConstraintMode; struct AgcConfig { - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); std::map metering_modes; std::map exposure_modes; std::map constraint_modes; @@ -72,7 +72,7 @@ class Agc : public AgcAlgorithm public: Agc(Controller *controller); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; // AGC handles "pausing" for itself. bool IsPaused() const override; void Pause() override; diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index e575c14a92db..b38b037c7713 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -5,6 +5,7 @@ * alsc.cpp - ALSC (auto lens shading correction) control algorithm */ +#include #include #include @@ -50,12 +51,12 @@ char const *Alsc::Name() const return NAME; } -static void generate_lut(double *lut, boost::property_tree::ptree const ¶ms) +static void generate_lut(double *lut, const libcamera::YamlObject ¶ms) { - double cstrength = params.get("corner_strength", 2.0); + double cstrength = params["corner_strength"].get(2.0); if (cstrength <= 1.0) throw std::runtime_error("Alsc: corner_strength must be > 1.0"); - double asymmetry = params.get("asymmetry", 1.0); + double asymmetry = params["asymmetry"].get(1.0); if (asymmetry < 0) throw std::runtime_error("Alsc: asymmetry must be >= 0"); double f1 = cstrength - 1, f2 = 1 + sqrt(cstrength); @@ -73,50 +74,43 @@ static void generate_lut(double *lut, boost::property_tree::ptree const ¶ms) } } -static void read_lut(double *lut, boost::property_tree::ptree const ¶ms) +static void read_lut(double *lut, const libcamera::YamlObject ¶ms) { + if (params.size() != XY) + throw std::runtime_error( + "Alsc: invalid number of entries in LSC table"); + int num = 0; - const int max_num = XY; - for (auto &p : params) { - if (num == max_num) - throw std::runtime_error( - "Alsc: too many entries in LSC table"); - lut[num++] = p.second.get_value(); - } - if (num < max_num) - throw std::runtime_error("Alsc: too few entries in LSC table"); + for (const auto &p : params.asList()) + lut[num++] = p.get(0.0); } static void read_calibrations(std::vector &calibrations, - boost::property_tree::ptree const ¶ms, + const libcamera::YamlObject ¶ms, std::string const &name) { - if (params.get_child_optional(name)) { + if (params.contains(name)) { double last_ct = 0; - for (auto &p : params.get_child(name)) { - double ct = p.second.get("ct"); + for (const auto &p : params[name].asList()) { + double ct = p["ct"].get(0.0); if (ct <= last_ct) throw std::runtime_error( "Alsc: entries in " + name + " must be in increasing ct order"); AlscCalibration calibration; calibration.ct = last_ct = ct; - boost::property_tree::ptree const &table = - p.second.get_child("table"); + + const libcamera::YamlObject &table = p["table"]; + if (table.size() != XY) + throw std::runtime_error( + "Alsc: incorrect number of values for ct " + + std::to_string(ct) + " in " + + name); + int num = 0; - for (auto it = table.begin(); it != table.end(); it++) { - if (num == XY) - throw std::runtime_error( - "Alsc: too many values for ct " + - std::to_string(ct) + " in " + - name); - calibration.table[num++] = - it->second.get_value(); - } - if (num != XY) - throw std::runtime_error( - "Alsc: too few values for ct " + - std::to_string(ct) + " in " + name); + for (const auto &value : table.asList()) + calibration.table[num++] = value.get(0.0); + calibrations.push_back(calibration); LOG(RPiAlsc, Debug) << "Read " << name << " calibration for ct " << ct; @@ -124,35 +118,35 @@ static void read_calibrations(std::vector &calibrations, } } -void Alsc::Read(boost::property_tree::ptree const ¶ms) +void Alsc::Read(const libcamera::YamlObject ¶ms) { - config_.frame_period = params.get("frame_period", 12); - config_.startup_frames = params.get("startup_frames", 10); - config_.speed = params.get("speed", 0.05); - double sigma = params.get("sigma", 0.01); - config_.sigma_Cr = params.get("sigma_Cr", sigma); - config_.sigma_Cb = params.get("sigma_Cb", sigma); - config_.min_count = params.get("min_count", 10.0); - config_.min_G = params.get("min_G", 50); - config_.omega = params.get("omega", 1.3); - config_.n_iter = params.get("n_iter", X + Y); + config_.frame_period = params["frame_period"].get(12); + config_.startup_frames = params["startup_frames"].get(10); + config_.speed = params["speed"].get(0.05); + double sigma = params["sigma"].get(0.01); + config_.sigma_Cr = params["sigma_Cr"].get(sigma); + config_.sigma_Cb = params["sigma_Cb"].get(sigma); + config_.min_count = params["min_count"].get(10.0); + config_.min_G = params["min_G"].get(50); + config_.omega = params["omega"].get(1.3); + config_.n_iter = params["n_iter"].get(X + Y); config_.luminance_strength = - params.get("luminance_strength", 1.0); + params["luminance_strength"].get(1.0); for (int i = 0; i < XY; i++) config_.luminance_lut[i] = 1.0; - if (params.get_child_optional("corner_strength")) + if (params.contains("corner_strength")) generate_lut(config_.luminance_lut, params); - else if (params.get_child_optional("luminance_lut")) + else if (params.contains("luminance_lut")) read_lut(config_.luminance_lut, - params.get_child("luminance_lut")); + params["luminance_lut"]); else LOG(RPiAlsc, Warning) << "no luminance table - assume unity everywhere"; read_calibrations(config_.calibrations_Cr, params, "calibrations_Cr"); read_calibrations(config_.calibrations_Cb, params, "calibrations_Cb"); - config_.default_ct = params.get("default_ct", 4500.0); - config_.threshold = params.get("threshold", 1e-3); - config_.lambda_bound = params.get("lambda_bound", 0.05); + config_.default_ct = params["default_ct"].get(4500.0); + config_.threshold = params["threshold"].get(1e-3); + config_.lambda_bound = params["lambda_bound"].get(0.05); } static double get_ct(Metadata *metadata, double default_ct); diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.hpp b/src/ipa/raspberrypi/controller/rpi/alsc.hpp index d1dbe0d1d22d..9d28c1b49a6d 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.hpp @@ -52,7 +52,7 @@ public: char const *Name() const override; void Initialise() override; void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Prepare(Metadata *image_metadata) override; void Process(StatisticsPtr &stats, Metadata *image_metadata) override; diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index d4c934473832..1c40bf878cd3 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -5,6 +5,8 @@ * awb.cpp - AWB control algorithm */ +#include + #include #include "../lux_status.h" @@ -24,33 +26,35 @@ LOG_DEFINE_CATEGORY(RPiAwb) // todo - the locking in this algorithm needs some tidying up as has been done // elsewhere (ALSC and AGC). -void AwbMode::Read(boost::property_tree::ptree const ¶ms) +void AwbMode::Read(const libcamera::YamlObject ¶ms) { - ct_lo = params.get("lo"); - ct_hi = params.get("hi"); + ct_lo = params["lo"].get(0.0); + ct_hi = params["hi"].get(0.0); } -void AwbPrior::Read(boost::property_tree::ptree const ¶ms) +void AwbPrior::Read(const libcamera::YamlObject ¶ms) { - lux = params.get("lux"); - prior.Read(params.get_child("prior")); + lux = params["lux"].get(0.0); + prior.Read(params["prior"]); } static void read_ct_curve(Pwl &ct_r, Pwl &ct_b, - boost::property_tree::ptree const ¶ms) + const libcamera::YamlObject ¶ms) { + const auto &list = params.asList(); int num = 0; - for (auto it = params.begin(); it != params.end(); it++) { - double ct = it->second.get_value(); - assert(it == params.begin() || ct != ct_r.Domain().end); - if (++it == params.end()) + + for (auto it = list.begin(); it != list.end(); it++) { + double ct = it->get(0.0); + assert(it == list.begin() || ct != ct_r.Domain().end); + if (++it == list.end()) throw std::runtime_error( "AwbConfig: incomplete CT curve entry"); - ct_r.Append(ct, it->second.get_value()); - if (++it == params.end()) + ct_r.Append(ct, it->get(0.0)); + if (++it == list.end()) throw std::runtime_error( "AwbConfig: incomplete CT curve entry"); - ct_b.Append(ct, it->second.get_value()); + ct_b.Append(ct, it->get(0.0)); num++; } if (num < 2) @@ -58,19 +62,19 @@ static void read_ct_curve(Pwl &ct_r, Pwl &ct_b, "AwbConfig: insufficient points in CT curve"); } -void AwbConfig::Read(boost::property_tree::ptree const ¶ms) +void AwbConfig::Read(const libcamera::YamlObject ¶ms) { - bayes = params.get("bayes", 1); - frame_period = params.get("frame_period", 10); - startup_frames = params.get("startup_frames", 10); - convergence_frames = params.get("convergence_frames", 3); - speed = params.get("speed", 0.05); - if (params.get_child_optional("ct_curve")) - read_ct_curve(ct_r, ct_b, params.get_child("ct_curve")); - if (params.get_child_optional("priors")) { - for (auto &p : params.get_child("priors")) { + bayes = params["bayes"].get(1); + frame_period = params["frame_period"].get(10); + startup_frames = params["startup_frames"].get(10); + convergence_frames = params["convergence_frames"].get(3); + speed = params["speed"].get(0.05); + if (params.contains("ct_curve")) + read_ct_curve(ct_r, ct_b, params["ct_curve"]); + if (params.contains("priors")) { + for (const auto &p : params["priors"].asList()) { AwbPrior prior; - prior.Read(p.second); + prior.Read(p); if (!priors.empty() && prior.lux <= priors.back().lux) throw std::runtime_error( "AwbConfig: Prior must be ordered in increasing lux value"); @@ -80,28 +84,28 @@ void AwbConfig::Read(boost::property_tree::ptree const ¶ms) throw std::runtime_error( "AwbConfig: no AWB priors configured"); } - if (params.get_child_optional("modes")) { - for (auto &p : params.get_child("modes")) { - modes[p.first].Read(p.second); + if (params.contains("modes")) { + for (const auto &[key, value] : params["modes"].asDict()) { + modes[key].Read(value); if (default_mode == nullptr) - default_mode = &modes[p.first]; + default_mode = &modes[key]; } if (default_mode == nullptr) throw std::runtime_error( "AwbConfig: no AWB modes configured"); } - min_pixels = params.get("min_pixels", 16.0); - min_G = params.get("min_G", 32); - min_regions = params.get("min_regions", 10); - delta_limit = params.get("delta_limit", 0.2); - coarse_step = params.get("coarse_step", 0.2); - transverse_pos = params.get("transverse_pos", 0.01); - transverse_neg = params.get("transverse_neg", 0.01); + min_pixels = params["min_pixels"].get(16.0); + min_G = params["min_G"].get(32); + min_regions = params["min_regions"].get(10); + delta_limit = params["delta_limit"].get(0.2); + coarse_step = params["coarse_step"].get(0.2); + transverse_pos = params["transverse_pos"].get(0.01); + transverse_neg = params["transverse_neg"].get(0.01); if (transverse_pos <= 0 || transverse_neg <= 0) throw std::runtime_error( "AwbConfig: transverse_pos/neg must be > 0"); - sensitivity_r = params.get("sensitivity_r", 1.0); - sensitivity_b = params.get("sensitivity_b", 1.0); + sensitivity_r = params["sensitivity_r"].get(1.0); + sensitivity_b = params["sensitivity_b"].get(1.0); if (bayes) { if (ct_r.Empty() || ct_b.Empty() || priors.empty() || default_mode == nullptr) { @@ -110,10 +114,9 @@ void AwbConfig::Read(boost::property_tree::ptree const ¶ms) bayes = false; } } - fast = params.get( - "fast", bayes); // default to fast for Bayesian, otherwise slow - whitepoint_r = params.get("whitepoint_r", 0.0); - whitepoint_b = params.get("whitepoint_b", 0.0); + fast = params[fast].get(bayes); // default to fast for Bayesian, otherwise slow + whitepoint_r = params["whitepoint_r"].get(0.0); + whitepoint_b = params["whitepoint_b"].get(0.0); if (bayes == false) sensitivity_r = sensitivity_b = 1.0; // nor do sensitivities make any sense @@ -144,7 +147,7 @@ char const *Awb::Name() const return NAME; } -void Awb::Read(boost::property_tree::ptree const ¶ms) +void Awb::Read(const libcamera::YamlObject ¶ms) { config_.Read(params); } diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp index ac3dca6f42fc..41334f798e2f 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp @@ -19,20 +19,20 @@ namespace RPiController { // Control algorithm to perform AWB calculations. struct AwbMode { - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); double ct_lo; // low CT value for search double ct_hi; // high CT value for search }; struct AwbPrior { - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); double lux; // lux level Pwl prior; // maps CT to prior log likelihood for this lux level }; struct AwbConfig { AwbConfig() : default_mode(nullptr) {} - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); // Only repeat the AWB calculation every "this many" frames uint16_t frame_period; // number of initial frames for which speed taken as 1.0 (maximum) @@ -82,7 +82,7 @@ public: ~Awb(); char const *Name() const override; void Initialise() override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; // AWB handles "pausing" for itself. bool IsPaused() const override; void Pause() override; diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.cpp b/src/ipa/raspberrypi/controller/rpi/black_level.cpp index 6b3497f13c19..de3a1e98ca1c 100644 --- a/src/ipa/raspberrypi/controller/rpi/black_level.cpp +++ b/src/ipa/raspberrypi/controller/rpi/black_level.cpp @@ -31,13 +31,13 @@ char const *BlackLevel::Name() const return NAME; } -void BlackLevel::Read(boost::property_tree::ptree const ¶ms) +void BlackLevel::Read(const libcamera::YamlObject ¶ms) { - uint16_t black_level = params.get( - "black_level", 4096); // 64 in 10 bits scaled to 16 bits - black_level_r_ = params.get("black_level_r", black_level); - black_level_g_ = params.get("black_level_g", black_level); - black_level_b_ = params.get("black_level_b", black_level); + // 64 in 10 bits scaled to 16 bits + uint16_t black_level = params["black_level"].get(4096); + black_level_r_ = params["black_level_r"].get(black_level); + black_level_g_ = params["black_level_g"].get(black_level); + black_level_b_ = params["black_level_b"].get(black_level); LOG(RPiBlackLevel, Debug) << " Read black levels red " << black_level_r_ << " green " << black_level_g_ diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.hpp b/src/ipa/raspberrypi/controller/rpi/black_level.hpp index 65ec4d0ed26c..5a63b5faef21 100644 --- a/src/ipa/raspberrypi/controller/rpi/black_level.hpp +++ b/src/ipa/raspberrypi/controller/rpi/black_level.hpp @@ -18,7 +18,7 @@ class BlackLevel : public Algorithm public: BlackLevel(Controller *controller); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Prepare(Metadata *image_metadata) override; private: diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.cpp b/src/ipa/raspberrypi/controller/rpi/ccm.cpp index 821a4c7c98c5..0e02a524c68d 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.cpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.cpp @@ -37,17 +37,15 @@ Matrix::Matrix(double m0, double m1, double m2, double m3, double m4, double m5, m[0][0] = m0, m[0][1] = m1, m[0][2] = m2, m[1][0] = m3, m[1][1] = m4, m[1][2] = m5, m[2][0] = m6, m[2][1] = m7, m[2][2] = m8; } -void Matrix::Read(boost::property_tree::ptree const ¶ms) +void Matrix::Read(const libcamera::YamlObject ¶ms) { double *ptr = (double *)m; - int n = 0; - for (auto it = params.begin(); it != params.end(); it++) { - if (n++ == 9) - throw std::runtime_error("Ccm: too many values in CCM"); - *ptr++ = it->second.get_value(); - } - if (n < 9) - throw std::runtime_error("Ccm: too few values in CCM"); + + if (params.size() != 9) + throw std::runtime_error("Ccm: wrong number of values in CCM"); + + for (const auto ¶m : params.asList()) + *ptr++ = param.get(0.0); } Ccm::Ccm(Controller *controller) @@ -58,14 +56,14 @@ char const *Ccm::Name() const return NAME; } -void Ccm::Read(boost::property_tree::ptree const ¶ms) +void Ccm::Read(const libcamera::YamlObject ¶ms) { - if (params.get_child_optional("saturation")) - config_.saturation.Read(params.get_child("saturation")); - for (auto &p : params.get_child("ccms")) { + if (params.contains("saturation")) + config_.saturation.Read(params["saturation"]); + for (auto &p : params["ccms"].asList()) { CtCcm ct_ccm; - ct_ccm.ct = p.second.get("ct"); - ct_ccm.ccm.Read(p.second.get_child("ccm")); + ct_ccm.ct = p["ct"].get(0.0); + ct_ccm.ccm.Read(p["ccm"]); if (!config_.ccms.empty() && ct_ccm.ct <= config_.ccms.back().ct) throw std::runtime_error( diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.hpp b/src/ipa/raspberrypi/controller/rpi/ccm.hpp index 330ed51fe398..073f02526850 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.hpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.hpp @@ -20,7 +20,7 @@ struct Matrix { double m6, double m7, double m8); Matrix(); double m[3][3]; - void Read(boost::property_tree::ptree const ¶ms); + void Read(const libcamera::YamlObject ¶ms); }; static inline Matrix operator*(double d, Matrix const &m) { @@ -62,7 +62,7 @@ class Ccm : public CcmAlgorithm public: Ccm(Controller *controller = NULL); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void SetSaturation(double saturation) override; void Initialise() override; void Prepare(Metadata *image_metadata) override; diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index ae55aad56739..534f8b48a59b 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -36,21 +36,21 @@ char const *Contrast::Name() const return NAME; } -void Contrast::Read(boost::property_tree::ptree const ¶ms) +void Contrast::Read(const libcamera::YamlObject ¶ms) { // enable adaptive enhancement by default - config_.ce_enable = params.get("ce_enable", 1); + config_.ce_enable = params["ce_enable"].get(1); // the point near the bottom of the histogram to move - config_.lo_histogram = params.get("lo_histogram", 0.01); + config_.lo_histogram = params["lo_histogram"].get(0.01); // where in the range to try and move it to - config_.lo_level = params.get("lo_level", 0.015); + config_.lo_level = params["lo_level"].get(0.015); // but don't move by more than this - config_.lo_max = params.get("lo_max", 500); + config_.lo_max = params["lo_max"].get(500); // equivalent values for the top of the histogram... - config_.hi_histogram = params.get("hi_histogram", 0.95); - config_.hi_level = params.get("hi_level", 0.95); - config_.hi_max = params.get("hi_max", 2000); - config_.gamma_curve.Read(params.get_child("gamma_curve")); + config_.hi_histogram = params["hi_histogram"].get(0.95); + config_.hi_level = params["hi_level"].get(0.95); + config_.hi_max = params["hi_max"].get(2000); + config_.gamma_curve.Read(params["gamma_curve"]); } void Contrast::SetBrightness(double brightness) diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp index 85624539a1da..6b1e41724f5b 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.hpp @@ -32,7 +32,7 @@ class Contrast : public ContrastAlgorithm public: Contrast(Controller *controller = NULL); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void SetBrightness(double brightness) override; void SetContrast(double contrast) override; void Initialise() override; diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.cpp b/src/ipa/raspberrypi/controller/rpi/dpc.cpp index 110f50560e76..ac8aa78921c6 100644 --- a/src/ipa/raspberrypi/controller/rpi/dpc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/dpc.cpp @@ -29,9 +29,9 @@ char const *Dpc::Name() const return NAME; } -void Dpc::Read(boost::property_tree::ptree const ¶ms) +void Dpc::Read(const libcamera::YamlObject ¶ms) { - config_.strength = params.get("strength", 1); + config_.strength = params["strength"].get(1); if (config_.strength < 0 || config_.strength > 2) throw std::runtime_error("Dpc: bad strength value"); } diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.hpp b/src/ipa/raspberrypi/controller/rpi/dpc.hpp index d90285c4eb56..382e20a6f1db 100644 --- a/src/ipa/raspberrypi/controller/rpi/dpc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/dpc.hpp @@ -22,7 +22,7 @@ class Dpc : public Algorithm public: Dpc(Controller *controller); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Prepare(Metadata *image_metadata) override; private: diff --git a/src/ipa/raspberrypi/controller/rpi/geq.cpp b/src/ipa/raspberrypi/controller/rpi/geq.cpp index 4530cb75792c..cff3bfe01ed6 100644 --- a/src/ipa/raspberrypi/controller/rpi/geq.cpp +++ b/src/ipa/raspberrypi/controller/rpi/geq.cpp @@ -33,14 +33,14 @@ char const *Geq::Name() const return NAME; } -void Geq::Read(boost::property_tree::ptree const ¶ms) +void Geq::Read(const libcamera::YamlObject ¶ms) { - config_.offset = params.get("offset", 0); - config_.slope = params.get("slope", 0.0); + config_.offset = params["offset"].get(0); + config_.slope = params["slope"].get(0.0); if (config_.slope < 0.0 || config_.slope >= 1.0) throw std::runtime_error("Geq: bad slope value"); - if (params.get_child_optional("strength")) - config_.strength.Read(params.get_child("strength")); + if (params.contains("strength")) + config_.strength.Read(params["strength"]); } void Geq::Prepare(Metadata *image_metadata) diff --git a/src/ipa/raspberrypi/controller/rpi/geq.hpp b/src/ipa/raspberrypi/controller/rpi/geq.hpp index 8ba3046b2a2b..84104be40452 100644 --- a/src/ipa/raspberrypi/controller/rpi/geq.hpp +++ b/src/ipa/raspberrypi/controller/rpi/geq.hpp @@ -24,7 +24,7 @@ class Geq : public Algorithm public: Geq(Controller *controller); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Prepare(Metadata *image_metadata) override; private: diff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp index f77e9140ac10..cb93198d08a5 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.cpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp @@ -36,14 +36,14 @@ char const *Lux::Name() const return NAME; } -void Lux::Read(boost::property_tree::ptree const ¶ms) +void Lux::Read(const libcamera::YamlObject ¶ms) { reference_shutter_speed_ = - params.get("reference_shutter_speed") * 1.0us; - reference_gain_ = params.get("reference_gain"); - reference_aperture_ = params.get("reference_aperture", 1.0); - reference_Y_ = params.get("reference_Y"); - reference_lux_ = params.get("reference_lux"); + params["reference_shutter_speed"].get(0.0) * 1.0us; + reference_gain_ = params["reference_gain"].get(0.0); + reference_aperture_ = params["reference_aperture"].get(1.0); + reference_Y_ = params["reference_Y"].get(0.0); + reference_lux_ = params["reference_lux"].get(0.0); current_aperture_ = reference_aperture_; } diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp index 3ebd35d1e382..7d85199f7def 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp @@ -22,7 +22,7 @@ class Lux : public Algorithm public: Lux(Controller *controller); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Prepare(Metadata *image_metadata) override; void Process(StatisticsPtr &stats, Metadata *image_metadata) override; void SetCurrentAperture(double aperture); diff --git a/src/ipa/raspberrypi/controller/rpi/noise.cpp b/src/ipa/raspberrypi/controller/rpi/noise.cpp index 63cad639f313..66a2a7f3486c 100644 --- a/src/ipa/raspberrypi/controller/rpi/noise.cpp +++ b/src/ipa/raspberrypi/controller/rpi/noise.cpp @@ -39,10 +39,10 @@ void Noise::SwitchMode(CameraMode const &camera_mode, mode_factor_ = std::max(1.0, camera_mode.noise_factor); } -void Noise::Read(boost::property_tree::ptree const ¶ms) +void Noise::Read(const libcamera::YamlObject ¶ms) { - reference_constant_ = params.get("reference_constant"); - reference_slope_ = params.get("reference_slope"); + reference_constant_ = params["reference_constant"].get(0.0); + reference_slope_ = params["reference_slope"].get(0.0); } void Noise::Prepare(Metadata *image_metadata) diff --git a/src/ipa/raspberrypi/controller/rpi/noise.hpp b/src/ipa/raspberrypi/controller/rpi/noise.hpp index 1c9de5c87d08..353e79fa2a8c 100644 --- a/src/ipa/raspberrypi/controller/rpi/noise.hpp +++ b/src/ipa/raspberrypi/controller/rpi/noise.hpp @@ -19,7 +19,7 @@ public: Noise(Controller *controller); char const *Name() const override; void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Prepare(Metadata *image_metadata) override; private: diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.cpp b/src/ipa/raspberrypi/controller/rpi/sdn.cpp index 9384550983e7..619a793cbdfb 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.cpp @@ -32,10 +32,10 @@ char const *Sdn::Name() const return NAME; } -void Sdn::Read(boost::property_tree::ptree const ¶ms) +void Sdn::Read(const libcamera::YamlObject ¶ms) { - deviation_ = params.get("deviation", 3.2); - strength_ = params.get("strength", 0.75); + deviation_ = params["deviation"].get(3.2); + strength_ = params["strength"].get(0.75); } void Sdn::Initialise() {} diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.hpp b/src/ipa/raspberrypi/controller/rpi/sdn.hpp index 2371ce04163f..e69557908cea 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.hpp @@ -18,7 +18,7 @@ class Sdn : public DenoiseAlgorithm public: Sdn(Controller *controller = NULL); char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void Initialise() override; void Prepare(Metadata *image_metadata) override; void SetMode(DenoiseMode mode) override; diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp index 18825a43867b..491f88d06c79 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp @@ -37,11 +37,11 @@ void Sharpen::SwitchMode(CameraMode const &camera_mode, mode_factor_ = std::max(1.0, camera_mode.noise_factor); } -void Sharpen::Read(boost::property_tree::ptree const ¶ms) +void Sharpen::Read(const libcamera::YamlObject ¶ms) { - threshold_ = params.get("threshold", 1.0); - strength_ = params.get("strength", 1.0); - limit_ = params.get("limit", 1.0); + threshold_ = params["threshold"].get(1.0); + strength_ = params["strength"].get(1.0); + limit_ = params["limit"].get(1.0); LOG(RPiSharpen, Debug) << "Read threshold " << threshold_ << " strength " << strength_ diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp index 13a076a86895..6dfc79afb0ac 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp @@ -19,7 +19,7 @@ public: Sharpen(Controller *controller); char const *Name() const override; void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override; - void Read(boost::property_tree::ptree const ¶ms) override; + void Read(const libcamera::YamlObject ¶ms) override; void SetStrength(double strength) override; void Prepare(Metadata *image_metadata) override; diff --git a/src/ipa/raspberrypi/meson.build b/src/ipa/raspberrypi/meson.build index 32897e07dad9..517d815bb98c 100644 --- a/src/ipa/raspberrypi/meson.build +++ b/src/ipa/raspberrypi/meson.build @@ -4,7 +4,6 @@ ipa_name = 'ipa_rpi' rpi_ipa_deps = [ libcamera_private, - dependency('boost'), libatomic, ] diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 3b126bb5175e..f0f568d12513 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include