| Message ID | 20251028211751.2761420-4-rui.wang@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Hi Rui, Quoting Rui Wang (2025-10-28 21:17:37) > 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. I think this should be either part of the core Yaml helpers or there's something missing about how we can interact with reading yaml types. We shouldn't add all of this generic type handling inside the rkisp algorithm code. If the existing yaml interfaces aren't providing the type handling required, then this support needs to go there (along with tests). > 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 <rui.wang@ideasonboard.com> > --- > 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 <map> > +#include <optional> > +#include <vector> > + > +#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<uint32_t> &dst) > +{ > + dst = level[key].get<uint32_t>(); > +} > + > +inline void opt16(const YamlObject &level, const char *key, std::optional<uint16_t> &dst) > +{ > + dst = level[key].get<uint16_t>(); > +} > + > +inline void opt8(const YamlObject &level, const char *key, std::optional<uint8_t> &dst) > +{ > + dst = level[key].get<uint8_t>(); > +} > + > +inline void optbool(const YamlObject &level, const char *key, std::optional<bool> &dst) > +{ > + dst = level[key].get<bool>(); > +} > + > +inline void optbool(const YamlObject &level, const char *key, bool &dst, bool defaultVal) > +{ > + std::optional<bool> val = level[key].get<bool>(); > + dst = val.value_or(defaultVal); > +} > + > +inline void opt8(const YamlObject &level, const char *key, uint8_t &dst, uint8_t defaultVal) > +{ > + std::optional<uint8_t> val = level[key].get<uint8_t>(); > + dst = val.value_or(defaultVal); > +} > + > +inline void opt16(const YamlObject &level, const char *key, uint16_t &dst, uint16_t defaultVal) > +{ > + std::optional<uint16_t> val = level[key].get<uint16_t>(); > + dst = val.value_or(defaultVal); > +} > + > +inline void opt32(const YamlObject &level, const char *key, uint32_t &dst, uint32_t defaultVal) > +{ > + std::optional<uint32_t> val = level[key].get<uint32_t>(); > + dst = val.value_or(defaultVal); > +} > + > +inline bool optList8(const YamlObject &level, const char *key, std::vector<uint8_t> &dst, size_t expectedSize) > +{ > + std::optional<std::vector<uint8_t>> val = level[key].getList<uint8_t>(); > + if (!val || val->size() != expectedSize) > + return false; > + dst = *val; > + return true; > +} > + > +inline bool optList16(const YamlObject &level, const char *key, std::vector<uint16_t> &dst, size_t expectedSize) > +{ > + std::optional<std::vector<uint16_t>> val = level[key].getList<uint16_t>(); > + if (!val || val->size() != expectedSize) > + return false; > + dst = *val; > + return true; > +} > + > +template<typename EnumType> > +inline bool optEnum(const YamlObject &level, const char *key, EnumType &dst, EnumType defaultVal, > + const std::map<std::string, EnumType> &enumMap) > +{ > + std::optional<std::string> val = level[key].get<std::string>(); > + 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<std::vector<uint8_t>> val = level[key].getList<uint8_t>(); > + 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 */ > -- > 2.43.0 >
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 <map> +#include <optional> +#include <vector> + +#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<uint32_t> &dst) +{ + dst = level[key].get<uint32_t>(); +} + +inline void opt16(const YamlObject &level, const char *key, std::optional<uint16_t> &dst) +{ + dst = level[key].get<uint16_t>(); +} + +inline void opt8(const YamlObject &level, const char *key, std::optional<uint8_t> &dst) +{ + dst = level[key].get<uint8_t>(); +} + +inline void optbool(const YamlObject &level, const char *key, std::optional<bool> &dst) +{ + dst = level[key].get<bool>(); +} + +inline void optbool(const YamlObject &level, const char *key, bool &dst, bool defaultVal) +{ + std::optional<bool> val = level[key].get<bool>(); + dst = val.value_or(defaultVal); +} + +inline void opt8(const YamlObject &level, const char *key, uint8_t &dst, uint8_t defaultVal) +{ + std::optional<uint8_t> val = level[key].get<uint8_t>(); + dst = val.value_or(defaultVal); +} + +inline void opt16(const YamlObject &level, const char *key, uint16_t &dst, uint16_t defaultVal) +{ + std::optional<uint16_t> val = level[key].get<uint16_t>(); + dst = val.value_or(defaultVal); +} + +inline void opt32(const YamlObject &level, const char *key, uint32_t &dst, uint32_t defaultVal) +{ + std::optional<uint32_t> val = level[key].get<uint32_t>(); + dst = val.value_or(defaultVal); +} + +inline bool optList8(const YamlObject &level, const char *key, std::vector<uint8_t> &dst, size_t expectedSize) +{ + std::optional<std::vector<uint8_t>> val = level[key].getList<uint8_t>(); + if (!val || val->size() != expectedSize) + return false; + dst = *val; + return true; +} + +inline bool optList16(const YamlObject &level, const char *key, std::vector<uint16_t> &dst, size_t expectedSize) +{ + std::optional<std::vector<uint16_t>> val = level[key].getList<uint16_t>(); + if (!val || val->size() != expectedSize) + return false; + dst = *val; + return true; +} + +template<typename EnumType> +inline bool optEnum(const YamlObject &level, const char *key, EnumType &dst, EnumType defaultVal, + const std::map<std::string, EnumType> &enumMap) +{ + std::optional<std::string> val = level[key].get<std::string>(); + 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<std::vector<uint8_t>> val = level[key].getList<uint8_t>(); + 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 */
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 <rui.wang@ideasonboard.com> --- src/ipa/rkisp1/algorithms/yaml_helper.h | 123 ++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/ipa/rkisp1/algorithms/yaml_helper.h