[v2,1/3] ipa: libipa: pwl: Allow to parse a plain yaml value as single point PWL
diff mbox series

Message ID 20251106164239.460738-2-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • libipa: agc: Fix constraints yTarget handling and add PWL support
Related show

Commit Message

Stefan Klug Nov. 6, 2025, 4:42 p.m. UTC
In the tuning files, it is useful to specify some values as PWL that
produces a different output value depending on an input value. For
example it is useful to specify the relativeLuminanceTarget depending on
the lux level, so that the regulation regulates a bit darker in low
light scenes. For simple setups this is not necessary and a single value
is sufficient.

This patch extends the yaml loading code, so that either case is
supported transparently without the need for additional external code.
This way the following yaml expressions are all valid:

yTarget: [ 1000, 0.15, 2000, 0.17 ]  # Regular PWL
yTarget: [ 0, 0.17 ]                 # Single point PWL
yTarget: 0.17                        # Same as above

For cases (I'm not aware of any) where a single point Pwl is not allowed
there is no change as that must be checked externally anyways.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

---

Changes in v2:
- Added this patch
---
 src/ipa/libipa/pwl.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Kieran Bingham Nov. 6, 2025, 5:41 p.m. UTC | #1
Quoting Stefan Klug (2025-11-06 16:42:25)
> In the tuning files, it is useful to specify some values as PWL that
> produces a different output value depending on an input value. For
> example it is useful to specify the relativeLuminanceTarget depending on
> the lux level, so that the regulation regulates a bit darker in low
> light scenes. For simple setups this is not necessary and a single value
> is sufficient.
> 
> This patch extends the yaml loading code, so that either case is
> supported transparently without the need for additional external code.
> This way the following yaml expressions are all valid:
> 
> yTarget: [ 1000, 0.15, 2000, 0.17 ]  # Regular PWL
> yTarget: [ 0, 0.17 ]                 # Single point PWL
> yTarget: 0.17                        # Same as above
> 
> For cases (I'm not aware of any) where a single point Pwl is not allowed
> there is no change as that must be checked externally anyways.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> 
> ---
> 
> Changes in v2:
> - Added this patch
> ---
>  src/ipa/libipa/pwl.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp
> index 69a9334112e8..78ba43e39b77 100644
> --- a/src/ipa/libipa/pwl.cpp
> +++ b/src/ipa/libipa/pwl.cpp
> @@ -437,6 +437,15 @@ template<>
>  std::optional<ipa::Pwl>
>  YamlObject::Getter<ipa::Pwl>::get(const YamlObject &obj) const
>  {
> +       /* Treat a single value as single point PWL */
> +       if (obj.isValue()) {
> +               auto v = obj.get<double>();
> +               if (!v)
> +                       return std::nullopt;
> +
> +               return ipa::Pwl({ { { 0.0, *v } } });

Sounds reasonable to me.


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +       }
> +
>         if (!obj.size() || obj.size() % 2)
>                 return std::nullopt;
>  
> -- 
> 2.51.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp
index 69a9334112e8..78ba43e39b77 100644
--- a/src/ipa/libipa/pwl.cpp
+++ b/src/ipa/libipa/pwl.cpp
@@ -437,6 +437,15 @@  template<>
 std::optional<ipa::Pwl>
 YamlObject::Getter<ipa::Pwl>::get(const YamlObject &obj) const
 {
+	/* Treat a single value as single point PWL */
+	if (obj.isValue()) {
+		auto v = obj.get<double>();
+		if (!v)
+			return std::nullopt;
+
+		return ipa::Pwl({ { { 0.0, *v } } });
+	}
+
 	if (!obj.size() || obj.size() % 2)
 		return std::nullopt;