From patchwork Thu Jan 9 11:53:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22491 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 9B558C32EA for ; Thu, 9 Jan 2025 11:55:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3C1726851D; Thu, 9 Jan 2025 12:55:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SZhJzbFU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13560684E7 for ; Thu, 9 Jan 2025 12:55:16 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:93b9:eca8:897d:eae6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A9446F3; Thu, 9 Jan 2025 12:54:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1736423662; bh=y/72oxfBbHJsaPv/liZH+fW/XZcS/CceluJaJDIB9Y8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZhJzbFUe3Q7YaR+v6PvTKDlKCl9EopBg6gkwuUue5wjJ1daD0vHE14ZN1w1CIVwi hO9RZkhKlFm3eQ4s/LE6N5CY0zSmxLAC0ccnZflUTndgQzh/M4xngG8e8OGO3lzVDm jIDJ2onxsZojW38DiK0FpwbLcnEN6PDA9qqbNmJs= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 04/11] libipa: awb: Add helper functions for AWB mode support Date: Thu, 9 Jan 2025 12:53:55 +0100 Message-ID: <20250109115412.356768-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250109115412.356768-1-stefan.klug@ideasonboard.com> References: <20250109115412.356768-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The AWB modes are specified in the libcamera core controls. It is therefore quite likely that every AWB algorithm will implement them. Add helper functions for parsing and storing the configured modes and the currently selected mode to the AwbAlgorithm base class. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder Reviewed-by: Daniel Scally --- src/ipa/libipa/awb.cpp | 100 +++++++++++++++++++++++++++++++++++++++++ src/ipa/libipa/awb.h | 12 +++++ 2 files changed, 112 insertions(+) diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp index 74e88d513b27..07502da66f73 100644 --- a/src/ipa/libipa/awb.cpp +++ b/src/ipa/libipa/awb.cpp @@ -9,6 +9,8 @@ #include +#include + /** * \file awb.h * \brief Base classes for AWB algorithms @@ -132,6 +134,104 @@ namespace ipa { * \brief Controls info map for the controls provided by the algorithm */ +/** + * \var AwbAlgorithm::modes_ + * \brief Map of all configured modes + * \sa AwbAlgorithm::parseModeConfigs + */ + +/** + * \class AwbAlgorithm::ModeConfig + * \brief Holds the configuration of a single AWB mode + * + * Awb modes limit the regulation of the AWB algorithm to a specific range of + * colour temperatures. + */ + +/** + * \var AwbAlgorithm::ModeConfig::ctLo + * \brief The lowest valid colour temperature of that mode + */ + +/** + * \var AwbAlgorithm::ModeConfig::ctHi + * \brief The highest valid colour temperature of that mode + */ + +/** + * \brief Parse the mode configurations from the tuning data + * \param[in] tuningData the YamlObject representing the tuning data + * + * Utility function to parse the tuning data for a AwbMode entry and read all + * provided modes. It populetes AwbAlgorithm::controls_, AwbAlgorithm::modes_ + * and sets the current mode to AwbAuto. + * + * \return Zero on success, negative error code otherwise + */ +int AwbAlgorithm::parseModeConfigs(const YamlObject &tuningData) +{ + std::vector availableModes; + + const YamlObject &yamlModes = tuningData[controls::AwbMode.name()]; + if (!yamlModes.isDictionary()) { + LOG(Awb, Error) + << "AwbModes must be a dictionary."; + return -EINVAL; + } + + for (const auto &[modeName, modeDict] : yamlModes.asDict()) { + if (controls::AwbModeNameValueMap.find(modeName) == + controls::AwbModeNameValueMap.end()) { + LOG(Awb, Warning) + << "Skipping unknown awb mode '" + << modeName << "'"; + continue; + } + + if (!modeDict.isDictionary()) { + LOG(Awb, Error) + << "Invalid awb mode '" << modeName << "'"; + return -EINVAL; + } + + const auto &modeValue = static_cast( + controls::AwbModeNameValueMap.at(modeName)); + + auto &config = modes_[modeValue]; + auto hi = modeDict["hi"].get(); + if (!hi) { + LOG(Awb, Error) << "Failed to read hi param of mode " + << modeName; + return -EINVAL; + } + config.ctHi = *hi; + + auto lo = modeDict["lo"].get(); + if (!lo) { + LOG(Awb, Error) << "Failed to read low param of mode " + << modeName; + return -EINVAL; + } + config.ctLo = *lo; + + availableModes.push_back(modeValue); + } + + if (modes_.empty()) { + LOG(Awb, Error) << "No AWB modes configured"; + return -EINVAL; + } + + if (modes_.find(controls::AwbAuto) == modes_.end()) { + LOG(Awb, Error) << "AwbAuto mode is missing in the configuration."; + return -EINVAL; + } + + controls_[&controls::AwbMode] = ControlInfo(availableModes); + + return 0; +} + } /* namespace ipa */ } /* namespace libcamera */ diff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h index 2dd471606ec4..426fdd6dae77 100644 --- a/src/ipa/libipa/awb.h +++ b/src/ipa/libipa/awb.h @@ -7,7 +7,11 @@ #pragma once +#include + +#include #include + #include "libcamera/internal/yaml_parser.h" #include "vector.h" @@ -43,7 +47,15 @@ public: virtual void handleControls([[maybe_unused]] const ControlList &controls) {} protected: + int parseModeConfigs(const YamlObject &tuningData); + + struct ModeConfig { + double ctHi; + double ctLo; + }; + ControlInfoMap::Map controls_; + std::map modes_; }; } /* namespace ipa */