From patchwork Tue Oct 28 17:08:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 24856 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 AC8CCBE080 for ; Tue, 28 Oct 2025 17:09:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5FA3B60818; Tue, 28 Oct 2025 18:09:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qbQGOM36"; 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 ED32860805 for ; Tue, 28 Oct 2025 18:09:09 +0100 (CET) Received: from rui-Precision-7560.local (unknown [209.216.122.90]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0925B1AED; Tue, 28 Oct 2025 18:07:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761671241; bh=+eyGqc5p9uACWenOcU/Wnu+Z5BE8b3Mww6kmViso+Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qbQGOM3668kAd1A6/r9n3b7l5VA1vJkuVJAIzJktR6fHM9SKsHj7G3T6+DsAFEbdk Ra9zqUD9LpsvLWh+s0vJ9DKT0qulVS7k4c0DkH8l3ApDhGjvnL65ZPksjaT9ZsuImJ GXxzkworPGUmFGeqcjs4AVoF/M6QxE3oozMUmhM0= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 04/16] ipa: rkisp1: algorithms: Add YAML parsing helper utilities Date: Tue, 28 Oct 2025 13:08:33 -0400 Message-ID: <20251028170847.2673396-4-rui.wang@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251028170847.2673396-1-rui.wang@ideasonboard.com> References: <20251028170847.2673396-1-rui.wang@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" Introduce yaml_helper.h with standardized functions for parsing YAML configuration data in RkISP1 IPA algorithms. Provides type-safe parsing for optional values, lists, enums, and specialized filter coefficients. Key functions: - opt8/16/32/bool: Type-safe optional value parsing with defaults - optList8/16: List parsing with size validation - optEnum: String-to-enum mapping with validation - optFilterCoeffs: Specialized filter coefficient parsing Signed-off-by: Rui Wang --- src/ipa/rkisp1/algorithms/yaml_helper.h | 123 ++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/yaml_helper.h diff --git a/src/ipa/rkisp1/algorithms/yaml_helper.h b/src/ipa/rkisp1/algorithms/yaml_helper.h new file mode 100644 index 00000000..ed2ba926 --- /dev/null +++ b/src/ipa/rkisp1/algorithms/yaml_helper.h @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025, Ideas On Board + * + * RkISP1 YAML parsing helper functions + */ + +#pragma once + +#include +#include +#include + +#include "libcamera/internal/yaml_parser.h" + +namespace libcamera { + +namespace ipa::rkisp1::algorithms { + +namespace yamlHelper { + +inline void opt32(const YamlObject &level, const char *key, std::optional &dst) +{ + dst = level[key].get(); +} + +inline void opt16(const YamlObject &level, const char *key, std::optional &dst) +{ + dst = level[key].get(); +} + +inline void opt8(const YamlObject &level, const char *key, std::optional &dst) +{ + dst = level[key].get(); +} + +inline void optbool(const YamlObject &level, const char *key, std::optional &dst) +{ + dst = level[key].get(); +} + +inline void optbool(const YamlObject &level, const char *key, bool &dst, bool defaultVal) +{ + std::optional val = level[key].get(); + dst = val.value_or(defaultVal); +} + +inline void opt8(const YamlObject &level, const char *key, uint8_t &dst, uint8_t defaultVal) +{ + std::optional val = level[key].get(); + dst = val.value_or(defaultVal); +} + +inline void opt16(const YamlObject &level, const char *key, uint16_t &dst, uint16_t defaultVal) +{ + std::optional val = level[key].get(); + dst = val.value_or(defaultVal); +} + +inline void opt32(const YamlObject &level, const char *key, uint32_t &dst, uint32_t defaultVal) +{ + std::optional val = level[key].get(); + dst = val.value_or(defaultVal); +} + +inline bool optList8(const YamlObject &level, const char *key, std::vector &dst, size_t expectedSize) +{ + std::optional> val = level[key].getList(); + if (!val || val->size() != expectedSize) + return false; + dst = *val; + return true; +} + +inline bool optList16(const YamlObject &level, const char *key, std::vector &dst, size_t expectedSize) +{ + std::optional> val = level[key].getList(); + if (!val || val->size() != expectedSize) + return false; + dst = *val; + return true; +} + +template +inline bool optEnum(const YamlObject &level, const char *key, EnumType &dst, EnumType defaultVal, + const std::map &enumMap) +{ + std::optional val = level[key].get(); + if (!val) { + dst = defaultVal; + return true; + } + auto it = enumMap.find(*val); + if (it == enumMap.end()) + return false; + dst = it->second; + return true; +} + +inline bool optFilterCoeffs(const YamlObject &level, const char *key, uint8_t *coeffs, uint32_t &filterSize, size_t maxCoeffs) +{ + std::optional> val = level[key].getList(); + if (!val) + return false; + + size_t size = val->size(); + if (size == maxCoeffs - 1) { + filterSize = 0; // 9x9 filter + } else if (size == maxCoeffs) { + filterSize = 1; // 13x9 filter + } else { + return false; // Invalid size + } + + std::copy_n(val->begin(), size, coeffs); + return true; +} + +} /* namespace yamlHelper */ + +} /* namespace ipa::rkisp1::algorithms */ + +} /* namespace libcamera */